0
votes

How can I unit-test (using JUnit) an Apache Camel route defined in a Spring context file?

Since a Spring context file could have several other routes and bean definitions, I want to isolate just this route and initialize just the beans that it refers to.

The topic Test time exclusion on the Camel-Spring page discusses this scenario, but it applies to Route Builders defined in Java (not in Spring).

I'm using Camel 2.6

2

2 Answers

3
votes

You cannot, Spring loads all the beans from its file. You would need to separate your spring stuff into multiple xml files, and then only load the xml files you need to test.

0
votes

I'm not sure you can unit test one route the way you want.
Regarding exclusion, you can achieve it by annotating test class with:

@SpringBootTest(
        webEnvironment = SpringBootTest.WebEnvironment.NONE,
        properties = {
                "camel.springboot.xmlRoutes=false",
                "camel.springboot.javaRoutesExcludePattern=com/custompackage/**"
        })