Search in sources :

Example 61 with Mapping

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

the class JavaValidationServiceTest 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);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.DOUBLE);
    in.setClassName("java.lang.Double");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.LONG);
    out.setClassName("java.lang.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) AtlasJavaModelFactory(io.atlasmap.java.v2.AtlasJavaModelFactory) 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) AtlasConstants(io.atlasmap.api.AtlasConstants) 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) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Assert.assertEquals(org.junit.Assert.assertEquals) 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 62 with Mapping

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

the class JavaValidationServiceTest method testValidateMappingInvalidModuleType.

@Test
public void testValidateMappingInvalidModuleType() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("thisis_a_valid.name");
    mapping.getDataSource().add(generateDataSource("atlas:xml", DataSourceType.SOURCE, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID));
    mapping.getDataSource().add(generateDataSource("atlas:xml", DataSourceType.TARGET, AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID));
    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) Test(org.junit.Test)

Example 63 with Mapping

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

the class JavaValidationServiceTest method testValidateMappingMismatchedFieldType.

@Test
public void testValidateMappingMismatchedFieldType() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    assertNotNull(mapping);
    mapping.getMappings().getMapping().clear();
    // Mock MappedField
    mapping.getMappings().getMapping().add(createMockMapping());
    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 64 with Mapping

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

the class BaseMarshallerTest method generateProperties.

private void generateProperties(AtlasMapping mapping) {
    Property p = new Property();
    p.setName("foo");
    p.setValue("bar");
    p.setFieldType(FieldType.INTEGER);
    mapping.setProperties(new Properties());
    mapping.getProperties().getProperty().add(p);
}
Also used : Properties(io.atlasmap.v2.Properties) Property(io.atlasmap.v2.Property)

Example 65 with Mapping

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

the class BaseMarshallerTest method validateCollectionMapping.

private void validateCollectionMapping(Collection collection) {
    assertEquals(new BigInteger("2"), collection.getCollectionSize());
    assertEquals(CollectionType.LIST, collection.getCollectionType());
    Mapping mapping = (Mapping) collection.getMappings().getMapping().get(0);
    assertEquals(1, mapping.getInputField().size());
    validateJavaField((JavaField) mapping.getInputField().get(0));
    assertEquals(1, mapping.getOutputField().size());
    validateJavaField((JavaField) mapping.getOutputField().get(0));
    validateMapping(mapping, MappingType.MAP, generateMappingParams());
    mapping = (Mapping) collection.getMappings().getMapping().get(1);
    assertEquals(1, mapping.getInputField().size());
    validateJavaField((JavaField) mapping.getInputField().get(0));
    assertEquals(1, mapping.getOutputField().size());
    validateJavaField((JavaField) mapping.getOutputField().get(0));
    validateMapping(mapping, MappingType.MAP, generateMappingParams());
}
Also used : BigInteger(java.math.BigInteger) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

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