use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadComplexListNullItem.
@Test
public void testReadComplexListNullItem() throws Exception {
SourceCollectionsClass root = new SourceCollectionsClass();
List<SourceContact> contactList = new ArrayList<>();
root.setContactList(contactList);
for (int i = 0; i < 3; i++) {
if (i == 1) {
contactList.add(null);
} else {
SourceContact c = new SourceContact();
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 testProcessCollectionFieldAction.
@Test
public void testProcessCollectionFieldAction() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-fieldaction2.json").toURI());
SourceCollectionsClass source = new SourceCollectionsClass();
LinkedList<String> list = new LinkedList<>();
list.addAll(Arrays.asList(new String[] { "linkedList0", "linkedList1", "linkedList2" }));
source.setLinkedList(list);
ArrayList<SourceOrder> orderList = new ArrayList<>();
for (int i = 0; i < 3; i++) {
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++) {
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++) {
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");
ArrayList<String> result = targetCollections.getArrayList();
assertEquals(1, result.size());
assertEquals("linkedList0#linkedList1#linkedList2", result.get(0));
List<TargetOrder> targetOrderList = targetCollections.getOrderList();
assertEquals(3, targetOrderList.size());
for (int i = 0; i < 3; i++) {
TargetOrder order = targetOrderList.get(i);
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);
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);
assertEquals("First" + i, contact.getFirstName());
assertEquals("last" + i, contact.getLastName());
}
}
use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionEmptyItem.
@Test
public void testProcessCollectionEmptyItem() 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++) {
SourceOrder order = new SourceOrder();
if (i != 1) {
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++) {
SourceAddress addr = new SourceAddress();
if (i != 1) {
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++) {
SourceContact ct = new SourceContact();
if (i != 1) {
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());
}
}
}
use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaJavaCollectionTest method testProcessCollectionImpls.
@Test
public void testProcessCollectionImpls() throws Exception {
AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-impls.json").toURI());
SourceCollectionsClass source = new SourceCollectionsClass();
List<String> list = new LinkedList<>();
list.addAll(Arrays.asList(new String[] { "list0", "list1", "list2" }));
source.setList(list);
LinkedList<String> linkedList = new LinkedList<>();
linkedList.addAll(Arrays.asList(new String[] { "linkedList0", "linkedList1", "linkedList2" }));
source.setLinkedList(linkedList);
ArrayList<String> arrayList = new ArrayList<>();
arrayList.addAll(Arrays.asList(new String[] { "arrayList0", "arrayList1", "arrayList2" }));
source.setArrayList(arrayList);
Set<String> set = new HashSet<>();
set.addAll(Arrays.asList(new String[] { "set0", "set1", "set2" }));
source.setSet(new HashSet<>(set));
HashSet<String> hashSet = new HashSet<>();
hashSet.addAll(Arrays.asList(new String[] { "hashSet0", "hashSet1", "hashSet2" }));
source.setHashSet(hashSet);
AtlasSession session = context.createSession();
session.setSourceDocument("SourceCollectionsClass", source);
SourceFlatPrimitiveClass sfpc0 = new SourceFlatPrimitiveClass();
sfpc0.setBoxedStringField("sfpc0");
session.setSourceDocument("sfpc0", sfpc0);
SourceFlatPrimitiveClass sfpc1 = new SourceFlatPrimitiveClass();
sfpc1.setBoxedStringField("sfpc1");
session.setSourceDocument("sfpc1", sfpc1);
SourceFlatPrimitiveClass sfpc2 = new SourceFlatPrimitiveClass();
sfpc2.setBoxedStringField("sfpc2");
session.setSourceDocument("sfpc2", sfpc2);
SourceFlatPrimitiveClass sfpc3 = new SourceFlatPrimitiveClass();
sfpc3.setBoxedStringField("sfpc3");
session.setSourceDocument("sfpc3", sfpc3);
SourceFlatPrimitiveClass sfpc4 = new SourceFlatPrimitiveClass();
sfpc4.setBoxedStringField("sfpc4");
session.setSourceDocument("sfpc4", sfpc4);
context.process(session);
assertFalse(session.hasErrors(), printAudit(session));
TargetCollectionsClass targetCollections = (TargetCollectionsClass) session.getTargetDocument("TargetCollectionsClass");
list = targetCollections.getList();
assertEquals(4, list.size());
assertTrue(list.contains("arrayList0"));
assertTrue(list.contains("arrayList1"));
assertTrue(list.contains("arrayList2"));
assertTrue(list.contains("sfpc0"));
linkedList = targetCollections.getLinkedList();
assertEquals(4, linkedList.size());
assertTrue(linkedList.contains("set0"));
assertTrue(linkedList.contains("set1"));
assertTrue(linkedList.contains("set2"));
assertTrue(linkedList.contains("sfpc1"));
arrayList = targetCollections.getArrayList();
assertEquals(4, arrayList.size());
assertTrue(arrayList.contains("hashSet0"));
assertTrue(arrayList.contains("hashSet1"));
assertTrue(arrayList.contains("hashSet2"));
assertTrue(arrayList.contains("sfpc2"));
set = targetCollections.getSet();
assertEquals(4, set.size());
assertTrue(set.contains("list0"));
assertTrue(set.contains("list1"));
assertTrue(set.contains("list2"));
assertTrue(set.contains("sfpc3"));
hashSet = targetCollections.getHashSet();
assertEquals(4, hashSet.size());
assertTrue(hashSet.contains("linkedList0"));
assertTrue(hashSet.contains("linkedList1"));
assertTrue(hashSet.contains("linkedList2"));
assertTrue(hashSet.contains("sfpc4"));
TargetFlatPrimitiveClass tfpc0 = (TargetFlatPrimitiveClass) session.getTargetDocument("tfpc0");
assertTrue(tfpc0.getBoxedStringField().startsWith("list"));
TargetFlatPrimitiveClass tfpc1 = (TargetFlatPrimitiveClass) session.getTargetDocument("tfpc1");
assertTrue(tfpc1.getBoxedStringField().startsWith("linkedList"));
TargetFlatPrimitiveClass tfpc2 = (TargetFlatPrimitiveClass) session.getTargetDocument("tfpc2");
assertTrue(tfpc2.getBoxedStringField().startsWith("arrayList"));
TargetFlatPrimitiveClass tfpc3 = (TargetFlatPrimitiveClass) session.getTargetDocument("tfpc3");
assertTrue(tfpc3.getBoxedStringField().startsWith("set"));
TargetFlatPrimitiveClass tfpc4 = (TargetFlatPrimitiveClass) session.getTargetDocument("tfpc4");
assertTrue(tfpc4.getBoxedStringField().startsWith("hashSet"));
}
use of io.atlasmap.java.test.SourceCollectionsClass in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadComplexList.
@Test
public void testReadComplexList() 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();
c.setFirstName("firstName" + i);
contactList.add(c);
}
reader.setDocument(root);
readGroup("/contactList<>/firstName", FieldType.STRING);
assertEquals(0, audits.size());
assertEquals(3, fieldGroup.getField().size());
for (int i = 0; i < 3; i++) {
Field f = fieldGroup.getField().get(i);
assertEquals(String.format("/contactList<%s>/firstName", i), f.getPath());
assertEquals("firstName" + i, f.getValue());
}
}
Aggregations