Search in sources :

Example 26 with Mapping

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

the class BaseMarshallerTest method generateCollectionMapping.

protected AtlasMapping generateCollectionMapping() {
    AtlasMapping innerMapping1 = generateAtlasMapping();
    AtlasMapping innerMapping2 = generateAtlasMapping();
    Collection cMapping = new Collection();
    cMapping.getMappings().getMapping().addAll(innerMapping1.getMappings().getMapping());
    cMapping.getMappings().getMapping().addAll(innerMapping2.getMappings().getMapping());
    cMapping.setCollectionType(CollectionType.LIST);
    AtlasMapping mapping = generateAtlasMapping();
    mapping.getMappings().getMapping().clear();
    mapping.getMappings().getMapping().add(cMapping);
    return mapping;
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) Collection(io.atlasmap.v2.Collection)

Example 27 with Mapping

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

the class DefaultAtlasContextTest method testInit.

// (expected = AtlasException.class)
@Test
public void testInit() throws AtlasException {
    File file = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "atlasmapping.json").toFile();
    DefaultAtlasContext ctx = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), file.toURI(), AtlasMappingFormat.JSON);
    ctx.init();
    DataSource dataSource = new DataSource();
    dataSource.setUri("URI");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri(null);
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:source");
    dataSource.setDataSourceType(DataSourceType.SOURCE);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:target");
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    dataSource = new DataSource();
    dataSource.setUri("java:target");
    dataSource.setDataSourceType(DataSourceType.TARGET);
    dataSource.setId("io.atlasmap.core.DefaultAtlasContext.constants.docId");
    mapping.getDataSource().add(dataSource);
    ctx = new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping);
    ctx.getTargetModules().put("io.atlasmap.core.DefaultAtlasContext.constants.docId", new ConstantModule());
    ctx.init();
    @SuppressWarnings("unchecked") Map<String, AtlasModule> targetModules = spy(Map.class);
    when(targetModules.put(any(String.class), any(AtlasModule.class))).thenThrow(new RuntimeException("mockException"));
    ctx.setTargetModules(targetModules);
    ctx.init();
}
Also used : AtlasModule(io.atlasmap.spi.AtlasModule) File(java.io.File) DataSource(io.atlasmap.v2.DataSource) Test(org.junit.Test)

Example 28 with Mapping

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

the class DefaultAtlasContextTest method testProcess.

