Verifying exceptions
You can verify the details of an exception that was caught during propagation, by inspecting the generated test exception.
Before you begin
About this task
If a node in the sequence throws an exception that is not caught, it is returned to the caller of
the propagate()
or evaluate()
method. Details of a root cause
exception can be extracted from the exceptions nested in the TestException. If
the flow catches an exception by using either a TryCatch node
or a Catch terminal on a node in the sequence, the exception is processed as usual by the flow and
is not returned as a test exception to the propagate()
method.
The following example shows how the details of an exception generated by an MQGet node (when a queue does not exist) can be verified by
inspecting the generated test exception:
// Define the Spy on the HTTP Input which is used to inject the message
SpyObjectReference httpInputReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example1").node("HTTP Input");
NodeSpy httpInputNodeSpy = new NodeSpy(httpInputReference);
// Define the Spy on the HTTP Reply which is used to verify the operation
SpyObjectReference httpReplyReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example1").node("HTTP Reply");
NodeSpy httpReplyNodeSpy = new NodeSpy(httpReplyReference);
// Declare a new TestMessageAssembly object for the message being sent into the node
TestMessageAssembly inputMessageAssembly = new TestMessageAssembly();
/*
* Loading of message assembly would be done here
*/
// We expect that the failure thrown by the MQGet node is returned
TestException propagateEx = assertThrows(TestException.class, () -> {
// Now call propagate on the "out" terminal of the HTTP Input node
// Note: this approach works equally well with the evaluate method on an input terminal
httpInputNodeSpy.propagate(inputMessageAssembly, "out");
});
// Verify that one exception in the exception chain has message number BIP266 and contains
// the queue name 'QUEUE1' and the reason 'Unable to open queue'
assertThat(propagateEx, causedBy(hasMessageNumber(2666),
containsMessageText("Unable to open queue"),
containsMessageText("QUEUE1")));