Search in sources :

Example 21 with MockMessageConsumer

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);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 22 with MockMessageConsumer

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);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) MockRequestReplyProducer(com.adaptris.core.stubs.MockRequestReplyProducer) Test(org.junit.Test)

Example 23 with MockMessageConsumer

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);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 24 with MockMessageConsumer

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);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 25 with MockMessageConsumer

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);
    }
}
Also used : FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Aggregations

MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)31 Test (org.junit.Test)20 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)18 MockChannel (com.adaptris.core.stubs.MockChannel)10 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)5 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)4 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)4 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)4 MockStandaloneConsumer (com.adaptris.core.stubs.MockStandaloneConsumer)4 MockConnection (com.adaptris.core.stubs.MockConnection)3 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)2 MockRequestReplyProducer (com.adaptris.core.stubs.MockRequestReplyProducer)2 StateManagedStandaloneConsumer (com.adaptris.core.stubs.StateManagedStandaloneConsumer)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 AdaptrisMessageConsumer (com.adaptris.core.AdaptrisMessageConsumer)1 AdaptrisMessageProducer (com.adaptris.core.AdaptrisMessageProducer)1 Channel (com.adaptris.core.Channel)1 Service (com.adaptris.core.Service)1 ServiceImp (com.adaptris.core.ServiceImp)1