MuleESB / Apache Camel Interview Questions
How do you test Camel routes using camel-test and the MockEndpoint?
The Camel test kit allows you to stub real endpoints with in-memory MockEndpoints and set expectations on the messages they receive. The test extends CamelTestSupport, which boots a full in-memory CamelContext. MockEndpoints intercept to(uri) calls when you advise the route to replace real endpoints.
public class OrderRouteTest extends CamelTestSupport {
@Override
protected RoutesSupplier createRouteBuilder() {
return new OrderRoute(); // the route under test
}
@Test
public void testOrderRouted() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:jms:queue:processed");
mock.expectedMessageCount(1);
mock.expectedHeaderReceived("orderId", "ORD-001");
// Replace real endpoint with mock in route definition:
context.getRouteController().startRoute("order-route");
template.sendBodyAndHeader("direct:orders", "{amount:99}",
"orderId", "ORD-001");
mock.assertIsSatisfied();
}
}Use AdviceWith.adviceWith() to intercept and mock specific endpoints inside a route without modifying the route class. The ProducerTemplate (template field) lets you inject test messages into any direct: or other endpoint. MockEndpoint supports assertions on message count, body content, header values, received order, and no-messages-within-time. For Spring Boot integration tests, use @SpringBootTest with CamelSpringBootRunner.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
