HTTP - neilcatalan/MUnit-Implementation GitHub Wiki

HTTP Implementation

For HTTP implementation, I make use of the generic mock definition in Anypoint Studio since there is no OOTB component to use. Below is the mule configuration.

<flow name="httpFlow">
    <http:request config-ref="HTTP_Request_Configuration" path="${http.path}" method="GET" doc:name="HTTP">
        <http:request-builder>
            <http:header headerName="http" value=""/>
        </http:request-builder>
    </http:request>
    <choice doc:name="Choice">
        <when expression="#[message.inboundProperties.'http.status' == 200]">
            <set-payload value="#['SUCCESS']" doc:name="Set Payload (Success)"/>
        </when>
        <otherwise>
            <set-payload value="#['FAILURE']" doc:name="Set Payload (Failed)"/>
        </otherwise>
    </choice>
</flow>

Below is the test suite configuration:

<munit:config mock-inbounds="true" mock-connectors="true"  name="munit" doc:name="MUnit configuration"/>

<spring:beans>
	<spring:import resource="classpath:globalconfig.xml"/>
    <spring:import resource="classpath:http.xml"/>
</spring:beans>

<munit:test name="http-test-suite-httpFlowTestCase1" description="Test">
    <mock:when messageProcessor="http:request" doc:name="Mock">
        <mock:with-attributes>
            <mock:with-attribute name="doc:name" whereValue="#['HTTP']"/>
        </mock:with-attributes>
        <mock:then-return payload="#[]">
            <mock:inbound-properties>
                <mock:inbound-property key="http.status" value="#[200]"/>
            </mock:inbound-properties>
        </mock:then-return>

    </mock:when>

    <flow-ref name="httpFlow" doc:name="httpFlow"/>
</munit:test>

For this case I decided to set the MUnit to true, since we don't need to access external system. All inbounds and other connectors in our flow will not connect to external system. In this case only the HTTP request connector is the only connector that calls an external system, with that we need to define a mock definition for it.

⚠️ **GitHub.com Fallback** ⚠️