use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method getAtlasMappingFullValid.
protected AtlasMapping getAtlasMappingFullValid() {
AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
mapping.setName("thisis_a_valid.name");
mapping.getDataSource().add(generateDataSource("atlas:xml:MockXml", DataSourceType.SOURCE));
mapping.getDataSource().add(generateDataSource("atlas:xml:MockXml", DataSourceType.TARGET));
Mapping mapMapping = AtlasModelFactory.createMapping(MappingType.MAP);
Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
Mapping combineMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
// MappedField
XmlField inputField = AtlasXmlModelFactory.createXmlField();
inputField.setFieldType(FieldType.STRING);
inputField.setPath("firstName");
XmlField outputField = AtlasXmlModelFactory.createXmlField();
outputField.setFieldType(FieldType.STRING);
outputField.setPath("firstName");
mapMapping.getInputField().add(inputField);
mapMapping.getOutputField().add(outputField);
XmlField sIJavaField = AtlasXmlModelFactory.createXmlField();
sIJavaField.setFieldType(FieldType.STRING);
sIJavaField.setPath("displayName");
sepMapping.getInputField().add(sIJavaField);
XmlField sOJavaField = AtlasXmlModelFactory.createXmlField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(1);
sepMapping.getOutputField().add(sOJavaField);
XmlField cIJavaField = AtlasXmlModelFactory.createXmlField();
cIJavaField.setFieldType(FieldType.STRING);
cIJavaField.setPath("displayName");
combineMapping.getInputField().add(cIJavaField);
XmlField cOJavaField = AtlasXmlModelFactory.createXmlField();
cOJavaField.setFieldType(FieldType.STRING);
cOJavaField.setPath("lastName");
cOJavaField.setIndex(1);
combineMapping.getOutputField().add(cOJavaField);
mapping.getMappings().getMapping().add(mapMapping);
mapping.getMappings().getMapping().add(sepMapping);
mapping.getMappings().getMapping().add(combineMapping);
return mapping;
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.
@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
separateFieldMapping.setId("separate.firstName.lastName");
XmlField bIJavaField = xmlModelFactory.createXmlField();
bIJavaField.setFieldType(FieldType.BOOLEAN);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
separateFieldMapping.getInputField().add(bIJavaField);
XmlField sOJavaField = xmlModelFactory.createXmlField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
separateFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(separateFieldMapping);
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("separate.firstName.lastName", validation.getId());
assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingSupportedSourceToTargetConversion.
@Test
public void testValidateMappingSupportedSourceToTargetConversion() 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.CHAR);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
if (LOG.isDebugEnabled()) {
debugErrors(validations);
}
assertFalse(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertTrue(validationHelper.hasInfos());
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlValidationServiceTest method testValidateMappingPathNull.
@Test
public void testValidateMappingPathNull() 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.setPath(null);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
}
use of io.atlasmap.xml.v2.XmlField in project atlasmap by atlasmap.
the class XmlInstanceInspectionTest method testInspectXmlStringAsSource.
@Test
public void testInspectXmlStringAsSource() throws Exception {
final String source = "<data>\n" + " <intField>32000</intField>\n" + " <longField>12421</longField>\n" + " <stringField>abc</stringField>\n" + " <booleanField>true</booleanField>\n" + " <doubleField>12.0</doubleField>\n" + " <shortField>1000</shortField>\n" + " <floatField>234.5f</floatField>\n" + " <charField>A</charField>\n" + "</data>";
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectXmlDocument(source);
Assert.assertNotNull(xmlDocument);
Assert.assertNotNull(xmlDocument.getFields());
Assert.assertThat(xmlDocument.getFields().getField().size(), Is.is(1));
List<XmlComplexType> complexTypeList = xmlDocument.getFields().getField().stream().filter(xmlField -> xmlField instanceof XmlComplexType).map(xmlField -> (XmlComplexType) xmlField).collect(Collectors.toList());
Assert.assertThat(complexTypeList.size(), Is.is(1));
XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
Assert.assertNotNull(root);
Assert.assertThat(root.getXmlFields().getXmlField().size(), Is.is(8));
complexTypeList = root.getXmlFields().getXmlField().stream().filter(xmlField -> xmlField instanceof XmlComplexType).map(xmlField -> (XmlComplexType) xmlField).collect(Collectors.toList());
Assert.assertThat(complexTypeList.size(), Is.is(0));
// debugFields(xmlDocument.getFields());
}
Aggregations