You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Minh Tran <da...@gmail.com> on 2014/05/06 00:51:28 UTC

best way to unit test quartz routes

Hi

Most of my routes start with either direct or jms. So to test I would use the @MockEndpoints and set all my expectations then trigger the route using a ProducerTemplate. But I'm struggling to understand how I can do the same when it's a quartz component at the start of the route.

eg

<from uri="quartz:foo"/>
<to uri="bean:bar"/>

How do you trigger this from the unit test? I'd like to be able to set all my expectations before the route gets triggered.

Re: best way to unit test quartz routes

Posted by Minh Tran <da...@gmail.com>.
Thanks, it did give me some hints.

For anyone else interested, the solution I used was to configure the quartz component to not start the scheduler automatically as follows.

<bean id="quartz2" class="org.apache.camel.component.quartz2.QuartzComponent">
	<property name="autoStartScheduler" value="false"/>
</bean>

In the unit test, inject this component in

@Autowired
private QuartzComponent quartzComponent;

Then during tests, set all expectations first on mocked components as per normal and then call

quartzComponent.getScheduler().start()

No more race conditions!

On 06/05/2014, at 9:43 PM, Claus Ibsen <cl...@gmail.com> wrote:

> On Tue, May 6, 2014 at 1:36 PM, Minh Tran <da...@gmail.com> wrote:
>> No one else unit tests their quartz routes?
>> 
> 
> Well Camel tests its own components. So maybe take a peak there
> https://github.com/apache/camel/tree/master/components/camel-quartz/src/test
> 
>> On 06/05/2014, at 8:51 AM, Minh Tran <da...@gmail.com> wrote:
>> 
>>> Hi
>>> 
>>> Most of my routes start with either direct or jms. So to test I would use the @MockEndpoints and set all my expectations then trigger the route using a ProducerTemplate. But I'm struggling to understand how I can do the same when it's a quartz component at the start of the route.
>>> 
>>> eg
>>> 
>>> <from uri="quartz:foo"/>
>>> <to uri="bean:bar"/>
>>> 
>>> How do you trigger this from the unit test? I'd like to be able to set all my expectations before the route gets triggered.
>> 
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/


Re: best way to unit test quartz routes

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, May 6, 2014 at 1:36 PM, Minh Tran <da...@gmail.com> wrote:
> No one else unit tests their quartz routes?
>

Well Camel tests its own components. So maybe take a peak there
https://github.com/apache/camel/tree/master/components/camel-quartz/src/test

> On 06/05/2014, at 8:51 AM, Minh Tran <da...@gmail.com> wrote:
>
>> Hi
>>
>> Most of my routes start with either direct or jms. So to test I would use the @MockEndpoints and set all my expectations then trigger the route using a ProducerTemplate. But I'm struggling to understand how I can do the same when it's a quartz component at the start of the route.
>>
>> eg
>>
>> <from uri="quartz:foo"/>
>> <to uri="bean:bar"/>
>>
>> How do you trigger this from the unit test? I'd like to be able to set all my expectations before the route gets triggered.
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: best way to unit test quartz routes

Posted by Minh Tran <da...@gmail.com>.
No one else unit tests their quartz routes? 

On 06/05/2014, at 8:51 AM, Minh Tran <da...@gmail.com> wrote:

> Hi
> 
> Most of my routes start with either direct or jms. So to test I would use the @MockEndpoints and set all my expectations then trigger the route using a ProducerTemplate. But I'm struggling to understand how I can do the same when it's a quartz component at the start of the route.
> 
> eg
> 
> <from uri="quartz:foo"/>
> <to uri="bean:bar"/>
> 
> How do you trigger this from the unit test? I'd like to be able to set all my expectations before the route gets triggered.