返回值我在我的服务提出了以下路线:骆驼:模拟和组件的路线
public void configure() {
/*
* Scheduled Camel route to produce a monthly report from the audit table.
* This is scheduled to run the first day of every month.
*/
// @formatter:off
from(reportUri)
.routeId("monthly-report-route")
.log("Audit report processing started...")
.to("mybatis:updateProcessControl?statementType=Update")
.choice()
/*
* If the rows updated is 1, this service instance wins and can run the report.
* If the rows updated is zero, go to sleep and wait for the next scheduled run.
*/
.when(header("CamelMyBatisResult").isEqualTo(1))
.process(reportDateProcessor)
.to("mybatis:selectReport?statementType=SelectList&consumer.routeEmptyResultSet=true")
.process(new ReportProcessor())
.to("smtp://smtpin.tilg.com?to="
+ emailToAddr
+ "&from=" + emailFromAddr)
.id("RecipientList_ReportEmail")
.endChoice()
.end();
// @formatter:on
}
当我尝试在此运行测试它给了我一个错误,说明骆驼不能自动创建组件的MyBatis 。我对测试骆驼路线没有经验,所以我不完全确定该去哪里。第一个mybatis调用更新表中的一行,该行不在测试中,所以我希望做类似于端点被命中时的情况,返回值为1的CamelMyBatisResult头。第二个mybatis端点应该返回一个hashmap(第一个测试为空,第二个为填充)。我如何去执行骆驼测试的何时何种机制?我已经看过模拟端点骆驼文档,但我无法弄清楚如何应用它,并让它向交易所返回一个值,然后继续该路线(测试的最终结果是检查是否有电子邮件或不具有附接被发送)
编辑:使用两个替换()尝试设置*的方法和与呼叫替换的MyBatis端点内联的处理器:
@Test
public void test_reportRoute_NoResultsFound_EmailSent() throws Exception {
List<AuditLog> bodyList = new ArrayList<>();
context.getRouteDefinition("monthly-report-route").adviceWith(context,
new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith(TEST);
weaveById("updateProcControl").replace()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("CamelMyBatisResult", 1);
}
});
weaveById("selectReport").replace()
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(bodyList);
}
});
weaveById("RecipientList_reportEmail").replace()
.to("smtp://localhost:8083"
+"?to=" + "[email protected]"
+"&from=" + "[email protected]");
}
});
ProducerTemplate prod = context.createProducerTemplate();
prod.send(TEST, exch);
assertThat(exch.getIn().getHeader("CamelMyBatisResult"), is(1));
assertThat(exch.getIn().getBody(), is(""));
}
迄今为止,标题是仍然空(TEST变量是一个直接组件)
你能后你的错误?堆栈跟踪? –
自动创建东西并不是真正的问题;我想嘲笑那些端点并返回响应,因为它不是那些直接被测试的端点,所以我没有真正关心如何创建mybatis组件 – jbailie1991
在这种情况下,为每个.to()设置一个.id() )然后你拦截,替换。并设置硬编码的响应值。请参阅advicewith进行测试.. http://camel.apache.org/advicewith.html –