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());
}
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());
}
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>");
}
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>");
}
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());
}
Aggregations