Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Method

Description

mockEndpoints

Is used to easily mock all endpoints. See more details and examples at Mock.

mockEndpoints(patterns)

Is used to easily mock endpoints using a pattern. See more details and examples at Mock. See below for pattern matching. From Camel 2.10 onwards you can specify multiple patterns.

mockEndpointsAndSkip(patterns)

Is used to easily mock endpoints using a pattern, and skip sending to the original endpoint. See more details and examples at Mock. See below for pattern matching. You can specify multiple patterns.

weaveById(pattern)

Is used to select node(s) matching by id's, and weave in the following nodes. See below for pattern matching and examples.

weaveByToString(pattern)

Is used to select nodes(s) matching by their toString representation, and weave in the following nodes. See below for pattern matching and examples.

weaveByType(Class)

Camel 2.8: Is used to select node(s) matching by their class type (the classes from the org.apache.camel.model package), and weave in the following nodes. See below for examples.

weaveAddFirst

Camel 2.8: Is a short hand to easily weave in the following nodes in the start of the route.

weaveAddLast

Camel 2.8: Is a short hand to easily weave in the following nodes in the end of the route.

replaceFromWith(uri)

Camel 2.9: To replace the route input with a new endpoint uri.

...

Code Block
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
    @Override
    public void configure() throws Exception {
        replaceFromWith("seda:foo");
    }
});

Using mock endpoints

While routing messages, you may want to easily know how the messages was routed. For example you can let Camel mock all endpoints, which mean that when a message is sent to any endpoint, its first send to a mock endpoint, and then afterwards to the original endpoint. Then from your unit tests, you can setup expectations on the mock endpoints.

See more details at the section Mocking existing endpoints using the camel-test component at Mock.

Using isUseAdviceWith

Available as of Camel 2.9
It is recommended to override the method isUseAdviceWith and return true to instruct Camel that you are using adviceWith in the unit tests. Then in your unit test methods, after you have done the adviceWith you must start CamelContext by invoke the start method on the context instance. In the following we have an example. The route is using ActiveMQ to route messages. What we would like to do in a unit test is to test the route, but without having to set and use ActiveMQ. We do not have ActiveMQ on the classpath. So for that we need to advice the route and replace ActiveMQ with for example a SEDA endpoint instead.

...