我正在使用CamelTestSupport进行测试,
public class TestIntegrationBeanCtrlContrat extends CamelTestSupport {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:start")
protected ProducerTemplate template;
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
this.from("direct:start")
.bean(MyClassA.class, "methodOfMyClassA").to("mock:result");
}
};
}
@Test
public void test_ControleBean_Integration() {
this.template.sendBody(....);
}
我正在尝试将另一个 bean 的主体放入生产者模板中,例如:
template.sendBody( bean(MyClassB.class, "methodOfMyClassB") )
可以做到吗?
一般来说,我该怎么做才能在生产中设置输入。
我不确定我是否理解您的需求,但是如果您想在路由过程中注入某些 bean 的结果,您应该使用 Camel Mock 注入 bean 进程(在您的示例中为 MyClassB.methodOfMyClassB()):
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:start")
protected ProducerTemplate template;
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").bean("BeanA", "methodA").to("mock:beanB").to("mock:result");
}
};
}
@Test
public void test() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:beanB");
mock.whenAnyExchangeReceived(new Processor() {
public void process(Exchange exchange) throws Exception {
// call the method of your class here
exchange.getIn().setBody(MyClassB.methodOfMyClassB());
}
});
template.sendBody("Your message body...");
// check some results
mock.assertIsSatisfied();
}