我有一条相当简单的路线:
PerfStubRouteBuilder.java
public class PerfStubRouteBuilder extends SpringRouteBuilder {
/* (non-Javadoc)
* @see org.apache.camel.builder.RouteBuilder#configure()
*/
@Override
public void configure() throws Exception {
from("direct:test-aces-input")
.log("Creating test Accident Number header")
.setHeader("AccidentNumber", simple("AB999999999"))
.log("Test Accident Number header created : ${header.AccidentNumber}")
.end();
}
}
我正在如下测试:
PerfStubRouteBuilderTest.java
public class PerfStubRouteBuilderTest extends CamelTestSupport {
@Produce(uri = "direct:test-aces-input")
ProducerTemplate template;
PerfStubRouteBuilder route = new PerfStubRouteBuilder();
Exchange exch = new DefaultExchange(context);
@Override
protected RouteBuilder createRouteBuilder() {
return route;
}
@Test
public void test_PerfStubRouteBuilder_happyPath_addsAccidentNumberHeaderToExchange() throws Exception {
startCamelContext();
NotifyBuilder notify = new NotifyBuilder(context).from("direct:test-aces-input").whenDone(1).filter(header("AccidentNumber").isEqualTo("AB999999999")).create();
template.send(exch);
assertTrue(notify.matches(10, TimeUnit.SECONDS));
stopCamelContext();
}
}
assertTrue总是返回为false,所以我怀疑我没有正确使用NotifyBuilder,尽管目前还不能确定。本质上,我想检查交换是否通过路由并将实际路由中指定的标头添加到交换中。我要发生的是,如果与该标头值组合的交换使它到达路由的末尾,则发生匹配,因此发生了过滤步骤。我想避免在路由的末尾添加端点,例如,通过Advice考虑到路由本身的大小和简单性,为这种次要测试开始添加模拟端点似乎有点繁重
更新:
尝试从表达式中删除过滤器部分,将NotifyBuilder保留为
NotifyBuilder notify = new NotifyBuilder(context).from("direct:test-aces-input").whenDone(1).create();
,测试仍然失败 最佳答案
从测试中的端点创建交换,例如
Endpoint endpoint = context.getEndpoint("direct:test-aces-input");
Exchange exchange = endpoint.createExchange();
template.send(exchange);
或直接使用sendBody
tempalte.sendBody("")