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());
}
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());
}
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());
}
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);
}
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);
}
Aggregations