模拟骡子中的SubFlow

时间:2017-09-18 23:16:30

标签: mule munit

我正在尝试为以下流程创建MUnit。

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

<mule xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <db:oracle-config name="Oracle_Configuration" host="127.0.0.1" port="1521" instance="xe" user="system" password="madhu" doc:name="Oracle Configuration"/>
    <flow name="munitFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/munit" doc:name="HTTP"/>
        <object-to-string-transformer doc:name="Object to String"/>
        <set-payload value="#[payload]" doc:name="Set Payload"/>
        <flow-ref name="SubFlow1" doc:name="SubFlow1"/>
        <choice doc:name="Choice">
            <when expression="#[flowVars.temp == '1']">
                <set-payload value="Hello from madhu" doc:name="Set Payload"/>
            </when>
            <otherwise>
                <set-payload value="Hello from mitha" doc:name="Set Payload"/>
            </otherwise>
        </choice>
    </flow>
    <sub-flow name="SubFlow1">
        <choice doc:name="Choice">
            <when expression="#[payload=='1']">
                <set-variable variableName="temp" value="1" doc:name="set temp to 1"/>
            </when>
            <otherwise>
                <set-variable variableName="temp" value="2" doc:name="set temp to 2"/>
            </otherwise>
        </choice>
    </sub-flow>
</mule>

我为子流创建了两个测试流程,工作正常。 虽然我模拟子流来测试主流,但是流程正在执行子流程。任何想法,如果我在嘲笑子流程时遗漏了某些东西。任何帮助将受到高度赞赏。

这是我的测试套件

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

<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:mock="http://www.mulesoft.org/schema/mule/mock" 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:munit.xml"/>
    </spring:beans>
    <munit:test name="munit-test-suite-munitSub_FlowTest" description="Test">
        <munit:set payload="1" doc:name="Set Message"/>
        <flow-ref name="SubFlow1" doc:name="SubFlow1"/>
        <mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#['set temp to 1']"/>
            </mock:with-attributes>
        </mock:verify-call>
    </munit:test>
    <munit:test name="munit-test-suite-munitSub_FlowTest1" description="Test">
        <munit:set payload="2" doc:name="Set Message"/>
        <flow-ref name="SubFlow1" doc:name="SubFlow1"/>
        <mock:verify-call messageProcessor="mule:set-variable" doc:name="Verify Call">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#['set temp to 2']"/>
            </mock:with-attributes>
        </mock:verify-call>
    </munit:test>
    <munit:test name="munit-test-suite-munitFlowTest" description="Test">
        <mock:when messageProcessor=".*:.*" doc:name="Mock">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#['Set Payload']"/>
            </mock:with-attributes>
            <mock:then-return payload="#[samePayload()]"/>
        </mock:when>
        <mock:when messageProcessor="mule:sub-flow" doc:name="Mock">
            <mock:with-attributes>
                <mock:with-attribute name="doc:name" whereValue="#[matchContains('SubFlow1')]"/>
            </mock:with-attributes>
            <mock:then-return payload="#[samePayload()]">
                <mock:invocation-properties>
                    <mock:invocation-property key="temp" value="1"/>
                </mock:invocation-properties>
            </mock:then-return>
        </mock:when>
        <flow-ref name="munitFlow" doc:name="munitFlow"/>
        <munit:assert-payload-equals message="Wrong payload" expectedValue="Hello from madhu" doc:name="Assert Payload"/>
    </munit:test>
</mule>

1 个答案:

答案 0 :(得分:4)

罪魁祸首就是这个

     <mock:with-attribute name="doc:name" whereValue="#[matchContains('SubFlow1')]"/>

名称应为name not doc:name