com.atlassian.jira.webtests.util.mail
Class MailService

java.lang.Object
  extended by com.atlassian.jira.webtests.util.mail.MailService

public class MailService
extends Object

This class provides mail services like POP3 and SMTP for the acceptance tests. It will try to find free TCP/IP ports for the services within a given range.


Constructor Summary
MailService(com.atlassian.jira.testkit.client.log.FuncTestLogger log)
           
 
Method Summary
 void addUser(String email, String login, String password)
          Adds a user to the mail service.
 com.icegreen.greenmail.util.GreenMail configureAndStartGreenMail(JIRAServerSetup... serverSetups)
           
 int getImapPort()
           
 int getPop3Port()
           
 javax.mail.internet.MimeMessage getReceivedMessage()
          Get the first message of all messages received until now.
 javax.mail.internet.MimeMessage[] getReceivedMessages()
          Returns an array of all messages received until now.
 javax.mail.internet.MimeMessage[] getReceivedMessagesAndClear()
          Returns an array of all messages received until now, clearing the list on the mail server.
 int getSmtpPort()
           
 com.icegreen.greenmail.store.MailFolder getUserInbox(String userEmail)
          Get the inbox for the user with email userEmail.
 boolean isRunning()
          Returns true if the mail servers are running.
 void removeAllReceivedMessages()
          Removes all received mails.
 void sendTextMessage(String to, String from, String subject, String body)
          Sends an email with the content type "text/plain" and the given contents using the test SMTP server.
 void stop()
          Stops the SMTP and POP3 server.
 javax.mail.internet.MimeMessage waitAndGetReceivedMessage()
          Does the same as getReceivedMessage() but waits until a message is received or until a timeout is reached.
 boolean waitForIncomingMessage(int numberOfMessages)
          Wait until the specified number of mails is received or until 10 seconds have passed.
 boolean waitForIncomingMessage(long timeout, int numberOfMessages)
          Wait until the specified number of mails is received or until a timeout is reached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MailService

public MailService(com.atlassian.jira.testkit.client.log.FuncTestLogger log)
Method Detail

configureAndStartGreenMail

public com.icegreen.greenmail.util.GreenMail configureAndStartGreenMail(JIRAServerSetup... serverSetups)
                                                                 throws BindException
Throws:
BindException

stop

public void stop()
Stops the SMTP and POP3 server.


isRunning

public boolean isRunning()
Returns true if the mail servers are running.


addUser

public void addUser(String email,
                    String login,
                    String password)
Adds a user to the mail service. The SMTP server will then accept incoming mails for email and you can fetch these mails via POP3 using login/password for authentication.

Parameters:
email - email of the user to be created
login - login of the user to be created
password - password of the user to be created

getPop3Port

public int getPop3Port()
Returns:
the port the POP3 server is bound to

getSmtpPort

public int getSmtpPort()
Returns:
the port the SMTP server is bound to

getImapPort

public int getImapPort()
Returns:
the port the IMAP server is bound to

sendTextMessage

public void sendTextMessage(String to,
                            String from,
                            String subject,
                            String body)
Sends an email with the content type "text/plain" and the given contents using the test SMTP server.

Parameters:
to - email address this mail should be sent to
from - email address this mail should appear to be sent from
subject - subject of the email
body - body of the email

getReceivedMessages

public javax.mail.internet.MimeMessage[] getReceivedMessages()
Returns an array of all messages received until now.

Returns:
all received messages

getReceivedMessagesAndClear

public javax.mail.internet.MimeMessage[] getReceivedMessagesAndClear()
                                                              throws com.icegreen.greenmail.store.FolderException
Returns an array of all messages received until now, clearing the list on the mail server.

Returns:
all received messages
Throws:
com.icegreen.greenmail.store.FolderException - if there's a problem clearing the list

getReceivedMessage

public javax.mail.internet.MimeMessage getReceivedMessage()
Get the first message of all messages received until now.

Returns:
the first message received as MimeMessage or null if there was no message received

waitAndGetReceivedMessage

public javax.mail.internet.MimeMessage waitAndGetReceivedMessage()
                                                          throws InterruptedException
Does the same as getReceivedMessage() but waits until a message is received or until a timeout is reached.

Returns:
the first message received as MimeMessage or null if there was no message received
Throws:
InterruptedException

getUserInbox

public com.icegreen.greenmail.store.MailFolder getUserInbox(String userEmail)
                                                     throws com.icegreen.greenmail.store.FolderException
Get the inbox for the user with email userEmail. NOTE: if the user does not exist, one will be created.

Parameters:
userEmail - the email address of the user
Returns:
MailFolder of the user with the given email address
Throws:
com.icegreen.greenmail.store.FolderException - if the user doesn't have an inbox on this server

removeAllReceivedMessages

public void removeAllReceivedMessages()
                               throws com.icegreen.greenmail.store.FolderException
Removes all received mails.

Throws:
com.icegreen.greenmail.store.FolderException

waitForIncomingMessage

public boolean waitForIncomingMessage(int numberOfMessages)
                               throws InterruptedException
Wait until the specified number of mails is received or until 10 seconds have passed.

Throws:
InterruptedException

waitForIncomingMessage

public boolean waitForIncomingMessage(long timeout,
                                      int numberOfMessages)
                               throws InterruptedException
Wait until the specified number of mails is received or until a timeout is reached.

Throws:
InterruptedException


Copyright © 2002-2014 Atlassian. All Rights Reserved.