-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration to trim values before comparing to discriminator en…
…um (#455) Signed-off-by: Michael Edgar <[email protected]>
- Loading branch information
Showing
9 changed files
with
164 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/io/xlate/edi/internal/stream/validation/ValidatorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.xlate.edi.internal.stream.validation; | ||
|
||
public interface ValidatorConfig { | ||
|
||
boolean validateControlCodeValues(); | ||
|
||
boolean formatElements(); | ||
|
||
boolean trimDiscriminatorValues(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import io.xlate.edi.internal.schema.SchemaUtils; | ||
import io.xlate.edi.schema.EDIReference; | ||
|
@@ -822,6 +824,63 @@ void testImplementationValidSequenceWithCompositeDiscr() throws EDISchemaExcepti | |
assertEquals(expected, events); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"'41' , , '1000A'", | ||
"'41 ', true , '1000A'", | ||
"'41 ', false, 'L0001'", | ||
"'41 ', , 'L0001'", | ||
"' 41', , 'L0001'", | ||
"' 41', true , '1000A'", | ||
"' 41', false, 'L0001'", | ||
}) | ||
void testTrimDiscriminatorValue(String nm101, Boolean trimDiscriminator, String expectedLoopId) throws EDIStreamException, EDISchemaException { | ||
EDIInputFactory factory = EDIInputFactory.newFactory(); | ||
ByteArrayInputStream stream = new ByteArrayInputStream(("" | ||
+ "ISA*00* *00* *ZZ*ReceiverID *ZZ*Sender *200711*0100*^*00501*000000001*0*T*:~" | ||
+ "GS*HC*99999999999*888888888888*20111219*1340*1*X*005010X222~" | ||
+ "ST*837*0001*005010X222~" | ||
+ "BHT*0019*00*565743*20110523*154959*CH~" | ||
+ "NM1*" + nm101 + "*2*SAMPLE INC*****46*496103~" | ||
// Skip below in test | ||
+ "PER*IC*EDI DEPT*EM*[email protected]*TE*3305551212~" | ||
+ "NM1*40*2*PPO BLUE*****46*54771~" | ||
+ "HL*1**20*1~" | ||
+ "HL*2*1*22*0~" | ||
+ "SE*8*0001~" | ||
+ "GE*1*1~" | ||
+ "IEA*1*000000001~").getBytes()); | ||
|
||
factory.setProperty(EDIInputFactory.EDI_TRIM_DISCRIMINATOR_VALUES, trimDiscriminator); | ||
EDIStreamReader reader = factory.createEDIStreamReader(stream); | ||
List<EDIStreamValidationError> errors = new ArrayList<>(); | ||
String loopId = null; | ||
|
||
while (loopId == null && reader.hasNext()) { | ||
switch (reader.next()) { | ||
case START_TRANSACTION: | ||
reader.setTransactionSchema(SchemaFactory.newFactory() | ||
.createSchema(getClass().getResource("/x12/005010X222/837_loop1000_only.xml"))); | ||
break; | ||
case START_LOOP: | ||
loopId = reader.getReferenceCode(); | ||
break; | ||
case SEGMENT_ERROR: | ||
case ELEMENT_OCCURRENCE_ERROR: | ||
case ELEMENT_DATA_ERROR: | ||
errors.add(reader.getErrorType()); | ||
System.out.println("Unexpected error: " + reader.getErrorType() + "; " + reader.getText() + "; " + reader.getLocation()); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
assertEquals(0, errors.size(), () -> errors.toString()); | ||
|
||
assertEquals(expectedLoopId, loopId); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
@Test | ||
void testImplementation_Only_BHT_HL_Valid() throws EDISchemaException, EDIStreamException { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters