0
我想知道是否有辦法讓Junit測試春季集成路由器,而無需在春季集成示例項目中顯示的兩個不同上下文文件中定義輸入和映射通道?春季集成:JUnit測試路由器
我在我的項目中定義了多個路由器。我無法創建如此多的上下文文件。
<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>
在所需的端點上調用
start()
實際上,這取決於您要測試的內容。也許只是實例化MethodInvokingRouter並調用它的handleMessage。展示你的案例,請 –Hi Artem,謝謝你的回覆。我已經用代碼片段更新了這個問題。基本上,我有兩個層次的路由。第一個路由到不同的帳戶類型,並且對於每個帳戶類型,第二級路由器,路由到不同的請求。所有都在同一個文件中定義。我需要單獨測試這些路由器,而不必將其他路由器投入使用。 – Satya