public void testSendHtml() throws Exception { Support support = new Support() { @Override protected Future<Boolean> send(MailPlugin plugin) throws IOException, MessagingException { return plugin.send(Arrays.asList("dst@gmail.com"), "Testing Subject", "<html><body>hello wolrd</body></html>", "text/html;charset=UTF-8"); } }; support.doTest(); }
public void testSendPlain() throws Exception { Support support = new Support(); support.doTest(); }
public void testSendAttachment() throws Exception { final File f = new File(MailPluginTestCase.class.getResource("image.png").toURI()); Support support = new Support() { @Override protected Future<Boolean> send(MailPlugin plugin) throws IOException, MessagingException { return plugin.send(Arrays.asList("dst@gmail.com"), "Testing Subject", "Dear Mail Crawler," + "\n\n No spam to my email, please!", new FileDataSource(f)); } @Override protected void assertMessage(WiserMessage msg) throws MessagingException { super.assertMessage(msg); String data = new String(msg.getData()); String match = "name=image.png"; assertTrue("Was expecting " + data + " to contain <" + match + ">", data.contains(match)); } }; support.doTest(); } }
Support support = new Support() { @Override protected SMTPServer createServer(MessageHandlerFactory mhf) {
public void testAuthFailed() throws Exception { final AtomicBoolean done = new AtomicBoolean(); Support support = new Support() { @Override protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle lifeCycle = super.createLifeCycle(); lifeCycle.setProperty(MailPlugin.SMTP_USERNAME, "foo"); lifeCycle.setProperty(MailPlugin.SMTP_PASSWORD, "bar"); return lifeCycle; } @Override protected SMTPServer createServer(MessageHandlerFactory mhf) { SMTPServer smtpServer = super.createServer(mhf); smtpServer.setAuthenticationHandlerFactory(new LoginAuthenticationHandlerFactory(new UsernamePasswordValidator() { public void login(String username, String password) throws LoginFailedException { done.set(true); throw new LoginFailedException(); } })); return smtpServer; } @Override protected void assertResponse(Wiser wiser, Future<Boolean> response) throws MessagingException, ExecutionException, InterruptedException { assertFalse(response.get()); } }; support.doTest(); assertEquals(true, done.get()); }
public void testAuth() throws Exception { final AtomicReference<String> usernameRef = new AtomicReference<String>(); final AtomicReference<String> passwordRef = new AtomicReference<String>(); Support support = new Support() { @Override protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle lifeCycle = super.createLifeCycle(); lifeCycle.setProperty(MailPlugin.SMTP_USERNAME, "foo"); lifeCycle.setProperty(MailPlugin.SMTP_PASSWORD, "bar"); return lifeCycle; } @Override protected SMTPServer createServer(MessageHandlerFactory mhf) { SMTPServer smtpServer = super.createServer(mhf); smtpServer.setAuthenticationHandlerFactory(new LoginAuthenticationHandlerFactory(new UsernamePasswordValidator() { public void login(String username, String password) throws LoginFailedException { usernameRef.set(username); passwordRef.set(password); } })); return smtpServer; } }; support.doTest(); assertEquals("foo", usernameRef.get()); assertEquals("bar", passwordRef.get()); }