2010-11-11 126 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"); 
     } 
    }; 
} 
}