Search in sources :

Example 1 with MailImpl

use of ninja.postoffice.common.MailImpl in project ninja by ninjaframework.

the class CommonsMailHelperImplTest method testCreateMultiPartEmailWithContent.

@Test
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);
}
Also used : Mail(ninja.postoffice.Mail) MultiPartEmail(org.apache.commons.mail.MultiPartEmail) HtmlEmail(org.apache.commons.mail.HtmlEmail) MailImpl(ninja.postoffice.common.MailImpl) Test(org.junit.Test)

Example 2 with MailImpl

use of ninja.postoffice.common.MailImpl in project ninja by ninjaframework.

the class PostofficeMockImplTest method testSending.

@Test
public void testSending() throws Exception {
    // ////////////////////////////////////////////////////////////////////
    // Setup the mockpostoffice
    // ////////////////////////////////////////////////////////////////////
    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.
    assertEquals("second 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"));
}
Also used : Mail(ninja.postoffice.Mail) Postoffice(ninja.postoffice.Postoffice) MailImpl(ninja.postoffice.common.MailImpl) Test(org.junit.Test)

Aggregations

Mail (ninja.postoffice.Mail)2 MailImpl (ninja.postoffice.common.MailImpl)2 Test (org.junit.Test)2 Postoffice (ninja.postoffice.Postoffice)1 HtmlEmail (org.apache.commons.mail.HtmlEmail)1 MultiPartEmail (org.apache.commons.mail.MultiPartEmail)1