Search in sources :

Example 86 with Mappings

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

the class JavaValidationServiceTest method testValidateMappingSourceToTargetCustomUsingClassNames.

@Test
public void testValidateMappingSourceToTargetCustomUsingClassNames() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.DATE_TIME_TZ);
    in.setClassName("java.util.Date");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.DATE_TIME_TZ);
    out.setClassName("java.time.ZonedDateTime");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(0, validationHelper.getCount());
}
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.jupiter.api.Test)

Example 87 with Mappings

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

the class JavaValidationServiceTest method testValidateMappingSupportedSourceToTargetConversion.

@Test
public void testValidateMappingSupportedSourceToTargetConversion() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) 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());
    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.jupiter.api.Test)

Example 88 with Mappings

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

the class JavaValidationServiceTest method testValidateMappingSourceToTargetUnsupported.

@Test
public void testValidateMappingSourceToTargetUnsupported() throws Exception {
    AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
    assertNotNull(mapping);
    Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
    JavaField in = (JavaField) fieldMapping.getInputField().get(0);
    in.setFieldType(FieldType.DATE);
    in.setClassName("java.util.Date");
    JavaField out = (JavaField) fieldMapping.getOutputField().get(0);
    out.setFieldType(FieldType.BYTE);
    out.setClassName("java.lang.Byte");
    validations.addAll(sourceValidationService.validateMapping(mapping));
    validations.addAll(targetValidationService.validateMapping(mapping));
    if (LOG.isDebugEnabled()) {
        debugErrors(validations);
    }
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
    assertEquals(1, validationHelper.getCount());
    assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("out of range")));
}
Also used : DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) Disabled(org.junit.jupiter.api.Disabled) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) AtlasJavaModelFactory(io.atlasmap.java.v2.AtlasJavaModelFactory) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collector(java.util.stream.Collector) AtlasConstants(io.atlasmap.api.AtlasConstants) Logger(org.slf4j.Logger) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) MockField(io.atlasmap.v2.MockField) DefaultAtlasFieldActionService(io.atlasmap.core.DefaultAtlasFieldActionService) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) AtlasMapping(io.atlasmap.v2.AtlasMapping) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) JavaField(io.atlasmap.java.v2.JavaField) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.jupiter.api.Test)

Example 89 with Mappings

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

the class JavaModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
        throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
    }
    Object rootObject;
    String targetClassName = AtlasUtil.unescapeFromUri(AtlasUtil.getUriParameterValue(getUri(), "className"));
    String collectionTypeStr = AtlasUtil.unescapeFromUri(AtlasUtil.getUriParameterValue(getUri(), "collectionType"));
    CollectionType collectionType = collectionTypeStr != null ? CollectionType.fromValue(collectionTypeStr) : CollectionType.NONE;
    String collectionClassName = AtlasUtil.unescapeFromUri(AtlasUtil.getUriParameterValue(getUri(), "collectionClassName"));
    JavaFieldWriter writer = new JavaFieldWriter(this.writerUtil);
    Class<?> clazz = writerUtil.loadClass(targetClassName);
    if (collectionType == CollectionType.ARRAY) {
        rootObject = Array.newInstance(clazz, 0);
    } else if (collectionType != CollectionType.NONE) {
        if (collectionClassName != null) {
            rootObject = writerUtil.instantiateObject(writerUtil.loadClass(collectionClassName));
        } else {
            rootObject = writerUtil.instantiateObject(writerUtil.getDefaultCollectionImplClass(collectionType));
        }
        writer.setCollectionItemClass(clazz);
    } else {
        rootObject = writerUtil.instantiateObject(clazz);
    }
    writer.setRootObject(rootObject);
    writer.setTargetValueConverter(targetValueConverter);
    atlasSession.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : JavaFieldWriter(io.atlasmap.java.core.JavaFieldWriter) CollectionType(io.atlasmap.v2.CollectionType) AtlasException(io.atlasmap.api.AtlasException)

Example 90 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.json");
    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.jupiter.api.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)86 Mapping (io.atlasmap.v2.Mapping)50 Test (org.junit.jupiter.api.Test)45 BaseMapping (io.atlasmap.v2.BaseMapping)26 File (java.io.File)20 Mappings (io.atlasmap.v2.Mappings)16 Test (org.junit.Test)15 JavaField (io.atlasmap.java.v2.JavaField)14 AtlasContext (io.atlasmap.api.AtlasContext)12 AtlasSession (io.atlasmap.api.AtlasSession)12 DataSource (io.atlasmap.v2.DataSource)12 Validation (io.atlasmap.v2.Validation)11 Field (io.atlasmap.v2.Field)10 JsonField (io.atlasmap.json.v2.JsonField)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 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)7 ValidationScope (io.atlasmap.v2.ValidationScope)7