Search in sources :

Example 1 with MockMessageConsumer

use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.

the class ExceptionReportServiceTest method testBug2356.

@Test
public void testBug2356() throws Exception {
    ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
    MockMessageProducer mockProducer = new MockMessageProducer();
    StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
    MockChannel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    StandardWorkflow wf = new StandardWorkflow();
    wf.getServiceCollection().add(failingService);
    wf.setConsumer(consumer);
    channel.setMessageErrorHandler(speh);
    channel.getWorkflowList().add(wf);
    try {
        channel.prepare();
        channel.requestStart();
        consumer.submitMessage(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
        assertNotSame(XML_PAYLOAD, failedMessage.getContent());
        XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
        assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
        assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
        String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
        assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) ServiceImp(com.adaptris.core.ServiceImp) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) InsertNode(com.adaptris.util.text.xml.InsertNode) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 2 with MockMessageConsumer

use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.

the class FailedMessageRetrierCase method createWorkflow.

protected StandardWorkflow createWorkflow(String uniqueId) throws Exception {
    AdaptrisMessageConsumer consumer = new MockMessageConsumer();
    AdaptrisMessageProducer producer = new MockMessageProducer();
    StandardWorkflow workflow = new StandardWorkflow();
    workflow.setUniqueId(uniqueId);
    workflow.setConsumer(consumer);
    workflow.setProducer(producer);
    Channel channel = new MockChannel();
    channel.setUniqueId(null);
    channel.getWorkflowList().add(workflow);
    channel.prepare();
    return workflow;
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessageConsumer(com.adaptris.core.AdaptrisMessageConsumer) AdaptrisMessageProducer(com.adaptris.core.AdaptrisMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 3 with MockMessageConsumer

use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.

the class RequestReplyWorkflowTest method createChannel.

// private RequestReplyWorkflow workFlow;
// private MockMessageConsumer consumer;
// private MockRequestReplyProducer producer;
// private MockMessageProducer replyProducer;
private Channel createChannel() throws Exception {
    Channel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    MockRequestReplyProducer producer = new MockRequestReplyProducer();
    MockMessageProducer replyProducer = new MockMessageProducer();
    RequestReplyWorkflow workFlow = new RequestReplyWorkflow();
    workFlow.setConsumer(consumer);
    workFlow.setProducer(producer);
    workFlow.setReplyProducer(replyProducer);
    channel.getWorkflowList().addWorkflow(workFlow);
    channel.prepare();
    return 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) MockRequestReplyProducer(com.adaptris.core.stubs.MockRequestReplyProducer)

Example 4 with MockMessageConsumer

use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.

the class RequestReplyWorkflowTest method submitMessages.

private void submitMessages(Workflow wf, int number) {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("xxx");
    msg.addMetadata(REQUEST_METADATA_KEY, REQUEST_METADATA_VALUE);
    MockMessageConsumer m = (MockMessageConsumer) wf.getConsumer();
    for (int i = 0; i < number; i++) {
        m.submitMessage(msg);
    }
}
Also used : MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 5 with MockMessageConsumer

use of com.adaptris.core.stubs.MockMessageConsumer in project interlok by adaptris.

the class RequestReplyWorkflowTest method testWorkflow_NullReply.

@Test
public void testWorkflow_NullReply() throws Exception {
    Channel channel = new MockChannel();
    RequestReplyWorkflow workflow = new RequestReplyWorkflow();
    workflow.setConsumer(new MockMessageConsumer());
    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(null);
    when(requestor.request(any(AdaptrisMessage.class))).thenReturn(null);
    when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
    when(requestor.request(any(AdaptrisMessage.class), anyLong())).thenReturn(null);
    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);
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockChannel(com.adaptris.core.stubs.MockChannel) 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