Search in sources :

Example 1 with AdaptrisMessageFactory

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

the class XmlNotificationSerializerTest method testSerialize_WithContentEncoding_FromMessage.

@Test
public void testSerialize_WithContentEncoding_FromMessage() throws Exception {
    String myName = testName.getMethodName();
    Notification n = new Notification(myName, myName, 1, myName);
    n.setUserData(new Object());
    XmlNotificationSerializer serializer = new XmlNotificationSerializer();
    AdaptrisMessageFactory factory = new DefaultMessageFactory();
    factory.setDefaultCharEncoding("ISO-8859-1");
    AdaptrisMessage msg = serializer.serialize(n, factory.newMessage());
    XmlUtils utils = XmlHelper.createXmlUtils(msg, null, null);
    assertNotNull(msg.getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Message"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Type"));
    assertEquals(myName, utils.getSingleTextItem("/Notification/Source"));
    assertEquals("1", utils.getSingleTextItem("/Notification/SequenceNumber"));
    assertNotNull(utils.getSingleTextItem("/Notification/Timestamp"));
    assertEquals("ISO-8859-1", msg.getContentEncoding());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Notification(javax.management.Notification) Test(org.junit.Test)

Example 2 with AdaptrisMessageFactory

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

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

the class ZipAggregatorTest method testJoinMessage.

@Test
public void testJoinMessage() throws Exception {
    ZipAggregator aggr = new ZipAggregator();
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage original = fac.newMessage();
    AdaptrisMessage splitMsg1 = fac.newMessage("<document>hello</document>");
    splitMsg1.addMetadata(DEFAULT_FILENAME_METADATA, "file1.xml");
    AdaptrisMessage splitMsg2 = fac.newMessage("<document>world</document>");
    splitMsg2.addMetadata(DEFAULT_FILENAME_METADATA, "file2.xml");
    AdaptrisMessage willBeIgnoredMsg = fac.newMessage("<document>world</document>");
    aggr.joinMessage(original, Arrays.asList(splitMsg1, splitMsg2, willBeIgnoredMsg));
    boolean isZipped = new ZipInputStream(new ByteArrayInputStream(original.getPayload())).getNextEntry() != null;
    assertTrue(isZipped);
    Map<String, String> results = zipBytesToResultsMap(original.getPayload());
    assertEquals(2, results.size());
    assertTrue(results.containsKey("file1.xml"));
    assertTrue(results.containsKey("file2.xml"));
    assertEquals(results.get("file1.xml"), "<document>hello</document>");
    assertEquals(results.get("file2.xml"), "<document>world</document>");
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) ZipInputStream(java.util.zip.ZipInputStream) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 4 with AdaptrisMessageFactory

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

the class ZipAggregatorTest method testJoinMessageWithFilter.

@Test
public void testJoinMessageWithFilter() throws Exception {
    ZipAggregator aggr = new ZipAggregator();
    aggr.setFilterCondition(new MetadataFilenameCondition());
    AdaptrisMessage original = AdaptrisMessageFactory.getDefaultInstance().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));
    boolean isZipped = new ZipInputStream(new ByteArrayInputStream(original.getPayload())).getNextEntry() != null;
    assertTrue(isZipped);
    Map<String, String> results = zipBytesToResultsMap(original.getPayload());
    assertEquals(2, results.size());
    assertTrue(results.containsKey("file2.xml"));
    assertTrue(results.containsKey("file4.xml"));
    assertEquals(results.get("file2.xml"), "<document>world2</document>");
    assertEquals(results.get("file4.xml"), "<document>world4</document>");
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) ZipInputStream(java.util.zip.ZipInputStream) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 5 with AdaptrisMessageFactory

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

the class ReplaceFirstAggregatorTest method testAggregate_NoMatch.

@Test
public void testAggregate_NoMatch() throws Exception {
    ReplaceWithFirstMessage aggr = createAggregatorForTests();
    aggr.setFilterCondition(new LengthCheckCondition());
    AdaptrisMessageFactory fac = AdaptrisMessageFactory.getDefaultInstance();
    AdaptrisMessage original = fac.newMessage("Goodbye");
    AdaptrisMessage splitMsg1 = fac.newMessage("short");
    AdaptrisMessage splitMsg2 = fac.newMessage("justShort");
    AdaptrisMessage splitMsg3 = fac.newMessage("tooShort");
    AdaptrisMessage splitMsg4 = fac.newMessage("tooSmall");
    aggr.aggregate(original, Arrays.asList(splitMsg1, splitMsg2, splitMsg3, splitMsg4));
    assertEquals("Goodbye", original.getContent());
}
Also used : AdaptrisMessageFactory(com.adaptris.core.AdaptrisMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

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