Mule Subflow Testing

I started writing tests for my Mule project.

I wrote a functional test case for my main threads as follows.

public void testMainFlow_1() throws Exception{ MuleClient client = muleContext.getClient(); MuleMessage result = client.send(helloServiceAddress, fileAsString("SamplePayloads/input_Request.xml"), properties); assertNotNull("Null Result", result); assertEquals(result.getPayloadAsString(), fileAsString("SampleResponses/sampleResponse.xml")); } 

But how can I check my substreams. They have no endpoints. So how can I pass the payload to them and test it.

The following is the stream configuration.

 <flow name="main_flow" > .... .... <flow-ref name="subflow_1" /> .... .... <flow-ref name="subflow_2" /> .... .... </flow> <sub-flow name="subflow_1"> .... <some-transformer ... /> <out-bound call to web-service /> <some-transformer ... /> .... </sub-flow> <sub-flow name="subflow_2"> .... <some-transformer ... /> <out-bound call to web-service /> <some-transformer ... /> .... </sub-flow> 
+6
source share
3 answers

Using FunctionalTestCase , it should be as simple as:

 MessageProcessor subFlow = muleContext.getRegistry().lookupObject("subflow_1"); MuleEvent result = subFlow.process(getTestEvent("test_data")); 

but it does not work .

Currently, the best IMO approach is to have a test configuration that contains the streaming wrappers for the substreams you want to test and load this test configuration along with the main configuration into FunctionalTestCase .

An approach

@genjosanzo works, but it is based on combining a subflow with an existing main thread from the test code itself. I personally think it would be more difficult to create test threads.

+5
source

Using the latest version of Mule, we can test the subflow with the following script:

 SubflowInterceptingChainLifecycleWrapper subFlow = getSubFlow("subflowName"); subFlow.initialise(); MuleEvent event = subFlow.process(getTestEvent("")); MuleMessage message = event.getMessage(); assertEquals(expect, message.getPayload()); 
+2
source

Calling the subflow from the test case is quite simple, this is an example:

  @Test public void invokeSubFlow() throws Exception { MessageProcessor mp = (MessageProcessor) muleContext.getRegistry() .lookupObject("subflow_2"); FlowConstruct parentFlow = muleContext.getRegistry().lookupFlowConstruct("main_flow"); ((FlowConstructAware) mp).setFlowConstruct(muleContext.getRegistry() .lookupFlowConstruct("subflow_2")); Lifecycle lc = (Lifecycle) mp; lc.initialise(); lc.start(); MuleMessage muleMessage = new DefaultMuleMessage("test", muleContext); MuleEvent event = new DefaultMuleEvent(muleMessage, MessageExchangePattern.REQUEST_RESPONSE, new DefaultMuleSession(parentFlow,muleContext)); mp.process(event); } 
+1
source

All Articles