【发布时间】:2012-12-04 10:32:02
【问题描述】:
我有编写组件(端点)的骆驼项目。它用于路由 (mycomponent:somename) 我的路由单元测试在组件完成后开始失败。 (它使用一些与自己的客户端编写的http通信)我可以根据“无法连接到服务器......”,“无法读取属性......”看到错误。
所以,看起来端点没有被我用于此目的的直接替换。 我需要的,真正的路由单元测试,我不需要启动web服务来运行一些测试,应该只是路由测试。
示例代码:
public class MyTest extends CamelTestSupport {
@Override
public String isMockEndpoints() {
return "*";
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
includeRoutes(new MyRoute());
}
};
}
@Test
public void testRouteToRd() throws Exception {
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:incomponent"); // replacing from
}
});
getMockEndpoint("mock:myconnector:outcomponent").expectedMessageCount(1);
template.sendBody("direct:incomponent", OK_MESSAGE); // and sending to direct
assertMockEndpointsSatisfied();
}
}
为什么我开始使用这个配置来打真正的组件(在组件完成之前它运行良好) 谁能帮忙,谢谢。
我很抱歉,但复制粘贴和“玩”配置对我有帮助。替换了
@Override
public String isMockEndpoints() {
return "*";
}
与:
@Override
public String isMockEndpointsAndSkip() {
return "*";
}
现在我所有的测试都很好。但是仍然不明白为什么会这样,我用直接替换端点并将消息发送到直接(不是真实的)
所以,非常抱歉,如果不是好问题,请关闭。
【问题讨论】:
标签: java routing apache-camel