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());
}
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());
}
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());
}
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());
}
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());
}
}
Aggregations