unit testing functions with Apache Camel Exchange as parameter

Gob00st picture Gob00st · Feb 27, 2013 · Viewed 15.7k times · Source

I am doing java camel development and I want to unit test(junit4) a bunch of functions with Exchange being passed in as parameter.

For example :

public finalObject getProperty(final Exchange exchange, final String property) throws Exception {
   //all about getting property from xml message in exchange via xpath
}

Question: 1>Can I use EasyMock to mock Exchange ? And how to set a predefined xml as incoming message inside the exchange ?

2>If not do I need to setup camel test ? How to set a predefined xml as incoming message inside the exchange with camel test.

Thanks a lot.

Answer

Yogesh Chawla picture Yogesh Chawla · Jun 17, 2014

You can also create a new default exchange like this:

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