我的下一条路线是带有一个搜索字词的Bean:
from( receiveProtocol+"://"+ipMailServer+"?username="+username+"&password="+password+"&"+options+"&searchTerm=#allowedAddresses")
搜索字词bean就像是垃圾邮件过滤器:仅接受从发件人列表发送的电子邮件:
@Component
public class SpamFilter {
@Value( "${spring.mailserver.spamfilter}") String spamFilter; // Contains valid senders separated by comma.
@Bean
public SearchTerm allowedAddresses() {
String acceptedAddresses[]= spamFilter.split( ",");
SearchTermBuilder build = new SearchTermBuilder();
for ( int i= 0; i<acceptedAddresses.length; i++)
build= build.from( Op.or, acceptedAddresses[ i].trim());
return build.build();
}
}
一切都可以与路线和搜索词一起使用。我使用Mockito创建了一个单元测试,当路线中不包含搜索词时,该单元测试可以正常工作。我修改了模拟搜索项的测试,并添加了下一行:
@MockBean(name="allowedAddresses") SpamFilter spamFilter;
但是我得到下一个例外:
org.apache.camel.FailedToCreateRouteException: Failed to create route Email: Route(Email)[[From[imap://localhost?username=info@informer.d... because of Failed to resolve endpoint: imap://localhost?closeFolder=false&consumer.delay=10000&delete=false&disconnect=false&password=informer&peek=true&searchTerm=%23allowedAddresses&unseen=true&username=info%40informer.dispocargo.com due to: Could not find a suitable setter for property: searchTerm as there isn't a setter method with same type: java.lang.String nor type conversion possible: No type converter available to convert from type: java.lang.String to the required type: javax.mail.search.SearchTerm with value #allowedAddresses
我认为我在测试中缺少模拟某些方法,或者我错了。任何帮助将不胜感激,谢谢。
答案 0 :(得分:0)
您使用什么版本的骆驼?您是否尝试过使用新版本,因为它闻起来像一个已修复的错误。