Java 阿帕奇骆驼测试。删除路由策略

Java 阿帕奇骆驼测试。删除路由策略,java,apache-camel,apache-zookeeper,Java,Apache Camel,Apache Zookeeper,以下是Apache驼峰路线: ZooKeeperRoutePolicy routePolicy = new ZooKeeperRoutePolicy("zookeeper:localhost:2181/fuse-example/routePolicy", 1); from("file:camelInpit").routeId("systemARoute") .routePolicy(routePolicy) .log(Logging

以下是Apache驼峰路线:

ZooKeeperRoutePolicy routePolicy = new ZooKeeperRoutePolicy("zookeeper:localhost:2181/fuse-example/routePolicy", 1);
from("file:camelInpit").routeId("systemARoute")
                .routePolicy(routePolicy)
                .log(LoggingLevel.ERROR, "Starting route")
                [...]
我想在测试中删除routePolicy,因为在测试环境中并没有ZooKeeper,但这并不像看起来那个么容易

    context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            replaceFromWith("direct:aaa");
            weaveByType(RouteDefinition.class).selectIndex(1).remove();
        }
    });
weaveById(“策略”)
和设置id
routePolicy(…).id(“策略”)
没有帮助


如何在测试时动态删除路由策略?

这样做是不可能的吗

from("file:camelInpit").routeId("systemARoute")
                .choice()
                  .when(prodEnvironmentExpression)
                    .routePolicy(routePolicy)
                  .endChoice()
                .end()
                .log(LoggingLevel.ERROR, "Starting route")

如果您将其绑定到上下文,您可以通过使用在测试中轻松地对策略进行模拟,其中myPolicy是一个模拟策略或一个不执行任何操作的策略

如果您制作了一个抽象的MyCamelTestSupport来覆盖它,然后所有需要模拟它的测试都扩展了MyCamelTestSupport,那么就更容易了

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry jndi = super.createRegistry();
    jndi.bind("myPolicy", myPolicy);
    return jndi;
}

您可以访问原始路由并将其路由策略设置为null

    context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
        @Override
        public void configure() throws Exception {
            getOriginalRoute().setRoutePolicies(null);
        }
    });

但我们可能应该为此添加fluent DSL构建器,使其脱颖而出?

我正在使用
RouteBuilder
。是否可以将测试中的参数传递到
RouteBuilder
s?很抱歉,我不完全理解您的意思。据我所知,
prodEnvironmentExpression
应该是一些配置参数,在测试开始时自动启用。如何将测试中的参数传递给route,以使此表达式的计算结果为true?例如,如果您有web应用程序,则可以在prod/test环境中使用vm参数或环境变量。例如,使用PredicateBuilder,您可以创建来自RouteBuilder外部的“正常”值的表达式。我在OSGI容器中运行此应用程序,因此JVM参数使用起来不是很方便。如何在生产环境中创建ZooKeeperRoutePolicy?如您所见,目前我在代码中创建了它。我应该使用
camelContext.getRegistry()
并将我的策略绑定到Camel JNDI注册表吗?根据创建策略的方式,作为独立的,它将是main.bind(),如果使用ServletContextListener,则需要创建SimpleRegistry(put)或InitialContext(bind)并创建新的DefaultCamelContext(arg)其中arg是SimpleRegistry或InitialContext。我正在使用Blueprint在Apache Karaf OSGI容器中运行Camel。可能与创建其他bean的方式相同,