弹簧集成:JUnit测试路由器



我想知道是否有办法可以 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>
好的。

只要您的所有通道都是直接的,或者换句话说,SubscribableChannel并且您订阅了它们的具体端点,您只需用 auto-startup="false" 标记它们,并将 JUnit 测试代码中的存根处理程序提供给这些通道,这些处理程序适用于每个测试用例。或者使用其id在所需终结点上调用start()

最新更新