use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorTest method testAggregate_WithFilter.
@Test
public void testAggregate_WithFilter() throws Exception {
XmlDocumentAggregator aggr = createAggregatorForTests();
aggr.setMergeImplementation(new InsertNode(XPATH_ENVELOPE));
aggr.setFilterCondition(new EvenOddCondition());
AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
AdaptrisMessage original = fac.newMessage("<envelope/>");
AdaptrisMessage splitMsg1 = fac.newMessage("<document>hello</document>");
AdaptrisMessage splitMsg2 = fac.newMessage("<document>world</document>");
aggr.aggregate(original, Arrays.asList(new AdaptrisMessage[] { splitMsg1, splitMsg2 }));
XPath xpath = new XPath();
Document d = XmlHelper.createDocument(original, DocumentBuilderFactoryBuilder.newInstance());
assertEquals(1, xpath.selectNodeList(d, ENVELOPE_DOCUMENT).getLength());
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorCase method testJoinMessage_Fails.
@Test
public void testJoinMessage_Fails() throws Exception {
XmlDocumentAggregator aggr = createAggregatorForTests();
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 XmlAggregatorCase method testSetDocumentMerge.
@Test
public void testSetDocumentMerge() throws Exception {
XmlDocumentAggregator aggr = createAggregatorForTests();
assertNull(aggr.getMergeImplementation());
InsertNode inserter = new InsertNode(XPATH_ENVELOPE);
aggr.setMergeImplementation(inserter);
assertEquals(inserter, aggr.getMergeImplementation());
try {
aggr.setMergeImplementation(null);
fail();
} catch (Exception expected) {
}
assertEquals(inserter, aggr.getMergeImplementation());
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class XmlAggregatorTest method testSplitJoinService_WithExplicitDocumentEnoding.
@Test
public void testSplitJoinService_WithExplicitDocumentEnoding() 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));
XmlDocumentAggregator aggr = new XmlDocumentAggregator(new InsertNode(XPATH_ENVELOPE));
aggr.setDocumentEncoding("UTF-8");
service.setAggregator(aggr);
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("UTF-8", msg.getContentEncoding());
}
use of com.adaptris.util.text.xml.InsertNode in project interlok by adaptris.
the class IgnoreOriginalXmlAggregatorTest method testSplitJoinService_WithExplicitDocumentEnoding.
@Test
public void testSplitJoinService_WithExplicitDocumentEnoding() 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");
service.setAggregator(aggr);
execute(service, msg);
// Should now be 3 document nodes
// because we ignore the original
XPath xpath = new XPath();
assertEquals(3, xpath.selectNodeList(XmlHelper.createDocument(msg, true), "/new/document").getLength());
assertEquals("UTF-8", msg.getContentEncoding());
}
Aggregations