@Override protected SmtpSecure doParse(String s) throws Exception { return SmtpSecure.valueOf(s.toUpperCase()); } };
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(); }
@Override public void init() { smtpHost = getContext().getProperty(SMTP_HOST); smtpPort = getContext().getProperty(SMTP_PORT); smtpSecure = getContext().getProperty(SMTP_SECURE); smtpUsername = getContext().getProperty(SMTP_USERNAME); smtpPassword = getContext().getProperty(SMTP_PASSWORD); smtpFrom = getContext().getProperty(SMTP_FROM); debug = getContext().getProperty(DEBUG); }
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!"); }
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()); }
protected void execute(TestPluginLifeCycle lifeCycle, Wiser wiser) throws IOException, MessagingException, ExecutionException, InterruptedException { MailPlugin plugin = lifeCycle.getContext().getPlugin(MailPlugin.class); Future<Boolean> future = send(plugin); assertResponse(wiser, future); }
@Override protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle lifeCycle = super.createLifeCycle(); lifeCycle.setProperty(MailPlugin.SMTP_SECURE, SmtpSecure.TLS); 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; } };
@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)); } };
public void testFoo() throws Exception { Support support = new Support() { @Override protected void execute(TestPluginLifeCycle lifeCycle, Wiser wiser) throws IOException, MessagingException, ExecutionException, InterruptedException { Shell shell = lifeCycle.createShell(); lifeCycle.bindClass("produce", Commands.ProduceValue.class); lifeCycle.bindClass("consume", Commands.ConsumeObject.class); Commands.list.clear(); BaseProcessContext process = BaseProcessContext.create(shell, "produce | mail send -s the_subject -b admin@gmail.com | consume").execute(); ShellResponse.Ok ok = assertInstance(ShellResponse.Ok.class, process.getResponse()); Assert.assertEquals(1, wiser.getMessages().size()); WiserMessage msg = wiser.getMessages().get(0); Assert.assertEquals("foo@gmail.com", msg.getEnvelopeSender()); Assert.assertEquals("admin@gmail.com", msg.getEnvelopeReceiver()); Assert.assertEquals("the_subject", msg.getMimeMessage().getSubject()); String data = new String(msg.getData()); String content = (String)msg.getMimeMessage().getContent(); assertTrue(content.contains("<value>abc</value>")); assertTrue(data.contains("Content-Type: text/html;charset=UTF-8")); System.out.println("data = " + data); assertEquals(Arrays.<Object>asList(new Value("abc")), Commands.list); } }; support.doTest(); } }
protected TestPluginLifeCycle createLifeCycle() throws Exception { TestPluginLifeCycle test = new TestPluginLifeCycle(new MailPlugin(), new GroovyLanguageProxy(), new JavaLanguage()); test.setProperty(MailPlugin.SMTP_HOST, "localhost"); test.setProperty(MailPlugin.SMTP_PORT, 5000); test.setProperty(MailPlugin.SMTP_FROM, "foo@gmail.com"); return test; }
@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"); }
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()); }
@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 { Assert.assertTrue(response.get()); Assert.assertEquals(1, wiser.getMessages().size()); WiserMessage msg = wiser.getMessages().get(0); assertMessage(msg); }
@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
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(); } }
@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