use of io.atlasmap.xml.v2.XmlNamespace 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);
assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals("tns", namespace.getAlias());
assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
assertEquals(1, answer.getFields().getField().size());
XmlComplexType complex = XmlComplexType.class.cast(answer.getFields().getField().get(0));
assertEquals("tns: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("/tns: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("/tns:RootDocument/FirstElement/FirstValue", firstField.getPath());
break;
case "SecondElement":
assertEquals(FieldType.COMPLEX, field.getFieldType());
assertEquals("/tns:RootDocument/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("/tns:RootDocument/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 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);
assertNotNull(xmlDocument);
assertNotNull(xmlDocument.getFields());
assertEquals(1, xmlDocument.getFields().getField().size());
assertNotNull(xmlDocument.getXmlNamespaces());
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals("tns", namespace.getAlias());
assertEquals("http://example.com/", namespace.getUri());
// debugFields(xmlDocument.getFields());
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlSchemaInspector method populateNamespaces.
private void populateNamespaces() {
for (Entry<String, String> entry : namespaceContext.getNamespaceMap().entrySet()) {
String prefix = entry.getKey();
String uri = entry.getValue();
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) || AtlasXmlConstants.ATLAS_XML_SCHEMASET_NAMESPACE.equals(uri)) {
continue;
}
if (LOG.isTraceEnabled()) {
LOG.trace("adding a namespace >>> prefix={}, uri={}", prefix, uri);
}
if (xmlDocument.getXmlNamespaces() == null) {
xmlDocument.setXmlNamespaces(new XmlNamespaces());
}
XmlNamespace namespace = new XmlNamespace();
namespace.setAlias(prefix);
namespace.setUri(uri);
xmlDocument.getXmlNamespaces().getXmlNamespace().add(namespace);
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlModule method processPreTargetExecution.
@Override
public void processPreTargetExecution(AtlasInternalSession session) throws AtlasException {
XmlNamespaces xmlNs = null;
String template = null;
DataSource ds = getDataSource();
if (ds instanceof XmlDataSource) {
xmlNs = ((XmlDataSource) ds).getXmlNamespaces();
template = ((XmlDataSource) ds).getTemplate();
}
Map<String, String> nsMap = new HashMap<String, String>();
if (xmlNs != null && xmlNs.getXmlNamespace() != null && !xmlNs.getXmlNamespace().isEmpty()) {
for (XmlNamespace ns : xmlNs.getXmlNamespace()) {
nsMap.put(ns.getAlias(), ns.getUri());
}
}
XmlFieldWriter writer = new XmlFieldWriter(getClassLoader(), nsMap, template);
session.setFieldWriter(getDocId(), writer);
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processPreTargetExcution completed", getDocId());
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlSchemaInspectionMultipleNamespacesTest method testSyndesis.
@Test
public void testSyndesis() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-syndesis.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("tns", namespace.getAlias());
assertEquals("http://syndesis.io/v1/swagger-connector-template/request", namespace.getUri());
assertEquals(null, namespace.isTargetNamespace());
List<Field> fields = answer.getFields().getField();
assertEquals(1, fields.size());
XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
assertEquals("tns:request", complex.getName());
List<XmlField> rootFields = complex.getXmlFields().getXmlField();
assertEquals(1, rootFields.size());
complex = XmlComplexType.class.cast(rootFields.get(0));
assertEquals("tns:body", complex.getName());
List<XmlField> bodyFields = complex.getXmlFields().getXmlField();
assertEquals(1, bodyFields.size());
complex = XmlComplexType.class.cast(bodyFields.get(0));
assertEquals("Pet", complex.getName());
List<XmlField> petFields = complex.getXmlFields().getXmlField();
assertEquals(6, petFields.size());
for (XmlField xmlField : petFields) {
switch(xmlField.getName()) {
case "id":
assertEquals(FieldType.DECIMAL, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/id", xmlField.getPath());
break;
case "Category":
assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/Category", xmlField.getPath());
List<XmlField> categoryFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
assertEquals(2, categoryFields.size());
for (XmlField categoryField : categoryFields) {
switch(categoryField.getName()) {
case "id":
assertEquals(FieldType.DECIMAL, categoryField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/Category/id", categoryField.getPath());
break;
case "name":
assertEquals(FieldType.STRING, categoryField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/Category/name", categoryField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", categoryField.getPath()));
}
}
break;
case "name":
assertEquals(FieldType.STRING, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/name", xmlField.getPath());
break;
case "photoUrl":
assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/photoUrl", xmlField.getPath());
List<XmlField> photoUrlFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
assertEquals(1, photoUrlFields.size());
XmlField photoUrlField = photoUrlFields.get(0);
assertEquals(FieldType.STRING, photoUrlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/photoUrl/photoUrl<>", photoUrlField.getPath());
assertEquals(CollectionType.LIST, photoUrlField.getCollectionType());
break;
case "tag":
assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/tag", xmlField.getPath());
List<XmlField> tagFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
assertEquals(1, tagFields.size());
XmlField tagField = tagFields.get(0);
assertEquals(FieldType.COMPLEX, tagField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/tag/Tag<>", tagField.getPath());
assertEquals(CollectionType.LIST, tagField.getCollectionType());
List<XmlField> tagTagFields = XmlComplexType.class.cast(tagField).getXmlFields().getXmlField();
assertEquals(2, tagTagFields.size());
for (XmlField tagTagField : tagTagFields) {
switch(tagTagField.getName()) {
case "id":
assertEquals(FieldType.DECIMAL, tagTagField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/tag/Tag<>/id", tagTagField.getPath());
break;
case "name":
assertEquals(FieldType.STRING, tagTagField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/tag/Tag<>/name", tagTagField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", tagTagField.getPath()));
}
}
break;
case "status":
assertEquals(FieldType.STRING, xmlField.getFieldType());
assertEquals("/tns:request/tns:body/Pet/status", xmlField.getPath());
break;
default:
fail(String.format("Unknown field '%s'", xmlField.getPath()));
}
}
}
Aggregations