Search in sources :

Example 51 with Mappings

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

the class OverloadedFieldActionsTest method generateMappingDayOfWeek.

protected AtlasMapping generateMappingDayOfWeek(Class<?> clazz) {
    AtlasMapping m = new AtlasMapping();
    DataSource s = new DataSource();
    s.setDataSourceType(DataSourceType.SOURCE);
    s.setUri("atlas:java?className=io.atlasmap.java.test.SourceFlatPrimitiveClass");
    DataSource t = new DataSource();
    t.setDataSourceType(DataSourceType.TARGET);
    t.setUri("atlas:java?className=io.atlasmap.java.test.TargetFlatPrimitiveClass");
    m.getDataSource().add(s);
    m.getDataSource().add(t);
    Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
    JavaField srcF = new JavaField();
    Actions acts = new Actions();
    srcF.setActions(acts);
    JavaField tgtF = new JavaField();
    if (clazz.isAssignableFrom(String.class)) {
        srcF.setPath("boxedStringField");
        srcF.getActions().getActions().add(new DayOfWeekString());
        tgtF.setPath("boxedStringField");
    } else if (clazz.isAssignableFrom(Integer.class)) {
        srcF.setPath("intField");
        srcF.getActions().getActions().add(new DayOfWeekInteger());
        tgtF.setPath("boxedStringField");
    }
    mfm.getInputField().add(srcF);
    mfm.getOutputField().add(tgtF);
    Mappings maps = new Mappings();
    maps.getMapping().add(mfm);
    m.setMappings(maps);
    return m;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) Mappings(io.atlasmap.v2.Mappings) Actions(io.atlasmap.v2.Actions) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) DataSource(io.atlasmap.v2.DataSource)

Example 52 with Mappings

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

the class AtlasBaseActionsTest method runActionTestList.

public Object runActionTestList(List<Action> actions, String sourceFirstName, Object targetExpected, Class<?> targetClassExpected) throws Exception {
    System.out.println("Now running test for actions: " + actions);
    System.out.println("Input: " + sourceFirstName);
    System.out.println("Expected output: " + targetExpected);
    Mapping m = new Mapping();
    m.setMappingType(MappingType.MAP);
    m.getInputField().add(this.sourceField);
    m.getOutputField().add(this.targetField);
    if (actions != null) {
        m.getOutputField().get(0).setActions(new Actions());
        m.getOutputField().get(0).getActions().getActions().addAll(actions);
    }
    DataSource src = new DataSource();
    src.setDataSourceType(DataSourceType.SOURCE);
    src.setUri(this.docURI);
    DataSource tgt = new DataSource();
    tgt.setDataSourceType(DataSourceType.TARGET);
    tgt.setUri(this.docURI);
    AtlasMapping atlasMapping = new AtlasMapping();
    atlasMapping.setName("fieldactiontest");
    atlasMapping.setMappings(new Mappings());
    atlasMapping.getMappings().getMapping().add(m);
    atlasMapping.getDataSource().add(src);
    atlasMapping.getDataSource().add(tgt);
    String tmpFile = "target/fieldactions-" + this.getClass().getSimpleName() + "-tmp.txt";
    DefaultAtlasContextFactory.getInstance().getMappingService().saveMappingAsFile(atlasMapping, new File(tmpFile), AtlasMappingFormat.XML);
    AtlasContext context = atlasContextFactory.createContext(new File(tmpFile).toURI());
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(createSource(sourceFirstName));
    context.process(session);
    Object targetActual = session.getDefaultTargetDocument();
    assertNotNull(targetActual);
    targetActual = getTargetValue(targetActual, targetClassExpected);
    if (targetExpected != null) {
        assertEquals(targetExpected, targetActual);
    }
    return targetActual;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Actions(io.atlasmap.v2.Actions) AtlasContext(io.atlasmap.api.AtlasContext) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) SubString(io.atlasmap.v2.SubString) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) DataSource(io.atlasmap.v2.DataSource)

Example 53 with Mappings

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

the class JavaJavaComplexListTest method testGenerateListMappingBasic.

