Can we create Munit for on Error propagate in mule 4?

1.4k Views Asked by At

Does on Error Propagate Munit should fail or pass? Scenario: When I get db connectivity error, it triggers email with error notification. Flow reference to Error email flow. Flow reference is placed in On Error Propagate. I have mocked database with Error, DB CONNECTIVITY in error tab and wrap flow Ref in Try block. My tests are failing. Test suite should fail with error message or pass with green colour in Munit tests?

<munit:test name="implementation-suiteTest" doc:id="804123309-0b27-4e5a-beb3-5372b91eafc3" expectedErrorType="DB:QUERY_EXECUTION">
        <munit:behavior >
            <munit:set-event doc:name="Set Event" doc:id="5d0290f4-9855-42ba-b434-a4322457819c">
                <munit:payload value="#[output application/java --- readUrl('classpath://insertdatabaseFlowtest\mock_payload.dwl')]" />
            </munit:set-event>
            <munit-tools:mock-when doc:name="Mock " doc:id="d8493233-303b-4765-89b4-9ae19bdffa1f" processor="db:bulk-insert">
            <munit-tools:with-attributes>
                <munit-tools:with-attribute whereValue="b645fb60-7b08-4939-894d-a476ee58b325" attributeName="doc:id" />
            </munit-tools:with-attributes>
                <munit-tools:then-return >
                    <munit-tools:payload value="#[output application/java --- readUrl('classpath://insertdatatodatabaseFlowtest\mock_payload1.dwl')]" />
                    <munit-tools:error typeId="DB CONNECTIVITY" />
                </munit-tools:then-return>
        </munit-tools:mock-when>
            <munit-tools:mock-when doc:name="Send Email" doc:id="c9cb74e7-9b56-4634-a272-d954d4ab8fb2" processor="email:send">
                <munit-tools:with-attributes >
                    <munit-tools:with-attribute whereValue="3f8bda1c-2e22-43d8-8e0a-3da9a6653dd7" attributeName="doc:id" />
                </munit-tools:with-attributes>
                <munit-tools:then-return >
                    <munit-tools:payload value="#[output application/java --- readUrl('classpath://insertdatatodatabaseFlowtest\mock_payload2.dwl')]" />
                </munit-tools:then-return>
            </munit-tools:mock-when>
        </munit:behavior>
        <munit:execution>
            <try doc:name="Try" doc:id="e73eae0a-25fb-46bb-b0e9-e845bb7310e0" >
                <flow-ref doc:name="Flow-ref " doc:id="8582675c-3203-4f70-8988-370e82cd5249" name="insert-dataFlow" />
                <error-handler >
                    <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" doc:id="7999aa4b-4959-4c64-98c4-284f883c5778" >
                        <logger level="INFO" doc:name="Logger" doc:id="6018dc63-a176-41aa-9ca3-be39264c9e0f" />
                    </on-error-continue>
                </error-handler>
            </try>
        </munit:execution>
        <munit:validation>
            <munit-tools:assert-that doc:name="Assert that" doc:id="6b255b30-e43a-4001-a62d-e6374a9d16f0" expression="#[payload]" is="#[MunitTools::containsString('Error Email Sent')]"/>
        </munit:validation>
    </munit:test>

Thanks

0

There are 0 best solutions below