比方說,我有一個這樣的Apache的駱駝航線:Apache的駱駝MockEndpoint嘲笑輸出
from("direct:start")
.routeId("aRouteId")
.bean(someBusinnessTransformationBean).id("transformationBean")
.bean(aPersistenceBean).id("persistenceBean")
.to("direct:target");
,然後在我的單元測試,我做的是這樣的:
public class RouteTest extends CamelTestSupport {
@Override
public boolean isDumpRouteCoverage() { return true }
@Override
public boolean isUsedAdviceWith() { return true }
@EndpointInject(uri = "mock:mockTransformationBean")
protected MockEndpoint mockTransformationBean;
@EndpointInject(uri = "mock:mockPersistenceBean")
protected MockEndpoint mockPersistenceBean;
@Test
public void testRoute() throws Exception {
context.getRouteDefinition("aRouteId").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveById("transformationBean")
.replace()
.multicast()
.to(mockTransformationBean);
weaveById("persistenceBean")
.replace()
.multicast()
.to(mockPersistenceBean);
}
});
context.start();
// Asserts the expectedMessageCount
// Send a message with template.sendBody...
assertMockEndpointSatisfied();
}
}
問題:
我該如何正確地測試這條路線,而不是隻確保messageCount和接收體(在第一個bean上)。
一樣,我怎麼能嘲笑一個MockEndpoint的響應,使用的Mockito單元測試時,我可以這樣做:
when(mockTransformationBean.someHandler(...)).thenReturn(anExpectedObjectForMyUnitTestPropose);
乾杯,尼古拉斯
爲什麼不直接運行單元測試,然後將交換體與一些預期的體進行比較? –
因爲我找不到用apache camel MockEndpoint攔截bean的交換體的方法。我可以確保接收到的模擬物體,但是接下來,我想確保第一個bean轉換主體並向第二個bean發送不同的主體。 –
您可以在bean攔截之後執行adviceWith和將其發送到模擬端點。然後斷言該信息應該是什麼。 –