Camel endpoint not mocked

Viewed 1015

I've a simple camel route and want to test it, but instead of the MockEndpoint the real Endpoint is called:

import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;
    
@Component
@Slf4j
public class ProcessingRoute extends RouteBuilder {

    @Override
    public void configure() {

        from("direct:processKafkaMessage")
                .to("file:output");

        }
}

My test:

import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.camel.test.spring.junit5.MockEndpoints;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;

@ActiveProfiles("test")
@CamelSpringBootTest
@SpringBootTest()
@ContextConfiguration
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@MockEndpoints("file:output")
class ProcessingRouteIT {

    @Autowired
    private CamelContext camelContext;

    @Produce("direct:processKafkaMessage")
    private ProducerTemplate mockKafkaProducer;

    @EndpointInject("mock:file:output")
    private MockEndpoint mockCamel;

    @Test
    void processMessage_successful() throws Exception {
        mockCamel.expectedBodiesReceived("foo");
        mockKafkaProducer.sendBodyAndHeaders("foo", Collections.emptyMap());
        mockCamel.assertIsSatisfied();
    }

}

It's perfeclty fine if I use this code in a simple example project with nothing more inside. But when I put it in my application that has some more routes and other stuff inside, it does not mock the endpoint and write to the file instead.

13:58:09.579  INFO [main] o.a.c.t.s.j.CamelAnnotationsHandler      - Enabling auto mocking of endpoints matching pattern [file:output] on CamelContext with name [camelContext].
13:58:57.010  INFO [main] .i.e.InterceptSendToMockEndpointStrategy - Adviced endpoint [file://output] with mock endpoint [mock:file:output]

14:14:21.969  INFO [main] c.t.s.j.CamelSpringBootExecutionListener - CamelSpringBootExecutionListener before: class ProcessingRouteIT.processMessage_successful
14:14:21.971  INFO [main] c.t.s.j.CamelSpringBootExecutionListener - Initialized CamelSpringBootExecutionListener now ready to start CamelContext
14:14:26.953  INFO [main] o.a.camel.component.mock.MockEndpoint    - Asserting: mock://file:output is satisfied

I'm using in both applications the same versions of camel (3.3.0) and spring boot (2.3.1.RELEASE). Any Idea? I don't get it...

java.lang.AssertionError: mock://file:output Received message count. Expected: <1> but was: <0>
Expected :<1>
Actual   :<0>
0 Answers
Related