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