use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingSourceToTargetFormatConcerns.
@Test
public void testValidateMappingSourceToTargetFormatConcerns() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
XmlField in = (XmlField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.STRING);
XmlField out = (XmlField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.LONG);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertTrue(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertThat(2, is(validationHelper.getCount()));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("format")));
}
use of io.atlasmap.xml.v2.XmlField 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.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingSourceToTargetRangeConcerns.
@Test
public void testValidateMappingSourceToTargetRangeConcerns() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
XmlField in = (XmlField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.DOUBLE);
XmlField out = (XmlField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.LONG);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertTrue(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertThat(1, is(validationHelper.getCount()));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("range")));
}
use of io.atlasmap.xml.v2.XmlField 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.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlSchemaInspectionTest method testInspectPOExampleSchemaFile.
@Test
public void testInspectPOExampleSchemaFile() throws Exception {
File schemaFile = Paths.get("src/test/resources/inspect/po-example-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(2));
// PurchaseOrderType
XmlComplexType purchaseOrder = (XmlComplexType) xmlDocument.getFields().getField().get(0);
Assert.assertNotNull(purchaseOrder);
Assert.assertThat(purchaseOrder.getXmlFields().getXmlField().size(), Is.is(5));
// orderDate
XmlField orderDateAttr = purchaseOrder.getXmlFields().getXmlField().get(0);
Assert.assertNotNull(orderDateAttr);
Assert.assertThat(orderDateAttr.getName(), Is.is("tns:orderDate"));
Assert.assertNull(orderDateAttr.getValue());
Assert.assertThat(orderDateAttr.getPath(), Is.is("/tns:purchaseOrder/@tns:orderDate"));
Assert.assertThat(orderDateAttr.getFieldType(), Is.is(FieldType.DATE));
// shipTo
XmlField shipTo = purchaseOrder.getXmlFields().getXmlField().get(1);
Assert.assertNotNull(shipTo);
Assert.assertThat(shipTo.getName(), Is.is("tns:shipTo"));
Assert.assertNull(shipTo.getValue());
Assert.assertThat(shipTo.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo"));
Assert.assertThat(shipTo.getFieldType(), Is.is(FieldType.COMPLEX));
Assert.assertThat(((XmlComplexType) shipTo).getXmlFields().getXmlField().size(), Is.is(6));
// shipTo/@country
XmlField shipToCountry = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(0);
Assert.assertNotNull(shipTo);
Assert.assertThat(shipToCountry.getName(), Is.is("tns:country"));
Assert.assertThat(shipToCountry.getValue(), Is.is("US"));
Assert.assertThat(shipToCountry.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/@tns:country"));
Assert.assertThat(shipToCountry.getFieldType(), Is.is(FieldType.UNSUPPORTED));
XmlField shipToName = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(1);
Assert.assertNotNull(shipToName);
Assert.assertThat(shipToName.getName(), Is.is("tns:name"));
Assert.assertNull(shipToName.getValue());
Assert.assertThat(shipToName.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/tns:name"));
Assert.assertThat(shipToName.getFieldType(), Is.is(FieldType.STRING));
XmlField shipToStreet = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(2);
Assert.assertNotNull(shipToStreet);
Assert.assertThat(shipToStreet.getName(), Is.is("tns:street"));
Assert.assertNull(shipToStreet.getValue());
Assert.assertThat(shipToStreet.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/tns:street"));
Assert.assertThat(shipToStreet.getFieldType(), Is.is(FieldType.STRING));
XmlField shipToCity = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(3);
Assert.assertNotNull(shipToCity);
Assert.assertThat(shipToCity.getName(), Is.is("tns:city"));
Assert.assertNull(shipToCity.getValue());
Assert.assertThat(shipToCity.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/tns:city"));
Assert.assertThat(shipToCity.getFieldType(), Is.is(FieldType.STRING));
XmlField shipToState = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(4);
Assert.assertNotNull(shipToState);
Assert.assertThat(shipToState.getName(), Is.is("tns:state"));
Assert.assertNull(shipToState.getValue());
Assert.assertThat(shipToState.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/tns:state"));
Assert.assertThat(shipToState.getFieldType(), Is.is(FieldType.STRING));
XmlField shipToZip = ((XmlComplexType) shipTo).getXmlFields().getXmlField().get(5);
Assert.assertNotNull(shipToZip);
Assert.assertThat(shipToZip.getName(), Is.is("tns:zip"));
Assert.assertNull(shipToZip.getValue());
Assert.assertThat(shipToZip.getPath(), Is.is("/tns:purchaseOrder/tns:shipTo/tns:zip"));
Assert.assertThat(shipToZip.getFieldType(), Is.is(FieldType.DECIMAL));
// comment
XmlField comment = purchaseOrder.getXmlFields().getXmlField().get(3);
Assert.assertNotNull(comment);
Assert.assertThat(comment.getName(), Is.is("tns:comment"));
Assert.assertNull(comment.getValue());
Assert.assertThat(comment.getPath(), Is.is("/tns:purchaseOrder/tns:comment"));
Assert.assertThat(comment.getFieldType(), Is.is(FieldType.STRING));
// items
XmlField items = purchaseOrder.getXmlFields().getXmlField().get(4);
Assert.assertNotNull(items);
Assert.assertThat(items.getName(), Is.is("tns:items"));
Assert.assertNull(items.getValue());
Assert.assertThat(items.getPath(), Is.is("/tns:purchaseOrder/tns:items"));
Assert.assertThat(items.getFieldType(), Is.is(FieldType.COMPLEX));
Assert.assertThat(((XmlComplexType) items).getXmlFields().getXmlField().size(), Is.is(1));
// items/item
XmlComplexType item = (XmlComplexType) ((XmlComplexType) items).getXmlFields().getXmlField().get(0);
Assert.assertNotNull(item);
Assert.assertThat(item.getName(), Is.is("tns:item"));
Assert.assertNull(item.getValue());
Assert.assertThat(item.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item"));
Assert.assertThat(item.getFieldType(), Is.is(FieldType.COMPLEX));
Assert.assertThat(item.getCollectionType(), Is.is(CollectionType.LIST));
Assert.assertThat(item.getXmlFields().getXmlField().size(), Is.is(6));
// partNum
XmlField partNum = item.getXmlFields().getXmlField().get(0);
Assert.assertNotNull(partNum);
Assert.assertThat(partNum.getName(), Is.is("tns:partNum"));
Assert.assertNull(partNum.getValue());
Assert.assertThat(partNum.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/@tns:partNum"));
Assert.assertThat(partNum.getFieldType(), Is.is(FieldType.STRING));
Assert.assertThat(partNum.getTypeName(), Is.is("SKU"));
// productName
XmlField productName = item.getXmlFields().getXmlField().get(1);
Assert.assertNotNull(productName);
Assert.assertThat(productName.getName(), Is.is("tns:productName"));
Assert.assertNull(productName.getValue());
Assert.assertThat(productName.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/tns:productName"));
Assert.assertThat(productName.getFieldType(), Is.is(FieldType.STRING));
// quantity
XmlField quantity = item.getXmlFields().getXmlField().get(2);
Assert.assertNotNull(quantity);
Assert.assertThat(quantity.getName(), Is.is("tns:quantity"));
Assert.assertNull(quantity.getValue());
Assert.assertThat(quantity.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/tns:quantity"));
Assert.assertThat(quantity.getFieldType(), Is.is(FieldType.BIG_INTEGER));
Assert.assertNotNull(quantity.getRestrictions().getRestriction());
Assert.assertThat(quantity.getRestrictions().getRestriction().size(), Is.is(1));
Restriction qRestriction = quantity.getRestrictions().getRestriction().get(0);
Assert.assertNotNull(qRestriction);
Assert.assertNotNull(qRestriction.getType());
Assert.assertThat(qRestriction.getType(), Is.is(RestrictionType.MAX_EXCLUSIVE));
Assert.assertNotNull(qRestriction.getValue());
Assert.assertThat(qRestriction.getValue(), Is.is("99"));
// USPrice
XmlField usPrice = item.getXmlFields().getXmlField().get(3);
Assert.assertNotNull(usPrice);
Assert.assertThat(usPrice.getName(), Is.is("tns:USPrice"));
Assert.assertNull(usPrice.getValue());
Assert.assertThat(usPrice.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/tns:USPrice"));
Assert.assertThat(usPrice.getFieldType(), Is.is(FieldType.DECIMAL));
// comment
XmlField itemComment = item.getXmlFields().getXmlField().get(4);
Assert.assertNotNull(itemComment);
Assert.assertThat(itemComment.getName(), Is.is("tns:comment"));
Assert.assertNull(itemComment.getValue());
Assert.assertThat(itemComment.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/tns:comment"));
Assert.assertThat(itemComment.getFieldType(), Is.is(FieldType.STRING));
// shipDate
XmlField shipDate = item.getXmlFields().getXmlField().get(5);
Assert.assertNotNull(shipDate);
Assert.assertThat(shipDate.getName(), Is.is("tns:shipDate"));
Assert.assertNull(shipDate.getValue());
Assert.assertThat(shipDate.getPath(), Is.is("/tns:purchaseOrder/tns:items/tns:item/tns:shipDate"));
Assert.assertThat(shipDate.getFieldType(), Is.is(FieldType.DATE));
// namespaces
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://tempuri.org/po.xsd"));
// debugFields(xmlDocument.getFields());
}
Aggregations