You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "129073.d.0002" <un...@icloud.com> on 2017/03/21 00:15:37 UTC

testing routes when using spring boot

I found this Camel Spring Boot test

"https://github.com/apache/camel/tree/master/examples/camel-example-spring-boot".

It uses test setup:

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(classes = SampleCamelApplication.class)
public class SampleCamelApplicationTest {

    @Autowired
    private CamelContext camelContext;


I can't find a maven package (dependency) that includes
CamelSpringBootRunner.class .

What would be best practise way to get CamelContex when using
@RunWith(SpringRunner.class)?

Camel in Action 2ed does not help with testing in Spring Boot context :(



--
View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: testing routes when using spring boot

Posted by Minh Tran <da...@gmail.com>.
Have you got the right camel version? From memory, this class is fairly new so that could explain the missing class problem.

As to the missing CamelContext bean, sounds like it isn’t being created automatically and that could be because Spring Boot isn’t doing it’s magic with the CamelAutoConfiguration class. You can easily verify this by enabling debug logging in Spring Boot. On startup it lists what it is auto configuring and which one it has skipped and why.

Also don’t forget to add the @EnableAutoConfiguration on a Configuration bean somewhere in your tests. This is what tells Spring Boot to autoconfigure.

> On 21 Mar 2017, at 11:36 am, 129073.d.0002 <un...@icloud.com> wrote:
> 
> I have camel-test-spring in my pom but class not found. And I tried @Autowire
> CamelContext but component does not exist.
> 
> So I keep on debugging my setup.
> 
> Thanks for your answer, now I know that there is something else wrong with
> my project.
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812p5795814.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: testing routes when using spring boot

Posted by Minh Tran <da...@gmail.com>.
Try enabling debug logging on org.springframework.boot and see whether it is skipping the CamelAutoConfiguration class and why.

> On 21 Mar 2017, at 12:01 pm, 129073.d.0002 <un...@icloud.com> wrote:
> 
> I have this dependency in my pom
> 
> 		<dependency>
> 			<groupId>org.apache.camel</groupId>
> 			<artifactId>camel-spring-boot-starter</artifactId>
> 			<version>2.18.3</version>
> 		</dependency>
> 
> but when I tried to list all spring components, there is no CamelContext
> -component !?
> 
> I use 
> 
> @SpringBootApplication
> public class CamelSpringbootDemoApplication {
> ...
> 
> and that includes autoConfig.
> 
> 
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812p5795816.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


Re: testing routes when using spring boot

Posted by "129073.d.0002" <un...@icloud.com>.
I have this dependency in my pom

		<dependency>
			<groupId>org.apache.camel</groupId>
			<artifactId>camel-spring-boot-starter</artifactId>
			<version>2.18.3</version>
		</dependency>

but when I tried to list all spring components, there is no CamelContext
-component !?

I use 

@SpringBootApplication
public class CamelSpringbootDemoApplication {
...

and that includes autoConfig.






--
View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812p5795816.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: testing routes when using spring boot

Posted by "129073.d.0002" <un...@icloud.com>.
I have camel-test-spring in my pom but class not found. And I tried @Autowire
CamelContext but component does not exist.

So I keep on debugging my setup.

Thanks for your answer, now I know that there is something else wrong with
my project.



--
View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812p5795814.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: testing routes when using spring boot

Posted by Minh Tran <da...@gmail.com>.
Hi

You can find it in the camel-test-spring.jar. So add that dependency in your pom.

The way to get the camel context would be just to inject it in just like any other spring bean. For example:

@Autowired
private CamelContext context;

> On 21 Mar 2017, at 11:15 am, 129073.d.0002 <un...@icloud.com> wrote:
> 
> I found this Camel Spring Boot test
> 
> "https://github.com/apache/camel/tree/master/examples/camel-example-spring-boot".
> 
> It uses test setup:
> 
> @RunWith(CamelSpringBootRunner.class)
> @SpringBootTest(classes = SampleCamelApplication.class)
> public class SampleCamelApplicationTest {
> 
>    @Autowired
>    private CamelContext camelContext;
> 
> 
> I can't find a maven package (dependency) that includes
> CamelSpringBootRunner.class .
> 
> What would be best practise way to get CamelContex when using
> @RunWith(SpringRunner.class)?
> 
> Camel in Action 2ed does not help with testing in Spring Boot context :(
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/testing-routes-when-using-spring-boot-tp5795812.html
> Sent from the Camel - Users mailing list archive at Nabble.com.