我已經有一些麻煩了解你的確切使用情況,所以我會爲您指出駱駝AdviceWithRouteBuilder庫,您可以用於測試。我不是在駱駝基於XML的版本,所以我將使用Java DSL爲我的樣品100%的流體。這裏是鏈接到你可以作爲參考使用一些駱駝文檔: http://camel.apache.org/advicewith.html
//樣本航線
from("direct:myNormalInput").routeId("xxx")
.to("myBean", "myMethod").id("enrichmentBean")
.to("http://myawesomeurl").id("HttpCaller")
.to("myResponseBean", "myMethod").id("responseHandler");
//樣本單位測試
public void myTest throws Exception {
context.getRouteDefinition("xxx").adviceWith(context, new AdviceWithRouteBuilder() {
//You can replace your normal route's from statement
replaceFromWith("direct:testEntry");
//Swap out your enrichmentBean with a replace or remove it if you prefer
weaveById("enrichmentBean").replace().to("myTestBean", "myTestMethod");
//mock out your http call with a different url or a fake endpoint
weaveById("HttpCaller").replace().to("http://myTestUrl");
//extract your message at any point in processing to do some validation work
weaveById("responseHandler").after().to("mock:extract");
}
context.start();
template.sendBody("direct:testEntry", "myTestBody");
MockEndpoint test = getMockEndpoint("mock:extract");
int messageCount = test.getReceivedExchanges().size();
assertEquals(1, messageCount);
}