Search in sources :

Example 1 with EvenOddCondition

use of com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition 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());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) XPath(com.adaptris.util.text.xml.XPath) EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Document(org.w3c.dom.Document) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 2 with EvenOddCondition

use of com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition 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());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) XPath(com.adaptris.util.text.xml.XPath) EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) NullService(com.adaptris.core.NullService) XpathMessageSplitter(com.adaptris.core.services.splitter.XpathMessageSplitter) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 3 with EvenOddCondition

use of com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition in project interlok by adaptris.

the class MimeAggregatorCase method testAggregate_WithFilter.

@Test
public void testAggregate_WithFilter() throws Exception {
    MimeAggregator aggr = createAggregatorForTests();
    aggr.setOverwriteMetadata(false);
    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 }));
    String payload = original.getContent();
    assertFalse(payload.contains("hello"));
    assertTrue(payload.contains("world"));
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 4 with EvenOddCondition

use of com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition in project interlok by adaptris.

the class MimeAggregatorTest method testService_withFilter.

@Test
public void testService_withFilter() throws Exception {
    // This is a 100 line message, so we expect to get 11 parts.
    AdaptrisMessage msg = SplitterCase.createLineCountMessageInput();
    PooledSplitJoinService service = new PooledSplitJoinService();
    // The service doesn't actually matter right now.
    service.setService(createAddMetadataService(getName()));
    service.setTimeout(new TimeInterval(10L, TimeUnit.SECONDS));
    service.setSplitter(new LineCountSplitter());
    MimeAggregator aggr = createAggregatorForTests();
    aggr.setFilterCondition(new EvenOddCondition());
    service.setAggregator(aggr);
    execute(service, msg);
    BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
    assertEquals(6, input.size());
}
Also used : PooledSplitJoinService(com.adaptris.core.services.splitter.PooledSplitJoinService) EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) TimeInterval(com.adaptris.util.TimeInterval) BodyPartIterator(com.adaptris.util.text.mime.BodyPartIterator) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) LineCountSplitter(com.adaptris.core.services.splitter.LineCountSplitter) Test(org.junit.Test)

Example 5 with EvenOddCondition

use of com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition in project interlok by adaptris.

the class MultiPayloadMessageAggregatorTest method testWithFilter.

@Test
public void testWithFilter() throws Exception {
    aggregator.setReplaceOriginalMessage(false);
    aggregator.setFilterCondition(new EvenOddCondition());
    aggregator.aggregate(message, messages);
    assertFalse(aggregator.getReplaceOriginalMessage());
    // 2 to merge, of which one will be discarded + the original.
    assertEquals(2, message.getPayloadCount());
}
Also used : EvenOddCondition(com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition) Test(org.junit.Test)

Aggregations

EvenOddCondition (com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition)6 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)2 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)2 TimeInterval (com.adaptris.util.TimeInterval)2 InsertNode (com.adaptris.util.text.xml.InsertNode)2 XPath (com.adaptris.util.text.xml.XPath)2 NullService (com.adaptris.core.NullService)1 LineCountSplitter (com.adaptris.core.services.splitter.LineCountSplitter)1 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)1 BodyPartIterator (com.adaptris.util.text.mime.BodyPartIterator)1 Document (org.w3c.dom.Document)1