use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingInvalidCombineInputFieldType.
@Test
public void testValidateMappingInvalidCombineInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping combineFieldMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
combineFieldMapping.setId("combine.firstName.lastName");
XmlField bIJavaField = xmlModelFactory.createXmlField();
bIJavaField.setFieldType(FieldType.STRING);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
combineFieldMapping.getInputField().add(bIJavaField);
XmlField sOJavaField = xmlModelFactory.createXmlField();
sOJavaField.setFieldType(FieldType.BOOLEAN);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
combineFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(combineFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("combine.firstName.lastName", validation.getId());
assertEquals("Output field 'lastName' must be of type 'STRING' for a Combine Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.v2.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 io.atlasmap.v2.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 io.atlasmap.v2.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 io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testXmlFieldDoubleMinRangeOut.
@Test
public void testXmlFieldDoubleMinRangeOut() throws Exception {
String fieldPath = "/primitive/value";
FieldType fieldType = FieldType.DOUBLE;
Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-double-min-range-out.xml");
AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
assertEquals(0.0, session.head().getSourceField().getValue());
assertEquals(0, session.getAudits().getAudit().size());
}
Aggregations