2015-11-05 90 views

回答

6

是的,你可以做到这一点通过使用骆驼Advicedwith weaveById这是用来测试期间更换节点功能。

你必须设置在线路的处理器的ID,并使用该ID就可以织任何你想要的。下面的例子中,

@Before 
    protected void weaveMockPoints() throws Exception{ 

     context.getRouteDefinition("Route_ID").adviceWith(context,new AdviceWithRouteBuilder() {    
      @Override 
      public void configure() throws Exception {    

       weaveById("myprocessorId").replace().to(someEndpoint); 

      } 
     });    

     context().start(); 
    } 

唯一的事情是,你必须将其应用到尚未启动的路线。更好地做任何你想要的改变,然后像上面的例子一样开始你的camelcontext。

+1

我认为这是一个很好的解决方案为单位testing.I不知道** ** AdviceWith [AdviceWith文档】(https://camel.apache.org/advicewith.html)。 –

2

恕我直言,你需要执行Detour EIP(http://camel.apache.org/detour.html)。

from(start) 
    .when().method("controlBean", "isDetour") 
     .to("mock:detour") 
    .endChoice() 
    .otherwise() 
     .process(myprocessor) 
    .end() 
.to(end) 
+0

我希望避免这样的事情。我想我就替换。要(myProcessor)我所有的.process(myProcessor)引用,并使用拦截的方式。这两种方式对我来说都很难看,但是绕行的EIP感觉就像是两者中的更糟糕的一样。感谢您的快速反应! – David

1

首先,你需要扩展CamelTestSupport:

context.getRouteDefinitions().get(0).adviceWith (context, new AdviceWithRouteBuilder() { 
    @Override 
    public void configure() throws Exception { 
     weaveById("myprocessorId") 
     .replace().to("mock:myprocessor"); 
    } 
} 

而在你的路线: 类MyTest的在您的测试方法后,扩展CamelTestSupport {}

from(start) 
.process(myprocessor).id("myprocessorId") 
.to(end) 

问候

相关问题