Hi 

We are moving our Camel/ActiveMQ services from Karaf bundles with Spring 3 and 
XML-Config to Spring-Boot with Spring 4 and Java -Config. 

I have built a very small prototype of such a Spring Boot application with a 
Camel route and the corresponding route test. I would like to know if this is 
"state of the art" to build Camel routes and tests in Spring Boot or if this 
example still could be simplified or contains old concepts that could be 
replaced with a successor concept.

We use Spring Boot 1.4.2, Spring 4.3.4 and Camel 2.17.3

I followed http://camel.apache.org/spring-boot.html and 
http://camel.apache.org/spring-testing.html to build the example.

Thanks a lot
Stephan


**** Pom.xml dependencies ****
<!-- camel -->
<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-spring-javaconfig</artifactId>
</dependency>
<!-- test scope -->
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
</dependency>
<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-test-spring</artifactId>
        <scope>test</scope>
</dependency>

**** Route class ****
package prototype;
@Component
public class Route extends SpringRouteBuilder {
    @Autowired
    private CamelContext camelContext;

    @Override
    public void configure() {
        from("direct:route")
                .routeId("route")
                .to("mock:destination");
    }
}

**** Route test class ****
package prototype;
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(classes = { RouteTest.TestConfig.class}, loader = 
CamelSpringDelegatingTestContextLoader.class)
public class RouteTest {
    @Autowired
    protected CamelContext camelContext;

    @EndpointInject(uri = "mock:destination")
    protected MockEndpoint destination;

    @Produce(uri = "direct:route")
    protected ProducerTemplate producer;

    @Test
    @DirtiesContext
    public void testContextStartup() throws Exception {
        destination.expectedMessageCount(2);
        destination.expectedBodiesReceived("test1", "test2");

        producer.sendBody("test1");
        producer.sendBody("test2");

        destination.assertIsSatisfied();
    }

    @Configuration
    @ComponentScan("prototype")
    public static class TestConfig extends CamelConfiguration {
    }
}

Reply via email to