Search in sources :

Example 76 with AtlasSession

use of io.atlasmap.api.AtlasSession 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 77 with AtlasSession

use of io.atlasmap.api.AtlasSession 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 78 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class OverloadedFieldActionsTest method testMappingDayOfWeekString.

@Test
public void testMappingDayOfWeekString() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(generateMappingDayOfWeek(String.class));
    AtlasSession session = context.createSession();
    SourceFlatPrimitiveClass src = new SourceFlatPrimitiveClass();
    src.setBoxedStringField("mon");
    session.setInput(src);
    context.process(session);
    Object tgt = session.getOutput();
    assertNotNull(tgt);
    assertTrue(tgt.getClass().isAssignableFrom(TargetFlatPrimitiveClass.class));
    System.out.println(((TargetFlatPrimitiveClass) tgt).getBoxedStringField());
}
Also used : TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 79 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testProcessAtlasExceptionUnspported.

@Test(expected = AtlasException.class)
public void testProcessAtlasExceptionUnspported() throws AtlasException {
    AtlasSession session = spy(AtlasSession.class);
    context.process(session);
}
Also used : AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 80 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class AtlasEndpoint method populateTargetDocuments.

private void populateTargetDocuments(AtlasSession session, Exchange exchange) {
    Message outMessage = exchange.getOut();
    outMessage.setHeaders(exchange.getIn().getHeaders());
    outMessage.setAttachments(exchange.getIn().getAttachments());
    if (session.getMapping().getDataSource() == null) {
        return;
    }
    DataSource[] targetDataSources = session.getMapping().getDataSource().stream().filter(ds -> ds.getDataSourceType() == DataSourceType.TARGET).toArray(DataSource[]::new);
    if (targetDataSources.length == 0) {
        outMessage.setBody(session.getDefaultTargetDocument());
        return;
    }
    if (targetDataSources.length == 1) {
        String docId = targetDataSources[0].getId();
        if (docId == null || docId.isEmpty()) {
            outMessage.setBody(session.getDefaultTargetDocument());
        } else {
            outMessage.setBody(session.getTargetDocument(docId));
        }
        setContentType(targetDataSources[0], outMessage);
        return;
    }
    // TODO handle headers docId - https://github.com/atlasmap/atlasmap/issues/67
    Map<String, Object> targetDocuments = new HashMap<>();
    for (DataSource ds : targetDataSources) {
        String docId = ds.getId();
        if (docId == null || docId.isEmpty()) {
            outMessage.setBody(session.getDefaultTargetDocument());
            setContentType(ds, outMessage);
        } else {
            targetDocuments.put(docId, session.getTargetDocument(docId));
        }
    }
    exchange.setProperty(targetMapName, targetDocuments);
}
Also used : Message(org.apache.camel.Message) LoggerFactory(org.slf4j.LoggerFactory) DataSource(io.atlasmap.v2.DataSource) DefaultAtlasContextFactory(io.atlasmap.core.DefaultAtlasContextFactory) HashMap(java.util.HashMap) Exchange(org.apache.camel.Exchange) AtlasMappingFormat(io.atlasmap.core.AtlasMappingService.AtlasMappingFormat) ArrayList(java.util.ArrayList) UriEndpoint(org.apache.camel.spi.UriEndpoint) UriParam(org.apache.camel.spi.UriParam) Map(java.util.Map) ResourceEndpoint(org.apache.camel.component.ResourceEndpoint) ResourceHelper(org.apache.camel.util.ResourceHelper) AtlasContextFactory(io.atlasmap.api.AtlasContextFactory) ExchangePattern(org.apache.camel.ExchangePattern) Properties(java.util.Properties) Logger(org.slf4j.Logger) AtlasException(io.atlasmap.api.AtlasException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) DataSourceType(io.atlasmap.v2.DataSourceType) List(java.util.List) StringReader(java.io.StringReader) AtlasMapping(io.atlasmap.v2.AtlasMapping) Audit(io.atlasmap.v2.Audit) IOHelper(org.apache.camel.util.IOHelper) AtlasSession(io.atlasmap.api.AtlasSession) ObjectHelper(org.apache.camel.util.ObjectHelper) AtlasContext(io.atlasmap.api.AtlasContext) InputStream(java.io.InputStream) Message(org.apache.camel.Message) HashMap(java.util.HashMap) DataSource(io.atlasmap.v2.DataSource)

Aggregations

AtlasSession (io.atlasmap.api.AtlasSession)157 AtlasContext (io.atlasmap.api.AtlasContext)140 Test (org.junit.Test)134 File (java.io.File)129 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)123 TargetContact (io.atlasmap.java.test.TargetContact)31 BaseContact (io.atlasmap.java.test.BaseContact)26 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)13 BaseOrder (io.atlasmap.java.test.BaseOrder)12 TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetTestClass (io.atlasmap.java.test.TargetTestClass)11 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)9 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)8 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)7 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)7 URL (java.net.URL)4 Message (org.apache.camel.Message)4