Search in sources :

Example 56 with Mapping

use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.

the class JavaValidationServiceTest method getAtlasMappingFullValid.

protected AtlasMapping getAtlasMappingFullValid() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("thisis_a_valid.name");
    mapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.module.MockJavaClass", DataSourceType.SOURCE, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID));
    mapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.module.MockJavaClass", DataSourceType.TARGET, AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID));
    Mapping mapMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    Mapping combineMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
    // MappedField
    JavaField inputField = AtlasJavaModelFactory.createJavaField();
    inputField.setFieldType(FieldType.STRING);
    inputField.setPath("firstName");
    JavaField outputField = AtlasJavaModelFactory.createJavaField();
    outputField.setFieldType(FieldType.STRING);
    outputField.setPath("firstName");
    mapMapping.getInputField().add(inputField);
    mapMapping.getOutputField().add(outputField);
    JavaField sIJavaField = AtlasJavaModelFactory.createJavaField();
    sIJavaField.setFieldType(FieldType.STRING);
    sIJavaField.setPath("displayName");
    sepMapping.getInputField().add(sIJavaField);
    JavaField sOJavaField = AtlasJavaModelFactory.createJavaField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setPath("lastName");
    sOJavaField.setIndex(1);
    sepMapping.getOutputField().add(sOJavaField);
    JavaField cIJavaField = AtlasJavaModelFactory.createJavaField();
    cIJavaField.setFieldType(FieldType.STRING);
    cIJavaField.setPath("displayName");
    combineMapping.getInputField().add(cIJavaField);
    JavaField cOJavaField = AtlasJavaModelFactory.createJavaField();
    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) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 57 with Mapping

use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.

the class JavaValidationServiceTest method testValidateAtlasMappingFileConversionRequired.

@Test
public void testValidateAtlasMappingFileConversionRequired() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.COMPLEX);
    in.setClassName("io.atlasmap.java.module.MockJavaClass");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.STRING);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertThat(1, is(validationHelper.getCount()));
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("map.firstName.firstName", v.getId());
    assertEquals(ValidationStatus.WARN, v.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 58 with Mapping

use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.

the class JavaValidationServiceTest 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);
    JavaField in = (JavaField) 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) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 59 with Mapping

use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.

the class JavaValidationServiceTest method testIssue127.

@Test
public void testIssue127() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/Issue127Mapping.xml");
    assertNotNull(mapping);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(2, validations.size());
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("issue127-1", v.getId());
    assertEquals("Conversion from 'STRING' to 'INTEGER' can cause numeric format exceptions", v.getMessage());
    assertEquals(ValidationStatus.WARN, v.getStatus());
    v = validations.get(1);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("issue127-1", v.getId());
    assertEquals("Conversion from 'STRING' to 'INTEGER' can cause out of range exceptions", v.getMessage());
    assertEquals(ValidationStatus.WARN, v.getStatus());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 60 with Mapping

use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.

the class JavaValidationServiceTest method testValidateMappingHappyPathFromFile.

@Test
public void testValidateMappingHappyPathFromFile() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
    assertNotNull(mapping);
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)120 Mapping (io.atlasmap.v2.Mapping)83 Test (org.junit.Test)65 BaseMapping (io.atlasmap.v2.BaseMapping)29 Field (io.atlasmap.v2.Field)28 Validation (io.atlasmap.v2.Validation)26 DataSource (io.atlasmap.v2.DataSource)21 JavaField (io.atlasmap.java.v2.JavaField)19 MockField (io.atlasmap.v2.MockField)17 Mappings (io.atlasmap.v2.Mappings)11 SimpleField (io.atlasmap.v2.SimpleField)11 MappingType (io.atlasmap.v2.MappingType)10 PropertyField (io.atlasmap.v2.PropertyField)9 File (java.io.File)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 AtlasContext (io.atlasmap.api.AtlasContext)8 AtlasSession (io.atlasmap.api.AtlasSession)8 Actions (io.atlasmap.v2.Actions)8 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)8