Search in sources :

Example 1 with TargetCollectionsClass

use of io.atlasmap.java.test.TargetCollectionsClass 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());
    }
}
Also used : SourceAddress(io.atlasmap.java.test.SourceAddress) TargetContact(io.atlasmap.java.test.TargetContact) TargetCollectionsClass(io.atlasmap.java.test.TargetCollectionsClass) SourceOrder(io.atlasmap.java.test.SourceOrder) ArrayList(java.util.ArrayList) TargetAddress(io.atlasmap.java.test.TargetAddress) LinkedList(java.util.LinkedList) SourceCollectionsClass(io.atlasmap.java.test.SourceCollectionsClass) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) SourceContact(io.atlasmap.java.test.SourceContact) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 2 with TargetCollectionsClass

use of io.atlasmap.java.test.TargetCollectionsClass 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());
        }
    }
}
Also used : SourceAddress(io.atlasmap.java.test.SourceAddress) TargetContact(io.atlasmap.java.test.TargetContact) TargetCollectionsClass(io.atlasmap.java.test.TargetCollectionsClass) SourceOrder(io.atlasmap.java.test.SourceOrder) ArrayList(java.util.ArrayList) TargetAddress(io.atlasmap.java.test.TargetAddress) SourceCollectionsClass(io.atlasmap.java.test.SourceCollectionsClass) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) SourceContact(io.atlasmap.java.test.SourceContact) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 3 with TargetCollectionsClass

use of io.atlasmap.java.test.TargetCollectionsClass 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"));
}
Also used : TargetCollectionsClass(io.atlasmap.java.test.TargetCollectionsClass) ArrayList(java.util.ArrayList) SourceFlatPrimitiveClass(io.atlasmap.java.test.SourceFlatPrimitiveClass) LinkedList(java.util.LinkedList) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) SourceCollectionsClass(io.atlasmap.java.test.SourceCollectionsClass) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) HashSet(java.util.HashSet) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 4 with TargetCollectionsClass

use of io.atlasmap.java.test.TargetCollectionsClass in project atlasmap by atlasmap.

the class JavaFieldWriterTest method testWriteCollectionImpls.

@Test
public void testWriteCollectionImpls() throws Exception {
    writer.setRootObject(new TargetCollectionsClass());
    write("/list<0>", "list0");
    write("/linkedList<1>", "linkedList1");
    write("/arrayList<2>", "arrayList2");
    write("/set<3>", "set3");
    write("/hashSet<4>", "hashSet4");
    TargetCollectionsClass tcc = (TargetCollectionsClass) writer.getRootObject();
    ensureNotNullAndClass(tcc, TargetCollectionsClass.class);
    assertTrue(tcc.getList().contains("list0"));
    assertTrue(tcc.getLinkedList().contains("linkedList1"));
    assertTrue(tcc.getArrayList().contains("arrayList2"));
    assertTrue(tcc.getSet().contains("set3"));
    assertTrue(tcc.getHashSet().contains("hashSet4"));
}
Also used : TargetCollectionsClass(io.atlasmap.java.test.TargetCollectionsClass) Test(org.junit.jupiter.api.Test)

Example 5 with TargetCollectionsClass

use of io.atlasmap.java.test.TargetCollectionsClass in project atlasmap by atlasmap.

the class JavaFieldWriterTest method testListComplexSkipIndexedPath.

@Test
public void testListComplexSkipIndexedPath() throws Exception {
    writer.setRootObject(new TargetCollectionsClass());
    writeComplex("/contactList<0>", new TargetContact());
    write("/contactList<0>/firstName", "first0");
    writeComplex("/contactList<2>", new TargetContact());
    write("/contactList<2>/firstName", "first2");
    TargetCollectionsClass o = (TargetCollectionsClass) writer.getRootObject();
    assertEquals(3, o.getContactList().size());
    assertEquals("first0", o.getContactList().get(0).getFirstName());
    assertNull(o.getContactList().get(1));
    assertEquals("first2", o.getContactList().get(2).getFirstName());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) TargetCollectionsClass(io.atlasmap.java.test.TargetCollectionsClass) Test(org.junit.jupiter.api.Test)

Aggregations

TargetCollectionsClass (io.atlasmap.java.test.TargetCollectionsClass)6 Test (org.junit.jupiter.api.Test)6 AtlasContext (io.atlasmap.api.AtlasContext)4 AtlasSession (io.atlasmap.api.AtlasSession)4 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)4 SourceCollectionsClass (io.atlasmap.java.test.SourceCollectionsClass)4 TargetContact (io.atlasmap.java.test.TargetContact)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 SourceAddress (io.atlasmap.java.test.SourceAddress)3 SourceContact (io.atlasmap.java.test.SourceContact)3 SourceOrder (io.atlasmap.java.test.SourceOrder)3 TargetAddress (io.atlasmap.java.test.TargetAddress)3 TargetOrder (io.atlasmap.java.test.TargetOrder)3 LinkedList (java.util.LinkedList)2 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)1 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)1 HashSet (java.util.HashSet)1