Search in sources :

Example 41 with Mapping

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

the class JsonValidationServiceTest 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);
    JsonField in = (JsonField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.DOUBLE);
    JsonField out = (JsonField) 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")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) Assert.assertThat(org.junit.Assert.assertThat) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) After(org.junit.After) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Collector(java.util.stream.Collector) Before(org.junit.Before) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) MockField(io.atlasmap.v2.MockField) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) Assert.assertFalse(org.junit.Assert.assertFalse) AtlasJsonModelFactory(io.atlasmap.json.v2.AtlasJsonModelFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JsonField(io.atlasmap.json.v2.JsonField) Assert.assertEquals(org.junit.Assert.assertEquals) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 42 with Mapping

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

the class JsonValidationServiceTest 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);
    JsonField in = (JsonField) 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 : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 43 with Mapping

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

the class JsonValidationServiceTest 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);
    JsonField in = (JsonField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.STRING);
    JsonField out = (JsonField) 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")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) Assert.assertThat(org.junit.Assert.assertThat) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) After(org.junit.After) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Collector(java.util.stream.Collector) Before(org.junit.Before) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) MockField(io.atlasmap.v2.MockField) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) Assert.assertFalse(org.junit.Assert.assertFalse) AtlasJsonModelFactory(io.atlasmap.json.v2.AtlasJsonModelFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JsonField(io.atlasmap.json.v2.JsonField) Assert.assertEquals(org.junit.Assert.assertEquals) JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 44 with Mapping

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

the class JsonValidationServiceTest method getAtlasMappingFullValid.

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

Example 45 with Mapping

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

the class JsonValidationServiceTest method testValidateMappingHappyPath.

// @Test
// @Ignore // Note: manual utility to assist in creating files
// public void saveSampleFile() throws Exception {
// AtlasMappingUtil util = new
// AtlasMappingUtil("io.atlasmap.v2:io.atlasmap.java.v2");
// 
// AtlasMapping mapping = getAtlasMappingFullValid();
// util.marshallMapping(mapping,
// "src/test/resources/mappings/HappyPathMapping.xml");
// 
// mapping = getAtlasMappingFullValid();
// mapping.getMappings().getMapping().clear();
// mapping.getMappings().getMapping().add(createMockMapping());
// mappingUtil.marshallMapping(mapping,
// "src/test/resources/mappings/MisMatchedFieldTypes.xml");
// 
// }
@Test
public void testValidateMappingHappyPath() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    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