PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jira-project/jira-functional-tests/jira-func-tests/src/main/java/com/atlassian/jira/webtests/ztests/dashboard/TestEditPortalPage.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 202 lines | 128 code | 30 blank | 44 comment | 0 complexity | b6e70ec2ebffe939417dac59b16cfb7f MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.webtests.ztests.dashboard;
  2. import com.atlassian.core.util.collection.EasyList;
  3. import com.atlassian.jira.functest.framework.Administration;
  4. import com.atlassian.jira.functest.framework.BaseJiraFuncTest;
  5. import com.atlassian.jira.functest.framework.Dashboard;
  6. import com.atlassian.jira.functest.framework.LoginAs;
  7. import com.atlassian.jira.functest.framework.sharing.SharedEntityInfo;
  8. import com.atlassian.jira.functest.framework.sharing.TestSharingPermissionUtils;
  9. import com.atlassian.jira.functest.framework.suite.Category;
  10. import com.atlassian.jira.functest.framework.suite.WebTest;
  11. import org.junit.Before;
  12. import org.junit.Test;
  13. import javax.inject.Inject;
  14. import java.util.List;
  15. import static com.atlassian.jira.functest.framework.FunctTestConstants.ADMIN_USERNAME;
  16. import static com.atlassian.jira.functest.framework.FunctTestConstants.FRED_USERNAME;
  17. /**
  18. * Test the EditPortalPage action on professional and enterprise
  19. *
  20. * @since v3.13
  21. */
  22. @WebTest({Category.FUNC_TEST, Category.DASHBOARDS})
  23. //todo annotation @LoginAs was added automatically - consider removing it if not needed by this test (otherwise remove this comment)
  24. @LoginAs(user = ADMIN_USERNAME)
  25. public class TestEditPortalPage extends BaseJiraFuncTest {
  26. private static final SharedEntityInfo PAGE_FRED_PRIVATE = new SharedEntityInfo(10010L, "PrivateFredDashboard", "This is private to fred and should not be visible to anyone else.", true, TestSharingPermissionUtils.createPrivatePermissions());
  27. private static final SharedEntityInfo PAGE_FRED_PUBLIC = new SharedEntityInfo(10011L, "PublicFredDashboard", "This is a dashboard page that can be seen by everyone.", true, TestSharingPermissionUtils.createPublicPermissions());
  28. private static final SharedEntityInfo PAGE_EXISTS = new SharedEntityInfo(10012L, "Exists", null, true, TestSharingPermissionUtils.createPrivatePermissions());
  29. private static final SharedEntityInfo PAGE_ADMINNOTFAVOURITE = new SharedEntityInfo(10013L, "AdminNotFavourite", null, false, TestSharingPermissionUtils.createPublicPermissions());
  30. private static final SharedEntityInfo PAGE_ADMINFAVOURITE = new SharedEntityInfo(10014L, "AdminFavourite", null, true, TestSharingPermissionUtils.createPublicPermissions());
  31. private static final Long SYSTEM_DEFAULT_PAGE_ID = 10000L;
  32. private static final String FRED_USER_NAME = FRED_USERNAME;
  33. @Inject
  34. private Administration administration;
  35. @Before
  36. public void setUpTest() {
  37. administration.restoreData("BaseProfessionalPortalPage.xml");
  38. }
  39. /**
  40. * Make sure the page handles not having a page passed to it.
  41. */
  42. @Test
  43. public void testMissingPageId() {
  44. SharedEntityInfo page = new SharedEntityInfo(null, "testMissingPageId", null, true, null);
  45. _testCantEditPageWithFormError(page, "You must select a dashboard to edit.");
  46. }
  47. /**
  48. * Make sure you can't edit to something named the same thing under the same user.
  49. */
  50. @Test
  51. public void testEditNameAlreadyExists() {
  52. SharedEntityInfo page = new SharedEntityInfo(PAGE_ADMINFAVOURITE.getId(), "Exists", null, true, null);
  53. _testPageNotEdited(page, PAGE_ADMINFAVOURITE, "Dashboard with same name already exists.");
  54. }
  55. /**
  56. * Make sure you can't save a page with a blank name.
  57. */
  58. @Test
  59. public void testEditBlankName() {
  60. SharedEntityInfo page = new SharedEntityInfo(PAGE_EXISTS.getId(), "", null, true, null);
  61. _testPageNotEdited(page, PAGE_EXISTS, "You must specify a name to save the dashboard as.");
  62. }
  63. /**
  64. * Make sure you can't edit the system default dashboard page.
  65. */
  66. @Test
  67. public void testEditSystemDefaultPage() {
  68. SharedEntityInfo page = new SharedEntityInfo(SYSTEM_DEFAULT_PAGE_ID, "testEditSystemDefaultPage", null, true, null);
  69. _testCantEditPageWithFormError(page, "You cannot edit the system dashboard.");
  70. }
  71. /**
  72. * Make sure you can't edit a page that you don't have permission to edit.
  73. */
  74. @Test
  75. public void testNoPermissionToEdit() {
  76. navigation.login(FRED_USER_NAME);
  77. SharedEntityInfo page = new SharedEntityInfo(PAGE_EXISTS.getId(), "", null, true, null);
  78. // we dont distinguished between no page and page that is not yours.
  79. _testCantEditPageWithFormError(page, "You must select a dashboard to edit.");
  80. }
  81. /**
  82. * Make sure you can't edit a page that is shared with you but you don't have permission is edit.
  83. */
  84. @Test
  85. public void testNoPermissionToEditButPageIsShared() {
  86. navigation.login(FRED_USER_NAME);
  87. SharedEntityInfo page = new SharedEntityInfo(PAGE_ADMINFAVOURITE.getId(), "testNoPermissionToEditButPageIsShared", null, true, null);
  88. _testCantEditPageWithFormError(page, "You may only create, modify or delete dashboards that you own.");
  89. }
  90. /**
  91. * Make sure the page handles the case when a page does not exist.
  92. */
  93. @Test
  94. public void testNoPageExists() {
  95. SharedEntityInfo page = new SharedEntityInfo(666L, "testNoPageExists", null, true, null);
  96. // we dont distinguished between no page and page that is not yours.
  97. _testCantEditPageWithFormError(page, "You must select a dashboard to edit.");
  98. }
  99. /**
  100. * Make sure the edit view reflect the initial state of the input page.
  101. */
  102. @Test
  103. public void testEditViewReflectsData() {
  104. validateInitialState(PAGE_ADMINFAVOURITE);
  105. validateInitialState(PAGE_ADMINNOTFAVOURITE);
  106. navigation.login(FRED_USER_NAME);
  107. validateInitialState(PAGE_FRED_PRIVATE);
  108. validateInitialState(PAGE_FRED_PUBLIC);
  109. }
  110. /**
  111. * Make sure that the name and description can be changed. Also checks XSS problems do not exist.
  112. */
  113. @Test
  114. public void testXSSNameAdnDescription() {
  115. SharedEntityInfo page = new SharedEntityInfo(PAGE_EXISTS.getId(), "<script>alert('IName')</script>", "<script>alert('IDescription')</script>", true, TestSharingPermissionUtils.createPrivatePermissions());
  116. _testPageEditedCorrectly(page, EasyList.build(page, PAGE_ADMINFAVOURITE));
  117. }
  118. /**
  119. * Make sure that the page can save with the same name as it began with.
  120. */
  121. @Test
  122. public void testEditCanSaveItself() {
  123. SharedEntityInfo page = new SharedEntityInfo(PAGE_EXISTS);
  124. page.setDescription("A new description");
  125. _testPageEditedCorrectly(page, EasyList.build(page, PAGE_ADMINFAVOURITE));
  126. }
  127. /**
  128. * Make sure a page can be de-favourited.
  129. */
  130. @Test
  131. public void testChangeFavouriteToFalse() {
  132. SharedEntityInfo page = new SharedEntityInfo(PAGE_ADMINFAVOURITE);
  133. page.setFavourite(false);
  134. _testPageEditedCorrectly(page, EasyList.build(PAGE_EXISTS));
  135. navigation.dashboard().navigateToMy();
  136. assertions.getDashboardAssertions().assertDashboardPages(EasyList.build(page, PAGE_ADMINNOTFAVOURITE, PAGE_EXISTS), Dashboard.Table.OWNED);
  137. }
  138. /**
  139. * Make sure that a page can be made favourite.
  140. */
  141. @Test
  142. public void testChangeFavouriteToTrue() {
  143. SharedEntityInfo page = new SharedEntityInfo(PAGE_ADMINNOTFAVOURITE);
  144. page.setFavourite(true);
  145. _testPageEditedCorrectly(page, EasyList.build(PAGE_EXISTS, PAGE_ADMINFAVOURITE, page));
  146. navigation.dashboard().navigateToMy();
  147. assertions.getDashboardAssertions().assertDashboardPages(EasyList.build(PAGE_ADMINFAVOURITE, page, PAGE_EXISTS), Dashboard.Table.OWNED);
  148. }
  149. private void _testPageEditedCorrectly(final SharedEntityInfo page, List expectedPageList) {
  150. navigation.dashboard().editPage(page);
  151. assertions.getDashboardAssertions().assertDashboardPages(expectedPageList, Dashboard.Table.FAVOURITE);
  152. }
  153. private void _testPageNotEdited(final SharedEntityInfo page, final String expectedText) {
  154. navigation.dashboard().editPage(page);
  155. assertions.getJiraFormAssertions().assertAuiFieldErrMsg(expectedText);
  156. }
  157. private void _testPageNotEdited(final SharedEntityInfo page, final SharedEntityInfo oldPage, final String expectedText) {
  158. _testPageNotEdited(page, expectedText);
  159. validateInitialState(oldPage);
  160. }
  161. private void _testCantEditPageWithFormError(final SharedEntityInfo page, final String expectedText) {
  162. navigation.dashboard().editPage(page);
  163. assertions.getJiraFormAssertions().assertFormErrMsg(expectedText);
  164. }
  165. private void validateInitialState(final SharedEntityInfo page) {
  166. tester.gotoPage("secure/EditPortalPage!default.jspa?pageId=" + page.getId());
  167. tester.assertFormElementEquals("portalPageName", page.getName());
  168. tester.assertFormElementEquals("portalPageDescription", page.getDescription());
  169. tester.assertFormElementEquals("favourite", String.valueOf(page.isFavourite()));
  170. tester.assertFormElementEquals("pageId", String.valueOf(page.getId()));
  171. }
  172. }