Search in sources :

Example 36 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)

Example 37 with TargetOrder

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

the class BaseJavaFieldWriterTest method reset.

@BeforeEach
public void reset() {
    classLoader = Thread.currentThread().getContextClassLoader();
    writerUtil = new JavaFieldWriterUtil(conversionService);
    writer = new JavaFieldWriter(writerUtil);
    writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService, writerUtil));
    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);
    audits = new Audits();
}
Also used : Audits(io.atlasmap.v2.Audits) TargetContact(io.atlasmap.java.test.TargetContact) TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with TargetOrder

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

the class JavaFieldWriterTest method testSimpleWriteCollectionList.

@Test
public void testSimpleWriteCollectionList() throws Exception {
    writer.setRootObject(new TestListOrders());
    writeComplex("/orders<4>", new TargetOrder());
    writeComplex("/orders<4>/address", new TargetAddress());
    write("/orders<4>/address/addressLine1", "hello world.");
    TestListOrders o = (TestListOrders) writer.getRootObject();
    ensureNotNullAndClass(o, TestListOrders.class);
    ensureNotNullAndClass(o.getOrders(), LinkedList.class);
    assertEquals(5, o.getOrders().size());
    for (int i = 0; i < 5; i++) {
        System.out.println("Checking #" + i);
        if (i == 4) {
            ensureNotNullAndClass(o.getOrders().get(i), TargetOrder.class);
            ensureNotNullAndClass(o.getOrders().get(i).getAddress(), TargetAddress.class);
        } else {
            assertNull(o.getOrders().get(i));
        }
    }
    assertEquals("hello world.", o.getOrders().get(4).getAddress().getAddressLine1());
}
Also used : TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) Test(org.junit.jupiter.api.Test)

Example 39 with TargetOrder

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

the class JavaFieldWriterTest method testExpandCollectionList.

@Test
public void testExpandCollectionList() throws Exception {
    writer.setRootObject(new TestListOrders());
    writeComplex("/orders<4>", new TargetOrder());
    writeComplex("/orders<4>/address", new TargetAddress());
    write("/orders<4>/address/addressLine1", "hello world1.");
    writeComplex("/orders<14>", new TargetOrder());
    writeComplex("/orders<14>/address", new TargetAddress());
    write("/orders<14>/address/addressLine1", "hello world2.");
    writeComplex("/orders<2>", new TargetOrder());
    writeComplex("/orders<2>/address", new TargetAddress());
    write("/orders<2>/address/addressLine1", "hello world3.");
    TestListOrders o = (TestListOrders) writer.getRootObject();
    ensureNotNullAndClass(o, TestListOrders.class);
    ensureNotNullAndClass(o.getOrders(), LinkedList.class);
    assertEquals(15, o.getOrders().size());
    for (int i = 0; i < 15; i++) {
        System.out.println("Checking #" + i);
        if (i == 4 || i == 14 || i == 2) {
            ensureNotNullAndClass(o.getOrders().get(i), TargetOrder.class);
            ensureNotNullAndClass(o.getOrders().get(i).getAddress(), TargetAddress.class);
        } else {
            assertNull(o.getOrders().get(i));
        }
    }
    assertEquals("hello world1.", o.getOrders().get(4).getAddress().getAddressLine1());
    assertEquals("hello world2.", o.getOrders().get(14).getAddress().getAddressLine1());
    assertEquals("hello world3.", o.getOrders().get(2).getAddress().getAddressLine1());
}
Also used : TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) Test(org.junit.jupiter.api.Test)

Example 40 with TargetOrder

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

the class JavaFieldWriterUtilTest method testChildMap.

@Test
public void testChildMap() throws Exception {
    Object adjusted = writerUtil.adjustCollectionSize(targetOrderMap, new SegmentContext("targetOrderMap{foo}"));
    assertEquals(targetOrderMap, adjusted);
    try {
        writerUtil.setCollectionItem(targetOrderMap, new TargetOrder(), new SegmentContext("targetOrderMap{foo}"));
        fail("AtlasException is expected");
    } catch (AtlasException e) {
        assertTrue(e.getMessage().contains("TODO"), e.getMessage());
    }
    try {
        writerUtil.createComplexCollectionItem(targetOrderMap, TargetOrder.class, new SegmentContext("targetOrderMap{foo}"));
        fail("AtlasException is expected");
    } catch (AtlasException e) {
        assertTrue(e.getMessage().contains("TODO"), e.getMessage());
    }
    try {
        writerUtil.createComplexCollectionItem(this, targetOrderMap, new SegmentContext("targetOrderMap{foo}"));
        fail("AtlasException is expected");
    } catch (AtlasException e) {
        assertTrue(e.getMessage().contains("TODO"), e.getMessage());
    }
    try {
        writerUtil.setCollectionItem(targetOrderMap, new TargetOrder(), new SegmentContext("targetOrderMap{foo}"));
        fail("AtlasException is expected");
    } catch (AtlasException e) {
        assertTrue(e.getMessage().contains("TODO"), e.getMessage());
    }
}
Also used : SegmentContext(io.atlasmap.core.AtlasPath.SegmentContext) TargetOrder(io.atlasmap.java.test.TargetOrder) AtlasException(io.atlasmap.api.AtlasException) 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