Search in sources :

Example 26 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.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();
    assertNotNull(object);
    assertTrue(object instanceof TargetOrder);
    TargetOrder targetOrder = (TargetOrder) object;
    assertNotNull(targetOrder.getOrderId());
    assertEquals(new Integer(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) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 27 with TargetOrder

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

the class JavaJavaMultiSourceTest method testProcessComplex.

@Test
public void testProcessComplex() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-multisource-complex.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    BaseAddress sourceAddress = AtlasTestUtil.generateAddress(SourceAddress.class);
    session.setSourceDocument("con", sourceContact);
    session.setSourceDocument("addr", sourceAddress);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertEquals(TargetOrder.class.getName(), object.getClass().getName());
    TargetOrder targetOrder = (TargetOrder) object;
    AtlasTestUtil.validateOrder(targetOrder);
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) AtlasContext(io.atlasmap.api.AtlasContext) TargetOrder(io.atlasmap.java.test.TargetOrder) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) BaseAddress(io.atlasmap.java.test.BaseAddress) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 28 with TargetOrder

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

the class JsonJavaComplexTest method testProcessJsonJavaComplexOrderAutodetectRooted.

@Test
public void testProcessJsonJavaComplexOrderAutodetectRooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJava/atlasmapping-complex-order-autodetect-rooted.xml").toURI());
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJava/atlas-json-complex-order-autodetect-rooted.json");
    session.setDefaultSourceDocument(source);
    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.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 29 with TargetOrder

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

the class JsonJavaComplexTest method testProcessJsonJavaComplexOrderAutodetectUnrooted.

@Test
public void testProcessJsonJavaComplexOrderAutodetectUnrooted() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/jsonToJava/atlasmapping-complex-order-autodetect-unrooted.xml").toURI());
    AtlasSession session = context.createSession();
    String source = AtlasTestUtil.loadFileAsString("src/test/resources/jsonToJava/atlas-json-complex-order-autodetect-unrooted.json");
    session.setDefaultSourceDocument(source);
    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.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 30 with TargetOrder

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

the class JavaWriterUtilMock method getObjectFromParent.

/**
 * Retrieve a child object (which may be a complex class or collection class)
 * from the given parentObject.
 *
 * @param field
 *            - provided for convenience, probably not needed here
 * @param ParentObject
 *            - the object to find the child on
 * @param segmentContext
 *            - the segment of the field's path that references the child object
 */
@Override
public Object getObjectFromParent(Field field, Object parentObject, SegmentContext segmentContext) throws AtlasException {
    String segment = segmentContext.getSegment();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Retrieving child '" + segmentContext.getSegmentPath() + "'.\n\tparentObject: " + parentObject);
    }
    if (parentObject == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Cannot find child '" + segmentContext.getSegmentPath() + "', parent is null.");
        }
        return null;
    }
    // clean up our segment from something like "@addressLine1" to "addressLine1".
    // collection segments like "orders[4]" will be cleaned to "orders"
    String cleanedSegment = AtlasPath.cleanPathSegment(segmentContext.getSegment());
    Object childObject = null;
    if (parentObject instanceof TargetAddress && "addressLine1".equals(cleanedSegment)) {
        childObject = ((TargetAddress) parentObject).getAddressLine1();
    } else if ("orders".equals(cleanedSegment) && parentObject instanceof TestListOrders) {
        childObject = ((TestListOrders) parentObject).getOrders();
    } else if ("orders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
        childObject = ((TargetOrderArray) parentObject).getOrders();
    } else if ("address".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
        childObject = ((TargetOrder) parentObject).getAddress();
    } else if ("address".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = ((TargetTestClass) parentObject).getAddress();
    } else if ("listOrders".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = ((TargetTestClass) parentObject).getListOrders();
    } else if ("orderArray".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = ((TargetTestClass) parentObject).getOrderArray();
    } else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
        childObject = ((TargetOrder) parentObject).getContact();
    } else if ("numberOrders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
        childObject = ((TargetOrderArray) parentObject).getNumberOrders();
    } else if ("primitives".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = ((TargetTestClass) parentObject).getPrimitives();
    } else if ("intArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
        childObject = ((TargetFlatPrimitiveClass) parentObject).getIntArrayField();
    } else if ("boxedStringArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
        childObject = ((TargetFlatPrimitiveClass) parentObject).getBoxedStringArrayField();
    } else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = ((TargetTestClass) parentObject).getContact();
    } else if ("nothing".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        childObject = null;
    } else {
        String clz = parentObject.getClass().getSimpleName();
        String getter = "get" + cleanedSegment.substring(0, 1).toUpperCase() + cleanedSegment.substring(1);
        String fix = "} else if (\"" + cleanedSegment + "\".equals(cleanedSegment) && parentObject instanceof " + clz + ") {\n " + "childObject = ((" + clz + ")parentObject)." + getter + "();";
        LOG.error(fix);
        throw new AtlasException("Don't know how to handle get object from parent: " + parentObject + ", segment: " + cleanedSegment);
    }
    // FIXME: Matt, right? an @ here indicates use the getter, or does @ mean access
    // member?
    boolean useGetter = AtlasPath.isAttributeSegment(segment);
    if (useGetter) {
    // FIXME: matt, something like this, but with reflection and what not
    // childObject = parentObject.getAddressLine1();
    } else {
    // FIXME: Matt, something lik this, but with reflection
    // childObject = parentObject.addressLine1;
    }
    if (LOG.isDebugEnabled()) {
        if (childObject == null) {
            LOG.debug("Could not find child object for path: " + segmentContext.getSegmentPath());
        } else {
            LOG.debug("Found child object for path '" + segmentContext.getSegmentPath() + "': " + childObject);
        }
    }
    // TODO: matt, should we throw an exception here if null?
    return childObject;
}
Also used : TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) AtlasException(io.atlasmap.api.AtlasException) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray)

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