PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/jira-project/jira-functional-tests/jira-func-tests/src/main/java/com/atlassian/jira/webtests/ztests/attachment/TestEditAttachmentSettings.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 209 lines | 164 code | 31 blank | 14 comment | 0 complexity | dd199c0b81865cfca0977f3a34210bcc MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.webtests.ztests.attachment;
  2. import com.atlassian.integrationtesting.runner.restore.Restore;
  3. import com.atlassian.jira.functest.framework.Administration;
  4. import com.atlassian.jira.functest.framework.BaseJiraFuncTest;
  5. import com.atlassian.jira.functest.framework.LoginAs;
  6. import com.atlassian.jira.functest.framework.Navigation;
  7. import com.atlassian.jira.functest.framework.assertions.TextAssertions;
  8. import com.atlassian.jira.functest.framework.suite.Category;
  9. import com.atlassian.jira.functest.framework.suite.WebTest;
  10. import org.junit.Test;
  11. import org.xml.sax.SAXException;
  12. import javax.inject.Inject;
  13. import static com.atlassian.jira.functest.framework.FunctTestConstants.ADMIN_USERNAME;
  14. import static com.atlassian.jira.functest.framework.FunctTestConstants.FS;
  15. /**
  16. * @since v3.12
  17. */
  18. @WebTest({Category.FUNC_TEST, Category.ATTACHMENTS, Category.BROWSING})
  19. @Restore("TestEditAttachmentSettings.xml")
  20. @LoginAs(user = ADMIN_USERNAME)
  21. public class TestEditAttachmentSettings extends BaseJiraFuncTest {
  22. @Inject
  23. private Administration administration;
  24. @Inject
  25. private TextAssertions textAssertions;
  26. @Test
  27. public void testEditAttachmentSettingsValidation() {
  28. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  29. tester.clickLinkWithText("Edit Settings");
  30. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  31. tester.setFormElement("attachmentSize", "");
  32. tester.setFormElement("thumbnailsEnabled", "true");
  33. tester.submit("Update");
  34. //
  35. tester.assertTextPresent("Please specify the attachment size.");
  36. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  37. tester.setFormElement("attachmentSize", "-1");
  38. tester.setFormElement("thumbnailsEnabled", "true");
  39. tester.submit("Update");
  40. tester.assertTextPresent("Attachment size must be a positive number.");
  41. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  42. tester.setFormElement("attachmentSize", "0");
  43. tester.setFormElement("thumbnailsEnabled", "true");
  44. tester.submit("Update");
  45. tester.assertTextPresent("Attachment size must be a positive number.");
  46. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  47. tester.setFormElement("attachmentSize", "2147483648"); //Integer.MAX_VALUE + 1
  48. tester.setFormElement("thumbnailsEnabled", "true");
  49. tester.submit("Update");
  50. tester.assertTextPresent("Attachment size must be a number between 1 to 2147483647");
  51. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  52. tester.setFormElement("attachmentSize", "9999999999");
  53. tester.setFormElement("thumbnailsEnabled", "true");
  54. tester.submit("Update");
  55. tester.assertTextPresent("Attachment size must be a number between 1 to 2147483647");
  56. tester.checkCheckbox("attachmentPathOption", "DISABLED");
  57. tester.setFormElement("attachmentSize", "1");
  58. tester.setFormElement("thumbnailsEnabled", "true");
  59. tester.submit("Update");
  60. tester.assertTextPresent("Attachments must be enabled to enable thumbnails.");
  61. tester.checkCheckbox("attachmentPathOption", "DISABLED");
  62. tester.setFormElement("attachmentSize", "1");
  63. tester.setFormElement("thumbnailsEnabled", "false");
  64. tester.setFormElement("zipSupport", "true");
  65. tester.submit("Update");
  66. tester.assertTextPresent("Attachments must be enabled to enable ZIP support.");
  67. }
  68. @Test
  69. public void testSizeIsNotUpdatedIfAttachmentsDisabled() throws SAXException {
  70. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  71. tester.clickLinkWithText("Edit Settings");
  72. //set the attachment size to a known size
  73. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  74. tester.setFormElement("attachmentSize", "12345");
  75. tester.submit("Update");
  76. tester.assertTextPresent("12 kB");
  77. tester.clickLinkWithText("Edit Settings");
  78. //disable attachments and change the attachment size
  79. tester.checkCheckbox("attachmentPathOption", "DISABLED");
  80. tester.setFormElement("attachmentSize", "54321");
  81. tester.setFormElement("thumbnailsEnabled", "false");
  82. tester.setFormElement("zipSupport", "false");
  83. tester.submit("Update");
  84. tester.assertTextPresent("12 kB"); //the attachment size should not have been updated
  85. //go back to the edit page and assert the size value has not changed
  86. tester.clickLinkWithText("Edit Settings");
  87. tester.assertTextPresent("12345");
  88. tester.assertTextNotPresent("54321");
  89. }
  90. @Test
  91. public void testEditAttachmentSettingsJiraHome() {
  92. navigation.logout();
  93. navigation.login("sysadmin", "sysadmin");
  94. // this uses the default path (i.e. jira home)
  95. administration.attachments().enable("2940");
  96. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  97. tester.clickLinkWithText("Edit Settings");
  98. tester.setFormElement("thumbnailsEnabled", "true");
  99. tester.submit("Update");
  100. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "ON", "Attachment Path", "Default Directory", "Attachment Size", "3 kB", "Enable Thumbnails", "ON"});
  101. }
  102. @Test
  103. public void testEditAttachmentSettingsWithGlobalAdmin() {
  104. String attachmentPath = getEnvironmentData().getWorkingDirectory().getAbsolutePath() + FS + "attachments";
  105. //disable attachments so that the global admin does not have a link to the edit page
  106. navigation.logout();
  107. navigation.login("sysadmin", "sysadmin");
  108. navigation.gotoAdmin();
  109. administration.attachments().enable("8765");//enable to set the attachment size (so size that value of size is known)
  110. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  111. tester.clickLinkWithText("Edit Settings");
  112. tester.checkCheckbox("attachmentPathOption", "DISABLED");
  113. tester.setFormElement("thumbnailsEnabled", "false");
  114. tester.setFormElement("zipSupport", "false");
  115. tester.submit("Update");
  116. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "OFF", "Attachment Path", "Attachment Size", "9 kB", "Enable Thumbnails", "OFF"});
  117. //check global admin cannot see the edit config link
  118. navigation.logout();
  119. navigation.login("globaladmin", "globaladmin");
  120. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  121. tester.assertTextPresent("You can not enable thumbnails unless attachments are enabled.");
  122. tester.assertLinkNotPresentWithText("Edit Settings");
  123. //goto the edit page directly as the global admin and verify cannot change system admin options
  124. tester.gotoPage("/secure/admin/jira/EditAttachmentSettings!default.jspa");
  125. tester.assertFormElementNotPresent("attachmentPathOption"); //should be hidden as only system admin can update this field
  126. tester.assertFormElementNotPresent("attachmentPath"); //should be hidden as only system admin can update this field
  127. tester.setFormElement("attachmentSize", "5678");
  128. tester.setFormElement("thumbnailsEnabled", "true"); //try to enable thumbnails
  129. tester.submit("Update");
  130. tester.assertTextPresent("Attachments must be enabled to enable thumbnails."); //verify thumbnails cannot be enabled
  131. tester.setFormElement("thumbnailsEnabled", "false"); //set to false to check attachment size is not updated
  132. tester.submit("Update");
  133. //check its still off and that size hasnt changed
  134. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "OFF", "Attachment Path", "Attachment Size", "9 kB", "Enable Thumbnails", "OFF"});
  135. //enable attachments so that global admins can modify the size and enable thumbnails
  136. navigation.logout();
  137. navigation.login("sysadmin", "sysadmin");
  138. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  139. tester.clickLinkWithText("Edit Settings");
  140. tester.checkCheckbox("attachmentPathOption", "DEFAULT");
  141. tester.setFormElement("attachmentSize", "1234");
  142. tester.setFormElement("thumbnailsEnabled", "false");
  143. tester.submit("Update");
  144. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "ON", "Attachment Size", "1 kB", "Enable Thumbnails", "OFF"});
  145. //check global admins can now edit part of the attachment settings
  146. navigation.logout();
  147. navigation.login("globaladmin", "globaladmin");
  148. navigation.gotoAdminSection(Navigation.AdminSection.ATTACHMENTS);
  149. tester.assertLinkPresentWithText("Edit Settings");
  150. tester.clickLinkWithText("Edit Settings");
  151. tester.assertFormElementNotPresent("attachmentPathOption"); //should be hidden as only system admin can update this field
  152. tester.assertFormElementNotPresent("attachmentPath"); //should be hidden as only system admin can update this field
  153. tester.setFormElement("attachmentSize", "3456");
  154. tester.setFormElement("thumbnailsEnabled", "true");
  155. tester.submit("Update");
  156. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "ON", "Attachment Size", "3 kB", "Enable Thumbnails", "ON"});
  157. }
  158. @Test
  159. public void testEditAttachmentSize() {
  160. assertAttachmentSize(1, "0.0 kB");
  161. assertAttachmentSize(1024, "1.0 kB");
  162. assertAttachmentSize(1024 * 2, "2 kB");
  163. assertAttachmentSize(1024 * 1024, "1024 kB");
  164. assertAttachmentSize(1024 * 1024 + 1, "1.00 MB");
  165. assertAttachmentSize(1024 * 1024 * 155 / 100, "1.55 MB");
  166. assertAttachmentSize(1024 * 1024 * 10, "10.00 MB");
  167. assertAttachmentSize(Integer.MAX_VALUE, "2,048.00 MB");
  168. }
  169. private void assertAttachmentSize(int maxSizeInBytes, String maxSizePrettyFormat) {
  170. administration.attachments().enable(String.valueOf(maxSizeInBytes));
  171. textAssertions.assertTextSequence(tester.getDialog().getResponseText(), new String[]{"Allow Attachments", "ON", "Attachment Path", "Attachment Size", maxSizePrettyFormat, "Enable Thumbnails"});
  172. navigation.issue().goToCreateIssueForm(null, null);
  173. tester.assertTextPresent("The maximum file upload size is " + maxSizePrettyFormat + ".");
  174. navigation.issue().gotoIssue("HSP-1");
  175. tester.clickLink("attach-file");
  176. tester.assertTextPresent("The maximum file upload size is " + maxSizePrettyFormat + ".");
  177. }
  178. }