Search in sources :

Example 11 with Mappings

use of io.atlasmap.v2.Mappings 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 12 with Mappings

use of io.atlasmap.v2.Mappings 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)

Example 13 with Mappings

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

the class AtlasModuleSupportTest method testListTargetPathsListOfBaseMapping.

@Test
public void testListTargetPathsListOfBaseMapping() {
    List<BaseMapping> mappings = null;
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    mappings = new ArrayList<>();
    assertEquals(0, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mapping mapping = new Mapping();
    Field field = new MockField();
    field.setPath("MockPath");
    mapping.getOutputField().add(field);
    mappings.add(mapping);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Collection collection = null;
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    collection = new Collection();
    mappings.add(collection);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
    Mappings mapings = new Mappings();
    collection.setMappings(mapings);
    assertEquals(1, AtlasModuleSupport.listTargetPaths(mappings).size());
}
Also used : MockField(io.atlasmap.v2.MockField) Field(io.atlasmap.v2.Field) MockField(io.atlasmap.v2.MockField) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 14 with Mappings

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

the class AtlasModuleSupportTest method testListTargetPathsAtlasMapping.

@Test
public void testListTargetPathsAtlasMapping() {
    AtlasMapping atlasMapping = null;
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    atlasMapping = new AtlasMapping();
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    Mappings mappings = new Mappings();
    atlasMapping.setMappings(mappings);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    Mapping mapping = new Mapping();
    mappings.getMapping().add(mapping);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
    class MockMapping extends Mappings {

        private static final long serialVersionUID = 1L;

        @Override
        public List<BaseMapping> getMapping() {
            return null;
        }
    }
    Mappings mockMapping = new MockMapping();
    atlasMapping.setMappings(mockMapping);
    assertEquals(0, AtlasModuleSupport.listTargetPaths(atlasMapping).size());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 15 with Mappings

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

the class AtlasMappingServiceTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() {
    atlasMappingService = new AtlasMappingService();
    atlasMapping = new AtlasMapping();
    atlasMapping.setName("testname");
    Mappings mappings = new Mappings();
    Mapping mapping = new Mapping();
    mapping.setId("1");
    mapping.setAlias("alias1");
    mappings.getMapping().add(mapping);
    mapping = new Mapping();
    mapping.setId("2");
    mapping.setAlias("alias2");
    mappings.getMapping().add(mapping);
    atlasMapping.setMappings(mappings);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BeforeClass(org.junit.BeforeClass)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)55 Test (org.junit.Test)41 Mapping (io.atlasmap.v2.Mapping)34 BaseMapping (io.atlasmap.v2.BaseMapping)14 JavaField (io.atlasmap.java.v2.JavaField)12 DataSource (io.atlasmap.v2.DataSource)11 Mappings (io.atlasmap.v2.Mappings)11 File (java.io.File)11 Validation (io.atlasmap.v2.Validation)10 MockField (io.atlasmap.v2.MockField)8 AtlasMappingService (io.atlasmap.core.AtlasMappingService)7 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)7 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)7 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)7 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)7 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)7 DataSourceType (io.atlasmap.v2.DataSourceType)7 FieldType (io.atlasmap.v2.FieldType)7 MappingType (io.atlasmap.v2.MappingType)7 ValidationScope (io.atlasmap.v2.ValidationScope)7