Package ninja.postoffice

Examples of ninja.postoffice.Mail


public class MailImplTestHelper {

    public static Mail getMailImplWithDemoContent() {

        Mail mail = new MailImpl();

        mail.setSubject("subject");

        mail.setFrom("from1@domain");

        mail.addReplyTo("replyTo1@domain");
        mail.addReplyTo("replyTo2@domain");

        mail.setCharset("utf-8");
        mail.addHeader("header1", "value1");
        mail.addHeader("header2", "value2");

        mail.addTo("to1@domain");
        mail.addTo("to2@domain");

        mail.addCc("cc1@domain");
        mail.addCc("cc2@domain");

        mail.addBcc("bcc1@domain");
        mail.addBcc("bcc2@domain");

        mail.setBodyHtml("bodyHtml");

        mail.setBodyText("bodyText");

        return mail;

    }
View Full Code Here


        Postoffice postoffice = new PostofficeMockImpl();

        // /////////////////////////////////////////////////////////////////////
        // Sending of first mail.
        // /////////////////////////////////////////////////////////////////////
        Mail firstMail = new MailImpl();

        firstMail.setSubject("first mail");
        firstMail.addTo("to@localhost");
        firstMail.setFrom("from@localhost");
        firstMail.setBodyText("simple body text");

        // make sure that mocked mailer did not send email previously
        assertEquals(null, ((PostofficeMockImpl) postoffice).getLastSentMail());

        postoffice.send(firstMail);

        // and test that mail has been sent.
        assertEquals("first mail", ((PostofficeMockImpl) postoffice).getLastSentMail().getSubject());
        assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getTos()
                .contains("to@localhost"));
        assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getFrom().equals(
                "from@localhost"));
        assertTrue(((PostofficeMockImpl) postoffice).getLastSentMail().getBodyText().equals(
                "simple body text"));

        // /////////////////////////////////////////////////////////////////////
        // Sending of another mail. Check that mock mailer handles repeated
        // sending correctly.
        // /////////////////////////////////////////////////////////////////////
        Mail secondMail = new MailImpl();

        secondMail.setSubject("second mail");
        secondMail.addTo("to@localhost");
        secondMail.setFrom("from@localhost");
        secondMail.setBodyText("simple body text");

        // send simple mail via mocked postoffice
        postoffice.send(secondMail);

        // and test that mail has been sent.
View Full Code Here

    public void testThatMailImplWorksAsExpected() {

        // /////////////////////////////////////////////////////////////////////
        // Setup a simple mail with full content:
        // /////////////////////////////////////////////////////////////////////
        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        // /////////////////////////////////////////////////////////////////////
        // Test that content has been set correctly
        // /////////////////////////////////////////////////////////////////////
        MailImpl mailImpl = (MailImpl) mail;

        assertTrue(mailImpl.getSubject().equals("subject"));

        assertTrue(mailImpl.getFrom().contains("from1@domain"));

        assertTrue(mailImpl.getReplyTo().contains("replyTo1@domain"));
        assertTrue(mailImpl.getReplyTo().contains("replyTo2@domain"));

        mail.setCharset("utf-8");
        assertTrue(mailImpl.getCharset().contains("utf-8"));

        assertTrue(mailImpl.getHeaders().get("header1").equals("value1"));
        assertTrue(mailImpl.getHeaders().get("header2").equals("value2"));
View Full Code Here

    }

    @Test
    public void testCommonsMailer() throws Exception {

        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        // setup the postoffice:
        CommonsmailHelper commonsmailHelper = new CommonsmailHelperImpl();
        Postoffice postoffice =
                new PostofficeCommonsmailImpl(commonsmailHelper, "localhost", SMTP_TEST_PORT, false, null, null,
View Full Code Here

    public void testCreateMultiPartEmailWithContent() throws Exception {

        // /////////////////////////////////////////////////////////////////////
        // Test with text only content
        // /////////////////////////////////////////////////////////////////////
        Mail mail = new MailImpl();
        // set only text:
        mail.setBodyText("simple body text");

        MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);

        assertTrue(multiPartEmail instanceof MultiPartEmail);

        // /////////////////////////////////////////////////////////////////////
        // Test with html only content
        // /////////////////////////////////////////////////////////////////////
        mail = new MailImpl();
        // set only text:
        mail.setBodyHtml("<br>simple body text<br>");

        multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);

        assertTrue(multiPartEmail instanceof HtmlEmail);

        // /////////////////////////////////////////////////////////////////////
        // Test with html AND text content
        // /////////////////////////////////////////////////////////////////////
        mail = new MailImpl();
        // set only text:
        mail.setBodyText("simple body text");
        mail.setBodyHtml("<br>simple body text<br>");

        multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);

        assertTrue(multiPartEmail instanceof HtmlEmail);
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testDoPopulateMultipartMailWithContent() throws Exception {

        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);
        commonsmailHelper.doPopulateMultipartMailWithContent(multiPartEmail, mail);


View Full Code Here


    @Test
    public void testDoSetServerParameter() throws Exception {

        Mail mail = MailImplTestHelper.getMailImplWithDemoContent();

        MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail);

        commonsmailHelper.doSetServerParameter(
                multiPartEmail,
View Full Code Here

TOP

Related Classes of ninja.postoffice.Mail

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.