【发布时间】:2014-04-04 19:23:54
【问题描述】:
我想知道是否有一种方法可以让 Junit 测试 spring 集成路由器,而不必在 spring 集成示例项目中所示的两个不同的上下文文件中定义输入和映射通道?
我的项目中定义了多个路由器。我无法创建这么多上下文文件。
<int:gateway id="accountBuilder"
service-interface="some.package.AccountGateway" default-request-channel="accountRequest" default-reply-channel="allAccounts"/>
<int:channel id="accountRequest"/>
<int:channel id="allAccounts"/>
<int:splitter input-channel="accountRequest" output-channel="accountRequests" ref="accountSplitter" method="split"/>
<int:channel id="accountRequests">
<int:dispatcher task-executor="accountServiceTaskExecutor"/>
</int:channel>
<int:router input-channel="accountRequests" ref="accountRouter" method="routeAccountRequests">
<int:mapping channel="accountType1HeaderEnricher"/>
<int:mapping channel="accountType2HeaderEnricher"/>
<int:mapping channel="accountType3HeaderEnricher"/>
<int:mapping channel="accountType4HeaderEnricher"/>
</int:router>
<bean id="accountMessageStore" class="org.springframework.integration.store.SimpleMessageStore" />
<bean id="searchResultMessageStoreReaper" class="org.springframework.integration.store.MessageGroupStoreReaper">
<property name="messageGroupStore" ref="accountMessageStore" />
<property name="timeout" value="2000" />
</bean>
<int:channel id="accountType1HeaderEnricher"/>
<int:header-enricher input-channel="aAccountType1HeaderEnricher" output-channel="retailRequest">
<int:header name="accountType1CorrelationId" expression="headers.correlationId" />
<int:header name="accountType1SequenceSize" expression="headers.sequenceSize"/>
<int:header name="accountType1SequenceNumber" expression="headers.sequenceNumber"/>
</int:header-enricher>
<int:channel id="account1Request"/>
<int:splitter input-channel="account1Request" output-channel="account1Requests" ref="account1Splitter" method="split"/>
<int:channel id="account1Requests">
<int:dispatcher task-executor="accountServiceTaskExecutor"/>
</int:channel>
<int:router input-channel="account1Requests" ref="account1Router" method="routeAccount1Requests" default-output-channel="aggregatedAccount1HeaderEnricher">
<int:mapping channel="account1Request1"/>
<int:mapping channel="account1Request2"/>
</int:router>
【问题讨论】:
-
其实这取决于你要测试什么。也许实例化
MethodInvokingRouter并调用它的handleMessage就足够了。请展示你的情况 -
您好,Artem,感谢您的回复。我已经用代码 sn-p 更新了这个问题。基本上,我有两级路由。第一个路由到不同的帐户类型,对于每个帐户类型,第二级路由器路由到不同的请求。所有都在同一个文件中定义。我需要单独对这些路由器进行单元测试,而不需要将其他路由器投入使用。