use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class JavaJavaComplexTest method testProcessJavaJavaComplexWithAbstractBasic.
@Test
public void testProcessJavaJavaComplexWithAbstractBasic() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-complex-abstract.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());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof TargetOrder);
TargetOrder targetOrder = (TargetOrder) object;
assertNotNull(targetOrder.getOrderId());
assertEquals(new Integer(8765309), targetOrder.getOrderId());
// Address should _not_ be populated
assertNull(targetOrder.getAddress());
// Contact should only have firstName populated
assertNotNull(targetOrder.getContact());
assertTrue(targetOrder.getContact() instanceof TargetContact);
TargetContact targetContact = (TargetContact) targetOrder.getContact();
assertNotNull(targetContact.getFirstName());
assertEquals("Ozzie", targetContact.getFirstName());
assertNull(targetContact.getLastName());
assertNull(targetContact.getPhoneNumber());
assertNull(targetContact.getZipCode());
}
use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class JavaJavaMultiSourceTest method testProcessComplex.
@Test
public void testProcessComplex() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-multisource-complex.xml").toURI());
AtlasSession session = context.createSession();
BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
BaseAddress sourceAddress = AtlasTestUtil.generateAddress(SourceAddress.class);
session.setSourceDocument("con", sourceContact);
session.setSourceDocument("addr", sourceAddress);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertEquals(TargetOrder.class.getName(), object.getClass().getName());
TargetOrder targetOrder = (TargetOrder) object;
AtlasTestUtil.validateOrder(targetOrder);
}
use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class JsonJavaComplexTest method testProcessJsonJavaComplexOrderAutodetectRooted.
@Test
public void testProcessJsonJavaComplexOrderAutodetectRooted() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJava/atlasmapping-complex-order-autodetect-rooted.xml").toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJava/atlas-json-complex-order-autodetect-rooted.json");
session.setDefaultSourceDocument(source);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof TargetOrder);
AtlasTestUtil.validateOrder((TargetOrder) object);
}
use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class JsonJavaComplexTest method testProcessJsonJavaComplexOrderAutodetectUnrooted.
@Test
public void testProcessJsonJavaComplexOrderAutodetectUnrooted() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJava/atlasmapping-complex-order-autodetect-unrooted.xml").toURI());
AtlasSession session = context.createSession();
String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJava/atlas-json-complex-order-autodetect-unrooted.json");
session.setDefaultSourceDocument(source);
context.process(session);
Object object = session.getDefaultTargetDocument();
assertNotNull(object);
assertTrue(object instanceof TargetOrder);
AtlasTestUtil.validateOrder((TargetOrder) object);
}
use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class JavaWriterUtilMock method getObjectFromParent.
/**
* Retrieve a child object (which may be a complex class or collection class)
* from the given parentObject.
*
* @param field
* - provided for convenience, probably not needed here
* @param ParentObject
* - the object to find the child on
* @param segmentContext
* - the segment of the field's path that references the child object
*/
@Override
public Object getObjectFromParent(Field field, Object parentObject, SegmentContext segmentContext) throws AtlasException {
String segment = segmentContext.getSegment();
if (LOG.isDebugEnabled()) {
LOG.debug("Retrieving child '" + segmentContext.getSegmentPath() + "'.\n\tparentObject: " + parentObject);
}
if (parentObject == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cannot find child '" + segmentContext.getSegmentPath() + "', parent is null.");
}
return null;
}
// clean up our segment from something like "@addressLine1" to "addressLine1".
// collection segments like "orders[4]" will be cleaned to "orders"
String cleanedSegment = AtlasPath.cleanPathSegment(segmentContext.getSegment());
Object childObject = null;
if (parentObject instanceof TargetAddress && "addressLine1".equals(cleanedSegment)) {
childObject = ((TargetAddress) parentObject).getAddressLine1();
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TestListOrders) {
childObject = ((TestListOrders) parentObject).getOrders();
} else if ("orders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
childObject = ((TargetOrderArray) parentObject).getOrders();
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
childObject = ((TargetOrder) parentObject).getAddress();
} else if ("address".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = ((TargetTestClass) parentObject).getAddress();
} else if ("listOrders".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = ((TargetTestClass) parentObject).getListOrders();
} else if ("orderArray".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = ((TargetTestClass) parentObject).getOrderArray();
} else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
childObject = ((TargetOrder) parentObject).getContact();
} else if ("numberOrders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
childObject = ((TargetOrderArray) parentObject).getNumberOrders();
} else if ("primitives".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = ((TargetTestClass) parentObject).getPrimitives();
} else if ("intArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
childObject = ((TargetFlatPrimitiveClass) parentObject).getIntArrayField();
} else if ("boxedStringArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
childObject = ((TargetFlatPrimitiveClass) parentObject).getBoxedStringArrayField();
} else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = ((TargetTestClass) parentObject).getContact();
} else if ("nothing".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
childObject = null;
} else {
String clz = parentObject.getClass().getSimpleName();
String getter = "get" + cleanedSegment.substring(0, 1).toUpperCase() + cleanedSegment.substring(1);
String fix = "} else if (\"" + cleanedSegment + "\".equals(cleanedSegment) && parentObject instanceof " + clz + ") {\n " + "childObject = ((" + clz + ")parentObject)." + getter + "();";
LOG.error(fix);
throw new AtlasException("Don't know how to handle get object from parent: " + parentObject + ", segment: " + cleanedSegment);
}
// FIXME: Matt, right? an @ here indicates use the getter, or does @ mean access
// member?
boolean useGetter = AtlasPath.isAttributeSegment(segment);
if (useGetter) {
// FIXME: matt, something like this, but with reflection and what not
// childObject = parentObject.getAddressLine1();
} else {
// FIXME: Matt, something lik this, but with reflection
// childObject = parentObject.addressLine1;
}
if (LOG.isDebugEnabled()) {
if (childObject == null) {
LOG.debug("Could not find child object for path: " + segmentContext.getSegmentPath());
} else {
LOG.debug("Found child object for path '" + segmentContext.getSegmentPath() + "': " + childObject);
}
}
// TODO: matt, should we throw an exception here if null?
return childObject;
}
Aggregations