Search in sources :

Example 21 with TargetOrder

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

the class BaseDocumentWriterTest method reset.

@Before
public void reset() {
    classLoader = Thread.currentThread().getContextClassLoader();
    writer = new DocumentJavaFieldWriter(conversionService);
    writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService) {

        public Object convert(AtlasInternalSession session, LookupTable lookupTable, Field sourceField, Object parentObject, Field targetField) throws AtlasException {
            return targetField.getValue();
        }
    });
    field = null;
    segmentContexts = new LinkedList<>();
    targetTestClassInstance = new TargetTestClass();
    targetTestClassInstance.setContact(new TargetContact());
    targetTestClassInstance.setAddress(new TargetAddress());
    targetOrderListInstance = new TestListOrders();
    targetOrderListInstance.setOrders(new LinkedList<>());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetTestClassInstance.setListOrders(targetOrderListInstance);
    targetOrderArrayInstance = new TargetOrderArray();
    targetOrderArrayInstance.setOrders(new BaseOrder[2]);
    targetOrderArrayInstance.getOrders()[0] = new TargetOrder();
    targetOrderArrayInstance.getOrders()[1] = new TargetOrder();
    targetTestClassInstance.setOrderArray(targetOrderArrayInstance);
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) TargetContact(io.atlasmap.java.test.TargetContact) TargetAddress(io.atlasmap.java.test.TargetAddress) AtlasException(io.atlasmap.api.AtlasException) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) TestListOrders(io.atlasmap.java.test.TestListOrders) LookupTable(io.atlasmap.v2.LookupTable) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) Before(org.junit.Before)

Example 22 with TargetOrder

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

the class DocumentJavaFieldWriterTest method testExpandCollectionArray.

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

Example 23 with TargetOrder

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

the class DocumentJavaFieldWriterTest method testFullWrite.

@Test
public void testFullWrite() throws Exception {
    addClassForFieldPath("/", TargetTestClass.class);
    addClassForFieldPath("/address", TargetAddress.class);
    addClassForFieldPath("/listOrders", TestListOrders.class);
    addClassForFieldPath("/listOrders/orders<5>", TargetOrder.class);
    addClassForFieldPath("/listOrders/orders<5>/address", TargetAddress.class);
    addClassForFieldPath("/orderArray", TargetOrderArray.class);
    addClassForFieldPath("/orderArray/orders[5]", TargetOrder.class);
    addClassForFieldPath("/orderArray/orders[5]/contact", TargetContact.class);
    addClassForFieldPath("/primitives", TargetFlatPrimitiveClass.class);
    addClassForFieldPath("/primitives/intArrayField[]", int.class);
    addClassForFieldPath("/primitives/boxedStringArrayField[19]", String.class);
    addClassForFieldPath("/statesLong", StateEnumClassLong.class);
    write("/name", "someName");
    TargetTestClass o = (TargetTestClass) writer.getRootObject();
    ensureNotNullAndClass(o, TargetTestClass.class);
    assertEquals("someName", o.getName());
    write("/address/addressLine1", "123 any street");
    ensureNotNullAndClass(o.getAddress(), TargetAddress.class);
    assertEquals("123 any street", o.getAddress().getAddressLine1());
    write("/listOrders/orders<5>/orderId", 1234);
    ensureNotNullAndClass(o.getListOrders(), TestListOrders.class);
    ensureNotNullAndClass(o.getListOrders().getOrders(), LinkedList.class);
    assertEquals(6, o.getListOrders().getOrders().size());
    for (int i = 0; i < 6; i++) {
        System.out.println("Checking #" + i);
        BaseOrder order = o.getListOrders().getOrders().get(i);
        if (i == 5) {
            ensureNotNullAndClass(order, TargetOrder.class);
        } else {
            assertNull(order);
        }
    }
    BaseOrder order = o.getListOrders().getOrders().get(5);
    assertEquals((Integer) 1234, order.getOrderId());
    write("/listOrders/orders<2>/address/city", "Austin");
    assertEquals(6, o.getListOrders().getOrders().size());
    // ensure earlier fields are ok
    order = o.getListOrders().getOrders().get(5);
    assertEquals((Integer) 1234, order.getOrderId());
    // ensure our new field is ok
    order = o.getListOrders().getOrders().get(2);
    ensureNotNullAndClass(order.getAddress(), TargetAddress.class);
    assertEquals("Austin", order.getAddress().getCity());
    write("/orderArray/numberOrders", 56);
    ensureNotNullAndClass(o.getOrderArray(), TargetOrderArray.class);
    assertEquals((Integer) 56, o.getOrderArray().getNumberOrders());
    write("/orderArray/orders[2]/contact/firstName", "fName");
    ensureNotNullAndClass(o.getOrderArray().getOrders(), TargetOrder[].class);
    assertEquals(3, o.getOrderArray().getOrders().length);
    for (int i = 0; i < 3; i++) {
        System.out.println("Checking #" + i);
        BaseOrder order2 = o.getOrderArray().getOrders()[i];
        if (i == 2) {
            ensureNotNullAndClass(order2, TargetOrder.class);
        } else {
            assertNull(order2);
        }
    }
    ensureNotNullAndClass(o.getOrderArray().getOrders()[2].getContact(), TargetContact.class);
    // ensure previous fields are ok
    assertEquals((Integer) 56, o.getOrderArray().getNumberOrders());
    // ensure new field is ok
    assertEquals("fName", o.getOrderArray().getOrders()[2].getContact().getFirstName());
    write("/orderArray/orders[2]/contact/lastName", "lName");
    // ensure previous fields are ok
    assertEquals((Integer) 56, o.getOrderArray().getNumberOrders());
    assertEquals("fName", o.getOrderArray().getOrders()[2].getContact().getFirstName());
    // ensure new field is ok
    assertEquals("lName", o.getOrderArray().getOrders()[2].getContact().getLastName());
    // test writing primitive array values
    write("/primitives/intArrayField[10]", 3425);
    ensureNotNullAndClass(o.getPrimitives(), TargetFlatPrimitiveClass.class);
    ensureNotNullAndClass(o.getPrimitives().getIntArrayField(), int[].class);
    assertEquals(11, o.getPrimitives().getIntArrayField().length);
    assertEquals(3425, o.getPrimitives().getIntArrayField()[10]);
    write("/primitives/boxedStringArrayField[10]", "boxedString");
    ensureNotNullAndClass(o.getPrimitives().getBoxedStringArrayField(), String[].class);
    assertEquals(11, o.getPrimitives().getBoxedStringArrayField().length);
    for (int i = 0; i < 10; i++) {
        System.out.println("Checking #" + i);
        assertNull(o.getPrimitives().getBoxedStringArrayField()[i]);
    }
    ensureNotNullAndClass(o.getPrimitives().getBoxedStringArrayField()[10], String.class);
    assertEquals("boxedString", o.getPrimitives().getBoxedStringArrayField()[10]);
    // test writing enum values
    write("/statesLong", StateEnumClassLong.Massachusetts);
    assertNotNull(o.getStatesLong());
    assertEquals(StateEnumClassLong.Massachusetts, o.getStatesLong());
    // test overwriting values
    assertEquals("123 any street", o.getAddress().getAddressLine1());
    write("/address/addressLine1", "123 any street (2)");
    assertEquals("123 any street (2)", o.getAddress().getAddressLine1());
    order = o.getListOrders().getOrders().get(5);
    assertEquals((Integer) 1234, order.getOrderId());
    write("/listOrders/orders<5>/orderId", 2221234);
    assertEquals((Integer) 2221234, order.getOrderId());
    order = o.getListOrders().getOrders().get(2);
    assertEquals("Austin", order.getAddress().getCity());
    write("/listOrders/orders<2>/address/city", "Austin (2)");
    assertEquals("Austin (2)", order.getAddress().getCity());
    assertEquals((Integer) 56, o.getOrderArray().getNumberOrders());
    write("/orderArray/numberOrders", 22256);
    assertEquals((Integer) 22256, o.getOrderArray().getNumberOrders());
    assertEquals("fName", o.getOrderArray().getOrders()[2].getContact().getFirstName());
    write("/orderArray/orders[2]/contact/firstName", "fName (2)");
    assertEquals("fName (2)", o.getOrderArray().getOrders()[2].getContact().getFirstName());
    assertEquals("lName", o.getOrderArray().getOrders()[2].getContact().getLastName());
    write("/orderArray/orders[2]/contact/lastName", "lName (2)");
    assertEquals("lName (2)", o.getOrderArray().getOrders()[2].getContact().getLastName());
    assertEquals(3425, o.getPrimitives().getIntArrayField()[10]);
    write("/primitives/intArrayField[10]", 2223425);
    assertEquals(2223425, o.getPrimitives().getIntArrayField()[10]);
    assertEquals("boxedString", o.getPrimitives().getBoxedStringArrayField()[10]);
    write("/primitives/boxedStringArrayField[10]", "boxedString (2)");
    assertEquals("boxedString (2)", o.getPrimitives().getBoxedStringArrayField()[10]);
    assertEquals(StateEnumClassLong.Massachusetts, o.getStatesLong());
    write("/statesLong", StateEnumClassLong.Alabama);
    assertEquals(StateEnumClassLong.Alabama, o.getStatesLong());
}
Also used : BaseOrder(io.atlasmap.java.test.BaseOrder) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) Test(org.junit.Test)

