You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 12 Next »

Mock Component

The mock: component provides a powerful declarative testing mechanism which is similar to jMock in that it allows declarative expectations to be created on an endpoint up front, then a route used, then the expectations can be asserted in a test case to ensure the routing rules and processors worked as expected.

URI format

mock:someName

Where someName can be any string to uniquely identify the endpoint

Examples

Here's quick example of MockEndpoint in use, asserting the number of messages which are expected during a test run

MockEndpoint resultEndpoint = context.resolveEndpoint("mock:foo", MockEndpoint.class);

resultEndpoint.expectedMessageCount(2);

// send some messages
...

// now lets assert that the mock:foo endpoint received 2 messages
resultEndpoint.assertIsSatisfied();

You can see from the javadoc of MockEndpoint the various helper methods you can use. You can use other methods such as

Here's another example

resultEndpoint.expectedBodiesReceived("firstMessageBody", "secondMessageBody", "thirdMessageBody");

Or you could add an expectation on the headers or content of a specific message. For example

resultEndpoint.message(0).header("foo").isEqualTo("bar");

There are some examples of the Mock endpoint in use in the camel-corecore processor tests.

  • No labels