1

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:

  1. For a S3 connector added in single flow, we tried creating a mocked payload response. But the final output is actual payload always.
  2. 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.
  3. 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.

gsonal
  • 11
  • 1
  • 6

1 Answers1

0

From what I can see by the code you have provided, your Mock component isn't mocking the sub-flow, because your sub-flow has no attribute by "doc:name". It only has "name" attribute. So your configuration should look something like

<mock:with-attributes>
        <mock:with-attribute name="name" whereValue="#['copyactionflowRef']"/>
</mock:with-attributes>

If this doesn't work still, try changing whereValue="#[matchContains('copyactionflowRef')]"

Hope this helps!

Abhay Singh
  • 170
  • 5
  • After using "matchContains" check, the sub flow is getting mocked. But if the S3 connector is part of same flow, mocked object payload is again overridden. So, our problem is only partially solved. We still need a way to mock S3 connector in same flow. Thanks for the answer though. – gsonal Oct 19 '17 at 12:02