【发布时间】:2017-09-09 21:38:57
【问题描述】:
我查看了 Camel In Action 2 Chapter-9 示例,并查看了 previous question 和 this user-group thread,但仍然卡住...
我正在使用 Spring-boot 和 Camel 2.18.x 我正在尝试将这两个 examples from Camel sample code 合二为一: to mockEndpoint 和 replaceFrom
工作场景:
- 我直接创建测试路由-->seda
- 我使用 Advicewith,并模拟所有端点
- 我的测试工作正常
工作场景:
- 我改变了目的地,直接-->jms
- 最后我得到一个异常,并看到 JMS 未能创建会话。
期望:我假设 JMS 将被 mock 取代,并且日志似乎表明了这一点。不确定为什么要调用 JMSProducer。这是预期的行为吗?
示例路线:
from("direct:start")
.id("testroute")
.log("${body}")
//.to("seda:finish") //This works okay
.to("jms:XYZ_Q")
;
单元测试类:
@RunWith(CamelSpringBootRunner.class)
@MockEndpoints
@UseAdviceWith
@SpringBootTest(classes = {UnitTestApplication.class, SampleTest.class})
public class SampleTest {
@Autowired
private CamelContext camelContext;
@Autowired
private ProducerTemplate producerTemplate;
@Test
public void test01() throws Exception {
RouteDefinition route = camelContext.getRouteDefinition("testroute");
AdviceWithRouteBuilder adviceWithRB = new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:renamed");
}
};
route.adviceWith(camelContext, adviceWithRB);
camelContext.start();
producerTemplate.sendBody("direct:renamed", " 8888888820130601");
}
}
我预计 JMS 组件不会尝试做任何事情,而是会被 mock 替换。这是不是一个错误的理解?
【问题讨论】:
标签: apache-camel