Monday, August 8, 2016

Using MUnit with flows containing a Rollback Exception Strategy

Here is a flow containing a Rollback Exception Strategy:

The flow receives messages from a JMS Queue and processes them.  If an exception occurs, the Rollback Exception Strategy replays the message or sends it to a DLQ if the exception continues to occur.

An MUunit test might look like this:


This test is fine for test cases that don't throw an exception.  For test cases that do throw an exception, the MUnit test will never reach the Assert True component.  The exception gets caught by the Rollback Exception Strategy in the Main flow, but because there is no actual JMS Queue the message can't be rolled back and Rollback Exception Strategy re-throws the exception.

A strategy for tests that throw exceptions is to create in the MUnit fixture a wrapper flow that catches the exception and returns it in the payload.  See the following image; the wrapper flow InvokeMainFlowAndReturnException is called instead of the Main flow.  InvokeMainFlowAndReturnException calls the Main flow, catches the exception thrown by the Rollback Exception Strategy, and returns the exception in the payload. The expression that extracts the exception is simply #[exception.?cause]