2016-03-21 18 views
0

テストがうまくいかない理由を理解できません。私は傍受を試み、エンドポイントへの送信をスキップします。これはBeanリファレンスであり、何も起こりません。 バージョン2.16.2を使用しています。Apache camel。 InterceptSendToがBeanエンドポイントで動作しない

テストcamel.xml

<bean id="eb" class="com.rencap.emf.bpipe.EndpointBean"/>  
<camel:camelContext xmlns="http://camel.apache.org/schema/spring"> 
    <camel:endpoint id="requestEP" uri="direct:request"/> 
    <endpoint id="beanEP" uri="bean:eb?method=processMessage" /> 
    <camel:route id="testRoute"> 
     <camel:from ref="requestEP"/> 
     <camel:to ref="beanEP" /> 
    </camel:route> 
</camel:camelContext> 

EndpointBean.java

package com.rencap.emf.bpipe; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

public class EndpointBean { 
    private static Logger LOG = LoggerFactory.getLogger(EndpointBean.class); 

    public void processMessage(String msg){ 
     LOG.info("Processing message: {} ",msg); 
    } 
} 

ユニットテスト:

@EndpointInject(ref="requestEP") 
ProducerTemplate requestEP; 
@EndpointInject(ref="beanEP") 
ProducerTemplate beanEP; 
@Autowired 
ModelCamelContext camelContext; 
@Test 
public void test() throws Exception{ 

    camelContext.getRouteDefinition("testRoute").adviceWith(camelContext , new AdviceWithRouteBuilder(){ 
     @Override 
     public void configure() throws Exception { 
      interceptSendToEndpoint(beanEP.getDefaultEndpoint().getEndpointUri()). 
       to("mock:send"). 
       skipSendToOriginalEndpoint(); 
     } 
    });  
    TestUtils.waitingFor("Configuration applied", 2000); 

    MockEndpoint mockEP = camelContext.getEndpoint("mock:send",MockEndpoint.class); 
    mockEP.setExpectedCount(1); 

    requestEP.sendBody("Message"); 

    mockEP.assertIsSatisfied(); 

    TestUtils.waitingFor("All rows commited", 2000); 
} 

テストは常に失敗します。 ログ:

13:11:02.512 [main] INFO o.apache.camel.model.RouteDefinition - AdviceWith route after: Route(testRoute)[[From[ref:requestEP]] -> [InterceptSendToEndpoint[bean://eb?method=processMessage -> [To[mock:send]]], To[ref:beanEP]]] 
13:11:02.537 [main] INFO o.a.camel.spring.SpringCamelContext - Route: testRoute started and consuming from: Endpoint[direct://request] 
13:11:02.538 [main] INFO com.rencap.emf.bpipe.test.TestUtils - Wait 2000 ms. Configuration applied 
13:11:04.554 [main] INFO com.rencap.emf.bpipe.EndpointBean - Processing message: Message 
13:11:04.556 [main] INFO o.a.c.component.mock.MockEndpoint - Asserting: Endpoint[mock://send] is satisfied 

これは、エンドポイントに送信することは傍受やスキップされていないことを意味します。私は何かを理解していないかもしれませんが、私はこの方法の使用に関する制限を見つけることができません。

さらに、ログを持つエンドポイントで同じ問題が発生していることに気付きました。 beanEPを置き換えた場合:

<endpoint id="beanEP" uri="log:LOGMESSAGE" /> 

私は同じ結果を受け取ります。 しかし、私は

<endpoint id="beanEP" uri="seda:send" /> 

にそれを交換して、新しいルート追加した場合:私は、結果とテストを期待されます

<camel:route id="route2"> 
     <camel:from ref="sendEP"/> 
     <camel:log message="msg received ${body}"/> 
    </camel:route> 

がsuccessedされます。

どうすればいいですか?あるいは、この方法にいくつかの制限がありますか?

答えて

0

isUseAdviceWithを無効にすることをお勧めしました。私の場合、それはのように見えます:

public class TestTest extends CamelSpringTestSupport { 
    @Test 
    public void test() throws Exception{ 
     Endpoint beanEP = context.getEndpoint("beanEP"); 
     Endpoint requestEP = context.getEndpoint("requestEP"); 
     context.getRouteDefinition("testRoute").adviceWith(context , new AdviceWithRouteBuilder(){ 
      @Override 
      public void configure() throws Exception { 
       interceptSendToEndpoint(beanEP.getEndpointUri()). 
        to("mock:send"). 
        skipSendToOriginalEndpoint(); 
      } 
     });  
     context.start(); 
     TestUtils.waitingFor("Configuration applied", 2000); 
     MockEndpoint mockEP = context.getEndpoint("mock:send",MockEndpoint.class); 
     mockEP.setExpectedCount(1); 
     context.createProducerTemplate().sendBody(requestEP, "Message"); 
     mockEP.assertIsSatisfied(); 
     TestUtils.waitingFor("All rows commited", 2000); 
    } 
    @Override 
    protected AbstractApplicationContext createApplicationContext() { 
     return new ClassPathXmlApplicationContext("test-camel.xml"); 
    } 
    @Override 
    public boolean isUseAdviceWith(){ 
     return true; 
    } 
} 

それは動作します。

しかし、私は注釈を使用したいと思いますが、thisはまだ私のためにはまだ動作していません。

関連する問題