我有一个流,其中我有一个错误处理程序,删除输入文件。
<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>
问题是,当我运行这个测试时,源文件被删除了,我不希望这种情况发生。如何防止文件被删除?我可以以某种方式模拟文件删除流组件,使其不删除文件吗?或者我可以以某种方式模拟文件?
您应该能够使用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>