Search in sources :

Example 6 with MockWorkflowInterceptor

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

the class RequestReplyWorkflowTest method testWorkflow_HasInterceptor.

@Test
public void testWorkflow_HasInterceptor() throws Exception {
    Channel channel = createChannel();
    RequestReplyWorkflow workflow = (RequestReplyWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer replier = (MockMessageProducer) workflow.getReplyProducer();
    MockRequestReplyProducer requestor = (MockRequestReplyProducer) workflow.getProducer();
    createChannel();
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    workflow.addInterceptor(interceptor);
    try {
        start(channel);
        submitMessages(workflow, 1);
        doDefaultAssertions(requestor, replier);
        AdaptrisMessage replyMsg = replier.getMessages().get(0);
        assertTrue("Request Metadata", replyMsg.headersContainsKey(REQUEST_METADATA_KEY));
        assertEquals(1, interceptor.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) MockRequestReplyProducer(com.adaptris.core.stubs.MockRequestReplyProducer) Test(org.junit.Test)

Example 7 with MockWorkflowInterceptor

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

the class MultiProducerWorkflowTest method testWorkflowWithInterceptor.

@Test
public void testWorkflowWithInterceptor() throws Exception {
    MockMessageProducer mock1 = new MockMessageProducer();
    MockMessageProducer mock2 = new MockMessageProducer();
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    MockChannel channel = createChannel(Arrays.asList(new AdaptrisMessageProducer[] { mock1, mock2 }), Arrays.asList(new Service[] { new PayloadFromTemplateService().withTemplate(MODIFIED_PAYLOAD) }));
    try {
        MultiProducerWorkflow workflow = (MultiProducerWorkflow) channel.getWorkflowList().get(0);
        workflow.setUseProcessedMessage(false);
        workflow.addInterceptor(interceptor);
        channel.prepare();
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(ORIGINAL_PAYLOAD);
        workflow.onAdaptrisMessage(msg);
        assertEquals(1, mock1.getMessages().size());
        assertEquals(ORIGINAL_PAYLOAD, mock1.getMessages().get(0).getContent());
        assertEquals(1, mock2.getMessages().size());
        assertEquals(ORIGINAL_PAYLOAD, mock2.getMessages().get(0).getContent());
        assertEquals(1, interceptor.messageCount());
    } finally {
        channel.requestClose();
    }
}
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) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) Test(org.junit.Test)

Example 8 with MockWorkflowInterceptor

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

the class HttpConsumerTest method testPoolingWorkflow_WithoutInterceptor.

@Test
public void testPoolingWorkflow_WithoutInterceptor() throws Exception {
    HttpConnection connection = createConnection(null);
    MockMessageProducer mockProducer = new StaticMockMessageProducer();
    mockProducer.getMessages().clear();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(URL_TO_POST_TO);
    PoolingWorkflow workflow = new PoolingWorkflow();
    workflow.addInterceptor(new MockWorkflowInterceptor());
    workflow.setShutdownWaitTime(new TimeInterval(100L, TimeUnit.MILLISECONDS));
    StandardResponseProducer responder = new StandardResponseProducer(HttpStatus.OK_200);
    workflow.setConsumer(consumer);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(1L, TimeUnit.SECONDS)));
    workflow.getServiceCollection().add(new StandaloneProducer(mockProducer));
    workflow.getServiceCollection().add(new StandaloneProducer(responder));
    Channel channel = JettyHelper.createChannel(connection, workflow);
    try {
        channel.requestStart();
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setUrl(createProduceDestinationUrl(connection.getPort()));
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        // Because of redmineID #4715 it should just "return immediatel" which flushes the stream so there's no content.
        assertEquals("Reply Payloads", "", reply.getContent());
    } finally {
        stop(httpProducer);
        channel.requestClose();
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

MockWorkflowInterceptor (com.adaptris.core.stubs.MockWorkflowInterceptor)8 Test (org.junit.Test)8 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)7 MockChannel (com.adaptris.core.stubs.MockChannel)6 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)3 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)3 MockSkipProducerService (com.adaptris.core.stubs.MockSkipProducerService)3 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)3 Channel (com.adaptris.core.Channel)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 AddMetadataService (com.adaptris.core.services.metadata.AddMetadataService)2 FailFirstMockMessageProducer (com.adaptris.core.stubs.FailFirstMockMessageProducer)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 PoolingWorkflow (com.adaptris.core.PoolingWorkflow)1 WorkflowImp (com.adaptris.core.WorkflowImp)1 JmsTransactedWorkflow (com.adaptris.core.jms.JmsTransactedWorkflow)1 PasProducer (com.adaptris.core.jms.PasProducer)1 WaitService (com.adaptris.core.services.WaitService)1 EventHandlerAwareService (com.adaptris.core.stubs.EventHandlerAwareService)1 MockRequestReplyProducer (com.adaptris.core.stubs.MockRequestReplyProducer)1