Search in sources :

Example 1 with XmlContactAttribute

use of io.atlasmap.xml.test.v2.XmlContactAttribute in project atlasmap by atlasmap.

the class JavaXmlCombineTest method testProcessCombineSimple.

@Test
public void testProcessCombineSimple() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToXml/atlasmapping-combine-simple.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    JAXBElement<XmlContactAttribute> targetContact = AtlasXmlTestHelper.unmarshal((String) object, XmlContactAttribute.class);
    assertEquals("Ozzie    Smith   5551212                                                                                            81111", targetContact.getValue().getFirstName());
    assertNull(targetContact.getValue().getLastName());
    assertNull(targetContact.getValue().getPhoneNumber());
    assertNull(targetContact.getValue().getZipCode());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 2 with XmlContactAttribute

use of io.atlasmap.xml.test.v2.XmlContactAttribute in project atlasmap by atlasmap.

the class JavaXmlCombineTest method testProcessCombineOutOfOrder.

@Test
public void testProcessCombineOutOfOrder() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToXml/atlasmapping-combine-outoforder.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    JAXBElement<XmlContactAttribute> targetContact = AtlasXmlTestHelper.unmarshal((String) object, XmlContactAttribute.class);
    assertEquals("Ozzie Smith 5551212 81111", targetContact.getValue().getFirstName());
    assertNull(targetContact.getValue().getLastName());
    assertNull(targetContact.getValue().getPhoneNumber());
    assertNull(targetContact.getValue().getZipCode());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 3 with XmlContactAttribute

use of io.atlasmap.xml.test.v2.XmlContactAttribute in project atlasmap by atlasmap.

the class JavaXmlSeparateTest method testProcessSeparateSkip.

@Test
public void testProcessSeparateSkip() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToXml/atlasmapping-separate-skip.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    sourceContact.setFirstName("Dr. Mr. Ozzie L. Smith Jr.");
    sourceContact.setLastName(null);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    JAXBElement<XmlContactAttribute> targetContact = AtlasXmlTestHelper.unmarshal((String) object, XmlContactAttribute.class);
    AtlasTestUtil.validateXmlContactAttribute(targetContact.getValue());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 4 with XmlContactAttribute

use of io.atlasmap.xml.test.v2.XmlContactAttribute in project atlasmap by atlasmap.

the class JavaXmlSeparateTest method testProcessSeparateOutOfOrder.

@Test
public void testProcessSeparateOutOfOrder() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToXml/atlasmapping-separate-outoforder.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    sourceContact.setFirstName("Dr. Mr. Ozzie L. Smith Jr.");
    sourceContact.setLastName(null);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof String);
    JAXBElement<XmlContactAttribute> targetContact = AtlasXmlTestHelper.unmarshal((String) object, XmlContactAttribute.class);
    AtlasTestUtil.validateXmlContactAttribute(targetContact.getValue());
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 5 with XmlContactAttribute

use of io.atlasmap.xml.test.v2.XmlContactAttribute 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)

Aggregations

XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)10 Test (org.junit.Test)10 AtlasContext (io.atlasmap.api.AtlasContext)9 AtlasSession (io.atlasmap.api.AtlasSession)9 BaseContact (io.atlasmap.java.test.BaseContact)9 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)9 File (java.io.File)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SourceContact (io.atlasmap.java.test.SourceContact)1 TargetContact (io.atlasmap.java.test.TargetContact)1 HashMap (java.util.HashMap)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 DefaultMessage (org.apache.camel.impl.DefaultMessage)1 DirtiesContext (org.springframework.test.annotation.DirtiesContext)1