Class EmailBaseFuncTestCase

java.lang.Object
com.atlassian.jira.functest.framework.BaseJiraFuncTest
com.atlassian.jira.webtests.EmailBaseFuncTestCase
All Implemented Interfaces:
FunctTestConstants
Direct Known Subclasses:
AbstractSubscriptionEmailTest, BaseInProductDiagnosticsTest, TestAddUser, TestBulkDeleteIssuesNotifications, TestBulkHeaders, TestBulkMoveIssuesNotifications, TestBulkWorkflowTransitionNotification, TestCommentNotifications, TestCommentOperations, TestCommentResourceSafeguards, TestCommentResourceSafeguardsLdap, TestContactAdministrators, TestCurrentAssigneeNotifications, TestHandlers, TestHistoryMetadataNotifications, TestIssueDeleteNotifications, TestIssueNotifications, TestIssueResourceNotify, TestMailImageAttachments, TestMentions, TestMoveIssueNotifications, TestMoveSubTaskEnterprise, TestNonEnglishNotifications, TestNotificationEmails, TestOutgoingMailSettings, TestSendBulkMail, TestSendTestEmail, TestShareResource, TestXsrfOptionsAndSettings

public class EmailBaseFuncTestCase extends BaseJiraFuncTest implements FunctTestConstants
This class extends FuncTestCase by adding methods to test emails being sent from JIRA.
  • Field Details

  • Constructor Details

    • EmailBaseFuncTestCase

      public EmailBaseFuncTestCase()
  • Method Details

    • createMailService

      public void createMailService()
    • stopMailService

      public void stopMailService()
    • configureAndStartSmtpServer

      protected void configureAndStartSmtpServer()
      Use this method to start a 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.

    • configureAndStartImapServer

      protected void configureAndStartImapServer()
    • configureAndStartSmtpServer

      protected void configureAndStartSmtpServer(String from, String prefix)
    • configureAndStartMailServers

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

      protected void configureAndStartSmtpServerWithNotify()
    • startMailService

      protected void startMailService(JIRAServerSetup... jiraServerSetups)
    • parseEmailAddresses

      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
    • assertRecipientsHaveMessages

      protected void assertRecipientsHaveMessages(Collection<String> recipients) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • getMessagesForRecipient

      protected List<jakarta.mail.internet.MimeMessage> getMessagesForRecipient(String recipient) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • assertSendingMailIsEnabled

      protected void assertSendingMailIsEnabled()
    • setupPopService

      protected void setupPopService()
    • setupPopService

      protected void setupPopService(String handlerParameters)
    • setupImapService

      protected void setupImapService()
    • setupImapService

      protected void setupImapService(boolean markAsSeen)
    • setupImapService

      protected void setupImapService(String handlerParameters, boolean markAsSeen)
    • flushMailQueueAndWait

      protected void flushMailQueueAndWait(int emailCount) throws InterruptedException
      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
    • flushMailQueueAndWait

      protected void flushMailQueueAndWait(int emailCount, int waitPeriodMillis) throws InterruptedException
      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
    • flushMailQueueAndWaitForRecipients

      protected void flushMailQueueAndWaitForRecipients(int waitPeriodMillis, String... recipientAddresses) throws InterruptedException, jakarta.mail.MessagingException
      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
      jakarta.mail.MessagingException - if there is a problem extracting the sent messages
    • flushMailQueue

      protected void flushMailQueue()
    • waitForMail

      protected void waitForMail(int emailCount) throws InterruptedException
      Throws:
      InterruptedException
    • assertEmailBodyContains

      protected void assertEmailBodyContains(jakarta.mail.internet.MimeMessage email, String bodySubString) throws jakarta.mail.MessagingException, IOException
      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:
      jakarta.mail.MessagingException - Message error
      IOException - IO error
      See Also:
      • GreenMailUtil.getBody(jakarta.mail.Part)
    • assertEmailBodyContainsLine

      protected void assertEmailBodyContainsLine(jakarta.mail.internet.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:
      jakarta.mail.MessagingException - Message error
      IOException - IO error
      See Also:
      • GreenMailUtil.getBody(jakarta.mail.Part)
    • assertEmailReceivedWithBodyContainingLine

      protected void assertEmailReceivedWithBodyContainingLine(int expectedMatchingEmailsCount, Collection<jakarta.mail.internet.MimeMessage> emails, String... linePattern)
    • assertEmailBodyDoesntContain

      protected void assertEmailBodyDoesntContain(jakarta.mail.internet.MimeMessage email, String bodySubString) throws jakarta.mail.MessagingException, IOException
      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:
      jakarta.mail.MessagingException - Message error
      IOException - IO error
      See Also:
      • GreenMailUtil.getBody(jakarta.mail.Part)
    • assertEmailBodyContains

      protected void assertEmailBodyContains(String emailBody, String bodySubString) throws jakarta.mail.MessagingException, IOException
      Assert that the String emailBody contains bodySubString
      Parameters:
      emailBody - body
      bodySubString - expected substring
      Throws:
      jakarta.mail.MessagingException - message error
      IOException - IO error
    • assertEmailHasNumberOfParts

      protected void assertEmailHasNumberOfParts(jakarta.mail.internet.MimeMessage email, int expectedNumOfParts) throws jakarta.mail.MessagingException, IOException
      Throws:
      jakarta.mail.MessagingException
      IOException
    • assertEmailToEquals

      protected void assertEmailToEquals(jakarta.mail.internet.MimeMessage email, String expectedTo) throws jakarta.mail.MessagingException
      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:
      jakarta.mail.MessagingException - message error
      See Also:
    • assertEmailToEquals

      protected void assertEmailToEquals(jakarta.mail.internet.MimeMessage email, Collection<?> expectedToAddresses) throws jakarta.mail.MessagingException
      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:
      jakarta.mail.MessagingException - meesage error
    • assertEmailCcEquals

      protected void assertEmailCcEquals(jakarta.mail.internet.MimeMessage email, Collection<?> expectedCcAddresses) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • assertEmailFromEquals

      protected void assertEmailFromEquals(jakarta.mail.internet.MimeMessage email, String expectedTo) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • assertEmailSubjectEquals

      protected void assertEmailSubjectEquals(jakarta.mail.internet.MimeMessage email, String subject) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • assertEmailSent

      protected void assertEmailSent(String recipient, String subject, String issueComment) throws jakarta.mail.MessagingException, IOException
      Throws:
      jakarta.mail.MessagingException
      IOException
    • assertCorrectNumberEmailsSent

      protected void assertCorrectNumberEmailsSent(int numOfMessages) throws jakarta.mail.MessagingException
      Throws:
      jakarta.mail.MessagingException
    • getMailBox

      protected final EmailBaseFuncTestCase.MailBox getMailBox(String email) throws com.icegreen.greenmail.store.FolderException
      Throws:
      com.icegreen.greenmail.store.FolderException
    • assertMessageAndType

      protected final void assertMessageAndType(jakarta.mail.internet.MimeMessage message, String expectedComment, boolean html)
    • assertNotMessageAndType

      protected final void assertNotMessageAndType(jakarta.mail.internet.MimeMessage message, String expectedComment, boolean html)
    • hasBody

      public static org.hamcrest.TypeSafeMatcher<jakarta.mail.internet.MimeMessage> hasBody(org.hamcrest.Matcher<String> bodyMatcher)