Search in sources :

Example 26 with MockMessageConsumer

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

the class RetryMessageErrorHandlerTest method createWorkflow.

private StandardWorkflow createWorkflow(AdaptrisMessageProducer producer, Service[] services) throws Exception {
    StandardWorkflow workflow = new StandardWorkflow();
    workflow.setConsumer(new MockMessageConsumer());
    workflow.setProducer(producer);
    workflow.getServiceCollection().addAll(Arrays.asList(services));
    return workflow;
}
Also used : MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 27 with MockMessageConsumer

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

the class StandaloneConsumerTest method testSetAdaptrisMessageListener.

@Test
public void testSetAdaptrisMessageListener() throws Exception {
    MockMessageProducer prod = new MockMessageProducer();
    StandardWorkflow aml1 = new StandardWorkflow();
    aml1.setConsumer(new MockMessageConsumer());
    aml1.setProducer(prod);
    Channel channel = new MockChannel();
    channel.getWorkflowList().add(aml1);
    channel.prepare();
    LifecycleHelper.init(aml1);
    LifecycleHelper.start(aml1);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage("xxx");
    aml1.onAdaptrisMessage(msg);
    // test the WF directly...
    assertTrue(prod.getMessages().size() == 1);
    MockMessageConsumer consumer1 = new MockMessageConsumer();
    StandaloneConsumer sc = new StandaloneConsumer();
    sc.setConsumer(consumer1);
    sc.registerAdaptrisMessageListener(aml1);
    LifecycleHelper.init(sc);
    consumer1.submitMessage(msg);
    // basic test SC...
    assertTrue(((MockMessageProducer) aml1.getProducer()).getMessages().size() == 2);
    stop(sc);
    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 28 with MockMessageConsumer

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

the class PoolingWorkflowTest method testOnMessage_WithConsumeLocation.

@Test
public void testOnMessage_WithConsumeLocation() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    wf.setConsumer(new ConsumerWithLocation(getName()));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMessageHeader(getName(), "hello world");
    try {
        start(channel);
        MockMessageConsumer m = (MockMessageConsumer) wf.getConsumer();
        m.submitMessage(msg);
        waitForMessages(prod, 1);
        AdaptrisMessage consumed = prod.getMessages().get(0);
        assertTrue(consumed.headersContainsKey(CoreConstants.MESSAGE_CONSUME_LOCATION));
        assertEquals("hello world", consumed.getMetadataValue(CoreConstants.MESSAGE_CONSUME_LOCATION));
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) Test(org.junit.Test)

Example 29 with MockMessageConsumer

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

the class PoolingWorkflowTest method submitMessages.

private void submitMessages(PoolingWorkflow wf, int number) throws Exception {
    MockMessageConsumer m = (MockMessageConsumer) wf.getConsumer();
    for (int i = 0; i < number; i++) {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(String.valueOf(i));
        msg.addMetadata(COUNT, String.valueOf(i));
        m.submitMessage(msg);
    }
}
Also used : MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

Example 30 with MockMessageConsumer

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

the class PoolingWorkflowTest method buildChannel.

private MockChannel buildChannel(List<Service> services) throws Exception {
    MockChannel channel = new MockChannel();
    PoolingWorkflow wf = new PoolingWorkflow();
    MockMessageConsumer consumer = new MockMessageConsumer();
    MockMessageProducer producer = new MockMessageProducer();
    wf.getServiceCollection().addAll(services);
    wf.setConsumer(consumer);
    wf.setProducer(producer);
    channel.getWorkflowList().add(wf);
    return channel;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer)

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