use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaFieldWriterTest method testTopmostArrayComplex.
@Test
public void testTopmostArrayComplex() throws Exception {
writer.setRootObject(new TargetTestClass[0]);
writer.setCollectionItemClass(TargetTestClass.class);
writeComplex("/[0]/address", new TargetAddress());
write("/[0]/address/addressLine1", "zero");
writeComplex("/[1]/address", new TargetAddress());
write("/[1]/address/addressLine1", "one");
TargetTestClass[] o = (TargetTestClass[]) writer.getRootObject();
ensureNotNullAndClass(o, TargetTestClass[].class);
assertEquals("zero", o[0].getAddress().getAddressLine1());
assertEquals("one", o[1].getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaFieldWriterTest method testTopmostListComplex.
@Test
public void testTopmostListComplex() throws Exception {
writer.setRootObject(new ArrayList<TargetTestClass>());
writer.setCollectionItemClass(TargetTestClass.class);
writeComplex("/<0>/address", new TargetAddress());
write("/<0>/address/addressLine1", "zero");
writeComplex("/<1>/address", new TargetAddress());
write("/<1>/address/addressLine1", "one");
List<TargetTestClass> o = (List<TargetTestClass>) writer.getRootObject();
ensureNotNullAndClass(o, ArrayList.class);
assertEquals("zero", o.get(0).getAddress().getAddressLine1());
assertEquals("one", o.get(1).getAddress().getAddressLine1());
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadParentCollectionsChildren.
@Test
public void testReadParentCollectionsChildren() throws Exception {
TargetTestClass source = new TargetTestClass();
TargetOrderArray orderArray = new TargetOrderArray();
source.setOrderArray(orderArray);
TargetOrder[] orders = new TargetOrder[5];
orderArray.setOrders(orders);
for (int i = 0; i < 5; i++) {
TargetOrder order = new TargetOrder();
TargetContact c = new TargetContact();
c.setFirstName("f" + i);
c.setLastName("l" + i);
c.setPhoneNumber("p" + i);
c.setZipCode("z" + i);
order.setContact(c);
orders[i] = order;
}
reader.setDocument(source);
FieldGroup contactGroup = new FieldGroup();
contactGroup.setDocId("TargetTestClass");
contactGroup.setPath("/orderArray/orders[]/contact");
contactGroup.setFieldType(FieldType.COMPLEX);
Field firstNameField = new JavaField();
firstNameField.setDocId("TargetTestClass");
firstNameField.setPath("/orderArray/orders[]/contact/firstName");
firstNameField.setFieldType(FieldType.STRING);
contactGroup.getField().add(firstNameField);
fieldGroup = (FieldGroup) read(contactGroup);
assertEquals(0, audits.size());
assertEquals("/orderArray/orders[]/contact", fieldGroup.getPath());
assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
assertNull(fieldGroup.getCollectionType());
assertEquals(5, fieldGroup.getField().size());
Field contact0 = fieldGroup.getField().get(0);
assertEquals(FieldGroup.class, contact0.getClass());
FieldGroup contact0Group = (FieldGroup) contact0;
assertEquals(1, contact0Group.getField().size());
assertEquals("/orderArray/orders[0]/contact", contact0Group.getPath());
assertEquals(FieldType.COMPLEX, contact0Group.getFieldType());
assertNull(contact0Group.getCollectionType());
Field firstName0 = contact0Group.getField().get(0);
assertEquals("/orderArray/orders[0]/contact/firstName", firstName0.getPath());
assertEquals(FieldType.STRING, firstName0.getFieldType());
assertNull(firstName0.getCollectionType());
assertEquals("f0", firstName0.getValue());
contactGroup.setPath("/orderArray/orders[1]/contact");
firstNameField.setPath("/orderArray/orders[1]/contact/firstName");
fieldGroup = (FieldGroup) read(contactGroup);
assertEquals(0, audits.size());
assertEquals(1, fieldGroup.getField().size());
assertEquals("/orderArray/orders[1]/contact", fieldGroup.getPath());
assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
Field firstName1 = fieldGroup.getField().get(0);
assertEquals("/orderArray/orders[1]/contact/firstName", firstName1.getPath());
assertEquals(FieldType.STRING, firstName1.getFieldType());
assertEquals("f1", firstName1.getValue());
}
use of io.atlasmap.java.test.TargetTestClass 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.json").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(session.hasErrors(), printAudit(session));
TargetTestClass targetTestClass = (TargetTestClass) session.getTargetDocument("JavaTargetTestClass");
assertEquals(TargetTestClass.class.getName(), targetTestClass.getClass().getName());
assertEquals(TargetContact.class.getName(), targetTestClass.getContact().getClass().getName());
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());
assertNull(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:lastName").isNullOrEmpty();
}
use of io.atlasmap.java.test.TargetTestClass in project atlasmap by atlasmap.
the class DfdlCsvTest method test.
@Test
public void test() throws Exception {
URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/atlasmapping-dfdl-csv.json");
AtlasContext context = DefaultAtlasContextFactory.getInstance().createContext(url.toURI());
AtlasSession session = context.createSession();
TargetTestClass javaSource = new TargetTestClass();
javaSource.setContactList(new LinkedList<>());
TargetContact tc = new TargetContact();
tc.setFirstName("firstName1");
tc.setLastName("lastName1");
tc.setPhoneNumber("111-111-1111");
javaSource.getContactList().add(tc);
tc = new TargetContact();
tc.setFirstName("firstName2");
tc.setLastName("lastName2");
tc.setPhoneNumber("222-222-2222");
javaSource.getContactList().add(tc);
tc = new TargetContact();
tc.setFirstName("firstName3");
tc.setLastName("lastName3");
tc.setPhoneNumber("333-333-3333");
javaSource.getContactList().add(tc);
session.setSourceDocument("java-source", javaSource);
String csvSource = TestHelper.readStringFromFile("atlas-dfdl-csv-simple.csv");
session.setSourceDocument("dfdl-csv-source", csvSource);
context.process(session);
assertFalse(session.hasErrors(), TestHelper.printAudit(session));
assertTrue(session.hasWarns(), TestHelper.printAudit(session));
Object jt = session.getTargetDocument("java-target");
assertEquals(TargetTestClass.class, jt.getClass());
TargetTestClass javaTarget = TargetTestClass.class.cast(jt);
assertEquals(3, javaTarget.getContactList().size());
assertEquals("l1r1", javaTarget.getContactList().get(0).getFirstName());
assertEquals("l3r3", javaTarget.getContactList().get(2).getPhoneNumber());
Object dct = session.getTargetDocument("dfdl-csv-target");
String dfdlCsvTarget = String.class.cast(dct);
assertEquals(TestHelper.readStringFromFile("data/dfdl-csv-target.csv"), dfdlCsvTarget);
}
Aggregations