use of io.atlasmap.java.test.BaseOrder in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionList.
@Test
public void testProcessCollectionList() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-list.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(20, object.getContactList().size());
for (int i = 0; i < 20; i++) {
TargetContact contact = object.getContactList().get(i);
if (i == 4 || i == 19) {
assertEquals("Ozzie", contact.getFirstName());
} else {
assertNull(contact);
}
}
}
use of io.atlasmap.java.test.BaseOrder in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionArray.
@Test
public void testProcessCollectionArray() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-array.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(20, object.getContactArray().length);
for (int i = 0; i < 20; i++) {
TargetContact contact = object.getContactArray()[i];
if (i == 6 || i == 19) {
assertEquals("Ozzie", contact.getFirstName());
} else {
assertNull(contact);
}
}
}
use of io.atlasmap.java.test.BaseOrder in project atlasmap by atlasmap.
the class MultidocComplexTest method testProcessComplexBasicNullContact.
@Test
public void testProcessComplexBasicNullContact() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
AtlasSession session = context.createSession();
BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
javaSourceOrder.setContact(null);
session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass targetTestClass = (TargetTestClass) session.getTargetDocument("JavaTargetTestClass");
assertEquals(TargetTestClass.class.getName(), targetTestClass.getClass().getName());
assertEquals(TargetContact.class.getName(), targetTestClass.getContact().getClass().getName());
assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
assertEquals("Smith", targetTestClass.getContact().getLastName());
Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
assertTrue(jsonTargetOrder instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
assertNull(jsonTargetOrderObject.getContact().getLastName());
Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
assertNotNull(xmlOrderElement);
assertTrue(xmlOrderElement instanceof String);
XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
assertEquals("8765309", xmlOE.getOrderId());
assertEquals(null, xmlOE.getContact().getLastName());
}
use of io.atlasmap.java.test.BaseOrder in project atlasmap by atlasmap.
the class MultidocComplexTest method testProcessBasic.
@Test
public void testProcessBasic() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
AtlasSession session = context.createSession();
BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
assertEquals("Smith", targetTestClass.getContact().getLastName());
Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
assertTrue(jsonTargetOrder instanceof String);
AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
assertNotNull(xmlOrderElement);
assertTrue(xmlOrderElement instanceof String);
XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
assertEquals("8765309", xmlOE.getOrderId());
assertEquals("Ozzie", xmlOE.getContact().getFirstName());
assertEquals("Smith", xmlOE.getContact().getLastName());
}
use of io.atlasmap.java.test.BaseOrder in project atlasmap by atlasmap.
the class AtlasTestUtil method generateOrderClass.
public static BaseOrder generateOrderClass(Class<? extends BaseOrder> orderClazz, Class<? extends BaseAddress> addressClazz, Class<? extends BaseContact> contactClazz) throws Exception {
Class<?> targetClazz = AtlasTestUtil.class.getClassLoader().loadClass(orderClazz.getName());
BaseOrder newObject = (BaseOrder) targetClazz.newInstance();
newObject.setOrderId(8765309);
newObject.setAddress(generateAddress(addressClazz));
newObject.setContact(generateContact(contactClazz));
return newObject;
}
Aggregations