...
Warning | ||
---|---|---|
| ||
It is recommended to only advice a given route once (you can of course advice multiple routes). If you do it multiple times, then it may not work as expected, especially when any kind of error handling is involved. |
Tip | ||
---|---|---|
| ||
From Camel 2.9 onwards its recommended to override the |
Using AdviceWithRouteBuilder
...
Method | Description |
---|---|
| Is used to easily mock all endpoints. See more details and examples at Mock. |
| Is used to easily mock endpoints using a pattern. See more details and examples at Mock. See below for pattern matching. |
| Is used to select node(s) matching by id's, and weave in the following nodes. See below for pattern matching and examples. |
| Is used to select nodes(s) matching by their |
| 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. |
| Camel 2.8: Is a short hand to easily weave in the following nodes in the start of the route. |
| Camel 2.8: Is a short hand to easily weave in the following nodes in the end of the route. |
| Camel 2.9: To replace the route input to with a new endpoint uri. |
The pattern
option is used for matching. It uses the same rules as the Intercept, which is applied in the following order:
...
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { weaveAddFirst().to("mock:input"); weaveAddLast().to("mock:output"); } }); |
Replace from with another endpoint
Available as of Camel 2.9
...
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() { @Override public void configure() throws Exception { replaceFromreplaceFromWith("seda:foo"); } }); |
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.
Wiki Markup |
---|
{snippet:id=e1|lang=java|title=isUseAdviceWith|url=camel/trunk/components/camel-test/src/test/java/org/apache/camel/test/IsUseAdviceWithJUnit4Test.java} |