Stopping a flow before it completes
When you are testing part of a message flow, you can stop the flow before it completes,
by using the setStopAtInputTerminal()
and
setStopAtOutputTerminal()
methods on a node spy.
Before you begin
About this task
You can use the setStopAtInputTerminal()
method on a node spy to stop the
execution of a message flow at an input terminal, as if the input terminal was not connected. As a
result, the node and any subsequent nodes that it is connected to are not evaluated.
Alternatively, you can use the setStopAtOutputTerminal()
method to stop the
execution of the message flow at an output terminal, as if the output terminal was not connected. As
a result, the node is evaluated but subsequent nodes are not.
setStopAtInputTerminal()
method stops propagation at the input terminal on the MQOutput node:
// Define the Spy on the MQ Input which is used to inject the message
SpyObjectReference mqInputReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("MQ Input");
NodeSpy mqInputNodeSpy = new NodeSpy(mqInputReference);
// Define the Spy on the Compute node which is used to validate the operation
SpyObjectReference computeReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("Compute");
NodeSpy computeNodeSpy = new NodeSpy(computeReference);
// Define the Spy on the MQ Output node as we do not want this node to execute
SpyObjectReference mqOutputReference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example4").node("MQ Output");
NodeSpy mqOutputNodeSpy = new NodeSpy(mqOutputReference);
mqOutputNodeSpy.setStopAtInputTerminal("in");
// 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 */
// Declare a new TestMessageAssembly object for the expected message propagated from Compute2 node
TestMessageAssembly afterComputeExpectedMessageAssembly = new TestMessageAssembly();
/* Loading of message assembly would be done here */
// Send the message assembly to the 'out' terminal of the HTTP Input node
mqInputNodeSpy.propagate(inputMessageAssembly, "out");
// Assert the Compute node is called and that the expected message is returned
assertThat(computeNodeSpy, nodeCallCountIs(1));
assertThat(computeNodeSpy, terminalPropagateCountIs("out", 1));
// Proof that the MQ Output node is not called
assertThat(mqOutputNodeSpy, nodeCallCountIs(0));
// Assert that the actual message assembly matches the expected message assembly
assertThat(actualMessageAssembly, equalsMessage(afterComputeExpectedMessageAssembly));
You could achieve a similar result by using the setStopAtOutputTerminal()
method
to stop propagation at the 'out' terminal of the Compute
node.