Spring Integration:JUnit测试路由器

时间:2014-03-03 16:27:09

标签: spring-integration

我想知道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>

1 个答案:

答案 0 :(得分:0)

行。至于你的所有通道都是直接的,或者换句话说SubscribableChannel并且你有订阅它们的具体端点,你只需用auto-startup="false"标记它们,并从JUnit测试代码向这些通道提供存根处理程序,适用于每个测试用例。或者使用start()

在所需的端点上调用id