/** * Stop the processing chain on failure * * <p>Inserting this into a chain will stop the processing chain if the * previous processor ended up with an error (ie, {@link * ProcessingReport#isSuccess()} returns {@code false}).</p> * * @return a new chain */ public ProcessorChain<IN, OUT> failOnError() { return failOnError(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.chainStopped"))); }
/** * Stop the processing chain on failure * * <p>Inserting this into a chain will stop the processing chain if the * previous processor ended up with an error (ie, {@link * ProcessingReport#isSuccess()} returns {@code false}).</p> * * @return a new chain */ public ProcessorChain<IN, OUT> failOnError() { return failOnError(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.chainStopped"))); }
/** * Stop the processing chain on failure * * <p>Inserting this into a chain will stop the processing chain if the * previous processor ended up with an error (ie, {@link * ProcessingReport#isSuccess()} returns {@code false}).</p> * * @return a new chain */ public ProcessorChain<IN, OUT> failOnError() { return failOnError(new ProcessingMessage() .setMessage(BUNDLE.getMessage("processing.chainStopped"))); }
@Test public void noFailureDoesNotTriggerEarlyExit() throws ProcessingException { @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p1 = mock(Processor.class); @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p2 = mock(Processor.class); final Processor<MessageProvider, MessageProvider> processor = ProcessorChain.startWith(p1).failOnError().chainWith(p2) .getProcessor(); final MessageProvider input = mock(MessageProvider.class); final ProcessingReport report = new DummyReport(LogLevel.DEBUG); when(p1.process(report, input)).thenReturn(input); processor.process(report, input); verify(p1).process(same(report), any(MessageProvider.class)); verify(p2).process(same(report), any(MessageProvider.class)); }
@Test public void failingOnErrorExitsEarly() throws ProcessingException { @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p1 = mock(Processor.class); @SuppressWarnings("unchecked") final Processor<MessageProvider, MessageProvider> p2 = mock(Processor.class); final Processor<MessageProvider, MessageProvider> processor = ProcessorChain.startWith(p1).failOnError().chainWith(p2) .getProcessor(); final MessageProvider input = mock(MessageProvider.class); final ProcessingReport report = new DummyReport(LogLevel.ERROR); try { processor.process(report, input); fail("No exception thrown!!"); } catch (ProcessingException e) { assertMessage(e.getProcessingMessage()) .hasMessage(BUNDLE.getMessage("processing.chainStopped")); } verify(p1).process(same(report), any(MessageProvider.class)); verify(p2, never()).process(any(ProcessingReport.class), any(MessageProvider.class)); }