Search in sources :

Example 26 with MockChannel

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

the class MultiProducerWorkflowTest method testHandleProduceException.

@Test
public void testHandleProduceException() throws Exception {
    MockMessageProducer mock1 = new MockMessageProducer();
    MockMessageProducer mock2 = new MockMessageProducer();
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    try {
        MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
        workflow.setProducer(new MockMessageProducer() {

            @Override
            protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
                throw new ProduceException();
            }
        });
        workflow.setUseProcessedMessage(false);
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
        workflow.onAdaptrisMessage(msg);
        assertEquals(0, mock1.getMessages().size());
        assertEquals(0, mock2.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        assertEquals(ORIGINAL_PAYLOAD, meh.getMessages().get(0).getContent());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ArrayList(java.util.ArrayList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Test(org.junit.Test)

Example 27 with MockChannel

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

the class MultiProducerWorkflowTest method testOnMessage_SkipProducer.

@Test
public void testOnMessage_SkipProducer() throws Exception {
    MockMessageProducer mock1 = new MockMessageProducer();
    MockMessageProducer mock2 = new MockMessageProducer();
    MockMessageProducer workflowProducer = new MockMessageProducer();
    MockMessageProducer serviceProducer = new MockMessageProducer();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new StandaloneProducer(serviceProducer), new MockSkipProducerService() }));
    try {
        MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
        workflow.setProducer(workflowProducer);
        workflow.setUseProcessedMessage(false);
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
        workflow.onAdaptrisMessage(msg);
        assertEquals(1, mock1.messageCount());
        assertEquals(1, mock2.messageCount());
        assertEquals(1, serviceProducer.messageCount());
        assertEquals(0, workflowProducer.messageCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Test(org.junit.Test)

Example 28 with MockChannel

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

the class MultiProducerWorkflowTest method testOnMessage_withConsumeLocation_NoMatch.

@Test
public void testOnMessage_withConsumeLocation_NoMatch() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { producer }), Arrays.asList(new Service[] { new NullService() }));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
    MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
    workflow.setConsumer(new ConsumerWithLocation(getName()));
    try {
        start(channel);
        workflow.onAdaptrisMessage(msg);
        AdaptrisMessage consumed = producer.getMessages().get(0);
        assertFalse(consumed.headersContainsKey(CoreConstants.MESSAGE_CONSUME_LOCATION));
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) Test(org.junit.Test)

Example 29 with MockChannel

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

the class MultiProducerWorkflowTest method createChannel.

private MockChannel createChannel(List<AdaptrisMessageProducer> list, List<Service> services) throws Exception {
    MockChannel channel = new MockChannel();
    MultiProducerWorkflow workflow = new MultiProducerWorkflow();
    String uuid = UUID.randomUUID().toString();
    // workflow.getConsumer().setDestination(new ConfiguredConsumeDestination(uuid));
    for (AdaptrisMessageProducer p : list) {
        workflow.addStandaloneProducer(new StandaloneProducer(p));
    }
    workflow.getServiceCollection().addAll(services);
    channel.getWorkflowList().add(workflow);
    return channel;
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel)

Example 30 with MockChannel

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

the class MultiProducerWorkflowTest method testHandleRuntimeException.

@Test
public void testHandleRuntimeException() throws Exception {
    MockMessageProducer mock1 = new MockMessageProducer();
    MockMessageProducer mock2 = new MockMessageProducer();
    MockMessageProducer meh = new MockMessageProducer();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    try {
        MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
        workflow.setUseProcessedMessage(false);
        workflow.setProducer(new MockMessageProducer() {

            @Override
            protected void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
                throw new RuntimeException();
            }
        });
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
        workflow.onAdaptrisMessage(msg);
        assertEquals(0, mock1.getMessages().size());
        assertEquals(0, mock2.getMessages().size());
        assertEquals(1, meh.getMessages().size());
        assertEquals(ORIGINAL_PAYLOAD, meh.getMessages().get(0).getContent());
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ArrayList(java.util.ArrayList) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) Test(org.junit.Test)

Aggregations

MockChannel (com.adaptris.core.stubs.MockChannel)145 Test (org.junit.Test)125 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)92 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)62 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)59 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)56 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)40 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)32 TimeInterval (com.adaptris.util.TimeInterval)28 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)22 Iterator (java.util.Iterator)17 StandardWorkflow (com.adaptris.core.StandardWorkflow)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)11 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)10 Channel (com.adaptris.core.Channel)10 JmsConnectionErrorHandler (com.adaptris.core.jms.JmsConnectionErrorHandler)9 MockMessageConsumer (com.adaptris.core.stubs.MockMessageConsumer)9 JmsConnection (com.adaptris.core.jms.JmsConnection)8