Search in sources :

Example 1 with XmlComplexType

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

the class XmlServiceTest method testValidJsonData.

@Test
public void testValidJsonData() throws Exception {
    final String source = "<xs:schema attributeFormDefault=\"unqualified\" elementFormDefault=\"qualified\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + "  <xs:element name=\"data\">\n" + "    <xs:complexType>\n" + "      <xs:sequence>\n" + "        <xs:element type=\"xs:int\" name=\"intField\"/>\n" + "        <xs:element type=\"xs:long\" name=\"longField\"/>\n" + "        <xs:element type=\"xs:string\" name=\"stringField\"/>\n" + "        <xs:element type=\"xs:boolean\" name=\"booleanField\"/>\n" + "        <xs:element type=\"xs:double\" name=\"doubleField\"/>\n" + "        <xs:element type=\"xs:short\" name=\"shortField\"/>\n" + "        <xs:element type=\"xs:float\" name=\"floatField\"/>\n" + "        <xs:element type=\"xs:string\" name=\"charField\"/>\n" + "      </xs:sequence>\n" + "    </xs:complexType>\n" + "  </xs:element>\n" + "</xs:schema>";
    XmlInspectionRequest request = new XmlInspectionRequest();
    request.setType(InspectionType.SCHEMA);
    request.setXmlData(source);
    Response res = xmlService.inspectClass(request);
    Object entity = res.getEntity();
    assertEquals(byte[].class, entity.getClass());
    XmlInspectionResponse inspectionResponse = Json.mapper().readValue((byte[]) entity, XmlInspectionResponse.class);
    XmlDocument xmlDoc = inspectionResponse.getXmlDocument();
    assertEquals(1, xmlDoc.getFields().getField().size());
    XmlComplexType root = (XmlComplexType) xmlDoc.getFields().getField().get(0);
    assertNotNull(root);
    assertEquals(8, root.getXmlFields().getXmlField().size());
}
Also used : Response(javax.ws.rs.core.Response) XmlInspectionResponse(io.atlasmap.xml.v2.XmlInspectionResponse) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) XmlInspectionRequest(io.atlasmap.xml.v2.XmlInspectionRequest) XmlInspectionResponse(io.atlasmap.xml.v2.XmlInspectionResponse) Test(org.junit.Test)

Example 2 with XmlComplexType

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

the class XmlInstanceInspectionTest method testInspectXmlStringAsSourceAT370B.

@Test
public void testInspectXmlStringAsSourceAT370B() throws Exception {
    final String source = "<order>\n" + "   <orders>\n" + "      <order>\n" + "\t      <items>\n" + "\t\t     <item sku=\"4\"/>\n" + "\t\t     <item sku=\"7\"/>\n" + "\t      </items>\n" + "      </order>\n" + "      <order>\n" + "\t      <items>\n" + "\t\t     <item sku=\"5\"/>\n" + "\t\t     <item sku=\"8\"/>\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 3 with XmlComplexType

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

the class XmlInstanceInspectionTest method testInspectXmlStringAsSource.

@Test
public void testInspectXmlStringAsSource() throws Exception {
    final String source = "<data>\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);
    Assert.assertNotNull(xmlDocument);
    Assert.assertNotNull(xmlDocument.getFields());
    Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
    List<XmlComplexType> complexTypeList = xmlDocument.getFields().getField().stream().filter(xmlField -> xmlField instanceof XmlComplexType).map(xmlField -> (XmlComplexType) xmlField).collect(Collectors.toList());
    Assert.assertThat(complexTypeList.size(), Is.is(1));
    XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(8));
    complexTypeList = root.getXmlFields().getXmlField().stream().filter(xmlField -> xmlField instanceof XmlComplexType).map(xmlField -> (XmlComplexType) xmlField).collect(Collectors.toList());
    Assert.assertThat(complexTypeList.size(), Is.is(0));
// debugFields(xmlDocument.getFields());
}
Also used : List(java.util.List) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) Files(java.nio.file.Files) Paths(java.nio.file.Paths) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Document(org.w3c.dom.Document) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) XmlField(io.atlasmap.xml.v2.XmlField) Is(org.hamcrest.core.Is) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 4 with XmlComplexType

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

the class XmlInstanceInspectionTest method testInspectXmlStringAsSourceElementsWithAttrs.

@Test
public void testInspectXmlStringAsSourceElementsWithAttrs() throws Exception {
    final String source = "<data>\n" + "     <intField a='1'>32000</intField>\n" + "     <longField>12421</longField>\n" + "     <stringField>abc</stringField>\n" + "     <booleanField>true</booleanField>\n" + "     <doubleField b='2'>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);
    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(10));
// debugFields(xmlDocument.getFields());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Example 5 with XmlComplexType

use of io.atlasmap.xml.v2.XmlComplexType 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)

Aggregations

XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)28 XmlDocument (io.atlasmap.xml.v2.XmlDocument)20 Test (org.junit.Test)20 XmlField (io.atlasmap.xml.v2.XmlField)13 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)9 File (java.io.File)8 Field (io.atlasmap.v2.Field)3 XmlFields (io.atlasmap.xml.v2.XmlFields)2 XSAttributeDecl (com.sun.xml.xsom.XSAttributeDecl)1 XSAttributeUse (com.sun.xml.xsom.XSAttributeUse)1 XSElementDecl (com.sun.xml.xsom.XSElementDecl)1 XSRestrictionSimpleType (com.sun.xml.xsom.XSRestrictionSimpleType)1 XSSchema (com.sun.xml.xsom.XSSchema)1 XSSimpleType (com.sun.xml.xsom.XSSimpleType)1 FieldType (io.atlasmap.v2.FieldType)1 Restriction (io.atlasmap.xml.v2.Restriction)1 XmlInspectionRequest (io.atlasmap.xml.v2.XmlInspectionRequest)1 XmlInspectionResponse (io.atlasmap.xml.v2.XmlInspectionResponse)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1