You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Olivier.Roger" <ol...@bsb.com> on 2010/11/29 18:39:33 UTC

Unit Testing Route

Hello Camel,

I am using Camel for some time now and I was wondering how I could perform
unit test using the same camel context used in production but still being
able to test intermediate messages of the routes.

For instance, with the simple routes A --> B and B --> C.
At the moment I use 4 properties A,B,B' and C. In prod, B == B' and in test
A and C are direct: endpoint and B' and D are mock endpoint.

This allows to sent easily message using the template object and validate
the result by making mock assertions.

I wanted to know if there was a better solution than duplicating the
endpoint URI (B and B' here) for intermediate endpoints. 

Thanks in advance for your input!
-- 
View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Route-tp3284803p3284803.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unit Testing Route

Posted by Claus Ibsen <cl...@gmail.com>.
I have created a ticket
https://issues.apache.org/jira/browse/CAMEL-3578



On Thu, Dec 2, 2010 at 9:26 AM, Olivier.Roger <ol...@bsb.com> wrote:
>
> I agree, that would be nice to create mockEndpoint from any existing endpoint
> --
> View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Route-tp3284803p3289035.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Unit Testing Route

Posted by "Olivier.Roger" <ol...@bsb.com>.
I agree, that would be nice to create mockEndpoint from any existing endpoint
-- 
View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Route-tp3284803p3289035.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unit Testing Route

Posted by Tommy Chheng <to...@gmail.com>.
> Yeah I have been meant to added some more nicer syntax sugar for the
> approach above with the adviceWith and intercept in the Camel Test
> Kit.
> We should have something so you can easily instruct Camel to not send
> to X but send to mock:X instead (or what you want).
> Also to more easily replace parts of routes, and whatnot.
>
> So any ideas you may have in this area is welcome.

As an idea, would it be possible to just layer on the interception code 
with getMockEndpoint(of course, a different method name) in a test units?

I have a route stored as a class:
class TwitterRoute extends RouteBuilder { 
from("direct:input").handleFault().bean(classOf[TwitterData]).to("direct:output") 
}

If would be awesome if there was a function that work like 
getMockEndpoint but with any URI.  eg. val mock = 
getMockEndpoint("*direct:*output")

-
Tommy

Re: Unit Testing Route

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 29, 2010 at 7:01 PM, Claus Straube <cl...@catify.com> wrote:
>
> Hi,
>
> you can do this by intercepting your routes.
>
> public void testFoo() throws Exception {
>  RouteDefinition route = context.getRouteDefinitions().get("routeId");
> route.adviceWith(context, new RouteBuilder() {
>   public void configure() throws Exception {
>      interceptSendToEndpoint("seda:in")
>      .skipSendToOriginalEndpoint()
>      .to("mock:m1");
> }
> });
>
> Best regrads - Claus
>

Yeah I have been meant to added some more nicer syntax sugar for the
approach above with the adviceWith and intercept in the Camel Test
Kit.
We should have something so you can easily instruct Camel to not send
to X but send to mock:X instead (or what you want).
Also to more easily replace parts of routes, and whatnot.

So any ideas you may have in this area is welcome.


>
> Am Montag, den 29.11.2010, 09:39 +0100 schrieb "Olivier.Roger"
> <ol...@bsb.com>:
>>
>> Hello Camel,
>>
>> I am using Camel for some time now and I was wondering how I could perform
>> unit test using the same camel context used in production but still being
>> able to test intermediate messages of the routes.
>>
>> For instance, with the simple routes A --> B and B --> C.
>> At the moment I use 4 properties A,B,B' and C. In prod, B == B' and in
>> test
>> A and C are direct: endpoint and B' and D are mock endpoint.
>>
>> This allows to sent easily message using the template object and validate
>> the result by making mock assertions.
>>
>> I wanted to know if there was a better solution than duplicating the
>> endpoint URI (B and B' here) for intermediate endpoints.
>>
>> Thanks in advance for your input!
>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: Unit Testing Route

Posted by Claus Straube <cl...@catify.com>.
 Hi,

 you can do this by intercepting your routes.

 public void testFoo() throws Exception {
  RouteDefinition route = context.getRouteDefinitions().get("routeId");
 route.adviceWith(context, new RouteBuilder() {
    public void configure() throws Exception {
       interceptSendToEndpoint("seda:in")
       .skipSendToOriginalEndpoint()
       .to("mock:m1");
 }
 });

 Best regrads - Claus


 Am Montag, den 29.11.2010, 09:39 +0100 schrieb "Olivier.Roger" 
 <ol...@bsb.com>:
> Hello Camel,
>
> I am using Camel for some time now and I was wondering how I could 
> perform
> unit test using the same camel context used in production but still 
> being
> able to test intermediate messages of the routes.
>
> For instance, with the simple routes A --> B and B --> C.
> At the moment I use 4 properties A,B,B' and C. In prod, B == B' and 
> in test
> A and C are direct: endpoint and B' and D are mock endpoint.
>
> This allows to sent easily message using the template object and 
> validate
> the result by making mock assertions.
>
> I wanted to know if there was a better solution than duplicating the
> endpoint URI (B and B' here) for intermediate endpoints.
>
> Thanks in advance for your input!