use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_NoDefaults.
@Test
public void testInterceptor_NoDefaults() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setUseDefaultKeys(false);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertFalse(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertFalse(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_Defaults.
@Test
public void testInterceptor_Defaults() throws Exception {
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setAddDefaultKeysAsObjectMetadata(true);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertTrue(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
assertEquals("channelName", object.get(CoreConstants.CHANNEL_ID_KEY));
assertTrue(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
assertEquals("workflowName", object.get(CoreConstants.WORKFLOW_ID_KEY));
assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
assertEquals(msg.getUniqueId(), object.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class LoggingContextInterceptorTest method testInterceptor_KVP_Expression.
@Test
public void testInterceptor_KVP_Expression() throws Exception {
KeyValuePairList kvp = new KeyValuePairList();
kvp.add(new KeyValuePair("key1", "%message{mk1}"));
kvp.add(new KeyValuePair("key2", "%message{mk2}"));
LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
interceptor.setValuesToSet(kvp);
StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
MockMessageProducer prod = new MockMessageProducer();
wf.setProducer(prod);
wf.getServiceCollection().add(new LoggingContextToMetadata());
MockChannel c = new MockChannel();
c.setUniqueId("channelName");
c.getWorkflowList().add(wf);
try {
BaseCase.start(c);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
msg.addMetadata("mk1", "mv1");
msg.addMetadata("mk2", "mv2");
wf.onAdaptrisMessage(msg);
Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
assertTrue(metadata.containsKey("key1"));
assertEquals("mv1", metadata.get("key1"));
assertTrue(metadata.containsKey("key2"));
assertEquals("mv2", metadata.get("key2"));
} finally {
BaseCase.stop(c);
}
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testHandleChannelUnavailable_Bug2343.
@Test
public void testHandleChannelUnavailable_Bug2343() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
final Channel channel = createStartableChannel(activeMqBroker, true, "testHandleChannelUnavailable_Bug2343", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
try {
channel.requestStart();
channel.toggleAvailability(false);
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
channel.toggleAvailability(true);
}
}, 666);
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
use of com.adaptris.core.stubs.MockMessageProducer in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.
// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
MockMessageProducer meh = new MockMessageProducer();
Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
workflow.setStrict(Boolean.FALSE);
workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
send(sender, msgCount);
waitForMessages(meh, msgCount);
assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
} finally {
channel.requestClose();
}
assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Aggregations