Testing a sequence of nodes by using the propagate() method
You can test a sequence of message flow nodes by using the propagate()
method.
Before you begin
About this task
You can test a sequence of message flow nodes by using the propagate()
method,
which allows the message to be injected to an output terminal of a message flow node. When you use
the propagate()
method, the message flow node itself is not called, but the message
is propagated down the flow from the node's output terminal.
When the propagate()
method is called, the sequence of nodes is executed
synchronously on the unit test thread. The propagate()
method completes when
evaluation of the sequence of nodes completes. If any of the evaluated nodes make requests to other
flows (such as using a Callable Invoke node), invokes external APIs, or accesses external resources,
these must be running and available in order for the propagate to complete successfully.
This example propagates a message to the 'out' terminal of the HTTPInput node. The HTTPReply node detects that there was no initial HTTPInput node, so it does nothing. Other transports might need extra code to prevent errors from being generated.
// 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 Compute2 which is used to verify the required nodes were executed
SpyObjectReference compute2Reference = new SpyObjectReference().application("ExamplesApp").
messageFlow("Example1").node("Compute2");
NodeSpy compute2NodeSpy = new NodeSpy(compute2Reference);
// 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
*/
// Send the message assembly to the 'out' terminal of the HTTP Input node
httpInputNodeSpy.propagate(inputMessageAssembly, "out");
// Assert the HttpInput node was not called, because we injected the message at the
// output terminal using propagate
assertThat(httpInputNodeSpy, nodeCallCountIs(0));
// Assert the Compute2 node is called
assertThat(compute2NodeSpy, nodeCallCountIs(1));
// Assert the HTTP Reply node is called
assertThat(httpReplyNodeSpy, nodeCallCountIs(1));
propagate()
method to test a section of a message flow, you can
configure additional node spies and node stubs on the message flow to perform any of the following actions:- Observe and validate the message content at any node in the message flow
- Prevent message propagation past a specific message flow node terminal, by using the
setStopAtTerminal()
method - Substitute the operation of a message flow node