Foreach プロセッサーの前および内部のメッセージのモック

foreach​ スコープ内にプロセッサーがあり、反復ごとに異なる値を提供するとします。

<flow name="foreachFlow">
	<foreach doc:name="For Each">
		<flow-ref doc:name="Flow Reference" name="FlowToMock"/>
	</foreach>
</flow>

munit-tools:mock-when​ プロセッサーを使用してフロー内のプロセッサーをモックし、​then-call​ 操作を使用して ​foreach​ 状況に応じてペイロードを設定する新しいフローをコールします。

<munit-tools:mock-when doc:name="Mock when" processor="flow-ref">
	<munit-tools:with-attributes >
		<munit-tools:with-attribute attributeName="name" whereValue="FlowToMock" />
	</munit-tools:with-attributes>
	<munit-tools:then-call flow="MockedFlow" />
</munit-tools:mock-when>

then-call​ によってコールされたフロー内で、​Choice​ プロセッサーを使用して値を評価し、モックペイロードを設定できます。この場合、​foreach​ カウンターが評価され、設定するペイロードが決定されます。

<flow name="MockedFlow" >
	<choice doc:name="Choice">
		<when expression="#[vars.counter == 1]">
			<set-payload value='#["MOCKED1"]' doc:name="Set Payload" />
		</when>
		<when expression="#[vars.counter == 2]">
			<set-payload value='#["MOCKED2"]' doc:name="Set Payload" />
		</when>
		<otherwise >
			<set-payload value='#["DEFAULT"]' doc:name="Set Payload" />
		</otherwise>
	</choice>
</flow>

Mule メッセージのモック

file:list​ や ​ftp:list​ などのプロセッサーをモックするには、Mule メッセージコレクションをペイロードとして返す必要があります。​MunitTools​ には、これらのペイロードをモックする機能が用意されています。

fun createMessage(payload: Any, attributes: Any = null)

fun createMessage(payload: Any, mimeType: String|Null , attributes: Any, attributeMimeType: String|Null)
<flow doc:name="Flow" >
	<file:list doc:name="List" config-ref="File_Config" directoryPath="/tmp/"/>
</flow>

<munit-tools:mock-when processor="file:list">
   <munit-tools:with-attributes>
       <munit-tools:with-attribute attributeName="doc:name" whereValue="List"/>
   </munit-tools:with-attributes>
   <munit-tools:then-return>
       <munit-tools:payload value="#[[MunitTools::createMessage( &quot;ITEM-1&quot;,  &quot;text/plain&quot;, { property : 'ATTRIBUTE-1'}, null) , MunitTools::createMessage( &quot;ITEM-2&quot;,  &quot;text/plain&quot;, { property : 'ATTRIBUTE-2'}, null)]]" />
   </munit-tools:then-return>
</munit-tools:mock-when>