我正在尝试编写SpringBootTest来测试骆驼路线。我的路线如下:
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:连接被拒绝(连接被拒绝)
有人可以向我提供一些建议,告诉他们如何告诉我的SpringBootTest不要寻找正在运行的代理并尊重我已设置的模拟(假设模拟已正确设置)。
谢谢
答案 0 :(得分:1)
您正在尝试用from
拦截使用者(interceptSendToEndpoint
)。这是不可能的。为此,您需要replaceFromWith
。
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:triggerFoo");
//...
}
});
然后触发这样的路由:
template.sendBody("direct:triggerFoo", body);
您也正在拦截http4
生产者,但从您的路线看来,您似乎可能想拦截rest*
。