play-plugins icon indicating copy to clipboard operation
play-plugins copied to clipboard

How can I write a testcase to see if mailing works from my app

Open practicalwebdev opened this issue 12 years ago • 1 comments

If I do the following ->

public static FakeApplication app;
  @BeforeClass
  public static void startApp() {
    app = Helpers.fakeApplication();
    Helpers.start(app);
  }

  @AfterClass
  public static void stopApp() {
    Helpers.stop(app);
  } 

@Test
public void sendEmail() {
    MailerPlugin mailplugin = play.Play.application().plugin(MailerPlugin.class);
    MailerAPI mail = mailplugin.email();
    mail.setSubject("test for assist app");
    mail.addRecipient();
    mail.addFrom();
    //sends html
    //mail.sendHtml("<html>this is a test email</html>" );
    //sends text/text
    mail.send( "text" );
    //sends both text and html
    //mail.send( "text", "<html>html</html>");  
}

I have a nummpointerexception at MailerAPI mail = mailplugin.email(); which means the factory method -> play.Play.application().plugin(MailerPlugin.class); does not seem to return the plugin class.

I am new to play is this how I supposed to do this ?

thanks

practicalwebdev avatar Oct 19 '12 08:10 practicalwebdev

I used Greenmail to check that SMTP functionality was operating properly, and the contents of the email

buggtb avatar Jan 30 '14 11:01 buggtb