我正在编写集成测试以测试现有路由。得到响应的建议方法看起来是这样的(通过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“骆驼在行动”源有这样的路线建设者,那么它也失败了。
谢谢克劳斯。我已经更新了这个问题。 GetClaimListRouteBuilder.responseNode只是一个返回相同字符串的静态方法。我已经替换它并重新运行测试,结果相同。 – Damo 2010-11-11 22:20:41
克劳斯,我已经确定了一些问题并更新了我的问题。结果对你来说看起来很奇怪吗? – Damo 2010-11-12 00:04:42