0

在将有效负载发送到 JMS 队列之前,我在消息中设置了一些出站属性,并且我想在将消息发送到 JMS 队列之前测试这些属性是否在消息中正确设置。

我曾考虑在 JMS 出站端点之前使用 MUnit 间谍,但间谍只能验证会话属性、调用属性和有效负载。有没有另一种方法可以使用 MUnit XML 实现这一点?

我创建了一个迷你骡子项目来进一步说明这个问题。下面提供了代码。本质上,它只是一个调用子流的流,该子流在 mule 消息中设置出站属性,并且 MUnit 有一个 spy 断言在调用子流之后在 mule 消息中设置出站属性。但是,MUnit Spy 似乎无法访问 mule 出站属性。我想知道此时是否有另一种解决方法。我知道文档指定间谍只能验证会话和调用属性,以及此时的有效负载。欢迎任何建议。

Sandbox.xml - 主骡文件

    <?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <flow name="outbound-props-flow">
        <flow-ref name="outbound-props-sub-flow" doc:name="Call outbound-props-sub-flow"/>
        <logger message="#[message]" level="INFO" doc:name="Log Message"/>
    </flow>
    <sub-flow name="outbound-props-sub-flow">
        <set-property propertyName="outbound-prop-1" value="test1" doc:name="set-outbound-prop-1"/>
        <set-property propertyName="outbount-prop-2" value="test2" doc:name="set-outbound-prop-2"/>
    </sub-flow>
</mule>

MUnit 文件 - 测试主要流程

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/mock http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd">
    <munit:config name="munit" doc:name="MUnit configuration"/>
    <spring:beans>
        <spring:import resource="classpath:sandbox.xml"/>
    </spring:beans>
    <munit:test name="outbound-props-flow-outbound-props-flowTest" description="Test">
        <mock:spy messageProcessor="mule:sub-flow" doc:name="Spy">
            <mock:with-attributes>
                <mock:with-attribute name="name" whereValue="#[matchContains('outbound-props-sub-flow')]"/>
            </mock:with-attributes>
            <mock:assertions-after-call>
                <logger message="Message in SPY Module: #[message]" level="INFO" doc:name="Log Message in Spy"/>
                <munit:assert-on-equals message="outbound-props-1 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-1']]" doc:name="Assert outbound-props-1 is set properly"/>
                <munit:assert-on-equals message="outbound-props-2 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-2']]" doc:name="Assert outbound-props-2 is set properly"/>
            </mock:assertions-after-call>
        </mock:spy>
        <flow-ref name="outbound-props-flow" doc:name="Flow-ref to outbound-props-flow"/>
    </munit:test>
</mule>

谢谢,

胡安

4

1 回答 1

2

不要为此使用“间谍”,它有一些限制。看看文档:

https://docs.mulesoft.com/mule-user-guide/v/3.7/the-spy-message-processor#defining-spy-actions

您可以简单地在流 ref 之后添加断言。

<munit:test name="outbound-props-flow-outbound-props-flowTest" description="Test">  
    <flow-ref name="outbound-props-flow" doc:name="Flow-ref to outbound-props-flow"/>
    <munit:assert-on-equals message="outbound-props-1 is not set properly" expectedValue="test1" actualValue="#[message.outboundProperties['outbound-prop-1']]" doc:name="Assert outbound-props-1 is set properly"/>
    <munit:assert-on-equals message="outbound-props-2 is not set properly" expectedValue="test2" actualValue="#[message.outboundProperties['outbound-prop-2']]" doc:name="Assert outbound-props-2 is set properly"/>
</munit:test>
于 2015-12-24T20:51:02.630 回答