我正在尝试编写一个 SpringBootTest 来测试 Camel 路由。我的路线是这样的:
restConfiguration().producerComponent("http4")
.host("http://127.0.0.1);
from("rabbitmq:foo")
.to(rest:post")
.log("Hello!: ${body}");
这是我的测试:
@RunWith(CamelSpringRunner.class)
@MockEndpoints
@UseAdviceWith
@SpringBootTest
public class SimpleCamelRouteTest extends CamelTestSupport {
@EndpointInject(uri = "mock:rest")
private MockEndpoint mockEndpoint;
@Autowired
CamelContext context;
@Autowired
ProducerTemplate template;
@Before
public void setUp() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
interceptSendToEndpoint("rabbitmq:foo")
.skipSendToOriginalEndpoint()
.to("mock:foo");
interceptSendToEndpoint("http://*")
.skipSendToOriginalEndpoint()
.to("mock:rest");
}
});
context.start();
}
@Test
public void test() throws InterruptedException {
String body = "Camel";
mockEndpoint.expectedMessageCount(1);
template.sendBody("mock:foo", body);
mockEndpoint.assertIsSatisfied();
}
}
看起来它正试图在启动时连接到一个真正运行的 RabbitMq 实例:(
18-08-2019 13:20:07.729 [Camel (camel-1) thread #3 - RabbitMQConsumer] INFO o.a.c.c.rabbitmq.RabbitMQConsumer.call - Connection failed, will retry in 5000ms
java.net.ConnectException: 连接被拒绝 (Connection refused)
任何人都可以给我一些建议,告诉我如何告诉我的 SpringBootTest 不要寻找正在运行的代理并尊重我设置的模拟(假设模拟设置正确。)
白衣非少年
相关分类