use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNamespaces.
@Test
public void testMultipleNamespaces() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-schemaset.xml").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument answer = service.inspectSchema(schemaFile);
assertEquals(3, answer.getXmlNamespaces().getXmlNamespace().size());
for (XmlNamespace namespace : answer.getXmlNamespaces().getXmlNamespace()) {
switch(namespace.getAlias()) {
case "tns":
assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
break;
case "first":
assertEquals("io.atlasmap.xml.test:First", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
break;
case "second":
assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
break;
default:
fail(String.format("Unknown alias '%s'", namespace.getAlias()));
}
}
List<Field> fields = answer.getFields().getField();
assertEquals(1, fields.size());
XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
assertEquals("tns:RootDocument", complex.getName());
List<XmlField> rootFields = complex.getXmlFields().getXmlField();
assertEquals(4, rootFields.size());
for (XmlField xmlField : rootFields) {
switch(xmlField.getName()) {
case "Name":
assertEquals(FieldType.STRING, xmlField.getFieldType());
assertEquals("/tns:RootDocument/Name", xmlField.getPath());
break;
case "Value":
assertEquals(FieldType.STRING, xmlField.getFieldType());
assertEquals("/tns:RootDocument/Value", xmlField.getPath());
break;
case "first:FirstElement":
assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
assertEquals("/tns:RootDocument/first:FirstElement", xmlField.getPath());
List<XmlField> firstFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
assertEquals(2, firstFields.size());
for (XmlField firstField : firstFields) {
switch(firstField.getName()) {
case "Name":
assertEquals(FieldType.STRING, firstField.getFieldType());
assertEquals("/tns:RootDocument/first:FirstElement/Name", firstField.getPath());
break;
case "Value":
assertEquals(FieldType.STRING, firstField.getFieldType());
assertEquals("/tns:RootDocument/first:FirstElement/Value", firstField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", firstField.getPath()));
}
}
break;
case "second:SecondElement":
assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
assertEquals("/tns:RootDocument/second:SecondElement", xmlField.getPath());
List<XmlField> secondFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
assertEquals(2, secondFields.size());
for (XmlField secondField : secondFields) {
switch(secondField.getName()) {
case "Name":
assertEquals(FieldType.STRING, secondField.getFieldType());
assertEquals("/tns:RootDocument/second:SecondElement/Name", secondField.getPath());
break;
case "Value":
assertEquals(FieldType.STRING, secondField.getFieldType());
assertEquals("/tns:RootDocument/second:SecondElement/Value", secondField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", secondField.getPath()));
}
}
break;
default:
fail(String.format("Unknown field '%s'", xmlField.getPath()));
}
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNoNamespaceRootSchema.
@Test
public void testMultipleNoNamespaceRootSchema() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/multiple-no-namespace-root-schema.xml").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument answer = service.inspectSchema(schemaFile);
assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals("second", namespace.getAlias());
assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
// Note that the FirstElement also appears here as it's a top level element of namespace ""
assertEquals(2, answer.getFields().getField().size());
XmlComplexType complex = XmlComplexType.class.cast(answer.getFields().getField().get(1));
assertEquals("RootDocument", complex.getName());
assertEquals(2, complex.getXmlFields().getXmlField().size());
for (XmlField field : complex.getXmlFields().getXmlField()) {
switch(field.getName()) {
case "FirstElement":
assertEquals(FieldType.COMPLEX, field.getFieldType());
assertEquals("/RootDocument/FirstElement", field.getPath());
List<XmlField> firstFields = XmlComplexType.class.cast(field).getXmlFields().getXmlField();
assertEquals(1, firstFields.size());
XmlField firstField = firstFields.get(0);
assertEquals("FirstValue", firstField.getName());
assertEquals(FieldType.STRING, firstField.getFieldType());
assertEquals("/RootDocument/FirstElement/FirstValue", firstField.getPath());
break;
case "second:SecondElement":
assertEquals(FieldType.COMPLEX, field.getFieldType());
assertEquals("/RootDocument/second:SecondElement", field.getPath());
List<XmlField> secondFields = XmlComplexType.class.cast(field).getXmlFields().getXmlField();
assertEquals(1, secondFields.size());
XmlField secondField = secondFields.get(0);
assertEquals("SecondValue", secondField.getName());
assertEquals(FieldType.STRING, secondField.getFieldType());
assertEquals("/RootDocument/second:SecondElement/SecondValue", secondField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", field.getPath()));
}
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectPOExampleSchemaFile.
@Test
public void testInspectPOExampleSchemaFile() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/po-example-schema.xsd").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectSchema(schemaFile);
assertNotNull(xmlDocument);
assertNotNull(xmlDocument.getFields());
assertEquals(2, xmlDocument.getFields().getField().size());
// PurchaseOrderType
XmlComplexType purchaseOrder = (XmlComplexType) xmlDocument.getFields().getField().get(0);
assertNotNull(purchaseOrder);
assertEquals(5, purchaseOrder.getXmlFields().getXmlField().size());
// orderDate
XmlField orderDateAttr = purchaseOrder.getXmlFields().getXmlField().get(0);
assertNotNull(orderDateAttr);
assertEquals("orderDate", orderDateAttr.getName());
assertNull(orderDateAttr.getValue());
assertEquals("/tns:purchaseOrder/@orderDate", orderDateAttr.getPath());
assertEquals(FieldType.DATE, orderDateAttr.getFieldType());
assertEquals(true, orderDateAttr.isAttribute());
// shipTo
XmlField shipTo = purchaseOrder.getXmlFields().getXmlField().get(1);
assertNotNull(shipTo);
assertEquals("shipTo", shipTo.getName());
assertNull(shipTo.getValue());
assertEquals("/tns:purchaseOrder/shipTo", shipTo.getPath());
assertEquals(FieldType.COMPLEX, shipTo.getFieldType());
assertEquals(6, ((XmlComplexType) shipTo).getXmlFields().getXmlField().size());
// shipTo/@country
XmlField shipToCountry = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(0);
assertNotNull(shipTo);
assertEquals("country", shipToCountry.getName());
assertEquals("US", shipToCountry.getValue());
assertEquals("/tns:purchaseOrder/shipTo/@country", shipToCountry.getPath());
assertEquals(FieldType.STRING, shipToCountry.getFieldType());
assertEquals(true, shipToCountry.isAttribute());
XmlField shipToName = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(1);
assertNotNull(shipToName);
assertEquals("name", shipToName.getName());
assertNull(shipToName.getValue());
assertEquals("/tns:purchaseOrder/shipTo/name", shipToName.getPath());
assertEquals(FieldType.STRING, shipToName.getFieldType());
assertEquals(false, shipToName.isAttribute());
XmlField shipToStreet = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(2);
assertNotNull(shipToStreet);
assertEquals("street", shipToStreet.getName());
assertNull(shipToStreet.getValue());
assertEquals("/tns:purchaseOrder/shipTo/street", shipToStreet.getPath());
assertEquals(FieldType.STRING, shipToStreet.getFieldType());
assertEquals(false, shipToStreet.isAttribute());
XmlField shipToCity = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(3);
assertNotNull(shipToCity);
assertEquals("city", shipToCity.getName());
assertNull(shipToCity.getValue());
assertEquals("/tns:purchaseOrder/shipTo/city", shipToCity.getPath());
assertEquals(FieldType.STRING, shipToCity.getFieldType());
assertEquals(false, shipToCity.isAttribute());
XmlField shipToState = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(4);
assertNotNull(shipToState);
assertEquals("state", shipToState.getName());
assertNull(shipToState.getValue());
assertEquals("/tns:purchaseOrder/shipTo/state", shipToState.getPath());
assertEquals(FieldType.STRING, shipToState.getFieldType());
assertEquals(false, shipToState.isAttribute());
XmlField shipToZip = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(5);
assertNotNull(shipToZip);
assertEquals("zip", shipToZip.getName());
assertNull(shipToZip.getValue());
assertEquals("/tns:purchaseOrder/shipTo/zip", shipToZip.getPath());
assertEquals(FieldType.DECIMAL, shipToZip.getFieldType());
assertEquals(false, shipToZip.isAttribute());
// comment
XmlField comment = purchaseOrder.getXmlFields().getXmlField().get(3);
assertNotNull(comment);
assertEquals("tns:comment", comment.getName());
assertNull(comment.getValue());
assertEquals("/tns:purchaseOrder/tns:comment", comment.getPath());
assertEquals(FieldType.STRING, comment.getFieldType());
assertEquals(false, comment.isAttribute());
// items
XmlField items = purchaseOrder.getXmlFields().getXmlField().get(4);
assertNotNull(items);
assertEquals("items", items.getName());
assertNull(items.getValue());
assertEquals("/tns:purchaseOrder/items", items.getPath());
assertEquals(FieldType.COMPLEX, items.getFieldType());
assertEquals(false, items.isAttribute());
assertEquals(1, ((XmlComplexType) items).getXmlFields().getXmlField().size());
// items/item
XmlComplexType item = (XmlComplexType) ((XmlComplexType) items).getXmlFields().getXmlField().get(0);
assertNotNull(item);
assertEquals("item", item.getName());
assertNull(item.getValue());
assertEquals("/tns:purchaseOrder/items/item<>", item.getPath());
assertEquals(FieldType.COMPLEX, item.getFieldType());
assertEquals(false, item.isAttribute());
assertEquals(CollectionType.LIST, item.getCollectionType());
assertEquals(6, item.getXmlFields().getXmlField().size());
// partNum
XmlField partNum = item.getXmlFields().getXmlField().get(0);
assertNotNull(partNum);
assertEquals("partNum", partNum.getName());
assertNull(partNum.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/@partNum", partNum.getPath());
assertEquals(FieldType.STRING, partNum.getFieldType());
assertEquals("SKU", partNum.getTypeName());
assertEquals(true, partNum.isAttribute());
// productName
XmlField productName = item.getXmlFields().getXmlField().get(1);
assertNotNull(productName);
assertEquals("productName", productName.getName());
assertNull(productName.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/productName", productName.getPath());
assertEquals(FieldType.STRING, productName.getFieldType());
assertEquals(false, productName.isAttribute());
// quantity
XmlField quantity = item.getXmlFields().getXmlField().get(2);
assertNotNull(quantity);
assertEquals("quantity", quantity.getName());
assertNull(quantity.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/quantity", quantity.getPath());
assertEquals(FieldType.BIG_INTEGER, quantity.getFieldType());
assertEquals(false, quantity.isAttribute());
assertNotNull(quantity.getRestrictions().getRestriction());
assertEquals(1, quantity.getRestrictions().getRestriction().size());
Restriction qRestriction = quantity.getRestrictions().getRestriction().get(0);
assertNotNull(qRestriction);
assertNotNull(qRestriction.getType());
assertEquals(RestrictionType.MAX_EXCLUSIVE, qRestriction.getType());
assertNotNull(qRestriction.getValue());
assertEquals("99", qRestriction.getValue());
// USPrice
XmlField usPrice = item.getXmlFields().getXmlField().get(3);
assertNotNull(usPrice);
assertEquals("USPrice", usPrice.getName());
assertNull(usPrice.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/USPrice", usPrice.getPath());
assertEquals(FieldType.DECIMAL, usPrice.getFieldType());
assertEquals(false, usPrice.isAttribute());
// comment
XmlField itemComment = item.getXmlFields().getXmlField().get(4);
assertNotNull(itemComment);
assertEquals("tns:comment", itemComment.getName());
assertNull(itemComment.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/tns:comment", itemComment.getPath());
assertEquals(FieldType.STRING, itemComment.getFieldType());
assertEquals(false, itemComment.isAttribute());
// shipDate
XmlField shipDate = item.getXmlFields().getXmlField().get(5);
assertNotNull(shipDate);
assertEquals("shipDate", shipDate.getName());
assertNull(shipDate.getValue());
assertEquals("/tns:purchaseOrder/items/item<>/shipDate", shipDate.getPath());
assertEquals(FieldType.DATE, shipDate.getFieldType());
assertEquals(false, shipDate.isAttribute());
// namespaces
assertNotNull(xmlDocument.getXmlNamespaces());
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals("tns", namespace.getAlias());
assertEquals("http://tempuri.org/po.xsd", namespace.getUri());
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlInstanceInspectionTest method testInspectXmlStringWithDefaultNamespace.
@Test
public void testInspectXmlStringWithDefaultNamespace() throws Exception {
final String source = "<data xmlns=\"http://x.namespace.com/\">\n" + " <intField>32000</intField>\n" + " <longField>12421</longField>\n" + " <stringField>abc</stringField>\n" + " <booleanField>true</booleanField>\n" + " <doubleField>12.0</doubleField>\n" + " <shortField>1000</shortField>\n" + " <floatField>234.5f</floatField>\n" + " <charField>A</charField>\n" + "</data>";
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectXmlDocument(source);
assertNotNull(xmlDocument);
// check for namespace
assertNotNull(xmlDocument.getXmlNamespaces());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
assertNotNull(namespace);
assertNull(namespace.getAlias());
assertEquals("http://x.namespace.com/", namespace.getUri());
assertNotNull(xmlDocument.getFields());
assertEquals(1, xmlDocument.getFields().getField().size());
XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
assertNotNull(root);
assertEquals(8, root.getXmlFields().getXmlField().size());
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlInstanceInspectionTest method testInspectXmlStringAsSourceAttrsWithNamespace.
@Test
public void testInspectXmlStringAsSourceAttrsWithNamespace() throws Exception {
final String source = "<data xmlns:y=\"http://y.namespace.com/\" y:intField='32000' longField='12421' stringField='abc' " + "booleanField='true' doubleField='12.0' shortField='1000' floatField='234.5f' y:charField='A' />";
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectXmlDocument(source);
assertNotNull(xmlDocument);
assertNotNull(xmlDocument.getFields());
// check for namespace
assertNotNull(xmlDocument.getXmlNamespaces());
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertNotNull(namespace);
assertEquals("y", namespace.getAlias());
assertEquals("http://y.namespace.com/", namespace.getUri());
assertNotNull(xmlDocument.getFields());
assertEquals(1, xmlDocument.getFields().getField().size());
XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
assertNotNull(root);
assertEquals(8, root.getXmlFields().getXmlField().size());
// debugFields(xmlDocument.getFields());
}
Aggregations