use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_SkipProducer.
@Test
public void testOnMessage_SkipProducer() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer serviceProducer = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
try {
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals(1, serviceProducer.messageCount());
assertEquals(0, producer.messageCount());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testObtainWorkflowIdWithUniqueId.
@Test
public void testObtainWorkflowIdWithUniqueId() throws Exception {
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
channel.setUniqueId("Channel");
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
workflow.setUniqueId("Workflow");
channel.prepare();
assertEquals("Workflow@Channel", workflow.obtainWorkflowId());
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessageWithoutEvents.
@Test
public void testOnMessageWithoutEvents() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockMessageProducer eventProd = new MockMessageProducer();
DefaultEventHandler evtHandler = new DefaultEventHandler(eventProd);
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) }));
try {
channel.setEventHandler(evtHandler);
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
workflow.setSendEvents(false);
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make sure all produced", 1, producer.getMessages().size());
for (Iterator i = producer.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_2, m.getContent());
assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
}
waitForMessages(eventProd, 0);
assertEquals(0, eventProd.messageCount());
} finally {
stop(channel);
stop(evtHandler);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testRuntimeException.
@Test
public void testRuntimeException() throws Exception {
MockMessageProducer producer = new MockMessageProducer() {
@Override
protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
throw new RuntimeException();
}
};
MockMessageProducer meh = 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) }));
try {
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
channel.prepare();
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
start(channel);
workflow.onAdaptrisMessage(msg);
assertEquals("Make none produced", 0, producer.getMessages().size());
assertEquals(1, meh.getMessages().size());
for (Iterator i = meh.getMessages().iterator(); i.hasNext(); ) {
AdaptrisMessage m = (AdaptrisMessage) i.next();
assertEquals(PAYLOAD_1, m.getContent());
assertFalse("Does not contains correct metadata key", m.containsKey(METADATA_KEY));
}
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_SuccessCallback.
@Test
public void testOnMessage_SuccessCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new NullService() }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
try {
start(channel);
workflow.onAdaptrisMessage(msg, (m) -> {
onSuccess.set(true);
});
assertTrue(onSuccess.get());
} finally {
stop(channel);
}
}
Aggregations