Search in sources :

Example 6 with DefaultEventHandler

use of com.adaptris.core.DefaultEventHandler 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 7 with DefaultEventHandler

use of com.adaptris.core.DefaultEventHandler 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 8 with DefaultEventHandler

use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.

the class AdvancedMessageSplitterServiceTest method testEventHandlerPassedToServiceCollection.

@Test
public void testEventHandlerPassedToServiceCollection() throws Exception {
    AdvancedMessageSplitterService service = createForTests();
    EventHandlerAwareService ehService = new EventHandlerAwareService();
    service.setService(ehService);
    service.setSplitter(new SimpleRegexpMessageSplitter("\\|"));
    DefaultEventHandler eh = new DefaultEventHandler();
    service.registerEventHandler(eh);
    LifecycleHelper.init(service);
    LifecycleHelper.start(service);
    assertEquals(eh, ehService.eventHandler());
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler) Test(org.junit.Test)

Example 9 with DefaultEventHandler

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

Example 10 with DefaultEventHandler

use of com.adaptris.core.DefaultEventHandler in project interlok by adaptris.

the class LifecycleHelperTest method testRegisterEventHandler.

@Test
public void testRegisterEventHandler() throws Exception {
    registerEventHandler(new NullService(), new DefaultEventHandler());
    registerEventHandler(null, new DefaultEventHandler());
    registerEventHandler(new Channel(), new DefaultEventHandler());
}
Also used : DefaultEventHandler(com.adaptris.core.DefaultEventHandler) NullService(com.adaptris.core.NullService) Channel(com.adaptris.core.Channel) Test(org.junit.Test)

Aggregations

DefaultEventHandler (com.adaptris.core.DefaultEventHandler)21 Test (org.junit.Test)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)12 AppendingMessageAggregator (com.adaptris.core.services.aggregator.AppendingMessageAggregator)6 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)6 TimeInterval (com.adaptris.util.TimeInterval)6 ServiceException (com.adaptris.core.ServiceException)3 ConfiguredException (com.adaptris.core.services.exception.ConfiguredException)3 ThrowExceptionService (com.adaptris.core.services.exception.ThrowExceptionService)3 Adapter (com.adaptris.core.Adapter)2 Channel (com.adaptris.core.Channel)2 NullService (com.adaptris.core.NullService)2 StandaloneProducer (com.adaptris.core.StandaloneProducer)2 AdapterShutdownEvent (com.adaptris.core.event.AdapterShutdownEvent)2 BootstrapProperties (com.adaptris.core.management.BootstrapProperties)2 WaitService (com.adaptris.core.services.WaitService)2 JunitBootstrapProperties (com.adaptris.core.stubs.JunitBootstrapProperties)2 StaticMockEventProducer (com.adaptris.core.stubs.StaticMockEventProducer)2 URLString (com.adaptris.util.URLString)2 Properties (java.util.Properties)2