use of io.atlasmap.java.test.TargetOrder in project atlasmap by atlasmap.
the class DocumentJavaFieldWriterTest method testClassLookupFromField.
@Test
public void testClassLookupFromField() throws Exception {
JavaField f = createField("/", null);
f.setClassName(TestListOrders.class.getName());
f.setFieldType(FieldType.COMPLEX);
write(f);
TestListOrders o = (TestListOrders) writer.getRootObject();
ensureNotNullAndClass(o, TestListOrders.class);
f = createField("/orders<4>", null);
f.setClassName(TargetOrder.class.getName());
f.setFieldType(FieldType.COMPLEX);
write(f);
ensureNotNullAndClass(o.getOrders(), LinkedList.class);
assertEquals(5, o.getOrders().size());
for (int i = 0; i < 5; i++) {
System.out.println("Checking #" + i);
TargetOrder order = (TargetOrder) o.getOrders().get(i);
if (i == 4) {
ensureNotNullAndClass(order, TargetOrder.class);
} else {
assertNull(order);
}
}
f = createField("/orders<7>", null);
f.setClassName(TargetOrder.class.getName());
f.setFieldType(FieldType.COMPLEX);
write(f);
ensureNotNullAndClass(o.getOrders(), LinkedList.class);
assertEquals(8, o.getOrders().size());
for (int i = 0; i < 8; i++) {
System.out.println("Checking #" + i);
TargetOrder order = (TargetOrder) o.getOrders().get(i);
if (i == 4 || i == 7) {
ensureNotNullAndClass(order, TargetOrder.class);
} else {
assertNull(order);
}
}
f = createField("/orders<7>/address", null);
f.setClassName(TargetAddress.class.getName());
f.setFieldType(FieldType.COMPLEX);
write(f);
ensureNotNullAndClass(o.getOrders().get(7).getAddress(), TargetAddress.class);
write(createField("/orders<7>/address/addressLine1", "hello world1."));
assertEquals("hello world1.", o.getOrders().get(7).getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetOrder 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.TargetOrder 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.TargetOrder in project atlasmap by atlasmap.
the class JavaJavaComplexTest method testProcessBasic.
@Test
public void testProcessBasic() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-basic.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();
assertEquals(TargetOrder.class.getName(), object.getClass().getName());
TargetOrder targetOrder = (TargetOrder) object;
assertEquals(new Integer(8765309), targetOrder.getOrderId());
}
use of io.atlasmap.java.test.TargetOrder 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);
}
Aggregations