AdvancedMessageSplitterService extends MessageSplitterServiceImp implements EventHandlerAware, ServiceWrapper { @Override public void registerEventHandler(EventHandler eh) { eventHandler = eh; } AdvancedMessageSplitterService(); @Override void start(); @Override void stop(); Service getService(); void setService(Service sc); Boolean getSendEvents(); boolean sendEvents(); void setSendEvents(Boolean b); @Override void registerEventHandler(EventHandler eh); @Override void prepare(); @Override Service[] wrappedServices();  }
@Test public void testDoServiceWithFailures_NullEventHandler() 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); try { ExampleServiceCase.execute(service, msg); fail("Expecting failure from AlwaysFailService"); } catch (ServiceException expected) { ; } }
@Test public void testDoServiceWithEventHandler_Null() throws Exception { MockMessageProducer producer = new MockMessageProducer(); AdvancedMessageSplitterService service = createServiceImpl(new SimpleRegexpMessageSplitter("\\|"), producer); AdaptrisMessage msg = createMessage(REGEXP_DATA); service.registerEventHandler(null); ExampleServiceCase.execute(service, msg); assertEquals("Number of messages", 4, producer.getMessages().size()); 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))); } }
@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))); } }