【问题标题】:How to test an existing camel route?如何测试现有的骆驼路线?
【发布时间】:2023-03-03 09:15:15
【问题描述】:

我正在尝试测试现有的 Camel 路线,但事实证明它比我预期的要困难得多。我在网上看到的大多数文档似乎都在测试中创建了一个新路由,然后对其进行测试。如何测试我已经创建的路线?

为简单起见,我创建了我能想到的最简单的路线,但我终其一生都无法弄清楚如何在测试中使用该路线。

路线如下:

@Component
public class TestRouteBuilder extends RouteBuilder{

@Override
public void configure() throws Exception {
    from("direct:testStart")
            .log("Log triggered.")
            .to("direct:testEnd");
}
}

如何在测试中使用这条路线?

我在 Spring Boot 中使用 Camel,所以我的第一个想法是将路由注入测试,但这似乎不起作用。

任何帮助表示赞赏,谢谢。

【问题讨论】:

  • 再次阅读测试文档。或者购买其中一本书,例如 Camel in Action 或 Camel recipies,其中介绍了如何使用 Camel 进行测试。或者查看一些单元测试,它们是 Camel 测试路线的小例子。

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


【解决方案1】:

这可以通过多种方式实现。这是一种方式:

context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
   @Override
   public void configure() throws Exception {
      weaveAddLast().to("mock:result");
   }
});

你也可以使用CamelTestSupport:

@Override
public String isMockEndpoints() {
   // override this method and return the pattern for which endpoints to mock.
   // use * to indicate all
   return "*";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-28
    相关资源
    最近更新 更多