Package com.dumbster.smtp

Examples of com.dumbster.smtp.SimpleSmtpServer


        request.addParameter("website", "http://raibledesigns.com");
        request.addParameter("passwordHint", "Password is one with you.");

        HttpServletResponse response = new MockHttpServletResponse();
       
        SimpleSmtpServer server = SimpleSmtpServer.start(2525);
       
        ModelAndView mv = c.handleRequest(request, response);
        Errors errors =
            (Errors) mv.getModel().get(BindException.MODEL_KEY_PREFIX + "user");
        assertTrue("no errors returned in model", errors == null);
       
        // verify an account information e-mail was sent
        server.stop();
        assertTrue(server.getReceivedEmailSize() == 1);
       
        // verify that success messages are in the request
        assertNotNull(request.getSession().getAttribute("successMessages"));
        assertNotNull(request.getSession().getAttribute(Constants.REGISTERED));
    }
View Full Code Here


    public void testExecute() throws Exception {
        MockHttpServletRequest request = newGet("/passwordHint.html");
        request.addParameter("username", "tomcat");

        SimpleSmtpServer server = SimpleSmtpServer.start(2525);
       
        c.handleRequest(request, new MockHttpServletResponse());
       
        // verify an account information e-mail was sent
        server.stop();
        assertTrue(server.getReceivedEmailSize() == 1);
       
        // verify that success messages are in the session
        assertNotNull(request.getSession().getAttribute("messages"));
    }
View Full Code Here

* concurrency bug which may cause a lock: it may happen (and happens almost always on my machine) that notify()
* is called before wait(), so then the wait() waits indifinetly.
*/
public class SimpleSmtpServerStarter {
    public static SimpleSmtpServer start(int port) {
        final SimpleSmtpServer server = new SimpleSmtpServer(port);

        final Semaphore waitingThreadEnteredSynchronized = new Semaphore(0);
        final Semaphore serverStarted = new Semaphore(0);

        // First we start a thread where we will wait for the server to startup. We only proceed after the new
        // thread entered the synchronized block, by waiting on a semaphore (waitingThreadEnteredSynchronized).
        new Thread() {
            @Override
            public void run() {
                // Block until the server socket is created
                synchronized (server) {
                    waitingThreadEnteredSynchronized.release();
                    try {
                        server.wait();
                    } catch (InterruptedException e) {
                        // Ignore don't care.
                    }
                    serverStarted.release();
                }
View Full Code Here

    Assert.assertFalse(processor.supports(new Message().setProperty("to", "@invalid.com")));
  }

  @Test
  public void shouldSendEmailWithDefaultConfig() throws Exception {
    SimpleSmtpServer server = SimpleSmtpServer.start(2000); // this starts a fake STMP Server on the specified port

    MailProcessorConfig configuration = new MailProcessorConfig();
    configuration.setPort(2000);
    configuration.setAuth(false);
    MailProcessor processor = new MailProcessor(configuration);

    Message message = new Message();
    message.setProperty("to", "german.escobarc@gmail.com");
    message.setProperty("text", "This is a test");

    processor.process(message);

    Assert.assertTrue(server.getReceivedEmailSize() == 1);

    SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
    Assert.assertTrue(email.getHeaderValue("Subject").equals("Mokai Message"));
    Assert.assertTrue(email.getHeaderValue("From").equals("mokai@localhost.com"));
    Assert.assertTrue(email.getBody().equals("This is a test"));

    server.stop();
  }
View Full Code Here

    server.stop();
  }

  @Test
  public void shouldSendEmailOverridingConfig() throws Exception {
    SimpleSmtpServer server = SimpleSmtpServer.start(2000); // this starts a fake STMP Server on the specified port

    MailProcessorConfig configuration = new MailProcessorConfig();
    configuration.setPort(2000);
    configuration.setAuth(false);
    MailProcessor processor = new MailProcessor(configuration);

    Message message = new Message();
    message.setProperty("to", "german.escobarc@gmail.com");
    message.setProperty("from", "test@localhost");
    message.setProperty("subject", "This is the subject");
    message.setProperty("text", "This is a test");

    processor.process(message);

    Assert.assertTrue(server.getReceivedEmailSize() == 1);

    SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
    Assert.assertTrue(email.getHeaderValue("Subject").equals("This is the subject"));
    Assert.assertTrue(email.getHeaderValue("From").equals("test@localhost"));
    Assert.assertTrue(email.getBody().equals("This is a test"));

    server.stop();
  }
View Full Code Here

        user.setWebsite("http://raibledesigns.com");
        user.setPasswordHint("Password is one with you.");
        bean.setUser(user);
       
        // start SMTP Server
        SimpleSmtpServer server = SimpleSmtpServer.start(2525);
       
        assertEquals(bean.save(), "mainMenu");
        assertFalse(bean.hasErrors());
       
        // verify an account information e-mail was sent
        server.stop();
        assertTrue(server.getReceivedEmailSize() == 1);

        // verify that success messages are in the session
        assertNotNull(bean.getSession().getAttribute(Constants.REGISTERED));
    }
View Full Code Here

    }
   
    public void testExecute() throws Exception {
        bean.setUsername("tomcat");

        SimpleSmtpServer server = SimpleSmtpServer.start(2525);
       
        assertEquals(bean.execute(), "success");
        assertFalse(bean.hasErrors());

        // verify an account information e-mail was sent
        server.stop();
        assertTrue(server.getReceivedEmailSize() == 1);
       
        // verify that success messages are in the request
        assertNotNull(bean.getSession().getAttribute("messages"));
    }
View Full Code Here

TOP

Related Classes of com.dumbster.smtp.SimpleSmtpServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.