Example 24 with TargetOrder

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

the class JavaConstructServiceComplexArrayTest method testConstructTargetOrderArrayFiltered.

@Test
public void testConstructTargetOrderArrayFiltered() throws Exception {
    Object targetObject = constructService.constructClass(generateOrderArray("Target"), Arrays.asList("orders", "orders/address"));
    assertNotNull(targetObject);
    assertTrue(targetObject instanceof TargetOrderArray);
    TargetOrderArray orderArray = (TargetOrderArray) targetObject;
    assertNotNull(orderArray.getOrders());
    assertTrue(orderArray.getOrders().length > 0);
    assertNull(orderArray.getNumberOrders());
    for (int i = 0; i < orderArray.getOrders().length; i++) {
        TargetOrder order = (TargetOrder) orderArray.getOrders()[i];
        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());
        assertNull(order.getContact());
    }
}
Also used : TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Test(org.junit.Test)

Aggregations

TargetOrder (io.atlasmap.java.test.TargetOrder)24 Test (org.junit.Test)21 AtlasContext (io.atlasmap.api.AtlasContext)11 AtlasSession (io.atlasmap.api.AtlasSession)11 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)11 File (java.io.File)11 TargetAddress (io.atlasmap.java.test.TargetAddress)10 TargetContact (io.atlasmap.java.test.TargetContact)7 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)7 BaseOrder (io.atlasmap.java.test.BaseOrder)6 TargetTestClass (io.atlasmap.java.test.TargetTestClass)4 TestListOrders (io.atlasmap.java.test.TestListOrders)4 AtlasException (io.atlasmap.api.AtlasException)3 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 JavaClass (io.atlasmap.java.v2.JavaClass)2 JavaField (io.atlasmap.java.v2.JavaField)2 BaseAddress (io.atlasmap.java.test.BaseAddress)1 BaseContact (io.atlasmap.java.test.BaseContact)1 StateEnumClassLong (io.atlasmap.java.test.StateEnumClassLong)1 TargetParentOrder (io.atlasmap.java.test.TargetParentOrder)1