Search in sources :

Example 16 with TargetContact

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

the class AtlasMapMultiDocsTest method test.

@Test
@DirtiesContext
public void test() throws Exception {
    result.setExpectedCount(1);
    Map<String, Message> sourceMap = new HashMap<>();
    SourceContact javaSource = new SourceContact();
    javaSource.setFirstName("JavaFirstName");
    javaSource.setLastName("JavaLastName");
    javaSource.setPhoneNumber("JavaPhoneNumber");
    javaSource.setZipCode("JavaZipCode");
    Message msg = new DefaultMessage(camelContext);
    msg.setBody(javaSource);
    sourceMap.put("DOCID:JAVA:CONTACT:S", msg);
    msg = new DefaultMessage(camelContext);
    msg.setBody(JSON_SOURCE);
    sourceMap.put("DOCID:JSON:CONTACT:S", msg);
    msg = new DefaultMessage(camelContext);
    msg.setBody(XML_SOURCE);
    sourceMap.put("DOCID:XML:CONTACT:S", msg);
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBodyAndProperty("direct:start", null, "CAPTURED_OUT_MESSAGES_MAP", sourceMap);
    MockEndpoint.assertIsSatisfied(camelContext);
    Exchange exchange = result.getExchanges().get(0);
    Map<?, ?> targetMap = exchange.getProperty(AtlasConstants.ATLAS_TARGET_MAP, Map.class);
    TargetContact javaTarget = (TargetContact) targetMap.get("DOCID:JAVA:CONTACT:T");
    assertEquals("JavaFirstName", javaTarget.getFirstName());
    assertEquals("XmlLastName", javaTarget.getLastName());
    assertEquals("JsonPhoneNumber", javaTarget.getPhoneNumber());
    String jsonTarget = (String) targetMap.get("DOCID:JSON:CONTACT:T");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonTargetNode = mapper.readTree(jsonTarget);
    assertEquals("JsonFirstName", jsonTargetNode.get("firstName").asText());
    assertEquals("JavaLastName", jsonTargetNode.get("lastName").asText());
    assertEquals("XmlPhoneNumber", jsonTargetNode.get("phoneNumber").asText());
    String xmlTarget = (String) targetMap.get("DOCID:XML:CONTACT:T");
    JAXBElement<XmlContactAttribute> xmlTargetJaxb = AtlasXmlTestHelper.unmarshal(xmlTarget, XmlContactAttribute.class);
    XmlContactAttribute xmlTargetObj = xmlTargetJaxb.getValue();
    assertEquals("XmlFirstName", xmlTargetObj.getFirstName());
    assertEquals("JsonLastName", xmlTargetObj.getLastName());
    assertEquals("JavaPhoneNumber", xmlTargetObj.getPhoneNumber());
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) ProducerTemplate(org.apache.camel.ProducerTemplate) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) TargetContact(io.atlasmap.java.test.TargetContact) JsonNode(com.fasterxml.jackson.databind.JsonNode) Exchange(org.apache.camel.Exchange) SourceContact(io.atlasmap.java.test.SourceContact) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 17 with TargetContact

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

the class XmlJavaCombineTest method testProcessCombineOutOfOrder.

@Test
public void testProcessCombineOutOfOrder() throws Exception {
    AtlasSession session = processCombineMapping("src/test/resources/xmlToJava/atlasmapping-combine-outoforder.xml", new String(Files.readAllBytes(Paths.get("src/test/resources/xmlToJava/atlas-xml-combine.xml"))));
    TargetContact targetContact = (TargetContact) session.getDefaultTargetDocument();
    assertEquals("Ozzie Smith 5551212 81111", targetContact.getFirstName());
    assertNull(targetContact.getLastName());
    assertNull(targetContact.getPhoneNumber());
    assertNull(targetContact.getZipCode());
    assertFalse(session.hasErrors());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 18 with TargetContact

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

the class XmlJavaCombineTest method testProcessCombineNullInput.

@Test
public void testProcessCombineNullInput() throws Exception {
    AtlasSession session = processCombineMapping("src/test/resources/xmlToJava/atlasmapping-combine-inputnull.xml", new String(Files.readAllBytes(Paths.get("src/test/resources/xmlToJava/atlas-xml-combine-no-lastName.xml"))));
    TargetContact targetContact = (TargetContact) session.getDefaultTargetDocument();
    assertNotNull(targetContact);
    assertEquals("Ozzie  5551212 81111", targetContact.getFirstName());
    assertFalse(session.hasErrors());
}
Also used : TargetContact(io.atlasmap.java.test.TargetContact) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 19 with TargetContact

use of io.atlasmap.java.test.TargetContact 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 20 with TargetContact

use of io.atlasmap.java.test.TargetContact 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)

Aggregations

TargetContact (io.atlasmap.java.test.TargetContact)32 Test (org.junit.Test)30 AtlasSession (io.atlasmap.api.AtlasSession)25 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)25 AtlasContext (io.atlasmap.api.AtlasContext)13 File (java.io.File)13 TargetTestClass (io.atlasmap.java.test.TargetTestClass)8 BaseContact (io.atlasmap.java.test.BaseContact)7 TargetOrder (io.atlasmap.java.test.TargetOrder)7 TargetAddress (io.atlasmap.java.test.TargetAddress)6 BaseOrder (io.atlasmap.java.test.BaseOrder)4 SourceContact (io.atlasmap.java.test.SourceContact)4 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)3 AtlasException (io.atlasmap.api.AtlasException)2 TestListOrders (io.atlasmap.java.test.TestListOrders)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseAddress (io.atlasmap.java.test.BaseAddress)1 StateEnumClassLong (io.atlasmap.java.test.StateEnumClassLong)1 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)1