1

I have defined my unit test class like this


@RunWith(CamelSpringBootRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("aws-sqs:*")
@DisableJmx(value = false)
@SpringBootTest(classes = {EliteSqsRouteBuilder.class})
@TestPropertySource("classpath:application-local.properties")
public class EliteSqsRouteBuilderTest {
    @Autowired
    CamelContext camelContext;

    @Produce
    ProducerTemplate sqsProducerTemplate;

    @EndpointInject("mock:direct:zfre-ordertypedetermine-infra-dev")
    MockEndpoint finalSink;

    @MockBean
    EliteOrderProcess eliteOrderProcess;

    @Before
    public void setup() throws Exception {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    @DirtiesContext
    public void testSqsInboundRoute() throws Exception {

        AdviceWithRouteBuilder.adviceWith(camelContext, Constant.ELITE_PIPELINE_ROUTE_ID, routeBuilder -> {
            routeBuilder.replaceFromWith("mock:direct:elitepipeline-infra-order-dev");
        });

        //Send mock message to the route
        String expectedBody = "{id:\"123456789\"}";
        ProducerTemplate template = camelContext.createProducerTemplate();
        template.sendBody("direct:start", expectedBody);


        //Assertions. You may do additional assertions with the likes of Mockito
        finalSink.expectedBodiesReceived(expectedBody);
        finalSink.assertIsSatisfied();

    }

}

I am using camel version 3.1 and camel spring boot test is also of version 3.1.

I am getting the following exception

Unsatisfied dependency expressed through field 'camelContext'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 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)}
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.elitepipeline.routes.EliteSqsRouteBuilderTest': Unsatisfied dependency expressed through field 'camelContext'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 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)}

Anyone has any idea how to resolve this.

Atul Agrawal
  • 1,474
  • 5
  • 22
  • 41

0 Answers0