gpt4 book ai didi

java - 使用 @SpringBootTest 进行 Spring Boot 和 Camel 测试

转载 作者:行者123 更新时间:2023-12-02 12:19:20 30 4
gpt4 key购买 nike

我有 Spring Boot 应用程序,Spring Boot 版本为 1.5.8,还有 camel 2.20.1

简单路线:

@Component
public class MyRoute extends RouteBuilder {

public static final String IN = "file://in";

public static final String OUT = "file://out";

@Override
public void configure() throws Exception {
from(IN).routeId("myId").to(OUT);
}
}

简单测试:

//@SpringBootTest
public class MyRouteTest extends CamelTestSupport {


@Produce(uri = MyRoute.IN)
private ProducerTemplate producerTemplate;

@EndpointInject(uri = "mock:file:out")
private MockEndpoint mockEndpointOut;

@Override
public String isMockEndpoints() {
return "*";
}

@Test
public void simpleTest() throws Exception {
mockEndpointOut.expectedMessageCount(1);
producerTemplate.sendBody("Test");
mockEndpointOut.assertIsSatisfied();
}

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new MyRoute();
}

}

当我运行此测试时,它运行良好,我收到一条消息并且端点满意。如果我添加@SpringBootTest注解,测试失败?为什么 ?另外,当我运行 maven clean install 时,如果没有注释,它也会失败:(

有人知道这个注释对 Camel 测试有什么作用,或者我如何调整它才能工作?

谢谢

最佳答案

这是最后的效果:

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints
public class MyRouteTest2 {

@Autowired
private ProducerTemplate producerTemplate;

@EndpointInject(uri = "mock:file:out")
private MockEndpoint mockCamel;

@Test
public void test() throws InterruptedException {
String body = "Camel";
mockCamel.expectedMessageCount(1);

producerTemplate.sendBody("file:in", body);

mockCamel.assertIsSatisfied();
}
}

关于java - 使用 @SpringBootTest 进行 Spring Boot 和 Camel 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47796388/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com