【问题标题】:munit throw a specific exceptionmunit 抛出一个特定的异常
【发布时间】:2016-07-08 00:32:29
【问题描述】:

我试图在 munit 中抛出一个过滤器不接受的异常来测试我的错误处理,但我收到了这个错误

org.mule.api.MessagingException: Failed to invoke throw-an.
at get_data_filter_unaccepted_exception-test.mock:throw-an{doc:name=Throw unaccepted Exception, exception-ref=#[new org.mule.api.routing.filter.FilterUnacceptedException()], whenCalling=.*:.*}(get_data_from_qcfc-test-suite.xml:316)
at appleFlow.munit:test{initialState=started, description=Test, ignore=false, abstract=false, id=MunitTestFlow$$EnhancerByMUNIT$$904837f0{get_data_filter_unaccepted_exception-test}}(get_data_from_qcfc-test-suite.xml:315)
Caused by: org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "new org.mule.api.routing.filter.FilterUnacceptedException()" failed.
    at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:232)

这是我抛出的异常

<mock:when messageProcessor=".*:.*" doc:name="Mock API Token Web Service Call">
        <mock:with-attributes>
            <mock:with-attribute name="doc:name" whereValue="#['Get API Token']"/>
        </mock:with-attributes>
        <mock:then-return payload="#[getResource('api_token_success.xml').asString()]" mimeType="application/xml"/>

    </mock:when>

我认为是因为我的 MEL 声明

#[new org.mule.api.routing.filter.FilterUnacceptedException()]

【问题讨论】:

    标签: mule anypoint-studio munit


    【解决方案1】:

    你可以使用一个 groovy 组件来抛出你的异常

    <scripting:component doc:name="Throw Exception">
            <scripting:script engine="Groovy"><![CDATA[throw new org.mule.api.routing.filter.FilterUnacceptedException(); ]]></scripting:script>
        </scripting:component>
    

    希望对你有帮助。

    /T

    【讨论】:

      【解决方案2】:

      我在您粘贴的 sn-p 中没有看到 throw-an 调用。

      无论如何,org.mule.api.routing.filter.FilterUnacceptedException 的无参数构造函数是不公开的,请尝试使用 #[new org.mule.api.routing.filter.FilterUnacceptedException('Some message')]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-06-16
        • 2013-05-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多