mulemule-studioanypoint-studiomule4munit

How to omit one message processor in MUnit test?


I have a flow, in which I have an error handler which deletes an input file.

<on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="ebacee56-e127-4338-87a7-458659983dee" type="APP:UNSUPPORTED_DOCUMENT_TYPE">
    <logger level="INFO" doc:name="Wrong document type" doc:id="84408377-4f4b-4115-8205-531faa8b9afd" message="#["file: " ++ attributes.fileName ++ " - skipping wrong type"]" category="correctionsImport" />
    <delete doc:name="Delete inbound file" doc:id="6dc7298f-f0bc-4905-aa5d-c8972af9b225" config-ref="XMLFile" path="#[attributes.path]" />
</on-error-propagate>

I also have a MUnit test for this:

<test name="ImportCorrectionsFlowTestWithIncorrectDocumentType" doc:id="b4bd8c08-3c8d-4ac9-a4bd-a09afa43126f" description="Test" expectedErrorType="APP:UNSUPPORTED_DOCUMENT_TYPE">
    <execution>
        <read doc:name="POL249_C.INVOICE.CORRECTION-INCENTIVE-CREDIT-INCORRECT-DOCUMENT-TYPE.5921266020-test.xml" doc:id="b92e3cca-aacc-4259-a070-1967eceddc33" config-ref="XMLFileTest" path="corrections/incorrect/CORRECTION-INCENTIVE-CREDIT-INCORRECT-DOCUMENT-TYPE.xml" />
        <flow-ref doc:name="Flow-ref to ImportCorrectionsFlow" doc:id="d3409a91-7f64-47b6-a469-e0faa39696f7" name="ImportCorrectionsFlow" />
        <logger level="INFO" doc:name="Logger" doc:id="d69ee72f-ed46-4c4b-a142-7a140c0f5c64" />
    </execution>
</test>

The problem is, when I run this test, the source file is deleted, and I don't want this to happen. How can I prevent deletion of the file? Can I somehow mock the file deletion flow component so it doesn't delete the file? Or can I mock the file somehow?


Solution

  • You should be able to mock the delete operation using the mock-when processor:

    <munit:test name="ImportCorrectionsFlowTestWithIncorrectDocumentType" doc:id="b4bd8c08-3c8d-4ac9-a4bd-a09afa43126f" description="Test" expectedErrorType="APP:UNSUPPORTED_DOCUMENT_TYPE">
      <munit:behavior>
        <munit-tools:mock-when processor="file:delete">
          <munit-tools:with-attributes>
             <munit-tools:with-attribute attributeName="doc:name" whereValue="#['Delete inbound file']"/>
          </munit-tools:with-attributes>
        </munit-tools:mock-when>
      </munit:behavior>
      <munit:execution>
      ...
      </munit:execution>
    </munit:test>