PageRenderTime 50ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/atlassian/jira/plugins/bitbucket/pageobjects/page/BaseConfigureRepositoriesPage.java

https://bitbucket.org/atlassian/jira-bitbucket-connector/
Java | 181 lines | 115 code | 38 blank | 28 comment | 6 complexity | b486adbe2b3309692e440ebd7552336f MD5 | raw file
  1. package com.atlassian.jira.plugins.bitbucket.pageobjects.page;
  2. import com.atlassian.jira.plugins.bitbucket.pageobjects.component.BitBucketRepository;
  3. import com.atlassian.pageobjects.Page;
  4. import com.atlassian.pageobjects.PageBinder;
  5. import com.atlassian.pageobjects.binder.WaitUntil;
  6. import com.atlassian.pageobjects.elements.CheckboxElement;
  7. import com.atlassian.pageobjects.elements.ElementBy;
  8. import com.atlassian.pageobjects.elements.PageElement;
  9. import com.atlassian.pageobjects.elements.SelectElement;
  10. import com.atlassian.pageobjects.elements.query.Poller;
  11. import com.atlassian.pageobjects.elements.query.TimedCondition;
  12. import com.atlassian.webdriver.jira.JiraTestedProduct;
  13. import org.hamcrest.Matcher;
  14. import org.openqa.selenium.By;
  15. import javax.inject.Inject;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import static com.atlassian.pageobjects.elements.query.Poller.by;
  19. /**
  20. * Represents the page to link repositories to projects
  21. */
  22. public abstract class BaseConfigureRepositoriesPage implements Page
  23. {
  24. @Inject
  25. PageBinder pageBinder;
  26. @ElementBy(id = "Submit")
  27. PageElement addRepositoryButton;
  28. @ElementBy(name = "projectKey")
  29. SelectElement projectSelect;
  30. @ElementBy(id = "url")
  31. PageElement urlTextbox;
  32. @ElementBy(id = "adminUsername")
  33. PageElement adminUsernameTextbox;
  34. @ElementBy(id = "adminPassword")
  35. PageElement adminPasswordTextbox;
  36. @ElementBy(id = "addPostCommitService")
  37. CheckboxElement addPostCommitServiceCheckbox;
  38. @ElementBy(name = "sync_status_message")
  39. PageElement syncStatusDiv;
  40. @ElementBy(className = "gh_table")
  41. PageElement projectsTable;
  42. @ElementBy(id = "addedRepositoryId")
  43. PageElement addedRepositoryIdSpan;
  44. @ElementBy(tagName = "h2")
  45. PageElement addedRepositoryH2;
  46. @ElementBy(id = "aui-message-bar")
  47. PageElement messageBarDiv;
  48. protected JiraTestedProduct jiraTestedProduct;
  49. @Override
  50. public String getUrl()
  51. {
  52. return "/secure/admin/ConfigureBitbucketRepositories!default.jspa";
  53. }
  54. @WaitUntil
  55. public void waitUntilReady()
  56. {
  57. Poller.waitUntilTrue(addRepositoryButton.timed().isPresent());
  58. }
  59. /**
  60. * Returns a list of <tt>BitBucketRepository</tt> with the current list of repositories linked.
  61. *
  62. * @return List of <tt>BitBucketRepository</tt>
  63. */
  64. public List<BitBucketRepository> getRepositories()
  65. {
  66. List<BitBucketRepository> list = new ArrayList<BitBucketRepository>();
  67. for (PageElement row : projectsTable.findAll(By.tagName("tr")))
  68. {
  69. if (row.getText().contains("Force Sync"))
  70. {
  71. list.add(pageBinder.bind(BitBucketRepository.class, row));
  72. }
  73. }
  74. return list;
  75. }
  76. /**
  77. * Deletes all repositories
  78. *
  79. * @return BitBucketConfigureRepositoriesPage
  80. */
  81. public BaseConfigureRepositoriesPage deleteAllRepositories()
  82. {
  83. List<BitBucketRepository> repos;
  84. while (!(repos = getRepositories()).isEmpty())
  85. {
  86. repos.get(0).delete();
  87. }
  88. return this;
  89. }
  90. /**
  91. * Whether a repository is currently linked to a given project
  92. *
  93. * @param projectKey The JIRA project key
  94. * @param url The repository url
  95. * @return True if repository is linked, false otherwise
  96. */
  97. public boolean isRepositoryPresent(String projectKey, String url)
  98. {
  99. boolean commitFound = false;
  100. for (BitBucketRepository repo : getRepositories())
  101. {
  102. if (repo.getProjectKey().equals(projectKey) && repo.getUrl().equals(url))
  103. {
  104. commitFound = true;
  105. break;
  106. }
  107. }
  108. return commitFound;
  109. }
  110. /**
  111. * @param matcher
  112. */
  113. public void assertThatSyncMessage(Matcher<String> matcher)
  114. {
  115. Poller.waitUntil(syncStatusDiv.timed().getText(), matcher, by(30000));
  116. }
  117. protected void checkSyncProcessSuccess()
  118. {
  119. final String statusXpath = "//div[@name='sync_status_message']/div[@class='content']/strong";
  120. TimedCondition isMsgVisibleCond = syncStatusDiv.find(By.xpath(statusXpath)).timed().isVisible();
  121. Poller.waitUntilTrue("Expected sync status message to appear.", isMsgVisibleCond);
  122. TimedCondition syncFinishedCond = syncStatusDiv.find(By.xpath(statusXpath)).timed().hasText("Sync Finished:");
  123. Poller.waitUntilTrue("Expected sync status message to be 'Sync Finished'", syncFinishedCond);
  124. }
  125. /**
  126. * The current error status message
  127. *
  128. * @return error status message
  129. */
  130. public String getErrorStatusMessage()
  131. {
  132. return messageBarDiv.find(By.className("error")).timed().getText().now();
  133. }
  134. public abstract BaseConfigureRepositoriesPage addPublicRepoToProjectSuccessfully(String projectKey, String url);
  135. public abstract BaseConfigureRepositoriesPage addRepoToProjectFailingStep1(String projectKey, String url);
  136. public abstract BaseConfigureRepositoriesPage addRepoToProjectFailingStep2(String projectKey, String url);
  137. public abstract BaseConfigureRepositoriesPage addPrivateRepoToProjectSuccessfully(String projectKey, String url);
  138. public abstract String addPublicRepoToProjectAndInstallService(String projectKey, String url, String adminUsername, String adminPassword);
  139. public void setJiraTestedProduct(JiraTestedProduct jiraTestedProduct)
  140. {
  141. this.jiraTestedProduct = jiraTestedProduct;
  142. }
  143. }