use of com.adaptris.core.stubs.MockWorkflowInterceptor in project interlok by adaptris.
the class ExampleWorkflowCase method testSetInterceptors.
@Test
public void testSetInterceptors() throws Exception {
WorkflowImp wf = createWorkflowForGenericTests();
wf.setInterceptors(new ArrayList(Arrays.asList(new WorkflowInterceptor[] { new MockWorkflowInterceptor() })));
assertEquals(1, wf.getInterceptors().size());
try {
wf.addInterceptor(null);
fail();
} catch (IllegalArgumentException expected) {
}
assertEquals(1, wf.getInterceptors().size());
wf.addInterceptor(new MockWorkflowInterceptor());
assertEquals(2, wf.getInterceptors().size());
try {
wf.setInterceptors(null);
fail();
} catch (IllegalArgumentException expected) {
}
assertEquals(2, wf.getInterceptors().size());
}
use of com.adaptris.core.stubs.MockWorkflowInterceptor in project interlok by adaptris.
the class PoolingWorkflowTest method testWorkflowWithInterceptor.
@Test
public void testWorkflowWithInterceptor() throws Exception {
MockChannel channel = createChannel();
PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
wf.addInterceptor(interceptor);
try {
start(channel);
submitMessages(wf, 1);
waitForMessages(prod, 1);
assertMessages(prod, 1);
assertEquals(1, interceptor.messageCount());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockWorkflowInterceptor in project interlok by adaptris.
the class ThreadContextWorkflowTest method testOnMessageWithInterceptors.
@Test
public void testOnMessageWithInterceptors() throws Exception {
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
MockMessageProducer producer = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
int count = 10;
try {
ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
workflow.setAdditionalDebug(Boolean.TRUE);
workflow.addInterceptor(interceptor);
channel.prepare();
start(channel);
for (int i = 0; i < count; i++) {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
workflow.onAdaptrisMessage(msg);
}
assertEquals("Make sure all produced", count, producer.messageCount());
assertEquals("Make sure all intercepted", count, interceptor.messageCount());
for (AdaptrisMessage m : producer.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockWorkflowInterceptor in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessageWithInterceptors.
@Test
public void testOnMessageWithInterceptors() throws Exception {
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
MockMessageProducer producer = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
int count = 10;
try {
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
workflow.addInterceptor(interceptor);
channel.prepare();
start(channel);
for (int i = 0; i < count; i++) {
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
workflow.onAdaptrisMessage(msg);
}
assertEquals("Make sure all produced", count, producer.messageCount());
assertEquals("Make sure all intercepted", count, interceptor.messageCount());
for (AdaptrisMessage m : producer.getMessages()) {
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockWorkflowInterceptor in project interlok by adaptris.
the class ActiveMqJmsTransactedWorkflowTest method testWorkflowWithInterceptor.
@Test
public void testWorkflowWithInterceptor() throws Exception {
int msgCount = 10;
String destination = createSafeUniqueId(new Object());
Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesCommittedUsingTopic", destination);
JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
workflow.addInterceptor(interceptor);
try {
channel.requestStart();
StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
send(sender, msgCount);
waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
assertEquals(msgCount, interceptor.messageCount());
} finally {
channel.requestClose();
}
}
Aggregations