【问题标题】:Camel testing - java.lang.IllegalArgumentException: defaultEndpoint must be specified骆驼测试 - java.lang.IllegalArgumentException:必须指定 defaultEndpoint
【发布时间】:2017-04-02 07:30:40
【问题描述】:

我正在尝试使用 http://camel.apache.org/mock.html 为我的骆驼路线创建测试用例。我需要验证路线中的处理器。但是这个简单的测试对我不起作用。

public class CamelRouteTest  extends CamelTestSupport {

  @Override
  public String isMockEndpointsAndSkip() {
    // override this method and return the pattern for which endpoints to mock,
    // and skip sending to the original endpoint.
    return "mock:result";
  }

  @Test
  public void verifyMessageCount() throws Exception {
    template.sendBody("Test");
    getMockEndpoint("mock:result").expectedMessageCount(1);
    assertMockEndpointsSatisfied();
  }

  @Override
  protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start").to("mock:result");
        }
    };
  }
}

堆栈跟踪:

java.lang.IllegalArgumentException: defaultEndpoint must be specified
    at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:308)
    at org.apache.camel.impl.DefaultProducerTemplate.getMandatoryDefaultEndpoint(DefaultProducerTemplate.java:506)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:370)

【问题讨论】:

    标签: java apache-camel camel-test


    【解决方案1】:

    template.sendBody("Test") 尝试将Test 发送到默认端点。在您的代码中,未配置它会失败。

    你可以:

    • 指定使用哪个端点

      template.sendBody("direct:start", "Test");
      
    • 从上下文中获取一个端点并将其设置为默认端点

      Endpoint endpoint = context.getEndpoint("direct:start");
      template.setDefaultEndpoint(endpoint);
      template.sendBody("Test");
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多