use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JavaJavaComplexTest method testProcessComplexBasic.
@Test
public void testProcessComplexBasic() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-complex-simple.xml").toURI());
AtlasSession session = context.createSession();
BaseOrder sourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
session.setDefaultSourceDocument(sourceOrder);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
assertEquals(TargetContact.class.getName(), object.getContact().getClass().getName());
assertEquals("Ozzie", object.getContact().getFirstName());
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JavaJavaComplexTest method testProcessJavaJavaComplexAutoDetectFullActions.
@Test
public void testProcessJavaJavaComplexAutoDetectFullActions() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-complex-autodetect-full-actions.xml"));
AtlasSession session = context.createSession();
BaseOrder sourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
session.setDefaultSourceDocument(sourceOrder);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof TargetOrder);
// ensure our Uppercase action on first name did the right thing
assertEquals("OZZIE", ((TargetOrder) object).getContact().getFirstName());
assertEquals("smith", ((TargetOrder) object).getContact().getLastName());
// set values to normalized pre-action-processing state so rest of validation
// passes..
((TargetOrder) object).getContact().setFirstName("Ozzie");
((TargetOrder) object).getContact().setLastName("Smith");
AtlasTestUtil.validateOrder((TargetOrder) object);
}
use of io.atlasmap.api.AtlasSession 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);
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JavaJsonFlatMappingTest method testProcessJavaJsonFlatPrimitiveUnrooted.
@Test
public void testProcessJavaJsonFlatPrimitiveUnrooted() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-flatprimitive-unrooted.xml"));
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(generateFlatPrimitiveClass(SourceFlatPrimitiveClass.class));
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
}
use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.
the class JavaJsonFlatMappingTest method testProcessJavaJsonFlatPrimitiveRooted.
@Test
public void testProcessJavaJsonFlatPrimitiveRooted() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJson/atlasmapping-flatprimitive-rooted.xml"));
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(generateFlatPrimitiveClass(SourceFlatPrimitiveClass.class));
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof String);
AtlasJsonTestRootedMapper testMapper = new AtlasJsonTestRootedMapper();
TargetFlatPrimitive targetObject = testMapper.readValue((String) object, TargetFlatPrimitive.class);
AtlasTestUtil.validateJsonFlatPrimitivePrimitiveFields(targetObject);
}
Aggregations