没有嘲笑骆驼端点

时间:2020-08-13 12:18:38

标签: java spring-boot apache-camel spring-camel

我有一条简单的骆驼路线,想对其进行测试,但是真正的端点不是MockEndpoint,而是:

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");

        }
}

我的测试:

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();
    }

}

如果我在一个简单的示例项目中使用此代码,而里面没有更多内容,那就完美了。但是,当我将其放入具有更多路由和其他内容的应用程序中时,它不会模拟端点并写入文件。

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

我在两个应用程序中都使用了相同版本的骆驼(3.3.0)和弹簧靴(2.3.1.RELEASE)。 任何想法?我不明白...

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

0 个答案:

没有答案