首页 > 解决方案 > 我们可以在 mule 4 中为 on Error 传播创建 Munit 吗?

问题描述

On Error Propagate Munit 应该失败还是通过?场景:当我收到数据库连接错误时,它会触发带有错误通知的电子邮件。对错误电子邮件流的流引用。流参考放置在 On Error Propagate 中。我在错误选项卡中使用错误、DB CONNECTIVITY 模拟数据库,并在 Try 块中包装流 Ref。我的测试失败了。测试套件应该在 Munit 测试中失败并显示错误消息或以绿色通过?

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

谢谢

标签: mule4munit

解决方案


推荐阅读