Search in sources :

Example 6 with TargetTestClass

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

the class JavaJavaCollectionTest method testProcessCollectionListSimple.

@Test
public void testProcessCollectionListSimple() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-list-simple.xml").toURI());
    TargetTestClass input = new TargetTestClass();
    input.setContactList(new LinkedList<>());
    for (int i = 0; i < 5; i++) {
        input.getContactList().add(new TargetContact());
        input.getContactList().get(i).setFirstName("fname" + i);
    }
    AtlasSession session = context.createSession();
    session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
    assertEquals(5, object.getContactList().size());
    for (int i = 0; i < 5; i++) {
        assertEquals(input.getContactList().get(i).getFirstName(), object.getContactList().get(i).getFirstName());
    }
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 7 with TargetTestClass

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

the class JavaJavaCollectionTest method testProcessCollectionArray.

@Test
public void testProcessCollectionArray() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-array.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());
    TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
    assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
    assertEquals(20, object.getContactArray().length);
    for (int i = 0; i < 20; i++) {
        TargetContact contact = object.getContactArray()[i];
        if (i == 6 || i == 19) {
            assertEquals("Ozzie", contact.getFirstName());
        } else {
            assertNull(contact);
        }
    }
}
Also used : BaseOrder(io.atlasmap.java.test.BaseOrder) TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 8 with TargetTestClass

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

the class MultidocComplexTest method testProcessComplexBasicNullContact.

@Test
public void testProcessComplexBasicNullContact() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
    AtlasSession session = context.createSession();
    BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    javaSourceOrder.setContact(null);
    session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
    String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
    session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
    String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    TargetTestClass targetTestClass = (TargetTestClass) session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), targetTestClass.getClass().getName());
    assertEquals(TargetContact.class.getName(), targetTestClass.getContact().getClass().getName());
    assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
    assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
    assertEquals("Smith", targetTestClass.getContact().getLastName());
    Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
    assertTrue(jsonTargetOrder instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
    assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertNull(jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
    assertEquals("8765309", xmlOE.getOrderId());
    assertEquals(null, xmlOE.getContact().getLastName());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) XmlOrderElement(io.atlasmap.xml.test.v2.XmlOrderElement) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 9 with TargetTestClass

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

the class MultidocComplexTest method testProcessBasic.

@Test
public void testProcessBasic() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/multidoc/atlasmapping-complex-simple.xml").toURI());
    AtlasSession session = context.createSession();
    BaseOrder javaSourceOrder = AtlasTestUtil.generateOrderClass(SourceOrder.class, SourceAddress.class, SourceContact.class);
    session.setSourceDocument("JavaSourceOrder", javaSourceOrder);
    String jsonSourceOrder = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-json-complex-order-autodetect-unrooted.json");
    session.setSourceDocument("JsonSourceOrder", jsonSourceOrder);
    String xmlOrderAttribute = AtlasTestUtil.loadFileAsString("src/test/resources/multidoc/atlas-xml-complex-order-autodetect-attribute-ns.xml");
    session.setSourceDocument("XmlOrderAttribute", xmlOrderAttribute);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
    TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
    assertEquals(new Integer(8765309), targetTestClass.getOrder().getOrderId());
    assertEquals("Ozzie", targetTestClass.getContact().getFirstName());
    assertEquals("Smith", targetTestClass.getContact().getLastName());
    Object jsonTargetOrder = session.getTargetDocument("JsonTargetOrder");
    assertTrue(jsonTargetOrder instanceof String);
    AtlasJsonTestUnrootedMapper testMapper = new AtlasJsonTestUnrootedMapper();
    io.atlasmap.json.test.TargetOrder jsonTargetOrderObject = testMapper.readValue((String) jsonTargetOrder, io.atlasmap.json.test.TargetOrder.class);
    assertEquals(new Integer(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    XmlOrderElement xmlOE = AtlasXmlTestHelper.unmarshal((String) xmlOrderElement, XmlOrderElement.class).getValue();
    assertEquals("8765309", xmlOE.getOrderId());
    assertEquals("Ozzie", xmlOE.getContact().getFirstName());
    assertEquals("Smith", xmlOE.getContact().getLastName());
}
Also used : AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) XmlOrderElement(io.atlasmap.xml.test.v2.XmlOrderElement) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 10 with TargetTestClass

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

the class JavaJavaCollectionTest method testProcessCollectionFromNonCollection.

@Test
public void testProcessCollectionFromNonCollection() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-from-noncollection.xml").toURI());
    TargetTestClass input = new TargetTestClass();
    input.setContact(new TargetContact());
    input.getContact().setFirstName("first name");
    input.getContact().setLastName("last name");
    AtlasSession session = context.createSession();
    session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    TargetTestClass object = (TargetTestClass) session.getDefaultTargetDocument();
    assertEquals(1, object.getContactList().size());
    assertEquals("first name", object.getContactList().get(0).getFirstName());
    assertEquals("last name", object.getContactList().get(0).getLastName());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Aggregations

TargetTestClass (io.atlasmap.java.test.TargetTestClass)17 Test (org.junit.Test)14 AtlasContext (io.atlasmap.api.AtlasContext)11 AtlasSession (io.atlasmap.api.AtlasSession)11 TargetContact (io.atlasmap.java.test.TargetContact)11 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)11 File (java.io.File)11 BaseOrder (io.atlasmap.java.test.BaseOrder)8 TargetOrder (io.atlasmap.java.test.TargetOrder)4 AtlasException (io.atlasmap.api.AtlasException)3 TargetAddress (io.atlasmap.java.test.TargetAddress)3 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)3 TestListOrders (io.atlasmap.java.test.TestListOrders)3 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)2 XmlOrderElement (io.atlasmap.xml.test.v2.XmlOrderElement)2 StateEnumClassLong (io.atlasmap.java.test.StateEnumClassLong)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1 JavaField (io.atlasmap.java.v2.JavaField)1 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)1