use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class AggregatingJmsConsumeServiceTest method testService_MultipleMessages.
@Test
public void testService_MultipleMessages() throws Exception {
AggregatingQueueConsumer consumer = new AggregatingQueueConsumer();
consumer.setMessageAggregator(new IgnoreOriginalMimeAggregator());
AggregatingJmsConsumeService service = createService(activeMqBroker, consumer, getName());
try {
sendDataMessage(activeMqBroker, getName());
sendDataMessage(activeMqBroker, getName());
start(service);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(PAYLOAD);
msg.addMetadata(DEFAULT_FILTER_KEY, "JMSCorrelationID = '0001'");
service.doService(msg);
BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
assertEquals(2, input.size());
} finally {
stop(service);
}
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class AggregatingJmsConsumeServiceTest method sendDataMessage.
private void sendDataMessage(EmbeddedActiveMq broker, String queue) throws Exception {
PtpProducer producer = new PtpProducer().withQueue(queue);
MetadataCorrelationIdSource corr = new MetadataCorrelationIdSource();
corr.setMetadataKey(CORRELATION_ID_KEY);
producer.setCorrelationIdSource(corr);
StandaloneProducer sp = new StandaloneProducer(broker.getJmsConnection(new BasicActiveMqImplementation(), true), producer);
try {
start(sp);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(DATA_PAYLOAD);
msg.addMetadata(CORRELATION_ID_KEY, "0001");
sp.doService(msg);
} finally {
stop(sp);
}
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class BlobMessageTranslatorTest method testMoveMetadataAdaptrisMessageToJmsMessage.
@Test
public void testMoveMetadataAdaptrisMessageToJmsMessage() throws Exception {
MessageTypeTranslatorImp trans = new BlobMessageTranslator();
JmsConnection conn = null;
try {
conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
start(conn);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
addMetadata(msg);
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
trans.registerSession(session);
trans.registerMessageFactory(new DefaultMessageFactory());
start(trans);
Message jmsMsg = trans.translate(msg);
assertJmsProperties(jmsMsg);
} finally {
stop(trans);
stop(conn);
}
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class BlobMessageTranslatorTest method testMoveJmsHeadersJmsMessageToAdaptrisMessage.
@Test
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
MessageTypeTranslatorImp trans = new BlobMessageTranslator();
JmsConnection conn = null;
try {
conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
start(conn);
Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Message jmsMsg = createMessage(session);
jmsMsg.setJMSCorrelationID("ABC");
jmsMsg.setJMSDeliveryMode(1);
jmsMsg.setJMSPriority(4);
addProperties(jmsMsg);
long timestamp = System.currentTimeMillis();
jmsMsg.setJMSTimestamp(timestamp);
trans.registerSession(session);
trans.registerMessageFactory(new DefaultMessageFactory());
trans.setMoveJmsHeaders(true);
start(trans);
AdaptrisMessage msg = trans.translate(jmsMsg);
assertMetadata(msg);
assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
} finally {
stop(trans);
stop(conn);
}
}
use of com.adaptris.core.DefaultMessageFactory 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());
}
Aggregations