public class

EmailBaseFuncTestCase

extends BaseJiraFuncTest
implements FunctTestConstants
java.lang.Object
   ↳ com.atlassian.jira.functest.framework.BaseJiraFuncTest
     ↳ com.atlassian.jira.webtests.EmailBaseFuncTestCase
Known Direct Subclasses

Class Overview

This class extends FuncTestCase by adding methods to test emails being sent from JIRA.

Summary

Nested Classes
class EmailBaseFuncTestCase.MailBox  
Constants
String DEFAULT_FROM_ADDRESS
String DEFAULT_SUBJECT_PREFIX
String HTML_FORMAT_REGEX
String newline
[Expand]
Inherited Constants
From interface com.atlassian.jira.functest.framework.FunctTestConstants
Fields
protected MailService mailService
[Expand]
Inherited Fields
From class com.atlassian.jira.functest.framework.BaseJiraFuncTest
From interface com.atlassian.jira.functest.framework.FunctTestConstants
Public Constructors
EmailBaseFuncTestCase()
Public Methods
void createMailService()
void stopMailService()
Protected Methods
void assertCorrectNumberEmailsSent(int numOfMessages)
void assertEmailBodyContains(MimeMessage email, String bodySubString)
Asserts that the given email's body contains the bodySubString using indexOf.
void assertEmailBodyContains(String emailBody, String bodySubString)
Assert that the String emailBody contains bodySubString
void assertEmailBodyContainsLine(MimeMessage email, String... linePattern)
Asserts that the given email's body contains a line which matches the given string or pattern.
void assertEmailBodyDoesntContain(MimeMessage email, String bodySubString)
Asserts that the given email's body does not contain the bodySubString using indexOf.
void assertEmailCcEquals(MimeMessage email, Collection<?> expectedCcAddresses)
void assertEmailFromEquals(MimeMessage email, String expectedTo)
void assertEmailHasNumberOfParts(MimeMessage email, int expectedNumOfParts)
void assertEmailSent(String recipient, String subject, String issueComment)
void assertEmailSubjectEquals(MimeMessage email, String subject)
void assertEmailToEquals(MimeMessage email, String expectedTo)
Assert that the email was addressed to the expectedTo
void assertEmailToEquals(MimeMessage email, Collection<?> expectedToAddresses)
Assert that the email was addressed to each and everyone of the expectedAddresses
final void assertMessageAndType(MimeMessage message, String expectedComment, boolean html)
final void assertNotMessageAndType(MimeMessage message, String expectedComment, boolean html)
void assertRecipientsHaveMessages(Collection<String> recipients)
void assertSendingMailIsEnabled()
void configureAndStartMailServers(String from, String prefix, JIRAServerSetup... jiraServerSetups)
void configureAndStartSmtpServer()
Use this method to start a com.icegreen.greenmail.smtp.SmtpServer.
void configureAndStartSmtpServer(String from, String prefix)
void configureAndStartSmtpServerWithNotify()
void flushMailQueue()
void flushMailQueueAndWait(int emailCount)
This is useful for writing func tests that test that the correct notifications are being sent.
void flushMailQueueAndWait(int emailCount, int waitPeriodMillis)
Does the same as flushMailQueueAndWait(int) but allows the user to specify the wait period in case a lot of e-mails are being sent.
void flushMailQueueAndWaitForRecipients(int waitPeriodMillis, String... recipientAddresses)
Flushes the mail queue and waits for emails to arrive for specified recipients instead of a set number of emails.
final EmailBaseFuncTestCase.MailBox getMailBox(String email)
List<MimeMessage> getMessagesForRecipient(String recipient)
Collection<String> parseEmailAddresses(String emails)
Given a comma seperated list of email addresses, returns a collection of the email addresses.
void setupImapService(String handlerParameters)
void setupImapService()
void setupPopService(String handlerParameters)
void setupPopService()
void startMailService(JIRAServerSetup... jiraServerSetups)
void waitForMail(int emailCount)
[Expand]
Inherited Methods
From class com.atlassian.jira.functest.framework.BaseJiraFuncTest
From class java.lang.Object

Constants

public static final String DEFAULT_FROM_ADDRESS

Constant Value: "jiratest@atlassian.com"

public static final String DEFAULT_SUBJECT_PREFIX

Constant Value: "[JIRATEST]"

public static final String HTML_FORMAT_REGEX

Constant Value: "\s*

public static final String newline

Constant Value: " "

Fields

protected MailService mailService

Public Constructors

public EmailBaseFuncTestCase ()

Public Methods

public void createMailService ()

public void stopMailService ()

Protected Methods

protected void assertCorrectNumberEmailsSent (int numOfMessages)

Throws
MessagingException

protected void assertEmailBodyContains (MimeMessage email, String bodySubString)

Asserts that the given email's body contains the bodySubString using indexOf.

