Search in sources :

Example 36 with JavaField

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")));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DefaultAtlasConversionService(io.atlasmap.core.DefaultAtlasConversionService) AtlasValidationTestHelper(io.atlasmap.validators.AtlasValidationTestHelper) ValidationScope(io.atlasmap.v2.ValidationScope) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) MappingType(io.atlasmap.v2.MappingType) FieldType(io.atlasmap.v2.FieldType) Validation(io.atlasmap.v2.Validation) AtlasJavaModelFactory(io.atlasmap.java.v2.AtlasJavaModelFactory) Assert.assertThat(org.junit.Assert.assertThat) AtlasModelFactory(io.atlasmap.v2.AtlasModelFactory) After(org.junit.After) AtlasModuleMode(io.atlasmap.spi.AtlasModuleMode) Collector(java.util.stream.Collector) Before(org.junit.Before) AtlasConstants(io.atlasmap.api.AtlasConstants) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ValidationStatus(io.atlasmap.v2.ValidationStatus) Collectors(java.util.stream.Collectors) DataSourceType(io.atlasmap.v2.DataSourceType) AtlasMappingUtil(io.atlasmap.core.AtlasMappingUtil) Mapping(io.atlasmap.v2.Mapping) List(java.util.List) MockField(io.atlasmap.v2.MockField) AtlasModuleDetail(io.atlasmap.spi.AtlasModuleDetail) Assert.assertFalse(org.junit.Assert.assertFalse) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Assert.assertEquals(org.junit.Assert.assertEquals) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 37 with JavaField

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());
}
Also used : Validation(io.atlasmap.v2.Validation) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 38 with JavaField

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;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass)

Example 39 with JavaField

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();
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) DataSource(io.atlasmap.v2.DataSource)

Example 40 with JavaField

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;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField)

Aggregations

JavaField (io.atlasmap.java.v2.JavaField)53 Test (org.junit.Test)19 JavaClass (io.atlasmap.java.v2.JavaClass)16 Mapping (io.atlasmap.v2.Mapping)16 AtlasMapping (io.atlasmap.v2.AtlasMapping)15 Validation (io.atlasmap.v2.Validation)8 FieldType (io.atlasmap.v2.FieldType)7 Method (java.lang.reflect.Method)7 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)6 AtlasException (io.atlasmap.api.AtlasException)5 DataSource (io.atlasmap.v2.DataSource)5 Field (io.atlasmap.v2.Field)5 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)4 ValidationScope (io.atlasmap.v2.ValidationScope)4 ValidationStatus (io.atlasmap.v2.ValidationStatus)4 List (java.util.List)4 Logger (org.slf4j.Logger)4 AtlasConstants (io.atlasmap.api.AtlasConstants)3 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)3 AtlasPath (io.atlasmap.core.AtlasPath)3