2014-03-03 5 views
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> 
+1

을 사용하여 원하는 끝점에서 start()을 호출하십시오. 실제로 테스트 할 대상에 따라 다릅니다. 아마도'MethodInvokingRouter'를 인스턴스화하고'handleMessage'를 호출하는 것만으로 충분할 것입니다. 사례를 보여주세요, –

+0

안녕하세요, Artem, 답장을 보내 주셔서 감사합니다. 코드 스 니펫으로 질문을 업데이트했습니다. 기본적으로 두 가지 레벨 라우팅이 있습니다. 첫 번째는 다른 계정 유형으로 라우트하고 두 번째 레벨 라우터는 각 계정 유형에 대해 다른 요청으로 라우트합니다. 모두 동일한 파일에 정의되어 있습니다. 다른 라우터를 작동시키지 않고이 라우터를 개별적으로 테스트해야합니다. – Satya

답변

0

확인. 모든 채널이 dirrect이거나 다른 말로하면 SubscribableChannel이고 구체적인 엔드 포인트가 등록 된 경우 auto-startup="false"으로 표시하고 JUnit 테스트 코드의 스텁 처리기를 각 테스트 케이스에 적합한 해당 채널에 제공하면됩니다 . 또는 id

관련 문제