在骆驼语境中,我的路线定义如下:
(?<=TITLE\|prefix=)[\w]+|(?<=[\w]+\|suffix=)[\w]+
路由运行良好,并可以拨打服务器。我想测试此路由并检查标题,但是我有问题。
这是一个春季项目,所以我的测试类如下:
from("direct:getPets")
.routeId("getPets")
.to("http://localhost:4321/pets")
交换失败并返回空指针。
@RunWith(CamelSpringBootRunner.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.After_EACH_TEST_METHO)
@UseAdviceWith
public class TestRestEndpoint {
@Autowired
private CamelContext camelContext;
@Produce(uri = "direct:getPets")
private ProducerTemplate callServer;
@EndpointInject(uri = "mock:catchTestEndpoint")
@Test
public void should_return_json() throws Exception {
camelContext.getRouteDefinitions("getPets").adviceWith(camelContext, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddLast().to("mock:catchTestEndpoint");
}
});
camelContext.start();
callServer.sendBody("");
mockEndpoint.expectedMessageCount(1);
mockEndpoint.assertIsSatisfied();
}
}
答案 0 :(得分:0)
听起来像您附加的模拟音是null
。
如果问题中的代码确实是您的代码,则可能是因为端点URI中有错字。
请注意t
中“捕获”和“测试”之间多余的mock:catchtTestEndpoint