Search in sources :

Example 1 with XmlField

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;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 2 with XmlField

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());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 3 with XmlField

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());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 4 with XmlField

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());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlField(io.atlasmap.xml.v2.XmlField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 5 with XmlField

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());
}
Also used : List(java.util.List) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) Files(java.nio.file.Files) Paths(java.nio.file.Paths) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Document(org.w3c.dom.Document) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) Test(org.junit.Test) Assert(org.junit.Assert) Collectors(java.util.stream.Collectors) XmlField(io.atlasmap.xml.v2.XmlField) Is(org.hamcrest.core.Is) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.Test)

Aggregations

XmlField (io.atlasmap.xml.v2.XmlField)46 Test (org.junit.Test)31 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)21 Head (io.atlasmap.spi.AtlasInternalSession.Head)21 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)11 XmlDocument (io.atlasmap.xml.v2.XmlDocument)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Mapping (io.atlasmap.v2.Mapping)7 Field (io.atlasmap.v2.Field)6 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)6 File (java.io.File)6 Validation (io.atlasmap.v2.Validation)4 FieldType (io.atlasmap.v2.FieldType)3 Restriction (io.atlasmap.xml.v2.Restriction)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)2 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)2