Search in sources :

Example 1 with MockChannel

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

the class InFlightWorkflowInterceptorTest method testInterceptor.

@Test
public void testInterceptor() throws Exception {
    InFlightWorkflowInterceptor interceptor = new InFlightWorkflowInterceptor("testInterceptor");
    final PoolingWorkflow wf = createPoolingWorkflow("workflow", interceptor);
    wf.setPoolSize(1);
    wf.setShutdownWaitTime(new TimeInterval(10L, TimeUnit.SECONDS));
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new WaitService(new TimeInterval(2L, TimeUnit.SECONDS)));
    MockChannel c = new MockChannel();
    c.getWorkflowList().add(wf);
    try {
        LifecycleHelper.initAndStart(c);
        wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(0, interceptor.messagesPendingCount());
        new Thread(new Runnable() {

            @Override
            public void run() {
                wf.onAdaptrisMessage(AdaptrisMessageFactory.getDefaultInstance().newMessage());
            }
        }).start();
        LifecycleHelper.waitQuietly(100);
        assertEquals(1, interceptor.messagesInFlightCount());
        assertEquals(1, interceptor.messagesPendingCount());
        ExampleServiceCase.waitForMessages(prod, 2, 10000);
    } finally {
        LifecycleHelper.stopAndClose(c);
    }
}
Also used : WaitService(com.adaptris.core.services.WaitService) MockChannel(com.adaptris.core.stubs.MockChannel) TimeInterval(com.adaptris.util.TimeInterval) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) PoolingWorkflow(com.adaptris.core.PoolingWorkflow) Test(org.junit.Test)

Example 2 with MockChannel

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

the class LoggingContextInterceptorTest method testInterceptor_Defaults_NotAsObjectMetadata.

@Test
public void testInterceptor_Defaults_NotAsObjectMetadata() throws Exception {
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
        assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 3 with MockChannel

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

the class LoggingContextInterceptorTest method testInterceptor_NoDefaults.

@Test
public void testInterceptor_NoDefaults() throws Exception {
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    interceptor.setUseDefaultKeys(false);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
        assertFalse(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertFalse(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertFalse(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertFalse(object.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 4 with MockChannel

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

the class LoggingContextInterceptorTest method testInterceptor_Defaults.

@Test
public void testInterceptor_Defaults() throws Exception {
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    interceptor.setAddDefaultKeysAsObjectMetadata(true);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        Map<Object, Object> object = prod.getMessages().get(0).getObjectHeaders();
        assertTrue(metadata.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", metadata.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", metadata.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), metadata.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertTrue(object.containsKey(CoreConstants.CHANNEL_ID_KEY));
        assertEquals("channelName", object.get(CoreConstants.CHANNEL_ID_KEY));
        assertTrue(object.containsKey(CoreConstants.WORKFLOW_ID_KEY));
        assertEquals("workflowName", object.get(CoreConstants.WORKFLOW_ID_KEY));
        assertTrue(metadata.containsKey(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
        assertEquals(msg.getUniqueId(), object.get(CoreConstants.MESSAGE_UNIQUE_ID_KEY));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 5 with MockChannel

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

the class LoggingContextInterceptorTest method testInterceptor_KVP_Expression.

@Test
public void testInterceptor_KVP_Expression() throws Exception {
    KeyValuePairList kvp = new KeyValuePairList();
    kvp.add(new KeyValuePair("key1", "%message{mk1}"));
    kvp.add(new KeyValuePair("key2", "%message{mk2}"));
    LoggingContextWorkflowInterceptor interceptor = new LoggingContextWorkflowInterceptor(null);
    interceptor.setValuesToSet(kvp);
    StandardWorkflow wf = StatisticsMBeanCase.createWorkflow("workflowName", interceptor);
    MockMessageProducer prod = new MockMessageProducer();
    wf.setProducer(prod);
    wf.getServiceCollection().add(new LoggingContextToMetadata());
    MockChannel c = new MockChannel();
    c.setUniqueId("channelName");
    c.getWorkflowList().add(wf);
    try {
        BaseCase.start(c);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        msg.addMetadata("mk1", "mv1");
        msg.addMetadata("mk2", "mv2");
        wf.onAdaptrisMessage(msg);
        Map<String, String> metadata = prod.getMessages().get(0).getMessageHeaders();
        assertTrue(metadata.containsKey("key1"));
        assertEquals("mv1", metadata.get("key1"));
        assertTrue(metadata.containsKey("key2"));
        assertEquals("mv2", metadata.get("key2"));
    } finally {
        BaseCase.stop(c);
    }
}
Also used : StandardWorkflow(com.adaptris.core.StandardWorkflow) MockChannel(com.adaptris.core.stubs.MockChannel) KeyValuePair(com.adaptris.util.KeyValuePair) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) KeyValuePairList(com.adaptris.util.KeyValuePairList) 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