2010-11-11 72 views
3

我正在編寫集成測試以測試現有路由。得到響應的建議方法看起來是這樣的(通過Camel In Action 6.4.1節):Apache駱駝集成測試 - NotifyBuilder

public class TestGetClaim extends CamelTestSupport { 

    @Produce(uri = "seda:getClaimListStart") 
    protected ProducerTemplate producer; 

    @Test 
    public void testNormalClient() { 
     NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create(); 

     producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A")); 
     boolean matches = notify.matches(5, TimeUnit.SECONDS); 
     assertTrue(matches); 

     BrowsableEndpoint be = context.getEndpoint("seda:getClaimListResponse", BrowsableEndpoint.class); 
     List<Exchange> list = be.getExchanges(); 
     assertEquals(1, list.size()); 
     System.out.println("***RESPONSE is type "+list.get(0).getIn().getBody().getClass().getName()); 
    } 
} 

試運行,但我得到任何回報。 assertTrue(matches)在5秒超時後失敗。

如果我重寫的測試看起來像這樣我得到迴應:

@Test 
public void testNormalClient() { 
    producer.sendBody(new ClientRequestBean("TESTCLIENT", "Y", "A")); 
    Object resp = context.createConsumerTemplate().receiveBody("seda:getClaimListResponse"); 
    System.out.println("***RESPONSE is type "+resp.getClass().getName()); 
} 

的文檔解決此一盞小燈這樣誰能告訴我什麼,我做錯了與第一種方法?改爲採用第二種方法有什麼不妥之處嗎?

謝謝。

UPDATE 我已經打破下來,它看起來像這個問題是SEDA作爲組合開始端點路由中使用recipientList的組合。我也改變了NotifyBuilder的構造(我指定了錯誤的端點)。

  • 如果我更改啓動端點 直接,而不是SEDA則測試將工作;或
  • 如果我將recipientList 註釋掉,那麼測試將起作用。

這裏是我的路線的一個精簡版再現此問題:

public class TestRouteBuilder extends RouteBuilder { 

    @Override 
    public void configure() throws Exception { 
//  from("direct:start") //works 
     from("seda:start") //doesn't work 
     .recipientList(simple("exec:GetClaimList.bat?useStderrOnEmptyStdout=true&args=${body.client}")) 
     .to("seda:finish"); 
    } 

} 

需要注意的是,如果我從改變的源代碼NotifyTest駱駝在行動」源有這樣的路線建設者,那麼它也失敗了。

回答

2

嘗試使用:在getEndpoint「SEDA getClaimListResponse」,以確保端點URI是100%正確的

+0

謝謝克勞斯。我已經更新了這個問題。 GetClaimListRouteBuilder.responseNode只是一個返回相同字符串的靜態方法。我已經替換它並重新運行測試,結果相同。 – Damo 2010-11-11 22:20:41

+0

克勞斯,我已經確定了一些問題並更新了我的問題。結果對你來說看起來很奇怪嗎? – Damo 2010-11-12 00:04:42

0

FWIW:看來,notifyBuilder與SEDA隊列一起不太工作:測試類來說明:

public class NotifyBuilderTest extends CamelTestSupport { 

// Try these out! 
// String inputURI = "seda:foo"; // Fails 
// String inputURI = "direct:foo"; // Passes 

@Test 
public void testNotifyBuilder() { 

    NotifyBuilder b = new NotifyBuilder(context).from(inputURI) 
      .whenExactlyCompleted(1).create(); 

    assertFalse(b.matches()); 
    template.sendBody(inputURI, "Test"); 
    assertTrue(b.matches()); 

    b.reset(); 

    assertFalse(b.matches()); 
    template.sendBody(inputURI, "Test2"); 
    assertTrue(b.matches()); 
} 

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