我使用Apache Camel来编排对三个不同端点的多个HTTP调用。这是正常的,但我也想对这个Camel路线进行单元测试。
我可以正确断言已经调用了三个端点,但我不知道如何验证它们是否以正确的顺序被调用。我研究过使用MockEndpoint
和NotifyBuilder
。
如何在Camel Spring JUnit测试中验证是否以正确的顺序调用了端点?
答案 0 :(得分:0)
嗯我不确定是否有一种简单的方法可以做到这一点,但你可以使用AdviceWithRouteBuilder将bean编织到你的路由中,在每次发送之前将一个计数器放在标题中。
类似的东西:
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