MUnit 测试失败 - 无法处理事件,因为 "getCSVAccountsFlow" 已停止 MULE_ERROR-166

MUnit test fails - Cannot process event as "getCSVAccountsFlow" is stopped MULE_ERROR-166

我创建了一个具有 csv 文件输入的流程,然后使用 DataWeave 转换为 JSON,然后遍历每条记录并记录有效负载 - 简单,工作正常。

然后我使用 Mock 组件的 getResources 方法创建了以下 MUnit;但是,当我 运行 MUnit 测试时,出现以下错误:

错误:

ERROR 2015-12-06 15:25:48,613 [main] 
org.mule.exception.DefaultMessagingExceptionStrategy: 
********************************************************************************
Message               : Cannot process event as "getCSVAccountsFlow" is 
stopped
Code                  : MULE_ERROR-166
--------------------------------------------------------------------------------
Exception stack is:
1. Cannot process event as "getCSVAccountsFlow" is stopped 
(org.mule.api.lifecycle.LifecycleException)

org.mule.construct.AbstractPipeline$ProcessIfPipelineStartedMessageProcessor:440           
(http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/lifecycle/Lifecy
cleException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.lifecycle.LifecycleException: Cannot process event as "getCSVAccountsFlow" is stopped
at org.mule.construct.AbstractPipeline$ProcessIfPipelineStartedMessageProcessor.handleUnaccepted(AbstractPipeline.java:440)
at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:45)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

MUnit 测试:

<mule xmlns:mock="http://www.mulesoft.org/schema/mule/mock" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:munit="http://www.mulesoft.org/schema/mule/munit" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/mock         
http://www.mulesoft.org/schema/mule/mock/current/mule-mock.xsd 
http://www.mulesoft.org/schema/mule/munit 
http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core  
http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<munit:config name="munit" doc:name="MUnit configuration" />
<spring:beans>
    <spring:import resource="classpath:accounts.xml" />
</spring:beans>
<munit:test name="accounts-getCSVAccountsFlowTest"
    description="Test">

    <mock:when messageProcessor="File" doc:name="File Input"
        doc:description="Mocks the File processor that accepts a csv file">
        <mock:then-return
            payload="#[getResource('input/accounts.csv').asByteArray()]" />
    </mock:when>

    <flow-ref name="getCSVAccountsFlow" doc:name="Flow-ref to getCSVAccountsFlow" />
    <munit:assert-not-null doc:name="Assert Not Null Payload" />
</munit:test>
</mule>

流量:

<flow name="getCSVAccountsFlow" initialState="stopped">
    <file:inbound-endpoint path="src/main/resources/input"
        moveToDirectory="src/main/resources/output" responseTimeout="10000"
        doc:name="File">
        <file:filename-regex-filter pattern=".*csv"
            caseSensitive="false" />
    </file:inbound-endpoint>
    <dw:transform-message metadata:id="6b5dfac1-0410-40c4-b920-d7fdcd60333c" doc:name="Transform Message">
        <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map ((value , index) -> {
  Name: value.Name,
  BillingStreet: value.BillingStreet,
  BillingCity: value.BillingCity,
  BillingState: value.BillingState,
  BillingPostalCode: value.BillingPostalCode,
  BillingCountry: value.BillingCountry
})]]></dw:set-payload>
    </dw:transform-message>
    <foreach doc:name="For Each">
        <logger message="#[payload]" level="DEBUG" doc:name="Logger" />
    </foreach>
    <logger message="#[payload]" level="DEBUG" doc:name="Logger" />
</flow>

MUnit 测试失败,因为 Flow 的初始状态已停止。

<flow name="getCSVAccountsFlow" initialState="stopped">

通过以下方式将其设置为空:

  1. Select 您的流程并打开其属性
  2. 在 Flow Configuration 部分,将 Initial State 设置为 -- Empty --
  3. 重新运行 MUnit测试