2012-02-15 134 views
1

我有一個駱駝航線它看起來是這樣的:測試路線在Apache的駱駝

public class CamelReaderRoute extends RouteBuilder { 

@Override 
public void configure() throws Exception { 
    from("quartz://myjob?cron=0+0/5+*+*+*+?") 
      //....(some more content) 
      .routeId("MyCamelRoute"); 
} 

基本上石英「觸發」的路線,每五分鐘。當單元測試這條路線時,除非時間正好是00:00或00:05或00:10等,否則它不會發射。等等。

那麼如何更改「from」中使用的端點,以便該路線立即着火? 這是迄今爲止我的測試類:

public class CamelRouteTest extends CamelTestSupport { 

@Test 
public void shall_run_the_route_or_something() { 
    context.getRouteDefinition("MyCamelRoute") 
      .adviceWith(context, new AdviceWithRouteBuilder() { 
       @Override 
       public void configure() throws Exception { 
        //something should be done here?      
       } 
      }); 

我可以看到,在駱駝2.9我可以用我的replaceFromWith配置方法中,但由於依賴和某某,我堅持用駱駝2.8。他們是否有任何形式的替換?從2.9之前?

回答

4

有幾個選項,其中一個將設置石英「fireNow = true」選項以在路線啓動時調用(儘管它在部署時也會這樣做)。否則,只是分手的石英路由,因此處理可以直接調用...

from("quartz://myjob?cron=0+0/5+*+*+*+?") 
    .to("direct:process"); 

from("direct:process")... 

然後在你的單元測試...調用直接的路線等

template.sendBody("direct:process",null);