Search in sources :

Example 96 with AtlasMapping

use of io.atlasmap.v2.AtlasMapping in project atlasmap by atlasmap.

the class BaseMarshallerTest method generateMultiSourceMapping.

protected AtlasMapping generateMultiSourceMapping() {
    AtlasMapping mapping = generateSeparateAtlasMapping();
    DataSource sourceA = generateDataSource("srcId", "srcUri", DataSourceType.SOURCE);
    mapping.getDataSource().add(sourceA);
    DataSource targetA = generateDataSource("tgtId", "tgtUri", DataSourceType.TARGET);
    mapping.getDataSource().add(targetA);
    DataSource targetB = generateDataSource("tgtId", "tgtUri", DataSourceType.TARGET);
    mapping.getDataSource().add(targetB);
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().get(0).setDocId("docid");
    fm.getOutputField().get(0).setDocId("docid");
    fm.getOutputField().get(1).setDocId("docid");
    populateMapping(fm, MappingType.MAP, "MapPropertyFieldAlias", ",", ",");
    populateMappingString(fm, "description", "id", "lookupTableName", "strategy", "strategyClassName");
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Example 97 with AtlasMapping

use of io.atlasmap.v2.AtlasMapping 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 98 with AtlasMapping

use of io.atlasmap.v2.AtlasMapping 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());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) JsonNode(com.fasterxml.jackson.databind.JsonNode) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 99 with AtlasMapping

use of io.atlasmap.v2.AtlasMapping in project atlasmap by atlasmap.

the class ConstantPropertyTest method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/constant-property-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    TargetClass output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testValue", output.getTargetName());
    assertNotEquals("testPath", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
    System.setProperty("testProp", "testProp-sysProp");
    System.setProperty("PATH", "PATH-sysProp");
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testProp-sysProp", output.getTargetName());
    assertEquals("PATH-sysProp", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
    session.getProperties().put("testProp", "testProp-runtimeProp");
    session.getProperties().put("PATH", "PATH-runtimeProp");
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    output = TargetClass.class.cast(session.getTargetDocument("io.atlasmap.core.issue.TargetClass"));
    assertEquals("testProp-runtimeProp", output.getTargetName());
    assertEquals("PATH-runtimeProp", output.getTargetFirstName());
    assertEquals(777, output.getTargetInteger());
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasContext(io.atlasmap.api.AtlasContext) AtlasSession(io.atlasmap.api.AtlasSession) URL(java.net.URL) Test(org.junit.Test)

Example 100 with AtlasMapping

use of io.atlasmap.v2.AtlasMapping in project atlasmap by atlasmap.

the class BaseMappingTest method getAtlasMappingFullValid.

protected AtlasMapping getAtlasMappingFullValid() {
    AtlasMapping mapping = AtlasModelFactory.createAtlasMapping();
    mapping.setName("thisis_a_valid.name");
    DataSource src = new DataSource();
    src.setDataSourceType(DataSourceType.SOURCE);
    src.setUri("atlas:java?2");
    DataSource tgt = new DataSource();
    tgt.setDataSourceType(DataSourceType.TARGET);
    tgt.setUri("atlas:java?3");
    mapping.getDataSource().add(src);
    mapping.getDataSource().add(tgt);
    Mapping mapFieldMapping = AtlasModelFactory.createMapping(MappingType.MAP);
    MockField inputField = AtlasModelFactory.createMockField();
    inputField.setFieldType(FieldType.STRING);
    inputField.setCustom("java.lang.String");
    inputField.setName("inputName");
    mapFieldMapping.getInputField().add(inputField);
    MockField outputField = AtlasModelFactory.createMockField();
    outputField.setFieldType(FieldType.STRING);
    outputField.setCustom("java.lang.String");
    outputField.setName("outputName");
    mapFieldMapping.getOutputField().add(outputField);
    Mapping separateMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
    MockField sIJavaField = AtlasModelFactory.createMockField();
    sIJavaField.setFieldType(FieldType.STRING);
    sIJavaField.setCustom("java.lang.String");
    sIJavaField.setName("inputName");
    separateMapping.getInputField().add(sIJavaField);
    MockField sOJavaField = AtlasModelFactory.createMockField();
    sOJavaField.setFieldType(FieldType.STRING);
    sOJavaField.setCustom("java.lang.String");
    sOJavaField.setName("outputName");
    sOJavaField.setIndex(0);
    separateMapping.getOutputField().add(sOJavaField);
    mapping.getMappings().getMapping().add(mapFieldMapping);
    mapping.getMappings().getMapping().add(separateMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) MockField(io.atlasmap.v2.MockField) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)131 Test (org.junit.Test)84 Mapping (io.atlasmap.v2.Mapping)62 File (java.io.File)30 DataSource (io.atlasmap.v2.DataSource)21 Validation (io.atlasmap.v2.Validation)20 JavaField (io.atlasmap.java.v2.JavaField)15 MockField (io.atlasmap.v2.MockField)13 Mappings (io.atlasmap.v2.Mappings)10 AtlasContext (io.atlasmap.api.AtlasContext)9 AtlasSession (io.atlasmap.api.AtlasSession)9 Actions (io.atlasmap.v2.Actions)8 BaseMapping (io.atlasmap.v2.BaseMapping)8 LookupTable (io.atlasmap.v2.LookupTable)8 MappingType (io.atlasmap.v2.MappingType)8 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)7 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)7