Unit testing each route in a large camel context

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Unit testing each route in a large camel context

Gnanaguru S
This post was updated on .
Riders,

I have a came context like the below one. I am going to do unit testing for each and every route. I am still wondering why no body has asked this question early. ( May be I didnt find it )
How can I do unit testing for each and every route ?

Camel context:

<camelContext id="Sample-Context">
       
                <route id="Start">
                        <from uri=direct:A />
                        <to uri=direct:B />
                </route>
       
                <route id="Hop1">
                        <from uri=direct:B />
                        <to uri=direct:C />
                </route>
       
                <route id="Hop2">
                        <from uri=direct:C />
                        <to uri=direct:D />
                </route>
       
                <route id="Stop">
                        <from uri=direct:D />
                        <to uri=direct:E />
                </route>
       
        </camelContext>

My current test strategy:

1. I have four different camelcontext  xml's under my test resources
2. I have created four different test classes using JUnit ( Supported by camel)
3. If I take one route, I will mock the direct:B to mock:direct:B.
4. Apply assertions to the mock endpoints.

Alternative test strategy:

1. Instead of creating four different XML's, I can just keep one camel context xml and add property placeholders.
2. By changing the endpoints in the property placeholers, so that I can logically disable the remaining routes. Because direct endpoints cannot have more than one consumer and mock endpoint cannot have consumer at all.

But of all this, Is there any other simplified way to do the testing ? For large projects having large number of routes, Is there a way I can test individual routes from the same camelcontext files ? Instead of having multiple xml's.

I will great appreciate your help. Also I am planning to develop an article based on this conversation. Please drop in your ideas and comments.

Camel is a wonderful framework with wonderful test endpoint like Mock. Mock is very powerful in terms of asssertions, but wondering what are the other ways to utilize it well in large camel context.

Cheers,
Guru
gnanaguru.com
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

pradeep
This post was updated on .
Hi,

Since you are using spring DSL, Instead of copying the routes into test/resources xml file you can directly point the actual routes located in src/main/resources xml files in your test class and to replace the actual endpoints with the mock end point you can use property place holder pointed to separate properties file. So that you can test actual routes with mock endpoints.

Multiple xml files query: You can put all your routes into single xml and load that file into your test class. Extend your test class with CamelSpringTestSupport, this class provides a method to load your single xml file(http://camel.apache.org/spring-testing.html)

Hope this helps to you.
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

Willem.Jiang
Administrator
In reply to this post by Gnanaguru S
You can take a look at the camel-example-cafe in the camel examples directory, there are some trick to inject the mock endpoint.
At the mean time, you can leverage camel properties component to replace the direct endpoint with the mock endpoint.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On April 4, 2014 at 10:25:51 AM, Gnanaguru S ([hidden email]) wrote:

> Riders,
>  
> I have a came context like the below one. I am going to do unit testing for
> each and every route. I am still wondering why no body has asked this
> question early. ( May be I didnt find it )
> How can I do unit testing for each and every route ?
>  
> Camel context:
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> My current test strategy:
>  
> 1. I have four different camelcontext xml's under my test resources
> 2. I have created four different test classes using JUnit ( Supported by
> camel)
> 3. If I take one route, I will mock the direct:B to mock:direct:B.
> 4. Apply assertions to the mock endpoints.
>  
> Alternative test strategy:
>  
> 1. Instead of creating four different XML's, I can just keep one camel
> context xml and add property placeholders.
> 2. By changing the endpoints in the property placeholers, so that I can
> logically disable the remaining routes. Because direct endpoints cannot have
> more than one consumer and mock endpoint cannot have consumer at all.
>  
> But of all this, Is there any other simplied way to do the testing ? For
> large projects having large number of routes, Is there a way I can test
> individual routes from the same camelcontext files ? Instead of having
> multiple xml's.
>  
> I will great appreciate your help. Also I am planning to develop an article
> based on this conversation. Please drop in your ideas and comments.
>  
> Camel is a wonderful framework with wonderful test endpoint like Mock. Mock
> is very powerful in terms of asssertions, but wondering what are the other
> ways to utilize it well in large camel context.
>  
> Cheers,
> Guru
> gnanaguru.com
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Unit-testing-each-route-in-a-large-camel-context-tp5749750.html 
> Sent from the Camel - Users mailing list archive at Nabble.com.
>  

Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

Gnanaguru S
In reply to this post by pradeep
Hi Pradeep,

Sorry, May be I didnt convey it properly. If you refer the camel context above. I have direct endpoints, If I use a test class it wont work.

For example: I can mock direct:B, but if you refer 'Hop1' route it consumes from direct:B. In this scenario it will fail because, there cannot be more than one consumer for direct endpoint.

I think now you get an idea to help me better. :)

Cheers
Guru
gnanaguru.com
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

Gnanaguru S
In reply to this post by Gnanaguru S
Guys,

I couldnt really understand how to solve this. But, from morning from sitting with Camel JUnit test cases. Which made me realise, Camel is much more interesting if we write more unit test cases for it :)

I am just loving the adviceWith :) Camel test case support is more genenious than camel :)

Still continuing my exploration on better approaches to " Unit testing each route in a large camel context "

Cheers
Guru
gnanaguru.com
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

smehta34
Hi Guru,

Did you find solution of this post? Much appreciated if you can show how you tested your routes.

-Sachin
Reply | Threaded
Open this post in threaded view
|

Re: Unit testing each route in a large camel context

Gnanaguru S
Hi Sachin, 

Yes, you can do almost everything in camel unit testing. More than what I asked above.

I have documented everything here. Feel free to ask if you have specific question: 



Cheers
Guru 

Sent from my iPhone

On 6 Jul 2015, at 11:19 pm, smehta34 [via Camel] <[hidden email]> wrote:

Hi Guru,

Did you find solution of this post? Much appreciated if you can show how you tested your routes.

-Sachin


If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/Unit-testing-each-route-in-a-large-camel-context-tp5749750p5768922.html
To unsubscribe from Unit testing each route in a large camel context, click here.
NAML