use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectSchemaString.
@Test
public void testInspectSchemaString() 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>";
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectSchema(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));
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectShipOrderSchemaFile.
@Test
public void testInspectShipOrderSchemaFile() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/ship-order-schema.xsd").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectSchema(schemaFile);
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(4));
// @orderId
XmlField orderIdAttr = root.getXmlFields().getXmlField().get(0);
Assert.assertNotNull(orderIdAttr);
Assert.assertThat(orderIdAttr.getName(), Is.is("orderid"));
Assert.assertThat(orderIdAttr.getValue(), Is.is("2"));
Assert.assertThat(orderIdAttr.getPath(), Is.is("/shiporder/@orderid"));
Assert.assertThat(orderIdAttr.getFieldType(), Is.is(FieldType.STRING));
// orderperson
XmlField orderPerson = root.getXmlFields().getXmlField().get(1);
Assert.assertNotNull(orderPerson);
Assert.assertThat(orderPerson.getName(), Is.is("orderperson"));
Assert.assertNull(orderPerson.getValue());
Assert.assertThat(orderPerson.getPath(), Is.is("/shiporder/orderperson"));
Assert.assertThat(orderPerson.getFieldType(), Is.is(FieldType.STRING));
// shipTo
XmlField shipTo = root.getXmlFields().getXmlField().get(2);
Assert.assertNotNull(shipTo);
Assert.assertTrue(shipTo instanceof XmlComplexType);
Assert.assertThat(((XmlComplexType) shipTo).getXmlFields().getXmlField().size(), Is.is(4));
// item
XmlField item = root.getXmlFields().getXmlField().get(3);
Assert.assertNotNull(item);
Assert.assertTrue(item instanceof XmlComplexType);
Assert.assertThat(((XmlComplexType) item).getXmlFields().getXmlField().size(), Is.is(4));
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectSchemaFileWithNamespace.
@Test
public void testInspectSchemaFileWithNamespace() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/simple-namespace-schema.xsd").toFile();
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectSchema(schemaFile);
Assert.assertNotNull(xmlDocument);
Assert.assertNotNull(xmlDocument.getFields());
Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
Assert.assertNotNull(xmlDocument.getXmlNamespaces());
Assert.assertThat(xmlDocument.getXmlNamespaces().getXmlNamespace().size(), Is.is(1));
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
Assert.assertThat(namespace.getAlias(), Is.is("tns"));
Assert.assertThat(namespace.getUri(), Is.is("http://example.com/"));
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlDocument in project atlasmap by atlasmap.
the class XmlService method getClass.
@GET
@Path("/inspect")
@Produces(MediaType.APPLICATION_JSON)
public Response getClass(@QueryParam("uri") String uri, @QueryParam("type") String type) {
XmlDocument d = null;
try {
if (type == null) {
throw new Exception("uri and type parameters must be specified");
}
InspectionType inspectType = InspectionType.valueOf(type);
XmlInspectionService s = new XmlInspectionService();
switch(inspectType) {
case INSTANCE:
d = s.inspectXmlDocument(new File(uri));
break;
case SCHEMA:
d = s.inspectSchema(new File(uri));
break;
default:
throw new Exception("Unknown type specified: " + type);
}
} catch (Exception e) {
LOG.error("Error inspecting xml: " + e.getMessage(), e);
}
return Response.ok().entity(toJson(d)).build();
}
use of io.atlasmap.xml.v2.XmlDocument 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);
Assert.assertEquals(3, answer.getXmlNamespaces().getXmlNamespace().size());
for (XmlNamespace namespace : answer.getXmlNamespaces().getXmlNamespace()) {
switch(namespace.getAlias()) {
case "tns":
Assert.assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
Assert.assertEquals(null, namespace.isTargetNamespace());
break;
case "first":
Assert.assertEquals("io.atlasmap.xml.test:First", namespace.getUri());
Assert.assertEquals(null, namespace.isTargetNamespace());
break;
case "second":
Assert.assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
Assert.assertEquals(null, namespace.isTargetNamespace());
break;
default:
Assert.fail(String.format("Unknown alias '%s'", namespace.getAlias()));
}
}
List<Field> fields = answer.getFields().getField();
Assert.assertEquals(1, fields.size());
XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
Assert.assertEquals("tns:RootDocument", complex.getName());
List<XmlField> rootFields = complex.getXmlFields().getXmlField();
Assert.assertEquals(4, rootFields.size());
for (XmlField xmlField : rootFields) {
switch(xmlField.getName()) {
case "tns:Name":
Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
Assert.assertEquals("/tns:RootDocument/tns:Name", xmlField.getPath());
break;
case "tns:Value":
Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
Assert.assertEquals("/tns:RootDocument/tns:Value", xmlField.getPath());
break;
case "first:FirstElement":
Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
Assert.assertEquals("/tns:RootDocument/first:FirstElement", xmlField.getPath());
List<XmlField> firstFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
Assert.assertEquals(2, firstFields.size());
for (XmlField firstField : firstFields) {
switch(firstField.getName()) {
case "first:Name":
Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Name", firstField.getPath());
break;
case "first:Value":
Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Value", firstField.getPath());
break;
default:
Assert.fail(String.format("Unknown field '%s'", firstField.getPath()));
}
}
break;
case "second:SecondElement":
Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
Assert.assertEquals("/tns:RootDocument/second:SecondElement", xmlField.getPath());
List<XmlField> secondFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
Assert.assertEquals(2, secondFields.size());
for (XmlField secondField : secondFields) {
switch(secondField.getName()) {
case "second:Name":
Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Name", secondField.getPath());
break;
case "second:Value":
Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Value", secondField.getPath());
break;
default:
Assert.fail(String.format("Unknown field '%s'", secondField.getPath()));
}
}
break;
default:
Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
}
}
}
Aggregations