camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willem jiang <willem.ji...@gmail.com>
Subject Re: Integration tests on routes
Date Thu, 20 Dec 2012 07:33:20 GMT
Hi,

You bring up a very interesting topic of how to write the tests on came route.
These tests could be unit test, integration test, system test.

First you can break a big route into some same route which could be more testable by using
direct endpoint[1]
Then you can feed the real message to the route and using the mock endpoint to test the result,
like the unit test does.
After that, you can run some test on the routes as an integration test, In this time you may
not want to access the out side service like twitter or google search, but you can still feed
the real message as the twitter gives to you to your route.
If every thing looks good, you can still into the system test world to setup the real world
endpoint for you route. With the help of camel endpoint uri, it is very is to replace the
endpoint barely change your route.

I think you can take a look at the unit tests of cafe-example[2][3], it shows you an example
on how to write tests with came the routes.

[1]http://camel.apache.org/direct.html
[2]http://camel.apache.org/cafe-example.html
[3]https://svn.apache.org/repos/asf/camel/trunk/examples/camel-example-cafe


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Thursday, December 20, 2012 at 1:10 PM, Luca Foppiano wrote:

> Sorry but I've sent the email without it was finished...
>  
> After the test I had problem with the part that was supposed to create the
> route, in fact I've never managed to make it working using the route above
> (in the test at the end I was using a fake route)
>  
> I wanted to ask in fact if
>  
> 1) is this kind of integration test possible to be done?
> 2) do you think, as more expert than me, is a good requirement?
> 3) how would you normally build a route? Do you just start it everytime you
> need to test it or do you have a different approach?
>  
>  
> Thanks a lot in advance
> Kind regards
> --  
> Luca Foppiano
>  
> Software Engineer
> +31615253280
> luca@foppiano.org (mailto:luca@foppiano.org)
> www.foppiano.org (http://www.foppiano.org)
>  
> On Thu, Dec 20, 2012 at 6:05 AM, Luca Foppiano <luca@foppiano.org (mailto:luca@foppiano.org)>
wrote:
>  
> > Dear all,
> > reading the manual of Camel and in particular the chapter about
> > Testing, I've noted that all the examples of Unit tests are made by
> > creating a fake route (in the test) to test the single components, in
> > reality this works fine only on a small part of the route, like for example
> > processors, aggregation/split strategies, where we reference to a bean that
> > is out of our route implementation.
> >  
> > What I noted, while developing a route, is that most of the time is spent
> > by trial/error approach, in the sense that, I write my route, but then I
> > try it. What I would find very useful is to use, on the same route I'm
> > developing, to build an integration tests around it, so that I could just
> > run the test instead of build up and run the whole route infrastructure. I
> > tried the approach of writing your fake route in the tests but after a
> > while I've noted that I was changing the 'real' route without updating the
> > tests (indeed they were not failing).
> >  
> > I have made some experiments by creating routes and injects all the
> > endpoints, but when it was time to set up the route in the test, I've never
> > be able to.
> >  
> > just to explain, something like:
> >  
> > public class TwitterCrawlerRoute extends RouteBuilder {
> >  
> >  
> > @EndpointInject(ref = "sourceFileQuery")
> > private Endpoint sourceFileQuery;
> >  
> > @EndpointInject(ref = "outputDirectory")
> > private Endpoint outputDirectory;
> >  
> > public void configure() {
> >  
> > from(sourceFileQuery)
> > .routeId("TwitterUrlBuilder")
> > .split().tokenize("\n")
> > .transform(body().append(simple("baobao")))
> > .to(outputDirectory);
> > }
> > }
> >  
> > And in the test I was able to have mocks instead of the normal endpoint:
> >  
> > public class QueryBuilderRouteTest extends CamelTestSupport {
> > @Produce(uri = "direct:start")
> > protected ProducerTemplate template;
> >  
> > @EndpointInject(uri= "mock:queue")
> > protected MockEndpoint queryQueue;
> >  
> > @Test
> > public void testCountAndVerifyMessages() throws Exception {
> >  
> > String sentBody= "nike";
> >  
> > //queryQueue.expectsNoDuplicates();
> > queryQueue.expectedMessageCount(15);
> >  
> > template.sendBody(sentBody);
> >  
> > queryQueue.assertIsSatisfied();
> >  
> > assertEquals(15, queryQueue.getExchanges().size());
> > }
> > }
> >  
> > In fact I would like to know if is really possible to do that, and if is
> > there a way to pursue this needs, or, from your expert opinion, is not
> > really needed?
> >  
> >  
> > --
> > Luca Foppiano
> >  
> > Software Engineer
> > +31615253280
> > luca@foppiano.org (mailto:luca@foppiano.org)
> > www.foppiano.org (http://www.foppiano.org)
>  




Mime
View raw message