Parameters
email email to extract the content body from
bodySubString expected substring of the email body
Throws
MessagingException Message error
IOException IO error

protected void assertEmailBodyContains (String emailBody, String bodySubString)

Assert that the String emailBody contains bodySubString

Parameters
emailBody body
bodySubString expected substring
Throws
MessagingException message error
IOException IO error

protected void assertEmailBodyContainsLine (MimeMessage email, String... linePattern)

Asserts that the given email's body contains a line which matches the given string or pattern. If multiple lines are specified, they must appear in the given order.

Parameters
email email to extract the content body from
linePattern expected line or line pattern
Throws
MessagingException Message error
IOException IO error

protected void assertEmailBodyDoesntContain (MimeMessage email, String bodySubString)

Asserts that the given email's body does not contain the bodySubString using indexOf.

Parameters
email email to extract the content body from
bodySubString string to not occur in body
Throws
MessagingException Message error
IOException IO error

protected void assertEmailCcEquals (MimeMessage email, Collection<?> expectedCcAddresses)

Throws
MessagingException

protected void assertEmailFromEquals (MimeMessage email, String expectedTo)

Throws
MessagingException

protected void assertEmailHasNumberOfParts (MimeMessage email, int expectedNumOfParts)

Throws
IOException
MessagingException

protected void assertEmailSent (String recipient, String subject, String issueComment)

Throws
IOException
MessagingException

protected void assertEmailSubjectEquals (MimeMessage email, String subject)

Throws
MessagingException

protected void assertEmailToEquals (MimeMessage email, String expectedTo)

Assert that the email was addressed to the expectedTo

Parameters
email email to assert the value of the to header
expectedTo the single or comma seperated list of expected email addresses
Throws
MessagingException message error

protected void assertEmailToEquals (MimeMessage email, Collection<?> expectedToAddresses)

Assert that the email was addressed to each and everyone of the expectedAddresses

Parameters
email email to assert the value of the to header
expectedToAddresses collection of expected email addresses
Throws
MessagingException meesage error

protected final void assertMessageAndType (MimeMessage message, String expectedComment, boolean html)

protected final void assertNotMessageAndType (MimeMessage message, String expectedComment, boolean html)

protected void assertRecipientsHaveMessages (Collection<String> recipients)

Throws
MessagingException

protected void assertSendingMailIsEnabled ()

protected void configureAndStartMailServers (String from, String prefix, JIRAServerSetup... jiraServerSetups)

protected void configureAndStartSmtpServer ()

Use this method to start a com.icegreen.greenmail.smtp.SmtpServer.

This will also configure JIRA to use this SMTP server in the admin section. You should call this after your data import. This will override any existing mail servers setup already.

A simple SMTP server proxy is started by first attempting to start on a default port number. If this port is already used we try that port number plus one and so on for 10 attempts. this allows for multiple tests running in Bamboo concurrently, and also for a particular test machine maybe using that port already.

The tearDown() method will close the TCP socket.

protected void configureAndStartSmtpServer (String from, String prefix)

protected void configureAndStartSmtpServerWithNotify ()

protected void flushMailQueue ()

protected void flushMailQueueAndWait (int emailCount)

This is useful for writing func tests that test that the correct notifications are being sent. It goest to the admin section mail-queue and flushes the queue and waits till it recieves emailCount number of emails before timeout. If the timeout is reached before the expected number of emails arrives will fail.

Parameters
emailCount number of expected emails to wait to receive
Throws
InterruptedException if interrupted

protected void flushMailQueueAndWait (int emailCount, int waitPeriodMillis)

Does the same as flushMailQueueAndWait(int) but allows the user to specify the wait period in case a lot of e-mails are being sent.

Parameters
emailCount number of expected emails to wait to receive
waitPeriodMillis The amount of time to wait in millis until the e-mails should have arrived.
Throws
InterruptedException if interrupted

protected void flushMailQueueAndWaitForRecipients (int waitPeriodMillis, String... recipientAddresses)

Flushes the mail queue and waits for emails to arrive for specified recipients instead of a set number of emails.

Parameters
waitPeriodMillis The amount of time to wait in millis until the e-mails should have arrived.
recipientAddresses the addresses to wait for or fail
Throws
InterruptedException if interrupted
MessagingException if there is a problem extracting the sent messages

protected final EmailBaseFuncTestCase.MailBox getMailBox (String email)

Throws
FolderException

protected List<MimeMessage> getMessagesForRecipient (String recipient)

Throws
MessagingException

protected Collection<String> parseEmailAddresses (String emails)

Given a comma seperated list of email addresses, returns a collection of the email addresses.

Parameters
emails comma seperated list of email addresses
Returns
  • collection of individual email address

protected void setupImapService (String handlerParameters)

protected void setupImapService ()

protected void setupPopService (String handlerParameters)

protected void setupPopService ()

protected void startMailService (JIRAServerSetup... jiraServerSetups)

protected void waitForMail (int emailCount)