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)));
}
}
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)));
}
}
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());
}
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);
}
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());
}
Aggregations