Reputation: 8360
I am writing unit test for Camel route. I need to use @SpringBootTest so that I can also use @TestPropertySource. I have several property file mapped property classes.
My test code looks like this
@SpringBootTest(classes = {CamelAutoConfiguration.class})
@RunWith(CamelSpringBootRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:application-test.yml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ContextConfiguration(classes = {ApplicationConfig.class, SFTPConfig.class, CamelTestContextBootstrapper.class})
@EnableConfigurationProperties
public class RouteBuilderTest
{
@Autowired
private CamelContext camelContext;
I have added below dependency also as I am using junit4 in project.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<scope>test</scope>
</dependency>
Autowiring of CamelContext fails. With standard spring error.
No qualifying bean of type 'org.apache.camel.CamelContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Please help. Badly stuck on this.
Upvotes: 0
Views: 929
Reputation: 7656
You have multiple misused annotations in your test. Try this way:
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest(classes = {ApplicationConfig.class, SFTPConfig.class})
@ActiveProfiles("test")
@TestPropertySource(locations = "classpath:application-test.yml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class RouteBuilderTest
{
@Autowired
private CamelContext camelContext;
Upvotes: 1