use of org.talend.hl7.Field 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()));
}
}
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class BaseXmlInspectionServiceTest method debugFields.
protected void debugFields(Fields xmlFields) {
for (Field field : xmlFields.getField()) {
Assert.assertTrue(field instanceof XmlField);
XmlField xmlField = (XmlField) field;
printXmlField(xmlField);
if (xmlField instanceof XmlComplexType) {
debugFields(((XmlComplexType) xmlField).getXmlFields());
}
}
}
use of org.talend.hl7.Field 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);
Assert.assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
Assert.assertEquals("tns", namespace.getAlias());
Assert.assertEquals("http://syndesis.io/v1/swagger-connector-template/request", namespace.getUri());
Assert.assertEquals(null, namespace.isTargetNamespace());
List<Field> fields = answer.getFields().getField();
Assert.assertEquals(1, fields.size());
XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
Assert.assertEquals("tns:request", complex.getName());
List<XmlField> rootFields = complex.getXmlFields().getXmlField();
Assert.assertEquals(1, rootFields.size());
complex = XmlComplexType.class.cast(rootFields.get(0));
Assert.assertEquals("tns:body", complex.getName());
List<XmlField> bodyFields = complex.getXmlFields().getXmlField();
Assert.assertEquals(1, bodyFields.size());
complex = XmlComplexType.class.cast(bodyFields.get(0));
Assert.assertEquals("Pet", complex.getName());
List<XmlField> petFields = complex.getXmlFields().getXmlField();
Assert.assertEquals(6, petFields.size());
for (XmlField xmlField : petFields) {
switch(xmlField.getName()) {
case "id":
Assert.assertEquals(FieldType.DECIMAL, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/id", xmlField.getPath());
break;
case "Category":
Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/Category", xmlField.getPath());
List<XmlField> categoryFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
Assert.assertEquals(2, categoryFields.size());
for (XmlField categoryField : categoryFields) {
switch(categoryField.getName()) {
case "id":
Assert.assertEquals(FieldType.DECIMAL, categoryField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/Category/id", categoryField.getPath());
break;
case "name":
Assert.assertEquals(FieldType.STRING, categoryField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/Category/name", categoryField.getPath());
break;
default:
Assert.fail(String.format("Unknown field '%s'", categoryField.getPath()));
}
}
break;
case "name":
Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/name", xmlField.getPath());
break;
case "photoUrl":
Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl", xmlField.getPath());
List<XmlField> photoUrlFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
Assert.assertEquals(1, photoUrlFields.size());
XmlField photoUrlField = photoUrlFields.get(0);
Assert.assertEquals(FieldType.STRING, photoUrlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl/photoUrl", photoUrlField.getPath());
break;
case "tag":
Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/tag", xmlField.getPath());
List<XmlField> tagFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
Assert.assertEquals(1, tagFields.size());
XmlField tagField = tagFields.get(0);
Assert.assertEquals(FieldType.COMPLEX, tagField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag", tagField.getPath());
List<XmlField> tagTagFields = XmlComplexType.class.cast(tagField).getXmlFields().getXmlField();
Assert.assertEquals(2, tagTagFields.size());
for (XmlField tagTagField : tagTagFields) {
switch(tagTagField.getName()) {
case "id":
Assert.assertEquals(FieldType.DECIMAL, tagTagField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/id", tagTagField.getPath());
break;
case "name":
Assert.assertEquals(FieldType.STRING, tagTagField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/name", tagTagField.getPath());
break;
default:
Assert.fail(String.format("Unknown field '%s'", tagTagField.getPath()));
}
}
break;
case "status":
Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
Assert.assertEquals("/tns:request/tns:body/Pet/status", xmlField.getPath());
break;
default:
Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
}
}
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class XmlFieldWriterTest method testThrowExceptionOnNullXmlField.
@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullXmlField() throws Exception {
createWriter();
XmlField field = null;
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(mock(Field.class));
when(session.head().getTargetField()).thenReturn(field);
writer.write(session);
}
use of org.talend.hl7.Field in project atlasmap by atlasmap.
the class DefaultAtlasContext method processSourceFieldMappings.
private void processSourceFieldMappings(DefaultAtlasSession session, List<Field> sourceFields) throws AtlasException {
for (Field sourceField : sourceFields) {
session.head().setSourceField(sourceField);
AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
if (module == null) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Module not found for docId '%s'", sourceField.getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
return;
}
if (!module.isSupportedField(sourceField)) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unsupported source field type '%s' for DataSource '%s'", sourceField.getClass().getName(), module.getUri()), sourceField.getPath(), AuditStatus.ERROR, null);
return;
}
module.processSourceFieldMapping(session);
}
}
Aggregations