我想为我的一条骆驼路线写一个单元测试。在路线中有一个我想用存根代替的处理器。有什么办法可以做到这一点?我正在考虑使用intercept feature,但我似乎无法确定最佳方式。有没有办法在单元测试中覆盖处理器?
实施例:
from(start)
.process(myprocessor)
.to(end)
预先感谢。
我想为我的一条骆驼路线写一个单元测试。在路线中有一个我想用存根代替的处理器。有什么办法可以做到这一点?我正在考虑使用intercept feature,但我似乎无法确定最佳方式。有没有办法在单元测试中覆盖处理器?
实施例:
from(start)
.process(myprocessor)
.to(end)
预先感谢。
是的,你可以做到这一点通过使用骆驼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。
恕我直言,你需要执行Detour EIP(http://camel.apache.org/detour.html)。
from(start)
.when().method("controlBean", "isDetour")
.to("mock:detour")
.endChoice()
.otherwise()
.process(myprocessor)
.end()
.to(end)
我希望避免这样的事情。我想我就替换。要(myProcessor)我所有的.process(myProcessor)引用,并使用拦截的方式。这两种方式对我来说都很难看,但是绕行的EIP感觉就像是两者中的更糟糕的一样。感谢您的快速反应! – David
首先,你需要扩展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)
问候
我认为这是一个很好的解决方案为单位testing.I不知道** ** AdviceWith [AdviceWith文档】(https://camel.apache.org/advicewith.html)。 –