Contact Free trial Login

Enable Flow Sources

Because MUnit does not load any of your flow endpoints by default, you must use the Enable Flow Sources element within MUnit Test to configure which endpoints the MUnit runtime should load and execute for your tests.

For example, assume that your application has a flow with an HTTP listener that returns a specific payload:

<http:listener-config name="HTTP_Listener_config">
    <http:listener-connection host="localhost" port="1234"/>
</http:listener-config>

<flow name="http-example-flow">
    <http:listener path="/" config-ref="HTTP_Listener_config"/>
    <set-payload value="#['Hello World!']" mimeType="text/plain"/>
</flow>

For MUnit to reach the endpoint, you must enable the http-example-flow in your enable-flow-source property:

<http:request-config name="HTTP_Request_config">
    <http:request-connection host="localhost" port="1234"/>
</http:request-config>

<munit:test name="http-example-test">
    <munit:enable-flow-sources>
        <munit:enable-flow-source value="http-example-flow"/> (1)
    </munit:enable-flow-sources>

    <munit:execution>
        <http:request method="GET" path="/" config-ref="HTTP_Request_config"/>
    </munit:execution>

    <munit:validation>
        <munit-tools:assert-that expression="#[payload]"
                                 is="#[MunitTools::equalTo('Hello World!')]"/>
    </munit:validation>
</munit:test>
1 If the http-example-flow value is not listed as an enabled flow source, your MUnit test fails because it cannot initialize the HTTP listener configuration.

Enabling Flow Sources from Studio

You can also define flow sources using the Mule Properties view of your MUnit test in Anypoint Studio:

enable flow sources concept
  1. Click Add.

  2. Select the name of the flow you want to enable from the Name of the flow drop-down menu.

See Also