use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_ServiceFailsWithRetryHandlerFailureCallback.
@Test
public void testOnMessage_ServiceFailsWithRetryHandlerFailureCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
channel.setMessageErrorHandler(new RetryMessageErrorHandler(3, new TimeInterval(100l, TimeUnit.MILLISECONDS), 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);
}, (m) -> {
onSuccess.set(false);
});
assertFalse(onSuccess.get());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_withConsumeLocation.
@Test
public void testOnMessage_withConsumeLocation() throws Exception {
MockMessageProducer producer = new MockMessageProducer();
MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new NullService() }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
msg.addMessageHeader(getName(), "hello world");
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
workflow.setConsumer(new ConsumerWithLocation(getName()));
try {
start(channel);
workflow.onAdaptrisMessage(msg);
AdaptrisMessage consumed = producer.getMessages().get(0);
assertTrue(consumed.headersContainsKey(CoreConstants.MESSAGE_CONSUME_LOCATION));
assertEquals("hello world", consumed.getMetadataValue(CoreConstants.MESSAGE_CONSUME_LOCATION));
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_ServiceFailsFailureCallback.
@Test
public void testOnMessage_ServiceFailsFailureCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new MockMessageProducer(), Arrays.asList(new Service[] { new ThrowExceptionService(new ConfiguredException("expected")) }));
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
try {
start(channel);
workflow.onAdaptrisMessage(msg, (m) -> {
onSuccess.set(true);
}, (m) -> {
onSuccess.set(false);
});
assertFalse(onSuccess.get());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockChannel 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.MockChannel in project interlok by adaptris.
the class StandardWorkflowTest method testOnMessage_ProducerFailsWithRetryHandlerSuccessCallback.
@Test
public void testOnMessage_ProducerFailsWithRetryHandlerSuccessCallback() throws Exception {
AtomicBoolean onSuccess = new AtomicBoolean(false);
MockChannel channel = createChannel(new FailFirstMockMessageProducer(1), Arrays.asList(new Service[] { new NullService() }));
channel.setMessageErrorHandler(new RetryMessageErrorHandler(2, new TimeInterval(100l, TimeUnit.MILLISECONDS), 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);
}, (m) -> {
onSuccess.set(false);
});
Awaitility.await().atMost(Duration.ofSeconds(2)).with().pollInterval(Duration.ofMillis(100)).until(onSuccess::get);
assertTrue(onSuccess.get());
} finally {
stop(channel);
}
}
Aggregations