I am trying to create MUnit for the below flow.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<db:oracle-config name="Oracle_Configuration" host="127.0.0.1" port="1521" instance="xe" user="system" password="madhu" doc:name="Oracle Configuration"/>
<flow name="munitFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/munit" doc:name="HTTP"/>
<object-to-string-transformer doc:name="Object to String"/>
<set-payload value="#[payload]" doc:name="Set Payload"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<choice doc:name="Choice">
<when expression="#[flowVars.temp == '1']">
<set-payload value="Hello from madhu" doc:name="Set Payload"/>
</when>
<otherwise>
<set-payload value="Hello from mitha" doc:name="Set Payload"/>
</otherwise>
</choice>
</flow>
<sub-flow name="SubFlow1">
<choice doc:name="Choice">
<when expression="#[payload=='1']">
<set-variable variableName="temp" value="1" doc:name="set temp to 1"/>
</when>
<otherwise>
<set-variable variableName="temp" value="2" doc:name="set temp to 2"/>
</otherwise>
</choice>
</sub-flow>
</mule>
I have create two test flows for subflow, which is working fine. Eventhough I mocked subflow to test the main flow, the flow is executing the sub flow. Any ideas if I am missing something while mocking the sub flow. Any help will be highly appreciated.
This is my testsuite
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd">
<munit:config name="munit" doc:name="MUnit configuration"/>
<spring:beans>
<spring:import resource="classpath:munit.xml"/>
</spring:beans>
<munit:test name="munit-test-suite-munitSub_FlowTest" description="Test">
<munit:set payload="1" doc:name="Set Message"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['set temp to 1']"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="munit-test-suite-munitSub_FlowTest1" description="Test">
<munit:set payload="2" doc:name="Set Message"/>
<flow-ref name="SubFlow1" doc:name="SubFlow1"/>
<mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['set temp to 2']"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="munit-test-suite-munitFlowTest" description="Test">
<mock:when messageProcessor=".*:.*" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload']"/>
</mock:with-attributes>
<mock:then-return payload="#[samePayload()]"/>
</mock:when>
<mock:when messageProcessor="mule:sub-flow" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#[matchContains('SubFlow1')]"/>
</mock:with-attributes>
<mock:then-return payload="#[samePayload()]">
<mock:invocation-properties>
<mock:invocation-property key="temp" value="1"/>
</mock:invocation-properties>
</mock:then-return>
</mock:when>
<flow-ref name="munitFlow" doc:name="munitFlow"/>
<munit:assert-payload-equals message="Wrong payload" expectedValue="Hello from madhu" doc:name="Assert Payload"/>
</munit:test>
</mule>
The culprit is this
The name should be name not doc:name