We are trying to mock the Amazon S3 connector in an MUNIT suite. We have already tried multiple approaches, but the mock never seems to work:
- For a S3 connector added in single flow, we tried creating a mocked payload response. But the final output is actual payload always.
- Then we moved the S3 call to a sub flow and tried mocking the whole sub flow call itself, but it still always invokes the actual s3 bucket action.
- Using a spy around the sub flow call also made no difference.
Main flow:
<flow name="helios-s3-copy-file"
processingStrategy="synchronous">
<http:listener config-ref="HTTP_Listener_Configuration" path="/movefile" doc:name="HTTP"/>
<set-variable value="#['Test']" variableName="feedPathPrefix" doc:name="Set feed prefix" />
<set-variable variableName="srcPath"
value="#[feedPathPrefix + '/TestFilemule.xlsx']"
doc:name="Source" />
<set-variable variableName="destPath"
value="#[feedPathPrefix + '/dest/TestFilemule.xlsx']"
doc:name="Destination" />
<flow-ref name="copyactionflowRef" doc:name="copyactionflow"/>
<logger
level="INFO" doc:name="Logger" message="#[flowVars.copyMsg]"/>
<set-payload value="#[flowVars.copyMsg]" doc:name="Set Payload"/>
</flow>
<sub-flow name="copyactionflowRef">
<s3:copy-object config-ref="Amazon_S3__Configuration" sourceBucketName="some-bucket-name" sourceKey="#[srcPath]" destinationBucketName="some-bucket-name" destinationKey="#[destPath]" doc:name="Copy Processed File"/>
<set-variable variableName="copyMsg" value="#['Completed copy from ' + feedPathPrefix + ' to ' + destPath + ' directory']" doc:name="Variable"/>
</sub-flow>
Munit Test case:
<munit:test name="amazons3test-test-suite-helios-s3-copy-fileTest" description="Testing mocking of copy objects" >
<mock:when messageProcessor="mule:sub-flow" doc:name="Mock2">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['copyactionflowRef']"/>
</mock:with-attributes>
<mock:then-return payload="#['Copy completed payload']">
<mock:outbound-properties>
<mock:outbound-property key="copyMsg" value="Copy complete"/>
</mock:outbound-properties>
</mock:then-return>
</mock:when>
<!-- <mock:spy messageProcessor="mule:sub-flow" doc:name="Spy">
<mock:with-attributes>
<mock:with-attribute name="doc:name" whereValue="#['copyactionflowRef']"/>
</mock:with-attributes>
<mock:assertions-before-call>
<logger message="Must not make actual S3 call" level="INFO" doc:name="Logger"/>
</mock:assertions-before-call>
<mock:assertions-after-call>
<munit:set payload="#['mock payload']" doc:name="Set Message">
<munit:invocation-properties>
<munit:invocation-property key="copyMsg" value="Value from Spy"/>
</munit:invocation-properties>
</munit:set>
</mock:assertions-after-call>
</mock:spy> -->
<flow-ref name="helios-s3-copy-file" doc:name="Flow-ref to helios-s3-copy-file"/>
</munit:test>
We also logged a ticket in Mule forums, but we haven't got any solutions yet. Does anyone know how can we log a Jira in Mulesoft?
From some other questions on stackoverflow it seems same issue exists for many other OOB connections. MUNIT mock seems to have lot of flaws.