Search in sources :

Example 46 with MockMessageProducer

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

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

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

Example 49 with MockMessageProducer

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

the class ActiveMqJmsTransactedWorkflowTest method testHandleChannelUnavailable_Bug2343.

@Test
public void testHandleChannelUnavailable_Bug2343() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    final Channel channel = createStartableChannel(activeMqBroker, true, "testHandleChannelUnavailable_Bug2343", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setChannelUnavailableWaitInterval(new TimeInterval(1L, TimeUnit.SECONDS));
    try {
        channel.requestStart();
        channel.toggleAvailability(false);
        Timer t = new Timer();
        t.schedule(new TimerTask() {

            @Override
            public void run() {
                channel.toggleAvailability(true);
            }
        }, 666);
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages((MockMessageProducer) workflow.getProducer(), msgCount);
        assertEquals(msgCount, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) Timer(java.util.Timer) TimerTask(java.util.TimerTask) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 50 with MockMessageProducer

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

the class ActiveMqJmsTransactedWorkflowTest method testServiceExceptionNonStrictWithErrorHandler.

// In Non-Strict Mode, if you have configured an error handler, then
// the transaction is successful.
@Test
public void testServiceExceptionNonStrictWithErrorHandler() throws Exception {
    int msgCount = 10;
    String destination = createSafeUniqueId(new Object());
    MockMessageProducer meh = new MockMessageProducer();
    Channel channel = createStartableChannel(activeMqBroker, true, "testServiceExceptionNonStrictWithErrorHandler", destination);
    JmsTransactedWorkflow workflow = (JmsTransactedWorkflow) channel.getWorkflowList().get(0);
    workflow.setStrict(Boolean.FALSE);
    workflow.getServiceCollection().addService(new ThrowExceptionService(new ConfiguredException("Fail")));
    channel.setMessageErrorHandler(new StandardProcessingExceptionHandler(new ServiceList(new ArrayList<Service>(Arrays.asList(new Service[] { new StandaloneProducer(meh) })))));
    channel.prepare();
    try {
        channel.requestStart();
        StandaloneProducer sender = new StandaloneProducer(activeMqBroker.getJmsConnection(), new PtpProducer().withQueue((destination)));
        send(sender, msgCount);
        waitForMessages(meh, msgCount);
        assertEquals(0, ((MockMessageProducer) workflow.getProducer()).getMessages().size());
    } finally {
        channel.requestClose();
    }
    assertEquals(0, activeMqBroker.messagesOnQueue(destination));
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ServiceList(com.adaptris.core.ServiceList) MockChannel(com.adaptris.core.stubs.MockChannel) Channel(com.adaptris.core.Channel) JmsTransactedWorkflow(com.adaptris.core.jms.JmsTransactedWorkflow) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) Service(com.adaptris.core.Service) MockSkipProducerService(com.adaptris.core.stubs.MockSkipProducerService) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) PtpProducer(com.adaptris.core.jms.PtpProducer) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) StandaloneProducer(com.adaptris.core.StandaloneProducer) 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