0
我有以下途径:如何测试一个自定义的处理器 - Apache的骆驼弹簧试验
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:topic:inbox" />
<log message="To: ${in.header.recipients}" />
<to uri="bean:myLogger" />
</route>
</camelContext>
bean:myLogger
是我格式化我得到的日志信息定制处理器。我的自定义处理器中的process
方法只是调用附加消息类型(例如CC)和收件人电子邮件的私有方法。我正在努力研究如何测试实际产生的日志。我使用CamelSpringTestSupport
,我OK,当谈到测试myLogger端点:
@Produce(uri = "activemq:topic:inbox")
protected ProducerTemplate template;
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("file:src/main/resources/my-camel-context.xml");
}
@Test
public void testLogEndpoint() throws Exception {
String body = "Hello World";
template.sendBody("activemq:topic:inbox", body);
LOG.info("This is the message body we sent {} ", body);
}
不过,我真的不知道如何测试返回日志的格式。我是否以与上例类似的方式发送收件人的电子邮件?但是,如何检查格式是否正确?我真的比实际解决方案更注重这种方法。
非常感谢你的帮助,
一
嗨,克劳斯,谢谢你的回复。当你说在记录器中独立于bean创建日志格式时,你的意思是在路由中设置类似于 其中methodThatFormatsLogs是受保护的/自定义处理器中的私有方法格式化日志?谢谢 –
paranza
在bean中只有两种方法,一种是格式化日志消息,另一种是调用第一种方法,然后记录消息。然后,您可以测试第一种方法,并使用骆驼路线中的第二种方法。 –
谢谢,我明白你的意思了。这个问题来自于我的“格式化”方法实际上是一个无效的情况,当符合if条件时,只需写入LOG.info(“{} some text”,arg1,arg2)。 – paranza