You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vinayks <vi...@gmail.com> on 2012/11/04 10:13:47 UTC

Unit Testing Support for Camel Routes

Hi,

I would like to unit test my following piece of code. I would like to know
how to mock the ProducerTemplate and CamelContext.

DefaultExchange exchange = new DefaultExchange(camelContext);
		//Set the inputs required by the routes as the properties...
		exchange.setProperty("PERSON_ID", id);
    	myProducerTemplate = camelContext.createProducerTemplate();
    	Exchange orchestatedExchange =
cartProducerTemplate.send("direct:start", exchange);

appreciate pointers to resources.



--
View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unit Testing Support for Camel Routes

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use mock libraries such as EasyMock, Mockito, jMock and what
else is out there.


On Mon, Nov 5, 2012 at 3:59 AM, vinayks <vi...@gmail.com> wrote:
> Thanks Henri. I don't want to test the actual route. I have a separate tests to test the routes. I am writing mock junits for the method where I invoke this route.
>
> Thanks,
> Vinay
>
>
>
> On 04-Nov-2012, at 3:05 PM, "Henri Tremblay [via Camel]" <ml...@n5.nabble.com> wrote:
>
>> Hi,
>>
>> Can't you inject the ProducerTemplate instead of creating it directly from
>> the camel context? Then mocking it would be easy. I will suggest to do the
>> same with the CamelContext is you really need to. But a Camel test is
>> usually using a real context in which you put the routes you need.
>>
>> Regard,
>> Henri
>>
>>
>> On 4 November 2012 10:13, vinayks <[hidden email]> wrote:
>>
>> > Hi,
>> >
>> > I would like to unit test my following piece of code. I would like to know
>> > how to mock the ProducerTemplate and CamelContext.
>> >
>> > DefaultExchange exchange = new DefaultExchange(camelContext);
>> >                 //Set the inputs required by the routes as the
>> > properties...
>> >                 exchange.setProperty("PERSON_ID", id);
>> >         myProducerTemplate = camelContext.createProducerTemplate();
>> >         Exchange orchestatedExchange =
>> > cartProducerTemplate.send("direct:start", exchange);
>> >
>> > appreciate pointers to resources.
>> >
>> >
>> >
>> > --
>> > View this message in context:
>> > http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>> >
>>
>>
>> If you reply to this email, your message will be added to the discussion below:
>> http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098p5722105.html
>> To unsubscribe from Unit Testing Support for Camel Routes, click here.
>> NAML
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098p5722115.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Unit Testing Support for Camel Routes

Posted by vinayks <vi...@gmail.com>.
Thanks Henri. I don't want to test the actual route. I have a separate tests to test the routes. I am writing mock junits for the method where I invoke this route.

Thanks,
Vinay



On 04-Nov-2012, at 3:05 PM, "Henri Tremblay [via Camel]" <ml...@n5.nabble.com> wrote:

> Hi, 
> 
> Can't you inject the ProducerTemplate instead of creating it directly from 
> the camel context? Then mocking it would be easy. I will suggest to do the 
> same with the CamelContext is you really need to. But a Camel test is 
> usually using a real context in which you put the routes you need. 
> 
> Regard, 
> Henri 
> 
> 
> On 4 November 2012 10:13, vinayks <[hidden email]> wrote: 
> 
> > Hi, 
> > 
> > I would like to unit test my following piece of code. I would like to know 
> > how to mock the ProducerTemplate and CamelContext. 
> > 
> > DefaultExchange exchange = new DefaultExchange(camelContext); 
> >                 //Set the inputs required by the routes as the 
> > properties... 
> >                 exchange.setProperty("PERSON_ID", id); 
> >         myProducerTemplate = camelContext.createProducerTemplate(); 
> >         Exchange orchestatedExchange = 
> > cartProducerTemplate.send("direct:start", exchange); 
> > 
> > appreciate pointers to resources. 
> > 
> > 
> > 
> > -- 
> > View this message in context: 
> > http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098.html
> > Sent from the Camel - Users mailing list archive at Nabble.com. 
> > 
> 
> 
> If you reply to this email, your message will be added to the discussion below:
> http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098p5722105.html
> To unsubscribe from Unit Testing Support for Camel Routes, click here.
> NAML




--
View this message in context: http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098p5722115.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unit Testing Support for Camel Routes

Posted by Henri Tremblay <he...@gmail.com>.
Hi,

Can't you inject the ProducerTemplate instead of creating it directly from
the camel context? Then mocking it would be easy. I will suggest to do the
same with the CamelContext is you really need to. But a Camel test is
usually using a real context in which you put the routes you need.

Regard,
Henri


On 4 November 2012 10:13, vinayks <vi...@gmail.com> wrote:

> Hi,
>
> I would like to unit test my following piece of code. I would like to know
> how to mock the ProducerTemplate and CamelContext.
>
> DefaultExchange exchange = new DefaultExchange(camelContext);
>                 //Set the inputs required by the routes as the
> properties...
>                 exchange.setProperty("PERSON_ID", id);
>         myProducerTemplate = camelContext.createProducerTemplate();
>         Exchange orchestatedExchange =
> cartProducerTemplate.send("direct:start", exchange);
>
> appreciate pointers to resources.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Unit-Testing-Support-for-Camel-Routes-tp5722098.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>