use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JsonValidationServiceTest 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);
JsonField in = (JsonField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.DOUBLE);
JsonField out = (JsonField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.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")));
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JsonValidationServiceTest 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);
JsonField in = (JsonField) 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.Mapping in project atlasmap by atlasmap.
the class JsonValidationServiceTest 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);
JsonField in = (JsonField) fieldMapping.getInputField().get(0);
in.setFieldType(FieldType.STRING);
JsonField out = (JsonField) fieldMapping.getOutputField().get(0);
out.setFieldType(FieldType.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")));
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JsonValidationServiceTest method getAtlasMappingFullValid.
protected AtlasMapping getAtlasMappingFullValid() {
AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
mapping.setName("thisis_a_valid.name");
mapping.getDataSource().add(generateDataSource("atlas:json:MockJson", DataSourceType.SOURCE));
mapping.getDataSource().add(generateDataSource("atlas:json:MockJson", DataSourceType.TARGET));
Mapping mapMapping = AtlasModelFactory.createMapping(MappingType.MAP);
Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
Mapping combineMapping = AtlasModelFactory.createMapping(MappingType.COMBINE);
// MappedField
JsonField inputField = AtlasJsonModelFactory.createJsonField();
inputField.setFieldType(FieldType.STRING);
inputField.setPath("firstName");
JsonField outputField = AtlasJsonModelFactory.createJsonField();
outputField.setFieldType(FieldType.STRING);
outputField.setPath("firstName");
mapMapping.getInputField().add(inputField);
mapMapping.getOutputField().add(outputField);
JsonField sIJavaField = AtlasJsonModelFactory.createJsonField();
sIJavaField.setFieldType(FieldType.STRING);
sIJavaField.setPath("displayName");
sepMapping.getInputField().add(sIJavaField);
JsonField sOJavaField = AtlasJsonModelFactory.createJsonField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(1);
sepMapping.getOutputField().add(sOJavaField);
JsonField cIJavaField = AtlasJsonModelFactory.createJsonField();
cIJavaField.setFieldType(FieldType.STRING);
cIJavaField.setPath("displayName");
combineMapping.getInputField().add(cIJavaField);
JsonField cOJavaField = AtlasJsonModelFactory.createJsonField();
cOJavaField.setFieldType(FieldType.STRING);
cOJavaField.setPath("lastName");
cOJavaField.setIndex(1);
combineMapping.getOutputField().add(cOJavaField);
mapping.getMappings().getMapping().add(mapMapping);
mapping.getMappings().getMapping().add(sepMapping);
mapping.getMappings().getMapping().add(combineMapping);
return mapping;
}
use of io.atlasmap.v2.Mapping in project atlasmap by atlasmap.
the class JsonValidationServiceTest 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());
}
Aggregations