Search in sources :

Example 21 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.json").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(session.hasErrors(), printAudit(session));
    Object javaTargetTestClass = session.getTargetDocument("JavaTargetTestClass");
    assertEquals(TargetTestClass.class.getName(), javaTargetTestClass.getClass().getName());
    TargetTestClass targetTestClass = (TargetTestClass) javaTargetTestClass;
    assertEquals(Integer.valueOf(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(Integer.valueOf(8765309), jsonTargetOrderObject.getOrderId());
    assertEquals("Ozzie", jsonTargetOrderObject.getContact().getFirstName());
    assertEquals("Smith", jsonTargetOrderObject.getContact().getLastName());
    Object xmlOrderElement = session.getTargetDocument("XmlOrderElement");
    assertNotNull(xmlOrderElement);
    assertTrue(xmlOrderElement instanceof String);
    HashMap<String, String> ns = new HashMap<>();
    ns.put("ns", "http://atlasmap.io/xml/test/v2");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:orderId").isEqualTo("8765309");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:firstName").isEqualTo("Ozzie");
    assertThat(xmlOrderElement).withNamespaceContext(ns).valueByXPath("/ns:XmlOE/ns:Contact/ns:lastName").isEqualTo("Smith");
}
Also used : HashMap(java.util.HashMap) AtlasJsonTestUnrootedMapper(io.atlasmap.json.test.AtlasJsonTestUnrootedMapper) BaseOrder(io.atlasmap.java.test.BaseOrder) AtlasContext(io.atlasmap.api.AtlasContext) TargetTestClass(io.atlasmap.java.test.TargetTestClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.itests.reference.AtlasMappingBaseTest) Test(org.junit.jupiter.api.Test)

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

Example 23 with TargetTestClass

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

the class JavaJavaCollectionTest method testProcessCollectionArraySimple.

@Test
public void testProcessCollectionArraySimple() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-array-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 24 with TargetTestClass

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

the class JavaJavaCollectionTest method testProcessCollectionToNonCollection.

@Test
public void testProcessCollectionToNonCollection() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-collection-to-noncollection.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();
    assertNull(object.getContactArray());
    assertNull(object.getContactList());
    assertEquals("fname4", object.getContact().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 25 with TargetTestClass

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

the class JavaJavaComplexTest method testProcessLookup.

@Test
public void testProcessLookup() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-lookup.xml").toURI());
    TargetTestClass input = new TargetTestClass();
    input.setStatesLong(StateEnumClassLong.Arizona);
    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();
    assertNotNull(object);
    assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
    assertEquals(StateEnumClassShort.AZ, object.getStatesShort());
    input.setStatesLong(StateEnumClassLong.Alabama);
    session = context.createSession();
    session.setSourceDocument("io.atlasmap.java.test.TargetTestClass", input);
    context.process(session);
    object = (TargetTestClass) session.getDefaultTargetDocument();
    assertNotNull(object);
    assertEquals(TargetTestClass.class.getName(), object.getClass().getName());
    assertNull(object.getStatesShort());
    assertTrue(printAudit(session), session.hasErrors());
}
Also used : 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)46 Test (org.junit.jupiter.api.Test)28 AtlasContext (io.atlasmap.api.AtlasContext)26 AtlasSession (io.atlasmap.api.AtlasSession)26 TargetContact (io.atlasmap.java.test.TargetContact)24 File (java.io.File)24 BaseOrder (io.atlasmap.java.test.BaseOrder)15 Test (org.junit.Test)14 AtlasMappingBaseTest (io.atlasmap.itests.reference.AtlasMappingBaseTest)13 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)11 TargetAddress (io.atlasmap.java.test.TargetAddress)10 TargetOrder (io.atlasmap.java.test.TargetOrder)7 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)5 JavaField (io.atlasmap.java.v2.JavaField)5 Field (io.atlasmap.v2.Field)5 TestListOrders (io.atlasmap.java.test.TestListOrders)4 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)4 AtlasException (io.atlasmap.api.AtlasException)3 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)3 FieldGroup (io.atlasmap.v2.FieldGroup)2