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());
}
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());
}
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")));
}
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());
}
}
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());
}
Aggregations