Search in sources :

Example 76 with MockMessageProducer

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailuresIgnored.

@Test
public void testDoServiceWithFailuresIgnored() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    service.setIgnoreSplitMessageFailures(true);
    execute(service, msg);
    assertEquals("Number of messages", 0, producer.getMessages().size());
    // We should still get 4 messages as the splitCount. They may not have been successfully
    // processed, but they were still results from the split!
    assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
    int count = 0;
    for (AdaptrisMessage m : producer.getMessages()) {
        count++;
        assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 77 with MockMessageProducer

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_NullEventHandler_SendEvents.

@Test
public void testDoServiceWithFailures_NullEventHandler_SendEvents() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    service.registerEventHandler(null);
    service.setSendEvents(true);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 78 with MockMessageProducer

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithEventHandler_SendEventsDefault.

@Test
public void testDoServiceWithEventHandler_SendEventsDefault() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdvancedMessageSplitterService service = createServiceImpl(new SimpleRegexpMessageSplitter("\\|"), producer);
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    DefaultEventHandler eh = new DefaultEventHandler();
    MockMessageProducer ehp = new MockMessageProducer();
    eh.setProducer(ehp);
    eh.requestStart();
    service.registerEventHandler(eh);
    ExampleServiceCase.execute(service, msg);
    eh.requestClose();
    assertEquals("Number of messages", 4, producer.getMessages().size());
    assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
    assertEvents(ehp, 0, MessageLifecycleEvent.class);
    int count = 0;
    for (AdaptrisMessage m : producer.getMessages()) {
        count++;
        assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) Test(org.junit.Test)

Example 79 with MockMessageProducer

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithEventHandlerSendEventsFalse.

@Test
public void testDoServiceWithEventHandlerSendEventsFalse() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdvancedMessageSplitterService service = createServiceImpl(new SimpleRegexpMessageSplitter("\\|"), producer);
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    DefaultEventHandler eh = new DefaultEventHandler();
    MockMessageProducer ehp = new MockMessageProducer();
    eh.setProducer(ehp);
    eh.requestStart();
    service.registerEventHandler(eh);
    service.setSendEvents(false);
    ExampleServiceCase.execute(service, msg);
    eh.requestClose();
    assertEquals("Number of messages", 4, producer.getMessages().size());
    assertEquals("splitCount metadata", 4, Integer.parseInt(msg.getMetadataValue(MessageSplitterServiceImp.KEY_SPLIT_MESSAGE_COUNT)));
    assertEvents(ehp, 0, MessageLifecycleEvent.class);
    int count = 0;
    for (AdaptrisMessage m : producer.getMessages()) {
        count++;
        assertEquals(count, Integer.parseInt(m.getMetadataValue(KEY_CURRENT_SPLIT_MESSAGE_COUNT)));
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) Test(org.junit.Test)

Example 80 with MockMessageProducer

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

the class AdvancedMessageSplitterServiceTest method testDoServiceWithFailures_SendEventsTrue.

@Test
public void testDoServiceWithFailures_SendEventsTrue() throws Exception {
    MockMessageProducer producer = new MockMessageProducer();
    AdaptrisMessage msg = createMessage(REGEXP_DATA);
    AdvancedMessageSplitterService service = createAdvanced(new SimpleRegexpMessageSplitter("\\|"), new Service[] { new ThrowExceptionService(new ConfiguredException("Fail")), new StandaloneProducer(producer) });
    DefaultEventHandler eh = new DefaultEventHandler();
    MockMessageProducer ehp = new MockMessageProducer();
    eh.setProducer(ehp);
    LifecycleHelper.initAndStart(eh);
    service.registerEventHandler(eh);
    service.setSendEvents(true);
    try {
        ExampleServiceCase.execute(service, msg);
        fail("Expecting failure from AlwaysFailService");
    } catch (ServiceException expected) {
        ;
    }
    LifecycleHelper.stopAndClose(eh);
    assertEvents(ehp, 1, MessageLifecycleEvent.class);
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) DefaultEventHandler(com.adaptris.core.DefaultEventHandler) ThrowExceptionService(com.adaptris.core.services.exception.ThrowExceptionService) ConfiguredException(com.adaptris.core.services.exception.ConfiguredException) 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