Search in sources :

Example 66 with Mapping

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

the class BaseMarshallerTest method generateConstantMapping.

protected AtlasMapping generateConstantMapping() {
    AtlasMapping mapping = generateAtlasMapping();
    ConstantField inputField = new ConstantField();
    Actions actions = new Actions();
    actions.getActions().add(new Trim());
    populateFieldComplexObject(inputField, actions, CollectionType.ARRAY, FieldStatus.SUPPORTED, FieldType.INTEGER);
    populateFieldSimpleObject(inputField, 3, "docid", "/path", false, "bar");
    Mapping fm = (Mapping) mapping.getMappings().getMapping().get(0);
    fm.getInputField().add(inputField);
    fm.getOutputField().add(inputField);
    populateMapping(fm, MappingType.MAP, "MapPropertyFieldAlias", ",", ",");
    populateMappingString(fm, "description", "id", "lookupTableName", "strategy", "strategyClassName");
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) ConstantField(io.atlasmap.v2.ConstantField) Actions(io.atlasmap.v2.Actions) Trim(io.atlasmap.v2.Trim) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 67 with Mapping

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

the class BaseMarshallerTest method validateAtlasMapping.

protected void validateAtlasMapping(AtlasMapping atlasMapping) {
    assertNotNull(atlasMapping);
    assertEquals("junit", atlasMapping.getName());
    assertEquals(2, atlasMapping.getDataSource().size());
    valiateDataSource(atlasMapping.getDataSource().get(0), DataSourceType.SOURCE, "srcId", "srcUri");
    valiateDataSource(atlasMapping.getDataSource().get(1), DataSourceType.TARGET, "tgtId", "tgtUri");
    assertNotNull(atlasMapping.getLookupTables());
    assertEquals(1, atlasMapping.getLookupTables().getLookupTable().size());
    validateLookupTable(atlasMapping.getLookupTables().getLookupTable().get(0));
    assertNotNull(atlasMapping.getMappings());
    assertEquals(1, atlasMapping.getMappings().getMapping().size());
    Mapping mapping = (Mapping) atlasMapping.getMappings().getMapping().get(0);
    assertEquals(1, mapping.getInputField().size());
    validateJavaField((JavaField) mapping.getInputField().get(0));
    assertEquals(1, mapping.getOutputField().size());
    validateJavaField((JavaField) mapping.getOutputField().get(0));
    validateMapping(mapping, MappingType.MAP, generateMappingParams());
    assertNotNull(atlasMapping.getProperties());
    assertEquals(1, atlasMapping.getProperties().getProperty().size());
    validateProperty(atlasMapping.getProperties().getProperty().get(0));
}
Also used : Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 68 with Mapping

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

the class BaseMarshallerTest method generateSeparateAtlasMapping.

protected AtlasMapping generateSeparateAtlasMapping() {
    Actions actions = generateActions();
    StringList annotations = generateAnnotations();
    ModifierList modifierList = generateModifierList();
    StringList parameterizedTypes = generateParameterizedTypes();
    JavaField inputJavaField = generateJavaField(actions, annotations, modifierList, parameterizedTypes);
    JavaField outputJavaFieldA = generateJavaField(actions, annotations, modifierList, parameterizedTypes);
    JavaField outputJavaFieldB = generateJavaField(actions, annotations, modifierList, parameterizedTypes);
    Mapping fm = (Mapping) AtlasModelFactory.createMapping(MappingType.SEPARATE);
    fm.getInputField().add(inputJavaField);
    fm.getOutputField().add(outputJavaFieldA);
    fm.getOutputField().add(outputJavaFieldB);
    populateMapping(fm, MappingType.SEPARATE, "MapPropertyFieldAlias", ",", ",");
    populateMappingString(fm, "description", "id", "lookupTableName", "strategy", "strategyClassName");
    AtlasMapping mapping = generateAtlasMapping();
    mapping.getMappings().getMapping().clear();
    mapping.getMappings().getMapping().add(fm);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Actions(io.atlasmap.v2.Actions) StringList(io.atlasmap.v2.StringList) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping)

Example 69 with Mapping

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

the class JavaJavaFlatMappingTest method generateJavaJavaFlatMapping.

protected AtlasMapping generateJavaJavaFlatMapping() {
    AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
    atlasMapping.setName("JavaJavaFlatMapping");
    atlasMapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.test.SourceFlatPrimitiveClass", DataSourceType.SOURCE));
    atlasMapping.getDataSource().add(generateDataSource("atlas:java?className=io.atlasmap.java.test.TargetFlatPrimitiveClass", 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(generateJavaField(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 70 with Mapping

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

the class JavaJavaDateTimeMappingTest method doTest.

private void doTest(int offset) throws Exception {
    AtlasMapping atlasMapping = AtlasModelFactory.createAtlasMapping();
    atlasMapping.setName("JavaJavaDateTimeMapping");
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.SOURCE);
    addDataSource(atlasMapping, "atlas:java?className=io.atlasmap.java.test.DateTimeClass", DataSourceType.TARGET);
    List<BaseMapping> mappings = atlasMapping.getMappings().getMapping();
    for (int i = 0; i < DATE_TIME_FIELDS.length; i++) {
        int targetIndex = offset + i < DATE_TIME_FIELDS.length ? offset + i : offset + i - DATE_TIME_FIELDS.length;
        JavaField sourceField = copyJavaField(DATE_TIME_FIELDS[i]);
        JavaField targetField = copyJavaField(DATE_TIME_FIELDS[targetIndex]);
        if (UNSUPPORTED.containsKey(sourceField.getFieldType()) && UNSUPPORTED.get(sourceField.getFieldType()).equals(targetField.getFieldType())) {
            sourceField = copyJavaField(targetField);
        }
        Mapping mfm = AtlasModelFactory.createMapping(MappingType.MAP);
        mfm.getInputField().add(sourceField);
        mfm.getOutputField().add(targetField);
        mappings.add(mfm);
    }
    AtlasContext context = ((DefaultAtlasContextFactory) atlasContextFactory).createContext(atlasMapping);
    AtlasSession session = context.createSession();
    session.setDefaultSourceDocument(createSource());
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof DateTimeClass);
    validateTarget((DateTimeClass) object);
}
Also used : DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) AtlasMapping(io.atlasmap.v2.AtlasMapping) JavaField(io.atlasmap.java.v2.JavaField) DateTimeClass(io.atlasmap.java.test.DateTimeClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasSession(io.atlasmap.api.AtlasSession) BaseMapping(io.atlasmap.v2.BaseMapping)

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