Apache Camel tesing. Remove RoutePolicy
Here is the Apache Camel route:
ZooKeeperRoutePolicy routePolicy = new ZooKeeperRoutePolicy("zookeeper:localhost:2181/fuse-example/routePolicy", 1);
from("file:camelInpit").routeId("systemARoute")
.routePolicy(routePolicy)
.log(LoggingLevel.ERROR, "Starting route")
[...]
I want to remove routePolicy in my tests as there is no ZooKeeper in test environment, but it is not as easy as it seems
context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:aaa");
weaveByType(RouteDefinition.class).selectIndex(1).remove();
}
});
weaveById("policy")
and setting id routePolicy(...).id("policy")
doesn't help.
How can I delete dynamically RoutePolicies
during testing?
source to share
You can access the original route and set the route policies to zero
context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
getOriginalRoute().setRoutePolicies(null);
}
});
But do we have to add paid DSL developers for this to stand out?
source to share
If you bind it to a context, you can easily mock the policy in your tests using where myPolicy is a mock or a policy that does nothing.
It's even easier if you create an abstract program MyCamelTestSupport that re-evaluates this and then all your tests to mock it extend MyCamelTestSupport
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
jndi.bind("myPolicy", myPolicy);
return jndi;
}
source to share