Search in sources :

Example 46 with TargetOrder

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

the class XmlJavaComplexTest method testProcessXmlJavaComplexOrderAutodetectElement.

@Test
public void testProcessXmlJavaComplexOrderAutodetectElement() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/xmlToJava/atlasmapping-complex-order-autodetect-element.json").toURI());
    AtlasSession session = context.createSession();
    String sourceXml = AtlasTestUtil.loadFileAsString("src/test/resources/xmlToJava/atlas-xml-complex-order-autodetect-element.xml");
    session.setDefaultSourceDocument(sourceXml);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetOrder);
    AtlasTestUtil.validateOrder((TargetOrder) object);
}
Also used : AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.jupiter.api.Test) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest)

Example 47 with TargetOrder

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

the class JavaJavaComplexTest method testProcessJavaJavaComplexWithAbstractBasic.

@Test
public void testProcessJavaJavaComplexWithAbstractBasic() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-complex-abstract.json").toURI());
    AtlasSession session = context.createSession();
    BaseOrder sourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    session.setDefaultSourceDocument(sourceOrder);
    context.process(session);
    assertFalse(session.hasErrors(), printAudit(session));
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetOrder);
    TargetOrder targetOrder = (TargetOrder) object;
    assertNotNull(targetOrder.getOrderId());
    assertEquals(Integer.valueOf(8765309), targetOrder.getOrderId());
    // Address should _not_ be populated
    assertNull(targetOrder.getAddress());
    // Contact should only have firstName populated
    assertNotNull(targetOrder.getContact());
    assertTrue(targetOrder.getContact() instanceof TargetContact);
    TargetContact targetContact = (TargetContact) targetOrder.getContact();
    assertNotNull(targetContact.getFirstName());
    assertEquals("Ozzie", targetContact.getFirstName());
    assertNull(targetContact.getLastName());
    assertNull(targetContact.getPhoneNumber());
    assertNull(targetContact.getZipCode());
}
Also used : BaseOrder(io.atlasmap.java.test.BaseOrder) TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

Example 48 with TargetOrder

use of io.atlasmap.java.test.TargetOrder 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());
        }
    }
}
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

TargetOrder (io.atlasmap.java.test.TargetOrder)48 AtlasContext (io.atlasmap.api.AtlasContext)25 AtlasSession (io.atlasmap.api.AtlasSession)25 File (java.io.File)25 Test (org.junit.jupiter.api.Test)23 Test (org.junit.Test)21 TargetAddress (io.atlasmap.java.test.TargetAddress)20 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)14 TargetContact (io.atlasmap.java.test.TargetContact)14 BaseOrder (io.atlasmap.java.test.BaseOrder)13 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)11 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)11 TestListOrders (io.atlasmap.java.test.TestListOrders)8 TargetTestClass (io.atlasmap.java.test.TargetTestClass)7 AtlasException (io.atlasmap.api.AtlasException)4 JavaField (io.atlasmap.java.v2.JavaField)4 SourceAddress (io.atlasmap.java.test.SourceAddress)3 SourceCollectionsClass (io.atlasmap.java.test.SourceCollectionsClass)3 SourceContact (io.atlasmap.java.test.SourceContact)3 SourceOrder (io.atlasmap.java.test.SourceOrder)3