简体   繁体   English

JUnit + Apache骆驼

[英]JUnit + Apache Camel

Suppose I have these two routes 假设我有两条路线

<camelContext> 
    <route>
        <from ref="incoming" />
        <!-- some processors -->
        <inOnly ref="outgoing" />
    </route>

    <route>
        <from ref="outgoing" />
        <!-- some processors -->
        <inOnly ref="finish" />
    </route>
</camelContext>

In the real context they are JMS queues which is fine. 实际上,它们是JMS队列,这很好。 But I want to test that the routing is correct so I changed JMS components in the testContext.xml to: 但是我想测试路由是否正确,所以我将testContext.xml中的JMS组件更改为:

incoming -> direct
outgoing -> mock
finish -> mock

I want those inOnly queues to be mocks so I can test them for the number of messages. 我希望那些inOnly队列是模拟的,以便可以测试它们的消息数量。 The problem is that a mock queue cannot work as an input queue in the second route. 问题在于,模拟队列无法在第二个路由中充当输入队列。 How can I fix this? 我怎样才能解决这个问题?

I usually embedd an ActiveMQ broker when doing automated integration JUnit tests with Camel and JMS. 在与Camel和JMS进行自动集成JUnit测试时,我通常会嵌入 ActiveMQ代理。

I would also consider a simpler scenario where you have "outgoing" as a seda endpoint. 我还将考虑一个更简单的方案,其中您将“传出”作为seda端点。 Then you would only have to check the "finish" mock endpoint for messages, and you know the entire route works. 然后,您只需要检查“完成”模拟端点中的消息,就可以知道整个路由都有效。 For more complicated routing scenarios, it takes a bit of thinking to cover it in JUnit tests, if you should do it at all. 对于更复杂的路由方案,如果您应该完全这样做,则需要花一点时间在JUnit测试中进行介绍。

您可以使用存根组件而不是JMS等。它的seda / vm在后台排队,因此您可以从其中发送和使用消息http://camel.apache.org/stub

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

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