@Test
public void testGenerateListMappingBasic() throws Exception {
    AtlasMapping a = AtlasModelFactory.createAtlasMapping();
    a.setName("JavaJavaComplexListBase");
    DataSource s = new DataSource();
    s.setDataSourceType(DataSourceType.SOURCE);
    s.setUri("atlas:java?className=io.atlasmap.java.test.SourceOrderList");
    DataSource t = new DataSource();
    t.setDataSourceType(DataSourceType.TARGET);
    t.setUri("atlas:java?className=io.atlasmap.java.test.TargetOrderList");
    JavaField f1 = AtlasJavaModelFactory.createJavaField();
    f1.setPath("/numberOrders");
    f1.setModifiers(null);
    JavaField f2 = AtlasJavaModelFactory.createJavaField();
    f2.setPath("/orderBatchNumber");
    f2.setModifiers(null);
    Mapping m1 = AtlasModelFactory.createMapping(MappingType.MAP);
    m1.getInputField().add(f1);
    m1.getOutputField().add(f1);
    Mapping m2 = AtlasModelFactory.createMapping(MappingType.MAP);
    m2.getInputField().add(f2);
    m2.getOutputField().add(f2);
    JavaCollection cm = new JavaCollection();
    cm.setMappingType(MappingType.COLLECTION);
    cm.setCollectionType(CollectionType.LIST);
    JavaField f3 = AtlasJavaModelFactory.createJavaField();
    f3.setPath("/orders<>/orderId");
    f3.setModifiers(null);
    Mapping m3 = AtlasModelFactory.createMapping(MappingType.MAP);
    m3.getInputField().add(f3);
    m3.getOutputField().add(f3);
    if (cm.getMappings() == null) {
        cm.setMappings(new Mappings());
    }
    cm.getMappings().getMapping().add(m3);
    a.getDataSource().addAll(Arrays.asList(s, t));
    a.getMappings().getMapping().addAll(Arrays.asList(m1, m2, cm));
    AtlasMappingService atlasMappingService = new AtlasMappingService(Arrays.asList("io.atlasmap.v2", "io.atlasmap.java.v2", "io.atlasmap.xml.v2"));
    File path = new File("target/reference-mappings/javaToJava");
    path.mkdirs();
    atlasMappingService.saveMappingAsFile(a, new File(path, "atlasmapping-complex-list-autodetect-base.xml"));
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) JavaCollection(io.atlasmap.java.v2.JavaCollection) Mappings(io.atlasmap.v2.Mappings) AtlasMappingService(io.atlasmap.core.AtlasMappingService) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) DataSource(io.atlasmap.v2.DataSource) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Example 54 with Mappings

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

the class JavaJsonFlatMappingTest method generateJsonJavaFlatMapping.

protected AtlasMapping generateJsonJavaFlatMapping() {
    AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
    atlasMapping.setName("JsonJavaFlatMapping");
    atlasMapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.test.SourceFlatPrimitiveClass", DataSourceType.SOURCE));
    atlasMapping.getDataSource().add(generateDataSource("atlas:json", DataSourceType.TARGET));
    List<BaseMapping> mappings = atlasMapping.getMappings().getMapping();
    // Add fieldMappings
    for (String fieldName : FLAT_FIELDS) {
        Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
        mfm.getInputField().add(generateJavaField("/" + fieldName));
        mfm.getOutputField().add(generateJsonField("/" + fieldName));
        mappings.add(mfm);
    }
    return atlasMapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 55 with Mappings

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

the class JavaToXMLJSONMarshallingTest method testCombineMappingDemarshaller.

@Test
public void testCombineMappingDemarshaller() throws Exception {
    // this test is for AT-466: issue saving mappings in combine mode (parser
    // complaining about strategy property)
    // the json has been changed from what the UI was sending, now the "actions"
    // property on the output field is "null" rather than "[]"
    String filename = "src/test/resources/javaToXml/javaToXmlMapping-combine.json";
    AtlasMapping uMapping = mapper.readValue(new File(filename), AtlasMapping.class);
    assertNotNull(uMapping);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) File(java.io.File) Test(org.junit.Test)

Aggregations

AtlasMapping (io.atlasmap.v2.AtlasMapping)86 Mapping (io.atlasmap.v2.Mapping)50 Test (org.junit.jupiter.api.Test)45 BaseMapping (io.atlasmap.v2.BaseMapping)26 File (java.io.File)20 Mappings (io.atlasmap.v2.Mappings)16 Test (org.junit.Test)15 JavaField (io.atlasmap.java.v2.JavaField)14 AtlasContext (io.atlasmap.api.AtlasContext)12 AtlasSession (io.atlasmap.api.AtlasSession)12 DataSource (io.atlasmap.v2.DataSource)12 Validation (io.atlasmap.v2.Validation)11 Field (io.atlasmap.v2.Field)10 JsonField (io.atlasmap.json.v2.JsonField)7 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)7 DataSourceType (io.atlasmap.v2.DataSourceType)7 FieldType (io.atlasmap.v2.FieldType)7 MappingType (io.atlasmap.v2.MappingType)7 ProcessMappingResponse (io.atlasmap.v2.ProcessMappingResponse)7 ValidationScope (io.atlasmap.v2.ValidationScope)7