Pax考试karaf 4.0.7使用模拟javamail

时间:2017-07-18 13:13:02

标签: java junit apache-camel karaf pax-exam

我想在pax考试环境中使用javamail-mock2,但问题是pax考试无法从测试中看到META-INF文件夹。如何将javamail.providers文件添加到javamail-mock2将看到配置文件并加载模拟提供程序的套件中?

MP

DEBUG: JavaMail version 1.5.5
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map

测试/ JAVA /资源/ META-INF / javamail.providers

protocol=mock_smtp; type=transport; class=de.saly.javamail.mock2.MockTransport; vendor=JavaMail Mock2 provider;
protocol=mock_smtps; type=transport; class=de.saly.javamail.mock2.MockTransport; vendor=JavaMail Mock2 provider;
protocol=mock_pop3; type=store; class=de.saly.javamail.mock2.POP3MockStore; vendor=JavaMail Mock2 provider;
protocol=mock_imap; type=store; class=de.saly.javamail.mock2.IMAPMockStore; vendor=JavaMail Mock2 provider;
protocol=mock_pop3s; type=store; class=de.saly.javamail.mock2.POP3SSLMockStore; vendor=JavaMail Mock2 provider;
protocol=mock_imaps; type=store; class=de.saly.javamail.mock2.IMAPSSLMockStore; vendor=JavaMail Mock2 provider;
#Override real providers
protocol=smtp${mock.postfix}; type=transport; class=de.saly.javamail.mock2.MockTransport; vendor=JavaMail Mock2 provider;
protocol=smtps${mock.postfix}; type=transport; class=de.saly.javamail.mock2.MockTransport; vendor=JavaMail Mock2 provider;
protocol=pop3${mock.postfix}; type=store; class=de.saly.javamail.mock2.POP3MockStore; vendor=JavaMail Mock2 provider;
protocol=imap${mock.postfix}; type=store; class=de.saly.javamail.mock2.IMAPMockStore; vendor=JavaMail Mock2 provider;
protocol=pop3s${mock.postfix}; type=store; class=de.saly.javamail.mock2.POP3SSLMockStore; vendor=JavaMail Mock2 provider;
protocol=imaps${mock.postfix}; type=store; class=de.saly.javamail.mock2.IMAPSSLMockStore; vendor=JavaMail Mock2 provider;

最后我得到错误:

javax.mail.NoSuchProviderException: No provider for mock_imaps

1 个答案:

答案 0 :(得分:0)

javamail-mock2可能与OSGi不兼容。我们建立了一个模拟邮件包,用于在OSGi中测试Camel:https://github.com/apache/camel/tree/master/tests/test-bundles/mock-javamail_1.7