21

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.

RoundPi
  • 5,819
  • 7
  • 49
  • 75
  • 1
    Why do not you mock endpoints and mock their returned body. See http://camel.apache.org/mock.html http://camel.apache.org/testing.html You should ideally be focussing on mocking endpoints I guess. – Saurabh Feb 27 '13 at 13:56
  • @Saury: I am not that interested in endponts, all I want to test is the getting the xml message from Exchange. But let's say I have to lock endpoints to get a mock exchange, how do I set the content xml message inside the exchange ? – RoundPi Feb 27 '13 at 14:09

1 Answers1

46

You can also create a new default exchange like this:

    CamelContext ctx = new DefaultCamelContext(); 
    Exchange ex = new DefaultExchange(ctx);
Yogesh Chawla
  • 1,583
  • 18
  • 16