camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <>
Subject Re: My First Camel Route. Need help unit testing and refactoring.
Date Tue, 26 Feb 2013 02:54:26 GMT
When we write the unit tests for the camel route, we just want test the route logical.  
Because it is hard to setup all the environment, we don't want to get touch with the other
camel component in the unit test.

You can break the whole route into some small pieces with the help of direct endpoints, and
you can just feed the message to it by using the ProducerTemplate.

Back to the component, you can use the intercept[1] to change the behavior of camel route
to avoiding using the other compomnent and verify the result at the same time.


Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: |
Blog: ( (English)
 ( (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem

On Tuesday, February 26, 2013 at 5:01 AM, shyenuganti wrote:

> Here is a sample route written in Camel for our application. This is our
> first ever route in camel.  
> This route reads Event Table in Oracle and AS400 systems, extracts an XML
> message from the record and send the message to JMS queue.
> All the JDBC and JMS endpoints are based on JNDI Lookup.
> This is working fine. Now I am a bit confused on how to write
> unit/integration tests for this route. Can anyone help me with a sample
> unit test methods for this route?  
> Do we have to use "mocks" for testing? Cant we replace the components with
> mocks on the fly ? Should we have multiple application context files in
> test/resources thaat mocks the JPA and jms endpoints for testing ?  
> Any comments on the route structure or any refactoring/best practice ideas
> are welcome. Please assist.
> public class EventListenerRoute  
> extends RouteBuilder
> implements InitializingBean, DisposableBean{
> public void configure() throws Exception {
> from("as400Jpa://org.model.EventQueue?consumeDelete=false&consumer.delay=5000")
> .id("AS400ReaderEndpoint")
> .convertBodyTo(org.model.EventQueue.class)
> .to("direct:eventMessageList");
> from("oracleJpa://org.model.EventQueue?consumeDelete=false&consumer.delay=5000")
> .id("OracleReaderEndpoint")
> .convertBodyTo(org.model.EventQueue.class)
> .to("direct:eventMessageList");
> from("direct:eventMessageList").id("PseudoEventQueue")
> .log("Sending Message to Queue: jbossEventQueue")
> .to("jms:queue/jbossEventQueue?messageConverter=#myMessageConverter")
> .log("Sent message to jbossEventQueue");
> }
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at (

View raw message