PageRenderTime 37ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/jira-project/jira-functional-tests/jira-func-tests/src/main/java/com/atlassian/jira/webtests/ztests/email/TestBulkWorkflowTransitionNotification.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 179 lines | 136 code | 31 blank | 12 comment | 9 complexity | a8e3ee75b3d3e795ca60f284d48c92c1 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.webtests.ztests.email;
  2. import com.atlassian.core.util.collection.EasyList;
  3. import com.atlassian.core.util.map.EasyMap;
  4. import com.atlassian.integrationtesting.runner.restore.Restore;
  5. import com.atlassian.jira.functest.framework.BulkOperationProgress;
  6. import com.atlassian.jira.functest.framework.LoginAs;
  7. import com.atlassian.jira.functest.framework.locator.WebPageLocator;
  8. import com.atlassian.jira.functest.framework.navigation.IssueNavigatorNavigation;
  9. import com.atlassian.jira.functest.framework.suite.Category;
  10. import com.atlassian.jira.functest.framework.suite.WebTest;
  11. import com.atlassian.jira.webtests.EmailBaseFuncTestCase;
  12. import org.junit.Assert;
  13. import org.junit.Before;
  14. import org.junit.Test;
  15. import javax.inject.Inject;
  16. import javax.mail.MessagingException;
  17. import javax.mail.internet.MimeMessage;
  18. import java.io.IOException;
  19. import java.util.List;
  20. import java.util.Map;
  21. import static com.atlassian.jira.functest.framework.FunctTestConstants.ADMIN_USERNAME;
  22. @WebTest({Category.FUNC_TEST, Category.BULK_OPERATIONS, Category.EMAIL, Category.WORKFLOW})
  23. @Restore("TestBulkWorkflowTransitionNotification.xml")
  24. @LoginAs(user = ADMIN_USERNAME)
  25. public class TestBulkWorkflowTransitionNotification extends EmailBaseFuncTestCase {
  26. private static final String COMMENT_TEXT = "This comment should appear in the email body.";
  27. private static final String WORKFLOW_RESOLVE = "jira_5_5";
  28. private static final String WORKFLOW_REOPEN = "jira_3_4";
  29. @Inject
  30. private BulkOperationProgress bulkOperationProgress;
  31. @Before
  32. public void setUpTest() {
  33. // Notes about data:
  34. // * no custom workflows
  35. // * Default notification scheme enabled for Test project
  36. // * devman & fred are watchers on all issues, so they should receive notifications
  37. // * 1 issue unresolved, 1 resolved
  38. // * jira-developers in "Administrators" role, jira-users in "Developers" role, jira-administrators in "Users" role
  39. // * comment visibility options: Groups & Project Roles
  40. configureAndStartSmtpServerWithNotify();
  41. }
  42. @Test
  43. public void testResolvedCommentAppearsInEmail() throws MessagingException, InterruptedException, IOException {
  44. _testCommentAppearsInEmail("10000", "TST-1", WORKFLOW_RESOLVE, "Resolved", "Fixed", "[JIRATEST] (TST-1) First Issue", null);
  45. }
  46. @Test
  47. public void testReopenedCommentAppearsInEmail() throws MessagingException, InterruptedException, IOException {
  48. _testCommentAppearsInEmail("10001", "TST-2", WORKFLOW_REOPEN, "Reopened", null, "[JIRATEST] (TST-2) Second Issue", null);
  49. }
  50. @Test
  51. public void testCommentVisibilityInEmailForJiraAdmins() throws MessagingException, InterruptedException, IOException {
  52. final String commentLevel = "jira-administrators";
  53. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  54. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.FALSE, "fred@example.com", Boolean.FALSE));
  55. }
  56. @Test
  57. public void testCommentVisibilityInEmailForJiraDevs() throws MessagingException, InterruptedException, IOException {
  58. final String commentLevel = "jira-developers";
  59. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  60. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.TRUE, "fred@example.com", Boolean.FALSE));
  61. }
  62. @Test
  63. public void testCommentVisibilityInEmailForJiraUsers() throws MessagingException, InterruptedException, IOException {
  64. final String commentLevel = "jira-users";
  65. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  66. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.TRUE, "fred@example.com", Boolean.TRUE));
  67. }
  68. @Test
  69. public void testCommentVisibilityInEmailForProjectAdmins()
  70. throws MessagingException, InterruptedException, IOException {
  71. final String commentLevel = ADMIN_FULLNAME + "s";
  72. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  73. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.TRUE, "fred@example.com", Boolean.FALSE));
  74. }
  75. @Test
  76. public void testCommentVisibilityInEmailForProjectDevs()
  77. throws MessagingException, InterruptedException, IOException {
  78. final String commentLevel = "Developers";
  79. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  80. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.TRUE, "fred@example.com", Boolean.TRUE));
  81. }
  82. @Test
  83. public void testCommentVisibilityInEmailForProjectUsers()
  84. throws MessagingException, InterruptedException, IOException {
  85. final String commentLevel = "Users";
  86. _performBulkOperation("10000", WORKFLOW_RESOLVE, "Fixed", commentLevel);
  87. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.FALSE, "fred@example.com", Boolean.FALSE));
  88. }
  89. private void _testCommentAppearsInEmail(String chkId, String issueId, String workflow, String workflowName, String resolution, String subject, String commentLevel)
  90. throws InterruptedException, MessagingException, IOException {
  91. _performBulkOperation(chkId, workflow, resolution, commentLevel);
  92. // check the full details of admin's email
  93. List messagesForAdmin = getMessagesForRecipient("admin@example.com");
  94. Assert.assertTrue(messagesForAdmin.size() == 1);
  95. assertMailProperties((MimeMessage) messagesForAdmin.get(0), subject, COMMENT_TEXT, workflowName);
  96. // check only comment visibility for all users' emails
  97. assertCommentVisibility(EasyMap.build("admin@example.com", Boolean.TRUE, "devman@example.com", Boolean.TRUE, "fred@example.com", Boolean.TRUE));
  98. // also test that comments aren't created twice (however, comment appears twice because of open and closed divs)
  99. navigation.issue().viewIssue(issueId);
  100. assertions.getTextAssertions().assertTextPresentNumOccurences(new WebPageLocator(tester), COMMENT_TEXT, 2);
  101. }
  102. private void assertMailProperties(MimeMessage message, String subject, String comment, String workflowName)
  103. throws MessagingException, IOException {
  104. assertEmailSubjectEquals(message, subject);
  105. assertEmailFromEquals(message, "\"" + ADMIN_FULLNAME + " (JIRA)\" <jiratest@atlassian.com>");
  106. assertEmailBodyContains(message, comment);
  107. }
  108. private void assertCommentVisibility(Map visibility) throws MessagingException, InterruptedException, IOException {
  109. for (final Object o : visibility.keySet()) {
  110. String recipient = (String) o;
  111. Boolean isCommentVisible = (Boolean) visibility.get(recipient);
  112. List messages = getMessagesForRecipient(recipient);
  113. Assert.assertTrue(messages.size() == 1);
  114. if (isCommentVisible.booleanValue()) {
  115. assertEmailBodyContains((MimeMessage) messages.get(0), COMMENT_TEXT);
  116. } else {
  117. assertEmailBodyDoesntContain((MimeMessage) messages.get(0), COMMENT_TEXT);
  118. }
  119. }
  120. }
  121. private void _performBulkOperation(final String chkId, final String workflow, final String resolution, final String commentLevel)
  122. throws InterruptedException, MessagingException {
  123. navigation.issueNavigator().gotoNavigator();
  124. navigation.issueNavigator().bulkChange(IssueNavigatorNavigation.BulkChangeOption.ALL_PAGES);
  125. tester.checkCheckbox("bulkedit_" + chkId);
  126. navigation.clickOnNext();
  127. tester.setFormElement("operation", "bulk.workflowtransition.operation.name");
  128. navigation.clickOnNext();
  129. navigation.workflows().chooseWorkflowAction(workflow);
  130. if (resolution != null) {
  131. tester.selectOption("resolution", resolution);
  132. }
  133. tester.checkCheckbox("commentaction", "comment");
  134. tester.setFormElement("comment", COMMENT_TEXT);
  135. if (commentLevel != null) {
  136. tester.selectOption("commentLevel", commentLevel);
  137. }
  138. navigation.clickOnNext();
  139. navigation.clickOnNext();
  140. bulkOperationProgress.waitAndReloadBulkOperationProgressPage();
  141. // there should be 3 notifications
  142. flushMailQueueAndWait(3);
  143. MimeMessage[] mimeMessages = mailService.getReceivedMessages();
  144. Assert.assertEquals(3, mimeMessages.length);
  145. // assert recipients of emails
  146. assertRecipientsHaveMessages(EasyList.build("admin@example.com", "devman@example.com", "fred@example.com"));
  147. }
  148. }