【问题标题】:Is there a Annotation in Apache Camel to load a specific RouteBuilder during a test?Apache Camel 中是否有注释可以在测试期间加载特定的 RouteBuilder?
【发布时间】:2012-01-05 11:31:59
【问题描述】:

假设我在同一个 RouteBuilder 上有多个测试,每个测试的配置都不同。

现在,Spring 测试应该:

  • 扩展 AbstractJUnit4SpringContextTests 之类的东西
  • 使用@ContextConfiguration(locations="test-context.xml") 进行注释
  • 在上下文中包含 RouteBuilder:<camel:camelContext id="whatever"><camel:routeBuilder ref="routeBuilderUnderTesting" /></camel:camelContext>

这意味着每个测试类都必须有一个特定的上下文 xml 文件指向所需的 RouteBuilder(即正在测试的 RouteBuilder 的一个版本,但经过专门配置)

如果我希望所有版本的 RouteBuilders 都在同一个上下文 xml 中进行测试(或者甚至不这样做,只是用 @Component 注释它们而不是将它们放在 xml 中)并且在每个测试中指定实际的实现RouteBuilder 的测试?

camel spring test中是否有这样的注解(告诉测试哪个bean作为RouteBuilder运行)?

【问题讨论】:

    标签: integration-testing apache-camel spring-annotations


    【解决方案1】:

    查看此页面如何使用<camel:contextScan/> http://camel.apache.org/spring.html

    然后您可以使用 Spring @Component 注释来注释您的单元测试 RouteBuilder 类。

    【讨论】:

    • 确实阅读了该文档,但还不够。但是,我认为您可以在测试中自动连接上下文并使用 @Qualifier("mySpecificCamelContext") 进行注释
    【解决方案2】:

    为什么不使用没有弹簧的普通骆驼 TestSupport 类?在那里,您只需使用 new 实例化 RouteBuilder,而不必关心注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      相关资源
      最近更新 更多