dermoritz
dermoritz

Reputation: 13038

How to test a Camel in Spring Boot Camel project - all @EndpointInject are null but @Autowired working?

I have a yet very simple Spring Boot (2.5.1)/ Apache Camel (3.10.0) Application and i am struggling creating a simple test. In my case it even fails to inject endpoints:

So my first simple try is to get this green:

@CamelSpringBootTest
class UnmarshalXmlTest {

    @EndpointInject("mock:out")
    MockEndpoint outEndpoint;
    
    @Produce("direct:in")
    ProducerTemplate template;
    
    @Test
    void test() {
        assertNotNull(outEndpoint);
        assertNotNull(template);
    }

}

But it is red. Sadly the documentation is outdated (uses deprecated SingleRouteCamelConfiguration) and it is also not showing how to test a given route. The other doc is also not helping (using @CamelSpringTest instead is not helping).

It seems that spring annotations are working - adding stuff via @Autowired works!

This answer suggests that it should just work?! So how to get the camel annotations picked up and working?

Upvotes: 0

Views: 1004

Answers (1)

Greenev
Greenev

Reputation: 909

It seems that you also need @SpringBootTest annotation to get it solved

@CamelSpringBootTest
@SpringBootTest
class UnmarshalXmlTest {
    ...
}

Upvotes: 1

Related Questions