testing routes when using spring boot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

testing routes when using spring boot

129073.d.0002
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 :(
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

Minh Tran-2
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 <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

129073.d.0002
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

Minh Tran-2
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 <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

129073.d.0002
In reply to this post by 129073.d.0002
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.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

Minh Tran-2
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 <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

129073.d.0002
This post has NOT been accepted by the mailing list yet.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeConverter' defined in class path resource [org/apache/camel/spring/boot/TypeConversionConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.camel.TypeConverter]: Factory method 'typeConverter' threw exception; nested exception is java.lang.NullPointerException
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: testing routes when using spring boot

129073.d.0002
This post has NOT been accepted by the mailing list yet.
There was something in my project configuration, I guess.

Started from scratch and now it works as expected.

Sorry for trouble. I was first confused by maven repo not recognising
https://mvnrepository.com/search?q=CamelSpringBootRunner

Loading...