Using mock endpoints to verify routing logic
The ability to verify message flow using mock endpoints was built into the Camel framework from its inception. The Mock Component in the camel-core
library provides you with a testing DSL that allows you to verify which messages have reached various named mock:
endpoints defined in your route. This recipe will describe how to make use of this mock DSL.
Getting ready
To use this recipe you should first have a route test set up as described in the Testing routes defined in Java recipe.
The Java code for this recipe is located in the org.camelcookbook.examples.testing.mockreply
package.
How to do it...
To use mock endpoints, perform the following steps:
Within your route, use a
mock:
endpoint URI in any Camel DSL statement that produces a message to an endpoint, such asto(..)
orwireTap(..)
:from("direct:start") .choice() .when().simple("${body} contains 'Camel'") .setHeader("verified").constant(true) .to("mock:camel") .otherwise...