@Test
public void testProcess() throws AtlasException {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    when(session.getAtlasContext()).thenReturn(context);
    Head head = mock(Head.class);
    when(session.head()).thenReturn(head);
    when(head.setMapping(any(Mapping.class))).thenReturn(head);
    when(head.setLookupTable(any(LookupTable.class))).thenReturn(head);
    Field headField = mock(ConstantField.class);
    when(head.getSourceField()).thenReturn(headField);
    Audits audits = mock(Audits.class);
    when(session.getAudits()).thenReturn(audits);
    Validations validations = mock(Validations.class);
    when(session.getValidations()).thenReturn(validations);
    AtlasMapping mapping = mock(AtlasMapping.class);
    when(session.getMapping()).thenReturn(mapping);
    when(session.hasErrors()).thenReturn(true);
    context.process(session);
    when(session.hasErrors()).thenReturn(false);
    Mappings mappings = mock(Mappings.class);
    when(mapping.getMappings()).thenReturn(mappings);
    List<BaseMapping> baseMappings = new ArrayList<>();
    Collection baseMapping = mock(Collection.class);
    when(baseMapping.getMappingType()).thenReturn(MappingType.COLLECTION);
    baseMappings.add(baseMapping);
    when(mappings.getMapping()).thenReturn(baseMappings);
    Mappings subMappings = mock(Mappings.class);
    when(baseMapping.getMappings()).thenReturn(subMappings);
    List<BaseMapping> baseMappingList = new ArrayList<>();
    Mapping mappingElement1 = mock(Mapping.class);
    List<Field> sourceFieldList = new ArrayList<>();
    ConstantField sourceField = mock(ConstantField.class);
    sourceFieldList.add(sourceField);
    when(sourceField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getInputField()).thenReturn(sourceFieldList);
    List<Field> outputFieldList = new ArrayList<>();
    Field outputField = mock(Field.class);
    outputFieldList.add(outputField);
    when(outputField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getOutputField()).thenReturn(outputFieldList);
    when(mappingElement1.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement1);
    when(subMappings.getMapping()).thenReturn(baseMappingList);
    Mapping mappingElement2 = mock(Mapping.class);
    when(mappingElement2.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement2);
    List<Field> sourceFieldList2 = new ArrayList<>();
    ConstantField sourceField2 = mock(ConstantField.class);
    sourceFieldList2.add(sourceField2);
    when(sourceField2.getPath()).thenReturn("contact[1]");
    when(mappingElement2.getInputField()).thenReturn(sourceFieldList2);
    ConstantModule mockConstantModule = mock(ConstantModule.class);
    when(mockConstantModule.getCollectionSize(any(AtlasInternalSession.class), any(Field.class))).thenReturn(1);
    ConstantField clonedField = mock(ConstantField.class);
    when(clonedField.getPath()).thenReturn("cloned[1]");
    when(mockConstantModule.cloneField(any(Field.class))).thenReturn(clonedField);
    List<Field> mockSourceFieldList = new ArrayList<>();
    ConstantField mockSourceField = mock(ConstantField.class);
    mockSourceFieldList.add(mockSourceField);
    when(mockSourceField.getPath()).thenReturn("source[1]");
    when(mappingElement2.getInputField()).thenReturn(mockSourceFieldList);
    List<Field> mockOutputFieldList = new ArrayList<>();
    ConstantField mockOutputField = mock(ConstantField.class);
    mockOutputFieldList.add(mockOutputField);
    when(mockOutputField.getPath()).thenReturn("output[1]");
    when(mappingElement2.getOutputField()).thenReturn(mockOutputFieldList);
    context.getSourceModules().put(DefaultAtlasContext.CONSTANTS_DOCUMENT_ID, mockConstantModule);
    context.process(session);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ConstantField(io.atlasmap.v2.ConstantField) ArrayList(java.util.ArrayList) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Field(io.atlasmap.v2.Field) ConstantField(io.atlasmap.v2.ConstantField) Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTable(io.atlasmap.v2.LookupTable) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Example 29 with Mapping

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

the class DefaultAtlasContextTest method testLookupTable.

@Test
public void testLookupTable() throws Exception {
    LookupTable table = new LookupTable();
    table.setName("table");
    LookupEntry e = new LookupEntry();
    e.setSourceValue("foo");
    e.setTargetValue("bar");
    table.getLookupEntry().add(e);
    context.getLookupTables().put(table.getName(), table);
    Mapping m = (Mapping) AtlasModelFactory.createMapping(MappingType.LOOKUP);
    mapping.getMappings().getMapping().add(m);
    m.setLookupTableName("table");
    populateSourceField(m, FieldType.STRING, "foo");
    prepareTargetField(m, "/target");
    context.process(session);
    Assert.assertFalse(printAudit(session), session.hasErrors());
    Assert.assertEquals("bar", writer.targets.get("/target"));
}
Also used : LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test)

Example 30 with Mapping

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

the class BaseMappingTest method createMockMappedFields.

protected void createMockMappedFields(AtlasMapping mapping, Mapping mapFieldMapping) {
    // Mock MappedField
    MockField inputField = new MockField();
    inputField.setName("input.name");
    MockField outputField = new MockField();
    outputField.setName("out.name");
    mapFieldMapping.getInputField().add(inputField);
    mapFieldMapping.getOutputField().add(outputField);
    mapping.getMappings().getMapping().add(mapFieldMapping);
}
Also used : MockField(io.atlasmap.v2.MockField)

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