有流将调用 http-outbound 端点。如果 http 不可用,我想为该场景编写测试用例(捕获流程中的异常并按 POSTMAN 的预期工作)。我尝试使用throw an exception来模拟消息处理为 http:request 时要抛出的异常。但它没有奏效。有人可以帮助如何在 munit 中模拟异常吗?
以下是我尝试过的代码:
<munit:test name="test-project-test-suite-munit-testFlowTest3" description="Test" >
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload']"/>
</mock:with-attributes>
<mock:then-return payload="#['payload3']"/>
</mock:when>
<mock:when messageProcessor="mule:flow" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('munit-testFlow2')]"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:invocation-properties>
<mock:invocation-property key="variable2" value="#['response2']"/>
</mock:invocation-properties>
</mock:then-return>
</mock:when>
<mock:throw-an exception-ref="#[new org.mule.api.MessagingException()]" whenCalling="http:request" doc:name="Throw an Exception">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['HTTP-RES']"/>
</mock:with-attributes>
</mock:throw-an>
<flow-ref name="munit-testFlow" doc:name="munit-testFlow"/>
<munit:assert-payload-equals message="oops failed" expectedValue="#['error-response']" doc:name="Assert Payload"/>
</munit:test>