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