2017-01-06 5 views
3

Spring統合フロー用のJunitを作成しようとしていますが、メッセージを検査するチャネル(Direct Channel)にブリッジが定義されています。チャネルはPublish Subscribe Channelではないため、ブリッジはメッセージを受信して​​いません。私は、Junitの目的のためにチャンネルをPublish Subscribeチャンネルに変更したくありません。 Publish Subscribe Channel以外の方法はありますか?Spring Integration Junit Bridge直接チャネルtestchannel

<integration:channel id="processResponseChannel1" /> 
<integration:channel id="processResponseChannel2" /> 
<integration:channel id="processResponseChannel3" /> 
<integration:channel id="processResponseChannel4" /> 

<integration:service-activator 
    input-channel="processResponseChannel1" 
    output-channel="processResponseChannel2"      
    ref="processResponseActivator1"/> 

<integration:service-activator 
    input-channel="processResponseChannel2" 
    output-channel="processResponseChannel3"      
    ref="processResponseActivator2"/> 

<integration:service-activator 
    input-channel="processResponseChannel3" 
    output-channel="processResponseChannel4"      
    ref="processResponseActivator3"/> 

私は自分のJUnitでprocessResponseChannel2でメッセージを取得し、そのメッセージにいくつかのアサーションを実行したいです。

<integration:bridge input-channel="processResponseChannel2" 
output-channel="testChannel"/> 

<integration:channel id="testChannel"> 
    <integration:queue/> 
</integration:channel> 

Junitでは、私はtestChannel.receive(5000)を使用してメッセージを取得していますが、テストケースが失敗しています。 私はprocessResponseChannel2をpublishとして購読して、テストクラスを動作させたくありません。チャネルprocessResponseChannel2でメッセージを取得する他の方法はありますか。

答えて

2

AbstractMessageChannelとして目的のチャネルをテストケースに注入し、そのチャネルをChannelInterceptorで充実させることができます。 preSend()実装では、着信メッセージをアサートできます。

このようにして、設定は製造時のテストと同じままです。

+0

ありがとうございましたArtem。これは私のために働いた。 –

関連する問題