Search in sources :

Example 1 with TargetOrder

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

the class DocumentJavaFieldWriterTest method testClassLookupFromField.

@Test
public void testClassLookupFromField() throws Exception {
    JavaField f = createField("/", null);
    f.setClassName(TestListOrders.class.getName());
    f.setFieldType(FieldType.COMPLEX);
    write(f);
    TestListOrders o = (TestListOrders) writer.getRootObject();
    ensureNotNullAndClass(o, TestListOrders.class);
    f = createField("/orders<4>", null);
    f.setClassName(TargetOrder.class.getName());
    f.setFieldType(FieldType.COMPLEX);
    write(f);
    ensureNotNullAndClass(o.getOrders(), LinkedList.class);
    assertEquals(5, o.getOrders().size());
    for (int i = 0; i < 5; i++) {
        System.out.println("Checking #" + i);
        TargetOrder order = (TargetOrder) o.getOrders().get(i);
        if (i == 4) {
            ensureNotNullAndClass(order, TargetOrder.class);
        } else {
            assertNull(order);
        }
    }
    f = createField("/orders<7>", null);
    f.setClassName(TargetOrder.class.getName());
    f.setFieldType(FieldType.COMPLEX);
    write(f);
    ensureNotNullAndClass(o.getOrders(), LinkedList.class);
    assertEquals(8, o.getOrders().size());
    for (int i = 0; i < 8; i++) {
        System.out.println("Checking #" + i);
        TargetOrder order = (TargetOrder) o.getOrders().get(i);
        if (i == 4 || i == 7) {
            ensureNotNullAndClass(order, TargetOrder.class);
        } else {
            assertNull(order);
        }
    }
    f = createField("/orders<7>/address", null);
    f.setClassName(TargetAddress.class.getName());
    f.setFieldType(FieldType.COMPLEX);
    write(f);
    ensureNotNullAndClass(o.getOrders().get(7).getAddress(), TargetAddress.class);
    write(createField("/orders<7>/address/addressLine1", "hello world1."));
    assertEquals("hello world1.", o.getOrders().get(7).getAddress().getAddressLine1());
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) Test(org.junit.Test)

Example 2 with TargetOrder

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

the class JavaConstructServiceComplexArrayTest method testConstructTargetOrderArray.

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

Example 3 with TargetOrder

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

the class DocumentJavaFieldWriterTest method testSimpleWriteCollectionArray.

@Test
public void testSimpleWriteCollectionArray() throws Exception {
    addClassForFieldPath("/", TargetOrderArray.class);
    addClassForFieldPath("/orders[5]", TargetOrder.class);
    addClassForFieldPath("/orders[5]/address", TargetAddress.class);
    write("/orders[4]/address/addressLine1", "hello world.");
    TargetOrderArray o = (TargetOrderArray) writer.getRootObject();
    ensureNotNullAndClass(o, TargetOrderArray.class);
    ensureNotNullAndClass(o.getOrders(), TargetOrder[].class);
    assertEquals(5, o.getOrders().length);
    for (int i = 0; i < 5; i++) {
        System.out.println("Checking #" + i);
        if (i == 4) {
            ensureNotNullAndClass(o.getOrders()[i], TargetOrder.class);
            ensureNotNullAndClass(o.getOrders()[i].getAddress(), TargetAddress.class);
        } else {
            assertNull(o.getOrders()[i]);
        }
    }
    assertEquals("hello world.", o.getOrders()[4].getAddress().getAddressLine1());
}
Also used : TargetOrder(io.atlasmap.java.test.TargetOrder) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Test(org.junit.Test)

Example 4 with TargetOrder

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

the class JavaJavaComplexTest method testProcessBasic.

@Test
public void testProcessBasic() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-basic.xml").toURI());
    AtlasSession session = context.createSession();
    BaseOrder sourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    session.setDefaultSourceDocument(sourceOrder);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertEquals(TargetOrder.class.getName(), object.getClass().getName());
    TargetOrder targetOrder = (TargetOrder) object;
    assertEquals(new Integer(8765309), targetOrder.getOrderId());
}
Also used : BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 5 with TargetOrder

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

the class JavaJavaComplexTest method testProcessJavaJavaComplexAutoDetectFullActions.

@Test
public void testProcessJavaJavaComplexAutoDetectFullActions() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-complex-autodetect-full-actions.xml"));
    AtlasSession session = context.createSession();
    BaseOrder sourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    session.setDefaultSourceDocument(sourceOrder);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetOrder);
    // ensure our Uppercase action on first name did the right thing
    assertEquals("OZZIE", ((TargetOrder) object).getContact().getFirstName());
    assertEquals("smith", ((TargetOrder) object).getContact().getLastName());
    // set values to normalized pre-action-processing state so rest of validation
    // passes..
    ((TargetOrder) object).getContact().setFirstName("Ozzie");
    ((TargetOrder) object).getContact().setLastName("Smith");
    AtlasTestUtil.validateOrder((TargetOrder) object);
}
Also used : BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

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