Integration / Apache Camel Interview Questions
What is the Camel Test Kit (CamelTestSupport) and how do you write unit tests for routes?
CamelTestSupport (in the camel-test module) is the JUnit 4/5 base class that boots an isolated in-memory CamelContext for each test. It wires up the context, starts routes, and provides helper methods. When extending it, override createRouteBuilder() to supply the route under test.
@ExtendWith(CamelTestSupport.class)
public class PriceRouteTest extends CamelTestSupport {
@Override
protected RoutesSupplier createRouteBuilder() {
return new PriceRoute();
}
@Test
public void testDoublePriceTransformation() throws Exception {
// Use AdviceWith to intercept the real downstream endpoint:
AdviceWith.adviceWith(context, "price-route",
a -> a.mockEndpointsAndSkip("jms:*"));
MockEndpoint mock = getMockEndpoint("mock:jms:queue:output");
mock.expectedBodiesReceived("200.0");
template.sendBody("direct:price", 100.0);
mock.assertIsSatisfied();
}
}Key methods in CamelTestSupport: getMockEndpoint(uri) retrieves or creates a MockEndpoint, template is a ProducerTemplate for test message injection, assertMockEndpointsSatisfied() checks all mocks at once. AdviceWith lets you replace, insert, or skip route steps at test time without modifying the production route class — ideal for unit-testing complex multi-step routes. For Spring Boot integration testing, prefer @SpringBootTest with the camel-test-spring-junit5 module.
More Related questions...