Contact Us 1-800-596-4880

Enable Flow Sources

logo acb active Anypoint Code Builder

logo studio active Anypoint Studio

The Enable Flow Sources element within the MUnit test instructs MUnit which flow sources to load and execute for the test.

By default, MUnit doesn’t start any of the event sources (flow sources such as triggers and listeners). You must configure which flow sources must start for your tests.

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 invoke that listener, enable the http-example-flow in your enable-flow-source property within your MUnit test:

<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"/>
    </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>

If the http-example-flow value isn’t listed as an enabled flow source, your MUnit test fails because it can’t initialize the HTTP listener configuration.

MUnit starts flow sources at the beginning of the test and stops them at the end of the test. Flow sources aren’t executed during the before-suite/before-test, nor during the after-test/after-suite.
See Before/After scopes for additional information.