use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadComplexListEmptyItem.
@Test
public void testReadComplexListEmptyItem() throws Exception {
SourceCollectionsClass root = new SourceCollectionsClass();
List<SourceContact> contactList = new ArrayList<>();
root.setContactList(contactList);
for (int i = 0; i < 3; i++) {
SourceContact c = new SourceContact();
if (i != 1) {
c.setFirstName("firstName" + i);
}
contactList.add(c);
}
reader.setDocument(root);
readGroup("/contactList<>/firstName", FieldType.STRING);
assertEquals(0, audits.size());
assertEquals(2, fieldGroup.getField().size());
Field f = fieldGroup.getField().get(0);
assertEquals("/contactList<0>/firstName", f.getPath());
assertEquals("firstName0", f.getValue());
f = fieldGroup.getField().get(1);
assertEquals("/contactList<2>/firstName", f.getPath());
assertEquals("firstName2", f.getValue());
}
use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionNullItem.
@Test
public void testProcessCollectionNullItem() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-fieldaction2.json").toURI());
SourceCollectionsClass source = new SourceCollectionsClass();
ArrayList<SourceOrder> orderList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
if (i == 1) {
orderList.add(null);
continue;
}
SourceOrder order = new SourceOrder();
order.setOrderId(i);
order.setCreated(Date.from(Instant.now()));
orderList.add(order);
}
source.setOrderList(orderList);
ArrayList<SourceAddress> addressList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
if (i == 1) {
addressList.add(null);
continue;
}
SourceAddress addr = new SourceAddress();
addr.setCity("city" + i);
addr.setState("state" + i);
addressList.add(addr);
}
source.setAddressList(addressList);
ArrayList<SourceContact> contactList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
if (i == 1) {
contactList.add(null);
continue;
}
SourceContact ct = new SourceContact();
ct.setFirstName("first" + i);
ct.setLastName("last" + i);
contactList.add(ct);
}
source.setContactList(contactList);
AtlasSession session = context.createSession();
session.setSourceDocument("SourceCollectionsClass", source);
context.process(session);
assertFalse(session.hasErrors(), printAudit(session));
TargetCollectionsClass targetCollections = (TargetCollectionsClass) session.getTargetDocument("TargetCollectionsClass");
List<TargetOrder> targetOrderList = targetCollections.getOrderList();
assertEquals(3, targetOrderList.size());
for (int i = 0; i < 3; i++) {
TargetOrder order = targetOrderList.get(i);
if (i == 1) {
assertNull(order);
} else {
assertEquals(i, order.getOrderId());
assertNotNull(order.getCreated());
}
}
List<TargetAddress> targetAddrList = targetCollections.getAddressList();
assertEquals(3, targetAddrList.size());
for (int i = 0; i < 3; i++) {
TargetAddress addr = targetAddrList.get(i);
if (i == 1) {
assertNull(addr);
} else {
assertEquals("city" + i, addr.getCity());
assertEquals("STATE" + i, addr.getState());
}
}
List<TargetContact> targetContactList = targetCollections.getContactList();
assertEquals(3, targetContactList.size());
for (int i = 0; i < 3; i++) {
TargetContact contact = targetContactList.get(i);
if (i == 1) {
assertNull(contact);
} else {
assertEquals("First" + i, contact.getFirstName());
assertEquals("last" + i, contact.getLastName());
}
}
}
Aggregations