use of io.atlasmap.java.test.TargetTestClass 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.json").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(session.hasErrors(), printAudit(session));
Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
assertEquals(Integer.valueOf(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(Integer.valueOf(8765309), jsonTargetOrderObject.getOrderId());
assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
assertNotNull(xmlOrderElement);
assertTrue(xmlOrderElement instanceof String);
HashMap<String, String> ns = new HashMap<>();
ns.put("ns", "http://atlasmap.io/xml/test/v2");
assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:orderId").isEqualTo("8765309");
assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:firstName").isEqualTo("Ozzie");
assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:lastName").isEqualTo("Smith");
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionFromNonCollection.
@Test
public void testProcessCollectionFromNonCollection() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-from-noncollection.xml").toURI());
TargetTestClass input = new TargetTestClass();
input.setContact(new TargetContact());
input.getContact().setFirstName("first name");
input.getContact().setLastName("last name");
AtlasSession session = context.createSession();
session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
assertEquals(1, object.getContactList().size());
assertEquals("first name", object.getContactList().get(0).getFirstName());
assertEquals("last name", object.getContactList().get(0).getLastName());
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionArraySimple.
@Test
public void testProcessCollectionArraySimple() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-array-simple.xml").toURI());
TargetTestClass input = new TargetTestClass();
input.setContactList(new LinkedList<>());
for (int i = 0; i < 5; i++) {
input.getContactList().add(new TargetContact());
input.getContactList().get(i).setFirstName("fname" + i);
}
AtlasSession session = context.createSession();
session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
assertEquals(5, object.getContactList().size());
for (int i = 0; i < 5; i++) {
assertEquals(input.getContactList().get(i).getFirstName(), object.getContactList().get(i).getFirstName());
}
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionToNonCollection.
@Test
public void testProcessCollectionToNonCollection() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-to-noncollection.xml").toURI());
TargetTestClass input = new TargetTestClass();
input.setContactList(new LinkedList<>());
for (int i = 0; i < 5; i++) {
input.getContactList().add(new TargetContact());
input.getContactList().get(i).setFirstName("fname" + i);
}
AtlasSession session = context.createSession();
session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
assertNull(object.getContactArray());
assertNull(object.getContactList());
assertEquals("fname4", object.getContact().getFirstName());
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaJavaComplexTest method testProcessLookup.
@Test
public void testProcessLookup() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-lookup.xml").toURI());
TargetTestClass input = new TargetTestClass();
input.setStatesLong(StateEnumClassLong.Arizona);
AtlasSession session = context.createSession();
session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
context.process(session);
assertFalse(printAudit(session), session.hasErrors());
TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
assertNotNull(object);
assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
assertEquals(StateEnumClassShort.AZ, object.getStatesShort());
input.setStatesLong(StateEnumClassLong.Alabama);
session = context.createSession();
session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
context.process(session);
object = (TargetTestClass) session.getDefaultTargetDocument();
assertNotNull(object);
assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
assertNull(object.getStatesShort());
assertTrue(printAudit(session), session.hasErrors());
}
Aggregations