首页 > 解决方案 > 如何在 CDI 环境中模拟现有端点?

问题描述

我不能在模拟端点上断言。我在带有 Java DSL 路由的 WildFly 容器中使用 JUnit 和 CDI 注入。

...所以无论我嘲笑什么,都不是我的建议:) 并且所有断言都理所当然地失败了。

@RunWith(Arquillian.class)
public class MyTest extends CamelTestSupport {
  @Override
  public boolean isUseAdviceWith() {
    return true;
  }

  @Inject
  private CamelContext camelContext;

  @Test
  public void someTest() {
    camelContext.getRouteDefinition("routeid").adviceWith(camelContext,
      new AdviceWithRouteBuilder() {
        @Override
        public void configure () throws Exception {
          mockEndpoints();
        }
      });
    Collection list = context.getEndpoints(); // the ModelCamelContext is always empty, looks bad
    Collection list2 = camelContext.getEndpoints(); // has both route endpoints AND mocks, looks good
    getMockEndpoint("mock:someid").expectedMessageCount(1); // will always CREATE a new endpoint in the empty modelcamelcontext
    getMockEndpoint("mock:someid", false).expectedMessageCount(1); // will always crash, that endpoint ID is in the other context...

我会放弃注入的 CamelContext 但所有路由都只在那里创建,我不知道为什么。CamelTestSupport 的 ModelCamelContext 上下文总是空的……有些东西我初始化不同/错误,但我不能说什么。有人成功地使用了模拟的 Camel CDI 测试吗?

标签: javajunitapache-camelcdi

解决方案


推荐阅读