如何使用“引发异常”组件在m子单元中引发org.mule.module.ws.consumer.SoapFaultException

时间:2018-10-17 20:30:22

标签: mule mule-studio mule-component mule-esb munit

我在 Mule 中有一个要求,当我正在执行的组件为时,我需要抛出 org.mule.module.ws.consumer.SoapFaultException 类型的异常。 单元测试

期间,strong>网络服务使用者

到目前为止,我在下面尝试过但没有运气。

#[new org.mule.module.ws.consumer.SoapFaultException(message,new javax.xml.namespace.QName("InvalidMoniker"),new javax.xml.namespace.QName("InvalidMoniker"),new javax.xml.namespace.QName("InvalidMoniker"),'<?xml version="1.0" encoding="UTF-8"?> <detail>   <ExceptionCode>InvalidMoniker</ExceptionCode>   <Message>The specified moniker is invalid.      (8455323b-57d4-434d-9ae0-70899a879546)</Message> </detail>')]

它应该在有效载荷上引发异常,如下所示。

<?xml version="1.0" encoding="UTF-8"?>
<detail>
    <ExceptionCode>InvalidMoniker</ExceptionCode>
    <Message>The specified moniker is invalid.
        (8455323b-57d4-434d-9ae0-70899a879546)</Message>
</detail>

下面是我完整的munit测试用例。

<munit:test name="post:/addresses/lookup:application/json:sys-customer-mgmt-config-422-application/json-FlowTest" description="Verifying functionality of [post:/addresses/lookup:application/json:sys-customer-mgmt-config-422-application/json]" >
        <mock:throw-an exception-ref="#[new org.mule.module.ws.consumer.SoapFaultException(message,new javax.xml.namespace.QName(&quot;InvalidMoniker&quot;),new javax.xml.namespace.QName(&quot;InvalidMoniker&quot;),new javax.xml.namespace.QName(&quot;InvalidMoniker&quot;),'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;detail&gt;   &lt;ExceptionCode&gt;InvalidMoniker&lt;/ExceptionCode&gt;   &lt;Message&gt;The specified moniker is invalid.        (8455323b-57d4-434d-9ae0-70899a879546)&lt;/Message&gt; &lt;/detail&gt;')]" whenCalling=".*:.*" doc:name="Throw an Exception">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#['Call QAS DoGetAddress WS V3']"/>
            </mock:with-attributes>
        </mock:throw-an>
        <set-payload value="#[getResource('scaffolder/request/post_addresses_lookup_application_json.json').asString()]" doc:name="Set Payload"/>
        <http:request config-ref="HTTP_Request_Configuration_Munit" method="POST" path="/sys-customer-mgmt/v1/addresses/lookup" doc:name="HTTP">
            <http:request-builder>
                <http:header headerName="Accept" value="application/json" />
                <http:header headerName="Content-Type" value="application/json" />
            </http:request-builder>
            <http:success-status-code-validator values="422" />
        </http:request>
        <object-to-string-transformer doc:name="http response to string" />
        <munit:assert-true message="The HTTP Status code is not correct!" condition="#[messageInboundProperty('http.status').is(eq(422))]" doc:name="assert that - http.status eq 422" />
        <expression-component doc:name="assert JSON Payload"><![CDATA[org.skyscreamer.jsonassert.JSONAssert.assertEquals(getResource('addresses-lookup/422-response.json').asString(),payload,false);]]></expression-component>
    </munit:test>

有人可以帮忙吗?

0 个答案:

没有答案