use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class StandardProcessingExceptionHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
StandardProcessingExceptionHandler aeh = new StandardProcessingExceptionHandler(new StandaloneProducer(aep));
aeh.setAlwaysHandleException(true);
StandardProcessingExceptionHandler ceh = new StandardProcessingExceptionHandler(new StandaloneProducer(cep));
ceh.setAlwaysHandleException(true);
StandardProcessingExceptionHandler weh = new StandardProcessingExceptionHandler(new StandaloneProducer(wep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
assertEquals(1, aep.messageCount());
assertEquals(1, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class RequestReplyWorkflowTest method testWorkflow_HasObjectMetadata.
@Test
public void testWorkflow_HasObjectMetadata() throws Exception {
Channel channel = createChannel();
RequestReplyWorkflow workflow = (RequestReplyWorkflow) channel.getWorkflowList().get(0);
MockMessageProducer replier = (MockMessageProducer) workflow.getReplyProducer();
MockRequestReplyProducer requestor = (MockRequestReplyProducer) workflow.getProducer();
try {
start(channel);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("xxx");
msg.addMetadata(REQUEST_METADATA_KEY, REQUEST_METADATA_VALUE);
msg.addObjectHeader(REQUEST_OBJ_METADATA_KEY, this);
MockMessageConsumer m = (MockMessageConsumer) workflow.getConsumer();
m.submitMessage(msg);
doDefaultAssertions(requestor, replier);
AdaptrisMessage replyMsg = replier.getMessages().get(0);
assertTrue("Request Metadata", replyMsg.headersContainsKey(REQUEST_METADATA_KEY));
assertTrue("Contains object metadata", replyMsg.getObjectHeaders().containsKey(REQUEST_OBJ_METADATA_KEY));
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class RequestReplyWorkflowTest method testWorkflow_ReplyProducerFailure.
@Test
public void testWorkflow_ReplyProducerFailure() throws Exception {
Channel channel = new MockChannel();
RequestReplyWorkflow workflow = new RequestReplyWorkflow();
workflow.setConsumer(new MockMessageConsumer());
MockMessageProducer errorProducer = new MockMessageProducer();
workflow.setMessageErrorHandler(new StandardProcessingExceptionHandler(new StandaloneProducer(errorProducer)));
AdaptrisMessage reply = AdaptrisMessageFactory.getDefaultInstance().newMessage();
AdaptrisMessageProducer replier = mock(AdaptrisMessageProducer.class);
doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
doThrow(new ProduceException()).when(replier).produce(any(AdaptrisMessage.class));
when(replier.createName()).thenReturn("mock");
when(replier.createQualifier()).thenReturn("mock");
when(replier.isTrackingEndpoint()).thenReturn(false);
AdaptrisMessageProducer requestor = mock(AdaptrisMessageProducer.class);
when(requestor.request(any(AdaptrisMessage.class))).thenReturn(reply);
when(requestor.request(any(AdaptrisMessage.class))).thenReturn(reply);
when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(reply);
when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(reply);
when(requestor.createName()).thenReturn("mock");
when(requestor.createQualifier()).thenReturn("mock");
when(requestor.isTrackingEndpoint()).thenReturn(false);
workflow.setProducer(requestor);
workflow.setReplyProducer(replier);
channel.getWorkflowList().add(workflow);
try {
start(channel);
submitMessages(workflow, 1);
assertEquals(1, errorProducer.getMessages().size());
} finally {
stop(channel);
}
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_True.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_True() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
aeh.setAlwaysHandleException(true);
RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
ceh.setAlwaysHandleException(true);
RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(wep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
waitForMessages(wep, 1, 1000);
waitForMessages(cep, 1, 1000);
waitForMessages(aep, 1, 1000);
assertEquals(1, aep.messageCount());
assertEquals(1, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.
the class RetryMessageErrorHandlerTest method testMultipleErrorHandlers_AlwaysHandle_False.
@Test
public void testMultipleErrorHandlers_AlwaysHandle_False() throws Exception {
MockMessageProducer aep = new MockMessageProducer();
MockMessageProducer wep = new MockMessageProducer();
MockMessageProducer cep = new MockMessageProducer();
RetryMessageErrorHandler aeh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(aep));
aeh.setAlwaysHandleException(false);
RetryMessageErrorHandler weh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(wep));
RetryMessageErrorHandler ceh = new RetryMessageErrorHandler(1, DEFAULT_RETRY_INTERVAL, new StandaloneProducer(cep));
Adapter adapter = AdapterTest.createAdapter(getName());
adapter.setMessageErrorHandler(aeh);
MockMessageConsumer consumer = new MockMessageConsumer();
adapter.getChannelList().clear();
adapter.getChannelList().add(createChannel(consumer, ceh, weh, new ThrowExceptionService(new ConfiguredException(getName()))));
try {
start(adapter);
consumer.submitMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
waitForMessages(wep, 1, 1000);
assertEquals(0, aep.messageCount());
assertEquals(0, cep.messageCount());
assertEquals(1, wep.messageCount());
} finally {
stop(adapter);
}
}
Aggregations