PageRenderTime 77ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/jira-project/jira-functional-tests/jira-func-tests/src/main/java/com/atlassian/jira/functest/framework/EditIssueFieldVisibility.java

https://bitbucket.org/ahmed_bilal_360factors/jira7-core
Java | 198 lines | 159 code | 31 blank | 8 comment | 11 complexity | aa272a954e69a1c50370b43bd6c66aaa MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.jira.functest.framework;
  2. import com.atlassian.jira.testkit.client.log.FuncTestLogger;
  3. import com.meterware.httpunit.TableCell;
  4. import com.meterware.httpunit.WebLink;
  5. import com.meterware.httpunit.WebTable;
  6. import net.sourceforge.jwebunit.WebTester;
  7. import org.xml.sax.SAXException;
  8. import javax.inject.Inject;
  9. import java.io.IOException;
  10. import static com.atlassian.jira.functest.framework.FunctTestConstants.AFFECTS_VERSIONS_FIELD_ID;
  11. import static com.atlassian.jira.functest.framework.FunctTestConstants.COMPONENTS_FIELD_ID;
  12. import static com.atlassian.jira.functest.framework.FunctTestConstants.DUE_DATE_FIELD_ID;
  13. import static com.atlassian.jira.functest.framework.FunctTestConstants.FIELD_TABLE_ID;
  14. import static com.atlassian.jira.functest.framework.FunctTestConstants.FIX_VERSIONS_FIELD_ID;
  15. import static com.atlassian.jira.functest.framework.FunctTestConstants.SECURITY_LEVEL_FIELD_ID;
  16. import static org.junit.Assert.fail;
  17. /**
  18. * @since v7.1
  19. */
  20. public class EditIssueFieldVisibility {
  21. private static final String HIDE_FIELD_OPERATION_NAME = "Hide";
  22. private static final String SHOW_FIELD_OPERATION_NAME = "Show";
  23. private static final String OPTIONAL_FIELD_OPERATION_NAME = "Optional";
  24. private static final int FIELD_TABLE_FIELD_NAME_COLUMN_INDEX = 0;
  25. private static final int FIELD_TABLE_OPERATIONS_COLUMN_INDEX = 2;
  26. private static final String PAGE_ENTERPRISE_FIELD_CONFIGURATIONS = "/secure/admin/ViewFieldLayouts.jspa";
  27. private final Navigation navigation;
  28. private final WebTester tester;
  29. private final FuncTestLogger logger;
  30. @Inject
  31. public EditIssueFieldVisibility(final Navigation navigation,
  32. final WebTester tester,
  33. final FuncTestLogger logger) {
  34. this.navigation = navigation;
  35. this.tester = tester;
  36. this.logger = logger;
  37. }
  38. // changes a field from hide to show or vice wersa
  39. public void setHiddenFieldsOnEnterprise(final String fieldLayoutName, final String fieldName) {
  40. gotoFieldLayoutOnEnterprise(fieldLayoutName);
  41. assertViewIssueFields();
  42. doFieldOperation(fieldName, HIDE_FIELD_OPERATION_NAME);
  43. }
  44. private void gotoFieldLayoutOnEnterprise(final String fieldLayoutName) {
  45. navigation.gotoPage(PAGE_ENTERPRISE_FIELD_CONFIGURATIONS);
  46. tester.assertTextPresent("View Field Configurations");
  47. tester.clickLinkWithText(fieldLayoutName);
  48. }
  49. public void setShownFieldsOnEnterprise(final String fieldLayoutName, final String fieldName) {
  50. gotoFieldLayoutOnEnterprise(fieldLayoutName);
  51. assertViewIssueFields();
  52. doFieldOperation(fieldName, SHOW_FIELD_OPERATION_NAME);
  53. }
  54. public void setRequiredFieldsOnEnterprise(final String fieldLayoutName, final String fieldName) {
  55. gotoFieldLayoutOnEnterprise(fieldLayoutName);
  56. assertViewIssueFields();
  57. setRequiredField(fieldName);
  58. }
  59. public void setOptionalFieldsOnEnterprise(final String fieldLayoutName, final String fieldName) {
  60. gotoFieldLayoutOnEnterprise(fieldLayoutName);
  61. assertViewIssueFields();
  62. doFieldOperation(fieldName, OPTIONAL_FIELD_OPERATION_NAME);
  63. }
  64. public void setRequiredField(final String fieldName) {
  65. assertViewIssueFields();
  66. try {
  67. final WebTable fieldTable = tester.getDialog().getResponse().getTableWithID(FIELD_TABLE_ID);
  68. // First row is a headings row so skip it
  69. for (int i = 1; i < fieldTable.getRowCount(); i++) {
  70. final String field = fieldTable.getCellAsText(i, FIELD_TABLE_FIELD_NAME_COLUMN_INDEX);
  71. if (field.contains(fieldName)) {
  72. final TableCell linkCell = fieldTable.getTableCell(i, FIELD_TABLE_OPERATIONS_COLUMN_INDEX);
  73. final WebLink requiredLink = linkCell.getLinkWith("Required");
  74. if (requiredLink == null) {
  75. fail("Cannot find 'required' link for field '" + fieldName + "'.");
  76. } else {
  77. requiredLink.click();
  78. return;
  79. }
  80. }
  81. }
  82. fail("Cannot find field with id '" + fieldName + "'.");
  83. } catch (final SAXException e) {
  84. fail("Cannot find table with id '" + FIELD_TABLE_ID + "'.");
  85. e.printStackTrace();
  86. } catch (final IOException e) {
  87. fail("Cannot click 'required' link for field id '" + fieldName + "'.");
  88. }
  89. }
  90. // Sets fields to be required
  91. public void setRequiredFields() {
  92. resetFields();
  93. logger.log("Set fields to be required");
  94. gotoViewIssueFields();
  95. setRequiredField(AFFECTS_VERSIONS_FIELD_ID);
  96. setRequiredField(FIX_VERSIONS_FIELD_ID);
  97. setRequiredField(COMPONENTS_FIELD_ID);
  98. }
  99. public void setHiddenFields(final String fieldName) {
  100. logger.log("Hide field " + fieldName);
  101. gotoViewIssueFields();
  102. assertViewIssueFields();
  103. doFieldOperation(fieldName, HIDE_FIELD_OPERATION_NAME);
  104. }
  105. public void setShownFields(final String fieldName) {
  106. logger.log("Show field " + fieldName);
  107. gotoViewIssueFields();
  108. assertViewIssueFields();
  109. doFieldOperation(fieldName, SHOW_FIELD_OPERATION_NAME);
  110. }
  111. public void doFieldOperation(final String fieldName, final String linkName) {
  112. assertViewIssueFields();
  113. try {
  114. final WebTable fieldTable = tester.getDialog().getResponse().getTableWithID(FIELD_TABLE_ID);
  115. // First row is a headings row so skip it
  116. for (int i = 1; i < fieldTable.getRowCount(); i++) {
  117. final String field = fieldTable.getCellAsText(i, FIELD_TABLE_FIELD_NAME_COLUMN_INDEX);
  118. if (field.contains(fieldName)) {
  119. final TableCell linkCell = fieldTable.getTableCell(i, FIELD_TABLE_OPERATIONS_COLUMN_INDEX);
  120. final WebLink link = linkCell.getLinkWith(linkName);
  121. if (link == null) {
  122. // This is usually OK, as this happens when e.g. hiding a field that is already hidden
  123. logger.log("Link with name '" + linkName + "' does not exist.");
  124. return;
  125. } else {
  126. link.click();
  127. return;
  128. }
  129. }
  130. }
  131. fail("Cannot find field with id '" + fieldName + "'.");
  132. } catch (final SAXException e) {
  133. fail("Cannot find table with id '" + FIELD_TABLE_ID + "'.");
  134. e.printStackTrace();
  135. } catch (final IOException e) {
  136. fail("Cannot click '" + linkName + "' link for field id '" + fieldName + "'.");
  137. }
  138. }
  139. public void resetFields() {
  140. logger.log("Restore default field settings");
  141. gotoViewIssueFields();
  142. if (tester.getDialog().isLinkPresentWithText("Restore Defaults")) {
  143. tester.clickLinkWithText("Restore Defaults");
  144. }
  145. }
  146. public void setDueDateToRequried() {
  147. resetFields();
  148. logger.log("Set 'Due Date' Field to required");
  149. gotoViewIssueFields();
  150. setRequiredField(DUE_DATE_FIELD_ID);
  151. }
  152. public void setSecurityLevelToRequried() {
  153. resetFields();
  154. logger.log("Set 'Security Level' Field to required");
  155. gotoViewIssueFields();
  156. setRequiredField(SECURITY_LEVEL_FIELD_ID);
  157. }
  158. public void assertViewIssueFields() {
  159. tester.assertTextPresent("View Field Configuration");
  160. }
  161. private void gotoViewIssueFields() {
  162. navigation.gotoPage(PAGE_ENTERPRISE_FIELD_CONFIGURATIONS);
  163. tester.assertTextPresent("View Field Configurations");
  164. tester.clickLinkWithText("Configure");
  165. tester.assertTextPresent("View Field Configuration");
  166. }
  167. }