use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class IgnoreOriginalXmlAggregatorTest method testJoinMessage_NoTemplate.
@Test
public void testJoinMessage_NoTemplate() throws Exception {
XmlDocumentAggregator aggr = new IgnoreOriginalXmlDocumentAggregator();
aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>");
AdaptrisMessage splitMsg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>");
AdaptrisMessage splitMsg2 = new DefectiveMessageFactory().newMessage("<document>world</document>");
try {
aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
fail();
} catch (CoreException expected) {
}
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class IgnoreOriginalXmlAggregatorTest method testSplitJoinService_withFilter.
@Test
public void testSplitJoinService_withFilter() throws Exception {
// This is a XML doc with 3 iterable elements...
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(SplitterCase.XML_MESSAGE);
PooledSplitJoinService service = new PooledSplitJoinService();
// The service doesn't actually matter right now.
service.setService(asCollection(new NullService()));
service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
service.setSplitter(new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8));
IgnoreOriginalXmlDocumentAggregator aggr = new IgnoreOriginalXmlDocumentAggregator("<new/>", new InsertNode("/new"));
aggr.setDocumentEncoding("UTF-8");
aggr.setFilterCondition(new EvenOddCondition());
service.setAggregator(aggr);
execute(service, msg);
// Should now be 3 document nodes
// because we ignore the original
XPath xpath = new XPath();
assertEquals(1, xpath.selectNodeList(XmlHelper.createDocument(msg, true), "/new/document").getLength());
assertEquals("UTF-8", msg.getContentEncoding());
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorTest method testSplitJoinService_WithImplicitDocumentEnoding.
@Test
public void testSplitJoinService_WithImplicitDocumentEnoding() throws Exception {
// This is a XML doc with 3 iterable elements...
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(SplitterCase.XML_MESSAGE, "ISO-8859-1");
PooledSplitJoinService service = new PooledSplitJoinService();
// The service doesn't actually matter right now.
service.setService(asCollection(new NullService()));
service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
service.setSplitter(new XpathMessageSplitter(ENVELOPE_DOCUMENT, ENCODING_UTF8));
service.setAggregator(new XmlDocumentAggregator(new InsertNode(XPATH_ENVELOPE)));
execute(service, msg);
// Should now be 6 document nodes
XPath xpath = new XPath();
assertEquals(6, xpath.selectNodeList(XmlHelper.createDocument(msg, true), ENVELOPE_DOCUMENT).getLength());
assertEquals("ISO-8859-1", msg.getContentEncoding());
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorCase method testJoinMessage_OverwriteMetadata.
@Test
public void testJoinMessage_OverwriteMetadata() throws Exception {
XmlDocumentAggregator aggr = createAggregatorForTests();
aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
aggr.setOverwriteMetadata(true);
AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>");
original.addMetadata("originalKey", "originalValue");
AdaptrisMessage splitMsg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>");
AdaptrisMessage splitMsg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>");
splitMsg2.addMetadata("originalKey", "newValue");
aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
assertEquals("newValue", original.getMetadataValue("originalKey"));
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorCase method testJoinMessage_NoOverwriteMetadata.
@Test
public void testJoinMessage_NoOverwriteMetadata() throws Exception {
XmlDocumentAggregator aggr = createAggregatorForTests();
aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
aggr.setOverwriteMetadata(false);
AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().newMessage("<envelope/>");
original.addMetadata("originalKey", "originalValue");
AdaptrisMessage splitMsg1 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>hello</document>");
AdaptrisMessage splitMsg2 = AdaptrisMessageFactory.getDefaultInstance().newMessage("<document>world</document>");
splitMsg2.addMetadata("originalKey", "newValue");
aggr.joinMessage(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
assertEquals("originalValue", original.getMetadataValue("originalKey"));
}
Aggregations