Search in sources :

Example 31 with Mapping

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

the class BaseValidatorTest 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)

Example 32 with Mapping

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

the class BaseValidatorTest method getAtlasMappingWithLookupTables.

protected AtlasMapping getAtlasMappingWithLookupTables(String... names) {
    AtlasMapping mapping = this.getAtlasMappingFullValid();
    LookupTables lookupTables = new LookupTables();
    mapping.setLookupTables(lookupTables);
    for (String name : names) {
        LookupTable lookupTable = new LookupTable();
        lookupTable.setName(name);
        lookupTable.setDescription("desc_".concat(name));
        lookupTables.getLookupTable().add(lookupTable);
        Mapping lookupFieldMapping = AtlasModelFactory.createMapping(MappingType.LOOKUP);
        lookupFieldMapping.setDescription("field_desc_".concat(name));
        lookupFieldMapping.setLookupTableName(name);
        Field inputField = createInputJavaField("inputName");
        Field outputField = createInputJavaField("outputName");
        lookupFieldMapping.getInputField().add(inputField);
        lookupFieldMapping.getOutputField().add(outputField);
        mapping.getMappings().getMapping().add(lookupFieldMapping);
    }
    return mapping;
}
Also used : MockField(io.atlasmap.v2.MockField) Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) LookupTables(io.atlasmap.v2.LookupTables) LookupTable(io.atlasmap.v2.LookupTable) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 33 with Mapping

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

the class AtlasMappingServiceTest method assertAtlasMapping.

private void assertAtlasMapping(AtlasMapping mapping) {
    Assert.assertNotNull(mapping);
    Assert.assertEquals("core-unit-test", mapping.getName());
    Assert.assertNotNull(mapping.getMappings());
    Assert.assertNotNull(mapping.getMappings().getMapping());
    Assert.assertNotNull(mapping.getMappings().getMapping().get(0));
    BaseMapping m = mapping.getMappings().getMapping().get(0);
    Assert.assertEquals(MappingType.MAP, m.getMappingType());
    Assert.assertEquals(Mapping.class, m.getClass());
    Assert.assertNotNull(((Mapping) m).getInputField());
    Field input = ((Mapping) m).getInputField().get(0);
    Assert.assertEquals("/orderId", input.getPath());
    Assert.assertNotNull(((Mapping) m).getOutputField());
    Field output = ((Mapping) m).getOutputField().get(0);
    Assert.assertEquals("/orderId", output.getPath());
}
Also used : Field(io.atlasmap.v2.Field) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 34 with Mapping

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

the class Atlasmap233Test method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/atlasmap-233-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    session.setSourceDocument("io.atlasmap.core.issue.SourceClass", new SourceClass().setSourceInteger(-1));
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
    assertEquals(TargetClass.class, output.getClass());
    assertEquals(1, ((TargetClass) 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 35 with Mapping

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

the class CombineSeparateChangeDelimiterTest method test.

@Test
public void test() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/issue/combine-separate-change-delimiter-mapping.xml");
    AtlasMapping mapping = mappingService.loadMapping(url, AtlasMappingFormat.XML);
    AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(mapping);
    AtlasSession session = context.createSession();
    SourceClass source = new SourceClass().setSourceFirstName("Manjiro").setSourceLastName("Nakahama").setSourceName("Manjiro,Nakahama");
    session.setSourceDocument("io.atlasmap.core.issue.SourceClass", source);
    context.process(session);
    assertFalse(TestHelper.printAudit(session), session.hasErrors());
    assertFalse(TestHelper.printAudit(session), session.hasWarns());
    Object output = session.getTargetDocument("io.atlasmap.core.issue.TargetClass");
    assertEquals(TargetClass.class, output.getClass());
    TargetClass target = TargetClass.class.cast(output);
    assertEquals("Manjiro", target.getTargetFirstName());
    assertEquals("Nakahama", target.getTargetLastName());
    assertEquals("Manjiro,Nakahama", target.getTargetName());
}
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)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)120 Mapping (io.atlasmap.v2.Mapping)83 Test (org.junit.Test)65 BaseMapping (io.atlasmap.v2.BaseMapping)29 Field (io.atlasmap.v2.Field)28 Validation (io.atlasmap.v2.Validation)26 DataSource (io.atlasmap.v2.DataSource)21 JavaField (io.atlasmap.java.v2.JavaField)19 MockField (io.atlasmap.v2.MockField)17 Mappings (io.atlasmap.v2.Mappings)11 SimpleField (io.atlasmap.v2.SimpleField)11 MappingType (io.atlasmap.v2.MappingType)10 PropertyField (io.atlasmap.v2.PropertyField)9 File (java.io.File)9 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 AtlasContext (io.atlasmap.api.AtlasContext)8 AtlasSession (io.atlasmap.api.AtlasSession)8 Actions (io.atlasmap.v2.Actions)8 BaseValidatorTest (io.atlasmap.validators.BaseValidatorTest)8