2016-11-18 30 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"); 
     } 
    }; 
    } 
} 

スタックトレース:デフォルトのエンドポイントにTestを送信するために

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")試してみます。あなたのコードのように、これは設定されていませんが失敗します。

あなた可能性:

  • template.sendBody("direct:start", "Test"); 
    
  • 使用文脈からエンドポイントを取得し、デフォルトのエンドポイント

    Endpoint endpoint = context.getEndpoint("direct:start"); 
    template.setDefaultEndpoint(endpoint); 
    template.sendBody("Test"); 
    
として設定しているエンドポイントを指定
関連する問題