我使用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") )
有可能吗?
一般情况我该怎么做才能在produceTemplace中设置输入。
答案 0 :(得分:2)
我不确定我是否理解你的需求,但如果你想在路由过程中注入一些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();
}