Additional annotations

The Camel test kit also provides additional annotations, in order to simplify the code of your tests.

Instead of using the getMockEndpoint() method to get the mocked endpoints, you can use the @EndpointInject annotation:

@EndpointInject(uri = "mock:direct:france")
protected MockEndpoint franceEndpoint;

Now, we can directly use the franceEndpoint mock endpoint in the test methods:

@Test
public void aTest() throws Exception {
  …
  franceEndpoint.expectedBodiesReceived("<foo/>");
  …
  franceEndpoint.assertIsSatisfied();
}

Similarly, instead of defining the endpoint URI on the producer template, you can use the @Producer annotation to define where the producer template sends the message:

@Produce(uri = "direct:input"); protected ProducerTemplate ...

Get Mastering Apache Camel now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.