Search in sources :

Example 11 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory 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 12 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class ZipAggregatorTest method testAggregate_BrokenOutput.

@Test(expected = CoreException.class)
public void testAggregate_BrokenOutput() throws Exception {
    ZipAggregator aggr = new ZipAggregator();
    AdaptrisMessage original = new DefectiveMessageFactory(WhenToBreak.OUTPUT).newMessage();
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage splitMsg1 = fac.newMessage("<document>hello</document>");
    splitMsg1.addMetadata(DEFAULT_FILENAME_METADATA, "xfile1.xml");
    AdaptrisMessage splitMsg2 = fac.newMessage("<document>world2</document>");
    splitMsg2.addMetadata(DEFAULT_FILENAME_METADATA, "file2.xml");
    AdaptrisMessage splitMsg3 = fac.newMessage("<document>world3</document>");
    splitMsg3.addMetadata(DEFAULT_FILENAME_METADATA, "xfile3.xml");
    AdaptrisMessage splitMsg4 = fac.newMessage("<document>world4</document>");
    splitMsg4.addMetadata(DEFAULT_FILENAME_METADATA, "file4.xml");
    AdaptrisMessage willBeIgnoredMsg = fac.newMessage("<document>world4</document>");
    aggr.joinMessage(original, Arrays.asList(splitMsg1, splitMsg2, splitMsg3, splitMsg4, willBeIgnoredMsg));
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 13 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class ReplaceFirstAggregatorTest method testAggregate_BrokenOutput.

@Test(expected = CoreException.class)
public void testAggregate_BrokenOutput() throws Exception {
    ReplaceWithFirstMessage aggr = createAggregatorForTests();
    aggr.setOverwriteMetadata(true);
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage original = new DefectiveMessageFactory(WhenToBreak.OUTPUT).newMessage("Goodbye");
    AdaptrisMessage splitMsg1 = fac.newMessage("short");
    AdaptrisMessage splitMsg2 = fac.newMessage("justShort");
    AdaptrisMessage splitMsg3 = fac.newMessage("ofSufficientLength");
    AdaptrisMessage splitMsg4 = fac.newMessage("tooSmall");
    aggr.joinMessage(original, Arrays.asList(splitMsg1, splitMsg2, splitMsg3, splitMsg4));
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 14 with AdaptrisMessageFactory

use of com.adaptris.core.AdaptrisMessageFactory in project interlok by adaptris.

the class JmxNotificationConsumer method createMessage.

private AdaptrisMessage createMessage(Notification n) throws CoreException, IOException {
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.defaultIfNull(getMessageFactory());
    AdaptrisMessage msg = getSerializer().serialize(n, fac.newMessage());
    msg.addMessageHeader(JMX_NOTIF_SOURCE, n.getSource().toString());
    return msg;
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage)

Aggregations

AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)14 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 Test (org.junit.Test)10 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)3 CoreException (com.adaptris.core.CoreException)2 EvenOddCondition (com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition)2 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)2 MockEncoder (com.adaptris.core.stubs.MockEncoder)2 StubMessageFactory (com.adaptris.core.stubs.StubMessageFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 ZipInputStream (java.util.zip.ZipInputStream)2 XmlUtils (com.adaptris.util.XmlUtils)1 BodyPartIterator (com.adaptris.util.text.mime.BodyPartIterator)1 InsertNode (com.adaptris.util.text.xml.InsertNode)1 XPath (com.adaptris.util.text.xml.XPath)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1 MimeBodyPart (javax.mail.internet.MimeBodyPart)1 Notification (javax.management.Notification)1