Search in sources :

Example 1 with MockWorkflowInterceptor

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

the class ExampleWorkflowCase method testSetInterceptors.

@Test
public void testSetInterceptors() throws Exception {
    WorkflowImp wf = createWorkflowForGenericTests();
    wf.setInterceptors(new ArrayList(Arrays.asList(new WorkflowInterceptor[] { new MockWorkflowInterceptor() })));
    assertEquals(1, wf.getInterceptors().size());
    try {
        wf.addInterceptor(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(1, wf.getInterceptors().size());
    wf.addInterceptor(new MockWorkflowInterceptor());
    assertEquals(2, wf.getInterceptors().size());
    try {
        wf.setInterceptors(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    assertEquals(2, wf.getInterceptors().size());
}
Also used : ArrayList(java.util.ArrayList) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) WorkflowImp(com.adaptris.core.WorkflowImp) Test(org.junit.Test)

Example 2 with MockWorkflowInterceptor

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

the class PoolingWorkflowTest method testWorkflowWithInterceptor.

@Test
public void testWorkflowWithInterceptor() throws Exception {
    MockChannel channel = createChannel();
    PoolingWorkflow wf = (PoolingWorkflow) channel.getWorkflowList().get(0);
    MockMessageProducer prod = (MockMessageProducer) wf.getProducer();
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    wf.addInterceptor(interceptor);
    try {
        start(channel);
        submitMessages(wf, 1);
        waitForMessages(prod, 1);
        assertMessages(prod, 1);
        assertEquals(1, interceptor.messageCount());
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) Test(org.junit.Test)

Example 3 with MockWorkflowInterceptor

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

the class ThreadContextWorkflowTest method testOnMessageWithInterceptors.

@Test
public void testOnMessageWithInterceptors() throws Exception {
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    MockMessageProducer producer = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    int count = 10;
    try {
        ThreadContextWorkflow workflow = (ThreadContextWorkflow) channel.getWorkflowList().get(0);
        workflow.setAdditionalDebug(Boolean.TRUE);
        workflow.addInterceptor(interceptor);
        channel.prepare();
        start(channel);
        for (int i = 0; i < count; i++) {
            AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
            workflow.onAdaptrisMessage(msg);
        }
        assertEquals("Make sure all produced", count, producer.messageCount());
        assertEquals("Make sure all intercepted", count, interceptor.messageCount());
        for (AdaptrisMessage m : producer.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.headersContainsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 4 with MockWorkflowInterceptor

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

the class StandardWorkflowTest method testOnMessageWithInterceptors.

@Test
public void testOnMessageWithInterceptors() throws Exception {
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    MockMessageProducer producer = new MockMessageProducer();
    MockChannel channel = createChannel(producer, Arrays.asList(new Service[] { new AddMetadataService(Arrays.asList(new MetadataElement[] { new MetadataElement(METADATA_KEY, METADATA_VALUE) })), new PayloadFromTemplateService().withTemplate(PAYLOAD_2) }));
    int count = 10;
    try {
        StandardWorkflow workflow = (StandardWorkflow) channel.getWorkflowList().get(0);
        workflow.addInterceptor(interceptor);
        channel.prepare();
        start(channel);
        for (int i = 0; i < count; i++) {
            AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD_1);
            workflow.onAdaptrisMessage(msg);
        }
        assertEquals("Make sure all produced", count, producer.messageCount());
        assertEquals("Make sure all intercepted", count, interceptor.messageCount());
        for (AdaptrisMessage m : producer.getMessages()) {
            assertEquals(PAYLOAD_2, m.getContent());
            assertTrue("Contains correct metadata key", m.containsKey(METADATA_KEY));
            assertEquals(METADATA_VALUE, m.getMetadataValue(METADATA_KEY));
        }
    } finally {
        stop(channel);
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) FailFirstMockMessageProducer(com.adaptris.core.stubs.FailFirstMockMessageProducer) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) EventHandlerAwareService(com.adaptris.core.stubs.EventHandlerAwareService) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) AddMetadataService(com.adaptris.core.services.metadata.AddMetadataService) Test(org.junit.Test)

Example 5 with MockWorkflowInterceptor

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

the class ActiveMqJmsTransactedWorkflowTest method testWorkflowWithInterceptor.

@Test
public void testWorkflowWithInterceptor() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    Channel channel = createStartableChannel(activeMqBroker, false, "testMessagesCommittedUsingTopic", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    MockWorkflowInterceptor interceptor = new MockWorkflowInterceptor();
    workflow.addInterceptor(interceptor);
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PasProducer().withTopic(destination));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
        assertEquals(msgCount, interceptor.messageCount());
    } finally {
        channel.requestClose();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PasProducer(com.adaptris.core.jms.PasProducer) MockWorkflowInterceptor(com.adaptris.core.stubs.MockWorkflowInterceptor) 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