Search in sources :

Example 36 with Mappings

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

the class JavaValidationServiceTest 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 37 with Mappings

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

the class JavaValidationServiceTest 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);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.STRING);
    in.setClassName("java.lang.String");
    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(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) 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 38 with Mappings

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

the class JavaValidationServiceTest method testValidateMappingClassNotFound.

@Test
public void testValidateMappingClassNotFound() 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.setClassName("java.lang.String3");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(1, validations.size());
    Validation v = validations.get(0);
    assertEquals(ValidationScope.MAPPING, v.getScope());
    assertEquals("map.firstName.firstName", v.getId());
    assertEquals(ValidationStatus.ERROR, 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 39 with Mappings

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

the class BaseMarshallerTest method generateCollectionMapping.

protected AtlasMapping generateCollectionMapping() {
    AtlasMapping innerMapping1 = generateAtlasMapping();
    AtlasMapping innerMapping2 = generateAtlasMapping();
    Collection cMapping = (Collection) AtlasModelFactory.createMapping(MappingType.COLLECTION);
    cMapping.setMappings(new Mappings());
    cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
    cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
    cMapping.setCollectionType(CollectionType.LIST);
    cMapping.setCollectionSize(new BigInteger("2"));
    cMapping.setAlias("alias");
    cMapping.setDescription("description");
    AtlasMapping mapping = generateAtlasMapping();
    mapping.getMappings().getMapping().clear();
    mapping.getMappings().getMapping().add(cMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Collection(io.atlasmap.v2.Collection) BigInteger(java.math.BigInteger)

Example 40 with Mappings

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

the class CamelAtlasmap14Test method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/camel-atlasmap-14-mapping.json");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.JSON);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(generateTwitterStatus());
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    Object output = session.getDefaultTargetDocument();
    assertEquals(String.class, output.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String) output);
    assertNotNull(outJson.get("TwitterScreenName__c"));
    assertEquals("bobvila1982", outJson.get("TwitterScreenName__c").asText());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

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