use of io.atlasmap.java.v2.JavaField 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.java.v2.JavaField 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.java.v2.JavaField in project atlasmap by atlasmap.
the class JavaConstructServiceComplexArrayTest method generateOrderArray.
protected JavaClass generateOrderArray(String prefix) {
JavaClass j = classInspectionService.inspectClass("io.atlasmap.java.test." + prefix + "OrderArray");
for (JavaField jf : j.getJavaFields().getJavaField()) {
if (jf.getPath().equals("orders")) {
jf.setClassName("io.atlasmap.java.test." + prefix + "Order");
jf.setArraySize(new Integer(3));
}
if (jf instanceof JavaClass) {
for (JavaField cjf : ((JavaClass) jf).getJavaFields().getJavaField()) {
if (cjf.getPath().equals("orders/contact")) {
cjf.setClassName("io.atlasmap.java.test." + prefix + "Contact");
}
if (cjf.getPath().equals("orders/address")) {
cjf.setClassName("io.atlasmap.java.test." + prefix + "Address");
}
}
}
}
return j;
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class ConcurrencyChaosMonkeyTest method generateMappingURI.
protected URI generateMappingURI() throws Exception {
AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
mapping.setName("mockMapping");
DataSource src = new DataSource();
src.setDataSourceType(DataSourceType.SOURCE);
src.setUri("atlas:java?className=twitter4j.Status");
DataSource tgt = new DataSource();
tgt.setDataSourceType(DataSourceType.TARGET);
tgt.setUri("atlas:java?className=org.apache.camel.salesforce.dto.Contact");
mapping.getDataSource().add(src);
mapping.getDataSource().add(tgt);
Mapping sepMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
JavaField jNameField = new JavaField();
jNameField.setName("Name");
jNameField.setPath("User.name");
jNameField.setGetMethod("getName");
jNameField.setFieldType(FieldType.STRING);
JavaField jFirstNameField = new JavaField();
jFirstNameField.setName("FirstName");
jFirstNameField.setPath("FirstName");
jFirstNameField.setSetMethod("setFirstName");
jFirstNameField.setFieldType(FieldType.STRING);
jFirstNameField.setIndex(0);
JavaField jLastNameField = new JavaField();
jLastNameField.setName("LastName");
jLastNameField.setPath("LastName");
jLastNameField.setSetMethod("setLastName");
jLastNameField.setFieldType(FieldType.STRING);
jLastNameField.setIndex(1);
sepMapping.getInputField().add(jNameField);
sepMapping.getOutputField().add(jFirstNameField);
sepMapping.getOutputField().add(jLastNameField);
mapping.getMappings().getMapping().add(sepMapping);
Mapping textDescMapping = AtlasModelFactory.createMapping(MappingType.MAP);
JavaField jTextField = new JavaField();
jTextField.setName("Text");
jTextField.setPath("Text");
jTextField.setGetMethod("getText");
jTextField.setFieldType(FieldType.STRING);
JavaField jDescField = new JavaField();
jDescField.setName("Description");
jDescField.setPath("description");
jDescField.setSetMethod("setDescription");
jDescField.setFieldType(FieldType.STRING);
textDescMapping.getInputField().add(jTextField);
textDescMapping.getOutputField().add(jDescField);
mapping.getMappings().getMapping().add(textDescMapping);
Mapping screenTitleMapping = AtlasModelFactory.createMapping(MappingType.MAP);
JavaField jScreenField = new JavaField();
jScreenField.setName("ScreenName");
jScreenField.setPath("User.screenName");
jScreenField.setGetMethod("getScreenName");
jScreenField.setFieldType(FieldType.STRING);
JavaField jTitleField = new JavaField();
jTitleField.setName("Title");
jTitleField.setPath("Title");
jTitleField.setSetMethod("setTitle");
jTitleField.setFieldType(FieldType.STRING);
screenTitleMapping.getInputField().add(jScreenField);
screenTitleMapping.getOutputField().add(jTitleField);
mapping.getMappings().getMapping().add(screenTitleMapping);
File mappingFile = new File("target/junit-atlasmapping.xml");
atlasContextFactory.getMappingService().saveMappingAsFile(mapping, mappingFile);
return mappingFile.toURI();
}
use of io.atlasmap.java.v2.JavaField in project atlasmap by atlasmap.
the class JsonJsonFlatMappingTest method generateJavaField.
protected JavaField generateJavaField(String path) {
JavaField javaField = AtlasJavaModelFactory.createJavaField();
javaField.setPath(path);
javaField.setModifiers(null);
return javaField;
}
Aggregations