2017-09-18 2 views
0

Ich versuche, MUnit für den folgenden Fluss zu erstellen.Mocking SubFlow in Mule

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

Ich habe zwei Testabläufe für Subflow erstellen, die gut funktioniert. Obwohl ich den Unterfluss verspottete, um den Hauptfluss zu testen, führt der Fluss den Unterfluss aus. Irgendwelche Ideen, wenn ich etwas verpasse, während ich den Unterfluss verspotte. Jede Hilfe wird sehr geschätzt.

Das ist meine Testsuite

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

Antwort

3

Der Täter ist dies

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

Der Name Name nicht doc sein sollte: Name

+0

Do I Flow-ref Komponente oder Unter verspotten müssen Strömungskomponente? – MRavindran

+0

+0

Mit diesem gearbeitet. – MRavindran