使用Apache Camel Exchange作为参数来进行单元测试函数

21
我是在进行Java Camel开发,我想要使用传入Exchange作为参数的单元测试(Junit4)一些函数。
例如:
public finalObject getProperty(final Exchange exchange, final String property) throws Exception {
   //all about getting property from xml message in exchange via xpath
}

问题: 1>我可以使用EasyMock来模拟Exchange吗?如何设置预定义的XML作为交换中的传入消息? 2>如果不能,我需要设置camel测试吗?如何在camel测试中设置预定义的XML作为传入消息。
谢谢。

1
为什么不模拟端点并模拟它们返回的主体。请参阅http://camel.apache.org/mock.html http://camel.apache.org/testing.html 我想你最好专注于模拟端点。 - Saurabh
@Saury:我对端点不是很感兴趣,我只想测试从Exchange获取XML消息。但是假设我必须锁定端点才能获得模拟交换,我该如何在交换中设置内容XML消息? - RoundPi
1个回答

46

您也可以像这样创建一个新的默认交换机:

    CamelContext ctx = new DefaultCamelContext(); 
    Exchange ex = new DefaultExchange(ctx);

3
感谢提供这种简单易懂的方法来模拟和单元测试Camel处理器。 - Alex
这个 DefaultExchange() 方法是从哪里来的? - Gerry
@Gerry 这不是一个方法,而是一个构造函数。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接