use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JavaJsonCombineTest method testProcessCombineOutOfOrder.
@Test
public void testProcessCombineOutOfOrder() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-combine-outoforder.xml").toURI());
AtlasSession session = context.createSession();
BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
session.setDefaultSourceDocument(sourceContact);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper mapper = new AtlasJsonTestUnrootedMapper();
io.atlasmap.json.test.TargetContact targetContact = mapper.readValue((String) object, io.atlasmap.json.test.TargetContact.class);
assertEquals("Ozzie Smith 5551212 81111", targetContact.getFirstName());
assertNull(targetContact.getLastName());
assertNull(targetContact.getPhoneNumber());
assertNull(targetContact.getZipCode());
assertFalse(session.hasErrors());
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JsonJsonAutoConversionTest method executeMapping.
protected TargetFlatPrimitive executeMapping(String fileName) throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File(fileName).toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-flatprimitive-unrooted-autoconversion.json");
session.setDefaultSourceDocument(source);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
return testMapper.readValue((String) object, TargetFlatPrimitive.class);
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JsonJsonCollectionConversionTest method testProcessCollectionListSimple.
@Test
public void testProcessCollectionListSimple() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-collection-list-simple.xml").toURI());
// contact<>.firstName -> contact<>.name
String input = "{ \"contact\": [";
for (int i = 0; i < 3; i++) {
input += "{ \"firstName\": \"name" + i + "\"}";
input += (i == 2) ? "" : ",";
}
input += "] }";
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(input);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
String output = "{\"contact\":[";
for (int i = 0; i < 3; i++) {
output += "{\"name\":\"name" + i + "\"}";
output += (i == 2) ? "" : ",";
}
output += "]}";
assertEquals(output, object);
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JsonJsonCollectionConversionTest method testProcessCollectionToNonCollection.
@Test
public void testProcessCollectionToNonCollection() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-collection-to-noncollection.xml").toURI());
// contact<>.firstName -> contact.name
String input = "{ \"contact\": [";
for (int i = 0; i < 3; i++) {
input += "{ \"firstName\": \"name" + i + "\"}";
input += (i == 2) ? "" : ",";
}
input += "] }";
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(input);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
String output = "{\"contact\":{\"name\":\"name2\"}}";
assertEquals(output, object);
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JsonJsonComplexTest method testProcessJsonJsonComplexOrderAutodetectUnrooted.
@Test
public void testProcessJsonJsonComplexOrderAutodetectUnrooted() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJson/atlasmapping-complex-order-autodetect-unrooted.xml").toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJson/atlas-json-complex-order-autodetect-unrooted.json");
session.setDefaultSourceDocument(source);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
TargetOrder targetObject = testMapper.readValue((String) object, TargetOrder.class);
AtlasTestUtil.validateJsonOrder(targetObject);
}
Aggregations