【问题标题】:Apache Camel Test Support with POJO and OSGI reference bean带有 POJO 和 OSGI 参考 bean 的 Apache Camel 测试支持
【发布时间】:2016-02-03 23:16:07
【问题描述】:

我正在使用 CamelTestSupport 创建一个 Junit 测试。 Camel Route 很少引用 POJO Bean 和 OSGI 引用。OSGI 引用是一个接口。我曾使用SimpleRegistry 使用 Java DSL 捕获 POJO bean。但是,我不知道如何为此添加 OSGI 参考或OSGIServiceRegistry

我如何在注册表中拥有 OSGI 引用和 POJO Bean 以及 OSGI 引用,以便CamelTestSupport 可以触发测试方法?

供参考-

骆驼版 - 2.13.2

Junit 版本 - 4.11

【问题讨论】:

    标签: junit apache-camel osgi


    【解决方案1】:

    如果你使用蓝图,你可以尝试使用CamelBlueprintTestSupport而不是CamelTestSupport。如果还是不行,你可以看看CamelBlueprintTestSupport的代码,特别是createBundleContext()方法,它在启动时注册了一些服务。

    【讨论】:

    • 这个答案让我想起了@Override protected void addServicesOnStartup(Map<String, KeyValueHolder<Object, Dictionary>> services) { services.put("myService", asService(myService, "beer", "Carlsberg")); },它也可能对 OP 有帮助(它也在 camel-test-blueprint 中)。这个例子和更多文档可以在这里找到:camel.apache.org/blueprint-testing.html
    • 我开始使用 CamelBlueprintTestSupport。在蓝图配置出现一些初始错误后,我可以开始了。但是,测试方法现在无法从 bean 异常开始。 org.apache.camel.NoSuchBeanException:在注册表中找不到 bean。在 BlueprintTestSupport 的情况下,我们如何将 POJO bean 引用添加到注册表?
    • 我使用 CamelBlueprintTestSupport 和覆盖的 addServicesOnStartup() 和 getBlueprintDescriptor() 方法,测试能够解析 bean。感谢您建议将 CamelBlueprintTestSupport 与 OSGI 蓝图一起使用。
    猜你喜欢
    • 1970-01-01
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    相关资源
    最近更新 更多