use of io.atlasmap.v2.Validations in project atlasmap by atlasmap.
the class JavaValidationService method validateClass.
private void validateClass(String mappingId, JavaField field, List<Validation> validations) {
String clazzName = field.getClassName();
if (clazzName != null && !clazzName.isEmpty()) {
Integer major = detectClassVersion(clazzName);
if (major != null) {
if (major > versionMap.get(System.getProperty("java.vm.specification.version"))) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Class '%s' for field is compiled against unsupported JDK version: %d current JDK: %d", clazzName, major, versionMap.get(System.getProperty("java.vm.specification.version"))));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
} else {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Class '%s' for field is not found on the classpath", clazzName));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
}
}
}
use of io.atlasmap.v2.Validations 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.xml");
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());
assertThat(validationHelper.getCount(), is(0));
}
use of io.atlasmap.v2.Validations 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.xml");
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());
assertThat(validationHelper.getCount(), is(1));
assertTrue(validations.stream().anyMatch(atlasMappingError -> atlasMappingError.getMessage().contains("out of range")));
}
use of io.atlasmap.v2.Validations 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.xml");
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());
assertTrue(validationHelper.hasInfos());
}
use of io.atlasmap.v2.Validations 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")));
}
Aggregations