Dangson
Dangson

Reputation: 1

munit throw a specific exception

I am trying to throw a Filter Unaccepted Exception in munit to test my error handling but I am getting this error

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)

This is my throw an exception

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

I think it is because of my MEL statement

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

Upvotes: 0

Views: 2855

Answers (2)

Tony K
Tony K

Reputation: 128

You could use a groovy component to throw your exception like that

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

Hope it helps.

/T

Upvotes: 2

Manik Magar
Manik Magar

Reputation: 1401

I don't see throw-an call in the snippet you pasted.

Anyways, No argument constructor for org.mule.api.routing.filter.FilterUnacceptedException is not public, try using #[new org.mule.api.routing.filter.FilterUnacceptedException('Some message')]

Upvotes: 1

Related Questions