Skip to content

Commit

Permalink
Merge pull request #20 from MikeEdgar/19_fix_multiple_syntax_handling
Browse files Browse the repository at this point in the history
Fix handling of multiple syntax elements
  • Loading branch information
MikeEdgar committed May 11, 2020
2 parents 862d0e7 + 8752f4c commit fc99a46
Show file tree
Hide file tree
Showing 7 changed files with 2,600 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,10 @@ StructureType readComplexType(XMLStreamReader reader,

if (event == XMLStreamConstants.START_ELEMENT) {
requireElementStart(qnSyntax, reader);
readSyntax(reader, rules);
event = reader.nextTag();
do {
readSyntax(reader, rules);
event = reader.nextTag();
} while (event == XMLStreamConstants.START_ELEMENT && qnSyntax.equals(reader.getName()));
}

if (event == XMLStreamConstants.END_ELEMENT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,34 @@ public void testDiscriminatorMissingEnumeration() {
assertNotNull(cause);
assertEquals("Discriminator element does not specify value enumeration: 2.2", cause.getMessage());
}

@Test
public void testInvalidSyntaxTypeValue() {
SchemaFactory factory = SchemaFactory.newFactory();
InputStream stream = getClass().getResourceAsStream("/EDIFACT/fragment-uci-invalid-syntax-type.xml");
EDISchemaException thrown = assertThrows(EDISchemaException.class, () -> factory.createSchema(stream));
Throwable cause = thrown.getCause();
assertNotNull(cause);
assertEquals("Invalid syntax 'type': [conditional-junk]", cause.getMessage());
}

@Test
public void testInvalidMinOccursValue() {
SchemaFactory factory = SchemaFactory.newFactory();
InputStream stream = getClass().getResourceAsStream("/EDIFACT/fragment-uci-invalid-min-occurs.xml");
EDISchemaException thrown = assertThrows(EDISchemaException.class, () -> factory.createSchema(stream));
Throwable cause = thrown.getCause();
assertNotNull(cause);
assertEquals("Invalid minOccurs", cause.getMessage());
}

@Test
public void testDuplicateElementTypeNames() {
SchemaFactory factory = SchemaFactory.newFactory();
InputStream stream = getClass().getResourceAsStream("/EDIFACT/fragment-uci-duplicate-element-names.xml");
EDISchemaException thrown = assertThrows(EDISchemaException.class, () -> factory.createSchema(stream));
Throwable cause = thrown.getCause();
assertNotNull(cause);
assertEquals("duplicate name: DE0004", cause.getMessage());
}
}
16 changes: 16 additions & 0 deletions src/test/java/io/xlate/edi/internal/schema/StaEDISchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.junit.jupiter.api.Test;

import io.xlate.edi.schema.EDIComplexType;
import io.xlate.edi.schema.EDISchemaException;
import io.xlate.edi.schema.EDIType;

Expand Down Expand Up @@ -69,4 +70,19 @@ public void testRootTypeIsInterchangeV3() throws EDISchemaException, XMLStreamEx

assertEquals(EDIType.Type.INTERCHANGE, schema.getType(INTERCHANGE_V3).getType());
}

@Test
public void testLoadV3TransactionMultipleSyntaxElements_EDIFACT_CONTRL() throws EDISchemaException, XMLStreamException, FactoryConfigurationError {
StaEDISchema schema = new StaEDISchema(INTERCHANGE_V3, TRANSACTION_V3);
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).readTypes();
schema.setTypes(types);

assertEquals(EDIType.Type.TRANSACTION, schema.getType(TRANSACTION_V3).getType());
assertEquals(4, ((EDIComplexType) schema.getType("UCF")).getSyntaxRules().size());
assertEquals(4, ((EDIComplexType) schema.getType("UCI")).getSyntaxRules().size());
assertEquals(7, ((EDIComplexType) schema.getType("UCM")).getSyntaxRules().size());
}
}
Loading

0 comments on commit fc99a46

Please sign in to comment.