简体   繁体   English

如何测试骆驼路由依次调用了不同的端点?

[英]How can I test that a Camel route calls different endpoints in order?

I use Apache Camel to orchestrate a number of HTTP calls to three different endpoints. 我使用Apache Camel来协调对三个不同端点的许多HTTP调用。 This works correctly, but I'd like to unit test this Camel route as well. 这可以正常工作,但是我也想对该骆驼路线进行单元测试。

I can correctly assert that the three endpoints were called, but I don't know how to verify that they were called in the correct order. 我可以正确断言三个端点已被调用,但是我不知道如何验证它们是否以正确的顺序被调用。 I have looked into using MockEndpoint and NotifyBuilder . 我已经研究过使用MockEndpointNotifyBuilder

How can I verify in a Camel Spring JUnit test that the endpoints were called in the correct order? 如何在Camel Spring JUnit测试中验证以正确的顺序调用了端点?

Hmm I am not certain if there is an easy way to do this, but you could use the AdviceWithRouteBuilder to weave a bean into your route that puts a counter in the header before each send. 嗯,我不确定是否有简单的方法可以执行此操作,但是您可以使用AdviceWithRouteBuilder将Bean编织到路由中,从而在每次发送之前在标头中放置一个计数器。

Something like: 就像是:

weaveById("send1")
    .before()
    .bean(CounterIncrementor.class);

weaveById("send2")
    .before()
    .bean(CounterIncrementor.class);

weaveById("send3")
    .before()
    .bean(CounterIncrementor.class);

.................. ..................

List<Exchange> list = getMockEndpoint("mock:extract").getReceivedExchanges();
Exchange exchange = list.get(1);
Message in = exchange.getIn();
in.getHeader("MyCounterHeader", Integer.class);

//TODO verify you received the correct number

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM