Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unit testing functions with Apache Camel Exchange as parameter

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.

like image 482
RoundPi Avatar asked Feb 27 '13 13:02

RoundPi


People also ask

What is Exchange in Apache Camel?

An Exchange is the message container holding the information during the entire routing of a Message received by a Consumer . During processing down the Processor chain, the Exchange provides access to the current (not the original) request and response Message messages.

How do you mock a Camel endpoint?

Mocking existing endpoints with XML DSL The solution is to create a new XML file used by the unit test and then include the intended XML file which has the route you want to test. Then in your unit test you load the new XML file ( test-camel-route. xml ) instead of camel-route.

What is Camel framework?

Apache Camel ™ is a versatile open-source integration framework based on known Enterprise Integration Patterns. Camel empowers you to define routing and mediation rules in a variety of domain-specific languages (DSL, such as Java, XML, Groovy, Kotlin, and YAML).


1 Answers

You can also create a new default exchange like this:

    CamelContext ctx = new DefaultCamelContext(); 
    Exchange ex = new DefaultExchange(ctx);
like image 171
Yogesh Chawla Avatar answered Sep 28 '22 11:09

Yogesh Chawla