Spring Integration Junit Bridge是testChannel的直接渠道

时间:2017-01-06 02:12:39

标签: spring spring-integration

我正在尝试编写Junits for Spring集成流程,并且我为通道(直接通道)定义了一个桥梁,我想要检查该消息。由于频道不是发布订阅频道,因此网桥未收到该消息。出于Junit的目的,我不想将频道修改为发布订阅频道。有没有办法让它成为发布订阅频道?

<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作为发布订阅来使测试类工作。是否有其他方法可以在渠道processResponseChannel2中检索邮件。

1 个答案:

答案 0 :(得分:2)

您可以将所需的频道作为AbstractMessageChannel注入到您的测试用例中,并使用ChannelInterceptor丰富该频道。在preSend()实现中,您可以断言传入消息。

这样,您的配置将与测试和生产保持一致。

相关问题