Let's say I have an apache camel route like this:
from("direct:start")
.routeId("aRouteId")
.bean(someBusinnessTransformationBean).id("transformationBean")
.bean(aPersistenceBean).id("persistenceBean")
.to("direct:target");
And then, on my unit tests, I'm doing something like:
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();
}
}
Question:
How could I unit test this route properly, instead of just ensure the messageCount and received body (on the first bean).
Like, how could I mock the response of a MockEndpoint as I could do when using Mockito for unit testing:
when(mockTransformationBean.someHandler(...)).thenReturn(anExpectedObjectForMyUnitTestPropose);
Cheers, Nikolas