Camel NotifyBuilder 总是返回 false [英] Camel NotifyBuilder always returns false

查看:34
本文介绍了Camel NotifyBuilder 总是返回 false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当简单的路线:

I've got a fairly simple route:

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,尽管此时我不能确定.本质上,我想检查交换是否通过路由,并将实际路由中指定的标头添加到交换中.我想要发生的是,如果具有该标头值组合的交换使其到达路由的末尾,则发生匹配,因此是过滤步骤.我想避免在路由的末尾添加一个端点,例如,通过 AdviceWith 考虑到路由本身是多么的小和简单,开始为这样一个小测试添加模拟端点似乎有点重量级

assertTrue always come back as false, so I suspect I'm not using the NotifyBuilder correctly although at this point I can't be certain. Essentially I want to check that an exchange makes it through the route and the header specified in the actual route is added to the exchange. What I want to happen is for a match to occur if an exchange with that header value combo makes it to the end of the route, hence the filter step. I want to avoid adding an endpoint at the end of the route, for example, via AdviceWith given how small and simple the route itself is , it seems a bit heavyweight to start adding in mock endpoints for such a minor test

更新:

尝试从表达式中删除过滤器部分,将 NotifyBuilder 保留为 NotifyBuilder notify = new NotifyBuilder(context).from("direct:test-aces-input").whenDone(1).create(); ,测试还是失败

Tried removing the filter portion from the expression, leaving the NotifyBuilder as NotifyBuilder notify = new NotifyBuilder(context).from("direct:test-aces-input").whenDone(1).create(); , the test still fails

推荐答案

Endpoint endpoint = context.getEndpoint("direct:test-aces-input");
Exchange exchange = endpoint.createExchange();
template.send(exchange);

或者直接使用sendBody

or just directly use sendBody

tempalte.sendBody("")

这篇关于Camel NotifyBuilder 总是返回 false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