You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by biphasic <gr...@neovahealth.co.uk> on 2015/10/15 18:01:12 UTC

How to test routes when using another TestRunner

Hello,
I have a few tests to check my Camel routes that when run using the
SpringJUnit4ClassRunner work just fine. However, I want to test some routes
of my application with Cucumber (basically something similar to JUnit). This
requires me to use another TestRunner (Cucumber.class). When trying to call
my tests from a Cucumber stack, the class that extends
CamelSpringTestSupport will not set any form of context. It just skips
createApplicationContext(). I am still able to access beans though.

What I now did as an ugly fix was to set the context manually.

this.context = new
ClassPathXmlApplicationContext("classpath:context.xml").getBean("camelContext");

I can now send something to endpoints, can access beans and whatnot. But the
assertion of expectedMessages at my MockEndpoint still always fails. 

Is there something else that I manually have to recreate when extending
CamelSpringTestSupport and I cannot use the SpringJUnitClassRunner?

Thankful for any hints,
Cheers



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to test routes when using another TestRunner

Posted by biphasic <gr...@neovahealth.co.uk>.
Hey souciance, 
please feel free to look at the code which I uploaded yesterday since I think it's interesting for more people: https://github.com/NeovaHealth/ARNIE 

Have a look at the CamelConnector class. In World() in the stepDefinitions I create a test environment that sets up its own context with this.setUp(). 

For the tests you currently need a Postgresql endpoint. I'm working on disentangling this at the time. 
Kind regards, 
Greg 

Kind regards, 
Gregor Lenz 
Developer, Neova Health 
Office: 0845 003 9159 


----- Original Message -----

From: "souciance [via Camel]" <ml...@n5.nabble.com> 
To: "biphasic" <gr...@neovahealth.co.uk> 
Sent: Sunday, 8 November, 2015 10:48:06 PM 
Subject: Re: How to test routes when using another TestRunner 

Hi Greg, 

I am also trying to get cucumber working with camel, any chance you can share the snippet you added to get it to work? Thanks 
Souciance 


If you reply to this email, your message will be added to the discussion below: 
http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5773514.html 
To unsubscribe from How to test routes when using another TestRunner, click here . 
NAML 





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5773566.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to test routes when using another TestRunner

Posted by souciance <so...@gmail.com>.
Hi Greg,

I am also trying to get cucumber working with camel, any chance you can
share the snippet you added to get it to work? Thanks
Souciance



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5773514.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to test routes when using another TestRunner

Posted by souciance <so...@gmail.com>.
I got it to finally work. Thanks a lot!

Essentially you need to add this.setUp(); in the method that exist in the
class that extends CamelBlueprintTestSupport.

Then, your cucumber methods simply call the method..and that seems to do the
trick.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5773748.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to test routes when using another TestRunner

Posted by biphasic <gr...@neovahealth.co.uk>.
Thank you very much shuston and dermoritz,
It works now after I set the ApplicationContext as well! This enabled me to
find an even easier method: I just run
this.setUp()
a method included in CamelTestSupport and therefore SpringCamelTestSupport.
It creates Context() and ApplicationContext() and works with the Cucumber
stack as well. Really happy this works now. 
Cheers,
Greg



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5772710.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to test routes when using another TestRunner

Posted by dermoritz <ta...@hotmail.com>.
Probably it is enough to use

CamelContext context = new DefaultCamelContext();

This will create one with a JNDI-Registry (you have to register the beans
you need in test). Or u can use

CamelContext context = new DefaultCamelContext(new SimpleRegistry());

This registry is a simple map where you register the beans. 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-test-routes-when-using-another-TestRunner-tp5772687p5772708.html
Sent from the Camel - Users mailing list archive at Nabble.com.

RE: How to test routes when using another TestRunner

Posted by Steve Huston <sh...@riverace.com>.
I am a relative novice in this area, but I did have some tests running in Cucumber. To get the applicationcontext, see this stack overflow question: http://stackoverflow.com/questions/4914012/how-to-inject-applicationcontext-itself

Once you have that, you can get the CamelContext like:

CamelContext ctx = applicationContext.getBean("camel-context-name", CamelContext.class);

-Steve

> -----Original Message-----
> From: biphasic [mailto:gregorlenz@neovahealth.co.uk]
> Sent: Thursday, October 15, 2015 12:01 PM
> To: users@camel.apache.org
> Subject: How to test routes when using another TestRunner
> 
> Hello,
> I have a few tests to check my Camel routes that when run using the
> SpringJUnit4ClassRunner work just fine. However, I want to test some routes
> of my application with Cucumber (basically something similar to JUnit). This
> requires me to use another TestRunner (Cucumber.class). When trying to call
> my tests from a Cucumber stack, the class that extends
> CamelSpringTestSupport will not set any form of context. It just skips
> createApplicationContext(). I am still able to access beans though.
> 
> What I now did as an ugly fix was to set the context manually.
> 
> this.context = new
> ClassPathXmlApplicationContext("classpath:context.xml").getBean("camelC
> ontext");
> 
> I can now send something to endpoints, can access beans and whatnot. But
> the assertion of expectedMessages at my MockEndpoint still always fails.
> 
> Is there something else that I manually have to recreate when extending
> CamelSpringTestSupport and I cannot use the SpringJUnitClassRunner?
> 
> Thankful for any hints,
> Cheers
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-
> test-routes-when-using-another-TestRunner-tp5772687.html
> Sent from the Camel - Users mailing list archive at Nabble.com.