Search in sources :

Example 6 with XmlDocument

use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.

the class XmlInstanceInspectionTest method testInspectXmlStringAsSourceMultipleChildren.

@Test
public void testInspectXmlStringAsSourceMultipleChildren() throws Exception {
    final String source = "<data>\n" + "     <intFields><int>3200</int><int>2500</int><int>15</int></intFields>\n" + "     <longFields><long>12421</long></longFields>\n" + "     <stringFields><string>abc</string></stringFields>\n" + "     <booleanFields><boolean>true</boolean></booleanFields>\n" + "     <doubleFields><double>12.0</double></doubleFields>\n" + "     <shortFields><short>1000</short></shortFields>\n" + "     <floatFields><float>234.5f</float></floatFields>\n" + "     <charFields><char>A</char></charFields>\n" + "</data>";
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument xmlDocument = service.inspectXmlDocument(source);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(8));
    // children
    XmlComplexType childZero = (XmlComplexType) root.getXmlFields().getXmlField().get(0);
    Assert.assertNotNull(childZero);
    Assert.assertThat(childZero.getXmlFields().getXmlField().size(), Is.is(3));
    XmlField childZeroZero = childZero.getXmlFields().getXmlField().get(0);
    Assert.assertNotNull(childZeroZero);
    Assert.assertThat(childZeroZero.getName(), Is.is("int"));
    Assert.assertThat(childZeroZero.getValue(), Is.is("3200"));
    Assert.assertThat(childZeroZero.getPath(), Is.is("/data/intFields/int"));
    XmlField childZeroOne = childZero.getXmlFields().getXmlField().get(1);
    Assert.assertNotNull(childZeroOne);
    Assert.assertThat(childZeroOne.getName(), Is.is("int"));
    Assert.assertThat(childZeroOne.getValue(), Is.is("2500"));
    Assert.assertThat(childZeroOne.getPath(), Is.is("/data/intFields/int[1]"));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 7 with XmlDocument

use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.

the class XmlInstanceInspectionTest method testInspectXmlStringAsSourceAT370A.

@Test
public void testInspectXmlStringAsSourceAT370A() throws Exception {
    final String source = "<order>\n" + "   <orders>\n" + "      <order>\n" + "\t      <items>\n" + "\t\t     <item sku=\"4\"/>\n" + "\t\t     <item sku=\"5\"/>\n" + "\t      </items>\n" + "      </order>\n" + "   </orders>\n" + "</order>";
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument xmlDocument = service.inspectXmlDocument(source);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(1));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 8 with XmlDocument

use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.

the class XmlInstanceInspectionTest method testInspectXmlStringWithNamespaces.

@Test
public void testInspectXmlStringWithNamespaces() throws Exception {
    final String source = "<x:data xmlns:x=\"http://x.namespace.com/\">\n" + "     <x:intField>32000</x:intField>\n" + "     <x:longField>12421</x:longField>\n" + "     <x:stringField>abc</x:stringField>\n" + "     <x:booleanField>true</x:booleanField>\n" + "     <x:doubleField>12.0</x:doubleField>\n" + "     <x:shortField>1000</x:shortField>\n" + "     <x:floatField>234.5f</x:floatField>\n" + "     <x:charField>A</x:charField>\n" + "</x:data>";
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument xmlDocument = service.inspectXmlDocument(source);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    // check for namespace
    Assert.assertNotNull(xmlDocument.getXmlNamespaces());
    XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
    Assert.assertThat(xmlDocument.getXmlNamespaces().getXmlNamespace().size(), Is.is(1));
    Assert.assertNotNull(namespace);
    Assert.assertEquals("x", namespace.getAlias());
    Assert.assertEquals("http://x.namespace.com/", namespace.getUri());
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(8));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 9 with XmlDocument

use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.

the class XmlInstanceInspectionTest method testInspectInstanceFileWithXSIType.

@Test
public void testInspectInstanceFileWithXSIType() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/xsi-type-instance.xml")));
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument xmlDocument = service.inspectXmlDocument(instance);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(8));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 10 with XmlDocument

use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.

the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNoNamespaceSchemas.

@Test
public void testMultipleNoNamespaceSchemas() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-no-namespace-schemas.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
    XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
    Assert.assertEquals("tns", namespace.getAlias());
    Assert.assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
    Assert.assertEquals(null, namespace.isTargetNamespace());
    Assert.assertEquals(1, answer.getFields().getField().size());
    XmlComplexType complex = XmlComplexType.class.cast(answer.getFields().getField().get(0));
    Assert.assertEquals("tns:RootDocument", complex.getName());
    Assert.assertEquals(2, complex.getXmlFields().getXmlField().size());
    for (XmlField field : complex.getXmlFields().getXmlField()) {
        switch(field.getName()) {
            case "FirstElement":
                Assert.assertEquals(FieldType.COMPLEX, field.getFieldType());
                Assert.assertEquals("/tns:RootDocument/FirstElement", field.getPath());
                List<XmlField> firstFields = XmlComplexType.class.cast(field).getXmlFields().getXmlField();
                Assert.assertEquals(1, firstFields.size());
                XmlField firstField = firstFields.get(0);
                Assert.assertEquals("FirstValue", firstField.getName());
                Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/FirstElement/FirstValue", firstField.getPath());
                break;
            case "SecondElement":
                Assert.assertEquals(FieldType.COMPLEX, field.getFieldType());
                Assert.assertEquals("/tns:RootDocument/SecondElement", field.getPath());
                List<XmlField> secondFields = XmlComplexType.class.cast(field).getXmlFields().getXmlField();
                Assert.assertEquals(1, secondFields.size());
                XmlField secondField = secondFields.get(0);
                Assert.assertEquals("SecondValue", secondField.getName());
                Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/SecondElement/SecondValue", secondField.getPath());
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", field.getPath()));
        }
    }
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Aggregations

XmlDocument (io.atlasmap.xml.v2.XmlDocument)25 Test (org.junit.Test)22 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)20 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)10 File (java.io.File)10 XmlField (io.atlasmap.xml.v2.XmlField)8 Document (org.w3c.dom.Document)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Field (io.atlasmap.v2.Field)2 XmlInspectionService (io.atlasmap.xml.inspect.XmlInspectionService)2 XmlInspectionResponse (io.atlasmap.xml.v2.XmlInspectionResponse)2 IOException (java.io.IOException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 XSSchemaSet (com.sun.xml.xsom.XSSchemaSet)1 XSOMParser (com.sun.xml.xsom.parser.XSOMParser)1 DomAnnotationParserFactory (com.sun.xml.xsom.util.DomAnnotationParserFactory)1 Fields (io.atlasmap.v2.Fields)1 InspectionType (io.atlasmap.xml.v2.InspectionType)1 Restriction (io.atlasmap.xml.v2.Restriction)1 XmlFields (io.atlasmap.xml.v2.XmlFields)1