Search in sources :

Example 96 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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 97 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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 98 with MockMessageProducer

use of com.adaptris.core.stubs.MockMessageProducer 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)

Example 99 with MockMessageProducer

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

the class PollingTriggerTest method testTriggerWithStaticTemplate.

@Test
public void testTriggerWithStaticTemplate() throws Exception {
    Trigger trigger = new Trigger();
    MockMessageProducer mockProducer = new MockMessageProducer();
    Channel c = createChannel(new PollingTrigger(trigger, new StaticPollingTemplate(PAYLOAD)), mockProducer);
    // .setDestination(new ConfiguredConsumeDestination(getName(), null, getName()));
    try {
        BaseCase.start(c);
        trigger.fire();
        AdaptrisMessage msg = mockProducer.getMessages().get(0);
        assertEquals(PAYLOAD, msg.getContent());
    } finally {
        BaseCase.stop(c);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Test(org.junit.Test)

Example 100 with MockMessageProducer

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

the class PollingTriggerTest method testTrigger_TemplateFails.

@Test
public void testTrigger_TemplateFails() throws Exception {
    // setContent must have a encoding...
    String script = "message.setContent('" + PAYLOAD + "')";
    Trigger trigger = new Trigger();
    MockMessageProducer mockProducer = new MockMessageProducer();
    Channel c = createChannel(new PollingTrigger(trigger, new DynamicPollingTemplate(new EmbeddedScriptingService().withScript("nashorn", script))), mockProducer);
    try {
        BaseCase.start(c);
        trigger.fire();
        assertEquals(0, mockProducer.getMessages().size());
    } finally {
        BaseCase.stop(c);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) EmbeddedScriptingService(com.adaptris.core.services.EmbeddedScriptingService) Test(org.junit.Test)

Aggregations

MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)321 Test (org.junit.Test)306 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)156 MockChannel (com.adaptris.core.stubs.MockChannel)126 Channel (com.adaptris.core.Channel)125 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)73 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)69 StandaloneProducer (com.adaptris.core.StandaloneProducer)68 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)65 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)56 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)52 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)44 StandardWorkflow (com.adaptris.core.StandardWorkflow)40 TimeInterval (com.adaptris.util.TimeInterval)40 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)36 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)35 ServiceList (com.adaptris.core.ServiceList)33 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)33 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)27