Skip to content

Commit

Permalink
Add syntax rule to CONTRL schema, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeEdgar committed Jul 12, 2020
1 parent 8aa7b3f commit f77f27a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testLoadV3TransactionMultipleSyntaxElements_EDIFACT_CONTRL()
InputStream schemaStream = getClass().getResourceAsStream("/EDIFACT/CONTRL-v4r02.xml");
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream);
reader.nextTag(); // Pass by <schema> element
Map<String, EDIType> types = new SchemaReaderV3(reader, Collections.emptyMap()).readTypes();
Map<String, EDIType> types = new SchemaReaderV4(reader, Collections.emptyMap()).readTypes();
schema.setTypes(types);

assertEquals(EDIType.Type.TRANSACTION, schema.getType(StaEDISchema.TRANSACTION_ID).getType());
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/xlate/edi/internal/stream/ErrorEventsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ void testEDIFACT_BothGroupAndTransactionUsed() throws EDIStreamException {
assertTrue(!reader.hasNext(), "Unexpected errors exist");
}

@Test
void testEDIFACT_NeitherGroupNorTransactionUsed() throws EDIStreamException {
EDIInputFactory factory = EDIInputFactory.newFactory();
InputStream stream = new ByteArrayInputStream((""
+ "UNB+UNOA:4:::02+005435656:1+006415160:1+20060515:1434+00000000000001'"
+ "UNZ+0+00000000000001'").getBytes());

EDIStreamReader reader = factory.createEDIStreamReader(stream);
reader = factory.createFilteredReader(reader, errorFilter);

assertTrue(reader.hasNext(), "Expected errors not found");
reader.next();
assertEquals(EDIStreamValidationError.CONDITIONAL_REQUIRED_SEGMENT_MISSING, reader.getErrorType());
assertEquals("UNG", reader.getReferenceCode());

reader.next();
assertEquals(EDIStreamValidationError.CONDITIONAL_REQUIRED_SEGMENT_MISSING, reader.getErrorType());
assertEquals("UNH", reader.getReferenceCode());

assertTrue(!reader.hasNext(), "Unexpected errors exist");
}

@Test
void testValidEmptySegment() throws EDISchemaException, EDIStreamException {
EDIInputFactory factory = EDIInputFactory.newFactory();
Expand Down
16 changes: 10 additions & 6 deletions src/test/resources/EDIFACT/CONTRL-v4r02.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schema xmlns="http://xlate.io/EDISchema/v3">
<schema xmlns="http://xlate.io/EDISchema/v4">
<transaction>
<sequence>
<segment type="UCI" minOccurs="1" maxOccurs="1" />
<loop code="L0001" minOccurs="0" maxOccurs="999">
<loop code="SG1" minOccurs="0" maxOccurs="999">
<sequence>
<segment type="UCM" minOccurs="1" maxOccurs="1" />
<loop code="L0002" minOccurs="0" maxOccurs="999">
<loop code="SG2" minOccurs="0" maxOccurs="999">
<sequence>
<segment type="UCS" minOccurs="1" maxOccurs="1" />
<segment type="UCD" minOccurs="0" maxOccurs="99" />
</sequence>
</loop>
</sequence>
</loop>
<loop code="L0003" minOccurs="0" maxOccurs="999">
<loop code="SG3" minOccurs="0" maxOccurs="999">
<sequence>
<segment type="UCF" minOccurs="1" maxOccurs="1" />
<loop code="L0004" minOccurs="0" maxOccurs="999">
<loop code="SG4" minOccurs="0" maxOccurs="999">
<sequence>
<segment type="UCM" minOccurs="1" maxOccurs="1" />
<loop code="L0005" minOccurs="0" maxOccurs="999">
<loop code="SG5" minOccurs="0" maxOccurs="999">
<sequence>
<segment type="UCS" minOccurs="1" maxOccurs="1" />
<segment type="UCD" minOccurs="0" maxOccurs="99" />
Expand All @@ -31,6 +31,10 @@
</sequence>
</loop>
</sequence>
<syntax type="exclusion">
<position>2</position><!-- Loop L0001 -->
<position>3</position>
</syntax>
</transaction>
<elementType name="DE0004" number="4" base="string" maxLength="35" />
<elementType name="DE0007" number="7" base="identifier" maxLength="4">
Expand Down

0 comments on commit f77f27a

Please sign in to comment.