【问题标题】:How to omit one message processor in MUnit test?如何在 MUnit 测试中省略一个消息处理器?
【发布时间】:2021-05-15 14:12:51
【问题描述】:

我有一个流程,其中我有一个删除输入文件的错误处理程序。

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

我也有一个 MUnit 测试:

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

问题是,当我运行这个测试时,源文件被删除了,我不希望这种情况发生。如何防止删除文件?我可以以某种方式模拟文件删除流程组件,使其不删除文件吗?或者我可以以某种方式模拟文件吗?

【问题讨论】:

    标签: mule mule-studio anypoint-studio mule4 munit


    【解决方案1】:

    您应该能够使用 mock-when 处理器模拟删除操作:

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

    【讨论】:

    • 完美!非常感谢,就像一个魅力!
    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 2016-10-25
    • 2012-07-10
    • 1970-01-01
    相关资源
    最近更新 更多