Ich benutze Munit, um meinen Mule Flow zu testen, und ich verwende Mocks, um die Variablen so einzustellen, dass der Fluss keine Ausnahme auslöst. Wenn ich den Test auf eigene Faust durchführe, übergibt es, aber wenn ich meine volle Suite ausführe, scheitert nur dieser Test und das Debugging zeigt, dass die Mocks die Variablen nicht setzen, wenn sie als Suite laufen.Mocks funktionieren nicht in MUnit Suite, aber sie funktionieren, wenn Test durch Test ausgeführt wird
<?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: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: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:endpointproject.xml" />
</spring:beans>
<munit:test
name="test_FilePickUpFlow_CallsFileToStringTransformer_ExactlyOnce"
description="Test">
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="file:file-to-string-transformer"
times="1" doc:name="Verify Call" />
</munit:test>
<munit:test
name="test_FilePickUpFlow_CallsJsonToObjectTransformer_ExactlyOnce"
description="MUnit Test">
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="json:json-to-object-transformer"
times="1" doc:name="Verify Call" />
</munit:test>
<munit:test name="test_FilePickUpFlow_CallsJsonParseSubFlow_ExactlyOnce"
description="Validate calls to sub flows are being done properly ">
<set-payload
value="[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]"
doc:name="Set Payload" />
<flow-ref name="filePickUpFlow" doc:name="filePickUpFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call" times="1">
<mock:with-attributes>
<mock:with-attribute name="name"
whereValue="#[matchContains('jsonParseSubFlow')]" />
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="test_httpInboundFlow_CallsSetPayload_ExactlyOnce"
description="MUnit Test">
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="set-payload"
doc:name="Verify Call" />
</munit:test>
<munit:test
name="test_HttpInboundFlow_CallsJsonToObjectTransformer_ExactlyOnce"
description="MUnit Test">
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="json:json-to-object-transformer"
doc:name="Verify Call" times="1" />
</munit:test>
<munit:test name="test_HttpInboundFlow_CallsJsonParseSubFlow_ExactlyOnce"
description="Validate calls to sub flows are being done properly ">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="#['Set Payload To Query Params']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']" />
</mock:when>
<mock:when messageProcessor="json:json-to-object-transformer"
doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['JSON to Object']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{protocol=http, host=0.0.0.0, port=8085, path=, operation=GET}]']" />
</mock:when>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
times="1" doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name"
whereValue="#[matchContains('jsonParseSubFlow')]" />
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test
name="test_HttpInboundFlow_CallsSetEndpointVariablesSubFlow"
description="MUnit Test">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="#['Set Payload To Query Params']" />
</mock:with-attributes>
<mock:then-return
payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']" />
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set port variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="port" value="8085" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set path variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="path" value="#[]" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set host variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="host" value="0.0.0.0" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="set protocol variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="protocol" value="http" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name"
whereValue="set operation variable" />
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="operation" value="GET" />
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('setEndpointVariablesSubFlow')]"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
<munit:test name="test_HttpInboundFlow_CallsHttpEndpointSubFlow"
description="MUnit Test">
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['Set Payload To Query Params']"/>
</mock:with-attributes>
<mock:then-return payload="#['[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]']"/>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set port variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="port" value="8085"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set path variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="path" value="#[]"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set host variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="host" value="0.0.0.0"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set protocol variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="protocol" value="http"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<mock:when messageProcessor="mule:set-payload" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="set operation variable"/>
</mock:with-attributes>
<mock:then-return payload="#[]">
<mock:inbound-properties>
<mock:inbound-property key="operation" value="GET"/>
</mock:inbound-properties>
</mock:then-return>
</mock:when>
<munit:set payload="#[]" doc:name="Set Message">
<munit:inbound-properties>
<munit:inbound-property key="http.query.params"
value="ParameterMap{[json=[[{"protocol":"http","host":"0.0.0.0","port":"8085","path":"","operation":"GET"}]]]}" />
</munit:inbound-properties>
</munit:set>
<flow-ref name="httpInboundFlow" doc:name="httpInboundFlow" />
<mock:verify-call messageProcessor="mule:sub-flow"
doc:name="Verify Call">
<mock:with-attributes>
<mock:with-attribute name="name" whereValue="#[matchContains('httpEndpointSubFlow')]"/>
</mock:with-attributes>
</mock:verify-call>
</munit:test>
Ich kann nicht sehen, warum der Test wäre anders, wenn eine Suite, da ich keine Kommunikation zwischen den einzelnen haben, wissen Sie, wie ich dies vermeiden kann?
Der Test, der fehlschlägt, ist test_HttpInboundFlow_CallsHttpEndpointSubFlow.