2016-11-18 83 views
1

我正在嘗試使用http://camel.apache.org/mock.html爲我的駱駝路由創建測試用例。我需要驗證路由中的處理器。但簡單的測試不適合我。駱駝測試 - java.lang.IllegalArgumentException:必須指定defaultEndpoint

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) 

回答

3

template.sendBody("Test")嘗試發送Test到默認端點。就像你的代碼一樣,它沒有配置它失敗。

,你可以:

  • 指定使用

    template.sendBody("direct:start", "Test"); 
    
  • 從上下文得到一個端點並將其設置爲默認的端點

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