use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.
the class JavaConstructServiceComplexArrayTest method testConstructTargetOrderArray.
@Test
public void testConstructTargetOrderArray() throws Exception {
Object targetObject = constructService.constructClass(generateOrderArray("Target"), null);
assertNotNull(targetObject);
assertTrue(targetObject instanceof TargetOrderArray);
TargetOrderArray orderArray = (TargetOrderArray) targetObject;
for (int i = 0; i < orderArray.getOrders().length; i++) {
TargetOrder order = (TargetOrder) orderArray.getOrders()[i];
assertNotNull(order);
assertNotNull(order.getAddress());
assertTrue(order.getAddress() instanceof TargetAddress);
TargetAddress address = (TargetAddress) order.getAddress();
assertNull(address.getAddressLine1());
assertNull(address.getAddressLine2());
assertNull(address.getCity());
assertNull(address.getState());
assertNull(address.getZipCode());
assertNotNull(order.getContact());
assertTrue(order.getContact() instanceof TargetContact);
TargetContact contact = (TargetContact) order.getContact();
assertNull(contact.getFirstName());
assertNull(contact.getLastName());
assertNull(contact.getPhoneNumber());
assertNull(contact.getZipCode());
}
}
use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.
the class DocumentJavaFieldWriterTest method testSimpleWriteCollectionArray.
@Test
public void testSimpleWriteCollectionArray() throws Exception {
addClassForFieldPath("/", TargetOrderArray.class);
addClassForFieldPath("/orders[5]", TargetOrder.class);
addClassForFieldPath("/orders[5]/address", TargetAddress.class);
write("/orders[4]/address/addressLine1", "hello world.");
TargetOrderArray o = (TargetOrderArray) writer.getRootObject();
ensureNotNullAndClass(o, TargetOrderArray.class);
ensureNotNullAndClass(o.getOrders(), TargetOrder[].class);
assertEquals(5, o.getOrders().length);
for (int i = 0; i < 5; i++) {
System.out.println("Checking #" + i);
if (i == 4) {
ensureNotNullAndClass(o.getOrders()[i], TargetOrder.class);
ensureNotNullAndClass(o.getOrders()[i].getAddress(), TargetAddress.class);
} else {
assertNull(o.getOrders()[i]);
}
}
assertEquals("hello world.", o.getOrders()[4].getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.
the class JavaFieldWriterTest method testExpandCollectionArray.
@Test
public void testExpandCollectionArray() throws Exception {
writer.setRootObject(new TargetOrderArray());
writeComplex("/orders[4]", new TargetOrder());
writeComplex("/orders[4]/address", new TargetAddress());
write("/orders[4]/address/addressLine1", "hello world1.");
writeComplex("/orders[14]", new TargetOrder());
writeComplex("/orders[14]/address", new TargetAddress());
write("/orders[14]/address/addressLine1", "hello world2.");
writeComplex("/orders[2]", new TargetOrder());
writeComplex("/orders[2]/address", new TargetAddress());
write("/orders[2]/address/addressLine1", "hello world3.");
TargetOrderArray o = (TargetOrderArray) writer.getRootObject();
ensureNotNullAndClass(o, TargetOrderArray.class);
ensureNotNullAndClass(o.getOrders(), BaseOrder[].class);
assertEquals(15, o.getOrders().length);
for (int i = 0; i < 15; i++) {
System.out.println("Checking #" + i);
if (i == 4 || i == 14 || i == 2) {
ensureNotNullAndClass(o.getOrders()[i], TargetOrder.class);
ensureNotNullAndClass(o.getOrders()[i].getAddress(), TargetAddress.class);
} else {
assertNull(o.getOrders()[i]);
}
}
assertEquals("hello world1.", o.getOrders()[4].getAddress().getAddressLine1());
assertEquals("hello world2.", o.getOrders()[14].getAddress().getAddressLine1());
assertEquals("hello world3.", o.getOrders()[2].getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.
the class JavaFieldWriterTest method testSimpleWriteCollectionArray.
@Test
public void testSimpleWriteCollectionArray() throws Exception {
writer.setRootObject(new TargetOrderArray());
writeComplex("/orders[4]", new TargetOrder());
writeComplex("/orders[4]/address", new TargetAddress());
write("/orders[4]/address/addressLine1", "hello world.");
TargetOrderArray o = (TargetOrderArray) writer.getRootObject();
ensureNotNullAndClass(o, TargetOrderArray.class);
ensureNotNullAndClass(o.getOrders(), BaseOrder[].class);
assertEquals(5, o.getOrders().length);
for (int i = 0; i < 5; i++) {
System.out.println("Checking #" + i);
if (i == 4) {
ensureNotNullAndClass(o.getOrders()[i], TargetOrder.class);
ensureNotNullAndClass(o.getOrders()[i].getAddress(), TargetAddress.class);
} else {
assertNull(o.getOrders()[i]);
}
}
assertEquals("hello world.", o.getOrders()[4].getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetOrderArray 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