Search in sources :

Example 1 with SourceOrder

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

the class ClassHelperTest method testParentObjectForPathGrandParent.

@Test
public void testParentObjectForPathGrandParent() throws Exception {
    SourceAddress sourceAddress = new SourceAddress();
    SourceOrder sourceOrder = new SourceOrder();
    sourceOrder.setAddress(sourceAddress);
    SourceParentOrder sourceParentOrder = new SourceParentOrder();
    sourceParentOrder.setOrder(sourceOrder);
    Object parentObject = ClassHelper.parentObjectForPath(sourceParentOrder, new AtlasPath("/order/address/city"), true);
    assertNotNull(parentObject);
    assertTrue(parentObject instanceof SourceAddress);
    assertEquals(sourceAddress, parentObject);
}
Also used : SourceAddress(io.atlasmap.java.test.SourceAddress) SourceParentOrder(io.atlasmap.java.test.SourceParentOrder) SourceOrder(io.atlasmap.java.test.SourceOrder) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.Test)

Example 2 with SourceOrder

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

the class JavaConstructServiceComplexArrayTest method testConstructSourceOrderArray.

@Test
public void testConstructSourceOrderArray() throws Exception {
    Object targetObject = constructService.constructClass(generateOrderArray("Source"), null);
    assertNotNull(targetObject);
    assertTrue(targetObject instanceof SourceOrderArray);
    SourceOrderArray orderArray = (SourceOrderArray) targetObject;
    assertNotNull(orderArray.getOrders());
    assertTrue(orderArray.getOrders().length > 0);
    for (int i = 0; i < orderArray.getOrders().length; i++) {
        SourceOrder order = (SourceOrder) orderArray.getOrders()[i];
        assertNotNull(order.getAddress());
        assertTrue(order.getAddress() instanceof SourceAddress);
        SourceAddress address = (SourceAddress) order.getAddress();
        assertNull(address.getAddressLine1());
        assertNull(address.getAddressLine2());
        assertNull(address.getCity());
        assertNull(address.getState());
        assertNull(address.getZipCode());
        assertNotNull(order.getContact());
        assertTrue(order.getContact() instanceof SourceContact);
        SourceContact contact = (SourceContact) order.getContact();
        assertNull(contact.getFirstName());
        assertNull(contact.getLastName());
        assertNull(contact.getPhoneNumber());
        assertNull(contact.getZipCode());
    }
}
Also used : SourceAddress(io.atlasmap.java.test.SourceAddress) SourceOrderArray(io.atlasmap.java.test.SourceOrderArray) SourceOrder(io.atlasmap.java.test.SourceOrder) SourceContact(io.atlasmap.java.test.SourceContact) Test(org.junit.Test)

Example 3 with SourceOrder

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

the class ClassHelperTest method testParentObjectForPath.

@Test
public void testParentObjectForPath() throws Exception {
    SourceAddress sourceAddress = new SourceAddress();
    SourceOrder sourceOrder = new SourceOrder();
    sourceOrder.setAddress(sourceAddress);
    Object parentObject = ClassHelper.parentObjectForPath(sourceOrder, new AtlasPath("/address/city"), true);
    assertNotNull(parentObject);
    assertTrue(parentObject instanceof SourceAddress);
    assertEquals(sourceAddress, parentObject);
}
Also used : SourceAddress(io.atlasmap.java.test.SourceAddress) SourceOrder(io.atlasmap.java.test.SourceOrder) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.Test)

Example 4 with SourceOrder

use of io.atlasmap.java.test.SourceOrder 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 5 with SourceOrder

use of io.atlasmap.java.test.SourceOrder 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)

Aggregations

SourceOrder (io.atlasmap.java.test.SourceOrder)10 SourceAddress (io.atlasmap.java.test.SourceAddress)9 SourceContact (io.atlasmap.java.test.SourceContact)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Test (org.junit.jupiter.api.Test)4 AtlasContext (io.atlasmap.api.AtlasContext)3 AtlasSession (io.atlasmap.api.AtlasSession)3 AtlasPath (io.atlasmap.core.AtlasPath)3 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)3 SourceCollectionsClass (io.atlasmap.java.test.SourceCollectionsClass)3 TargetAddress (io.atlasmap.java.test.TargetAddress)3 TargetCollectionsClass (io.atlasmap.java.test.TargetCollectionsClass)3 TargetContact (io.atlasmap.java.test.TargetContact)3 TargetOrder (io.atlasmap.java.test.TargetOrder)3 File (java.io.File)3 SourceParentOrder (io.atlasmap.java.test.SourceParentOrder)2 JavaClass (io.atlasmap.java.v2.JavaClass)2 BaseOrder (io.atlasmap.java.test.BaseOrder)1 SourceOrderArray (io.atlasmap.java.test.SourceOrderArray)1