PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/it/JMCAdminTest.java

https://bitbucket.org/atlassian/jiraconnect-jiraplugin/
Java | 79 lines | 61 code | 14 blank | 4 comment | 5 complexity | ce8b1b5c17bfe0f1c8745dc9f5d5c73d MD5 | raw file
  1. package it;
  2. import com.atlassian.jira.pageobjects.JiraTestedProduct;
  3. import com.atlassian.jira.pageobjects.project.ViewProjectsPage;
  4. import com.atlassian.pageobjects.TestedProduct;
  5. import com.atlassian.pageobjects.TestedProductFactory;
  6. import com.atlassian.pageobjects.page.LoginPage;
  7. import com.atlassian.webdriver.pageobjects.WebDriverTester;
  8. import it.page.ProjectSettingsPage;
  9. import org.apache.commons.httpclient.HttpClient;
  10. import org.apache.commons.httpclient.methods.GetMethod;
  11. import org.junit.After;
  12. import org.junit.Before;
  13. import org.junit.Test;
  14. import java.io.IOException;
  15. import static org.junit.Assert.*;
  16. import static org.junit.Assert.assertEquals;
  17. /**
  18. */
  19. public class JMCAdminTest {
  20. final TestedProduct<WebDriverTester> jira = TestedProductFactory.create(JiraTestedProduct.class);
  21. @Before
  22. public void setUp() {
  23. jira.visit(LoginPage.class).loginAsSysAdmin(ViewProjectsPage.class);
  24. }
  25. @After
  26. public void tearDown() {
  27. // leave the project in a state we found it... and other projects expect
  28. ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
  29. if (!page.isJMCEnabled()) {
  30. page.toggleJMCOnOff();
  31. }
  32. if (page.isJMCEnabled()) {
  33. page.deactivateApiKey();
  34. }
  35. }
  36. @Test
  37. public void testEnableJMC() throws IOException {
  38. ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
  39. final boolean jmcOn = page.isJMCEnabled();
  40. assertTrue(jmcOn != page.toggleJMCOnOff().isJMCEnabled());
  41. if (!page.isJMCEnabled()) {
  42. page.toggleJMCOnOff();
  43. }
  44. final GetMethod pollMethodGoodKey = IssueResourceUtil.makeJMCPollRequest(jira, page.getJMCApiKey(), 0);
  45. final HttpClient client = new HttpClient();
  46. assertEquals(pollMethodGoodKey.getResponseBodyAsString(), 200, client.executeMethod(pollMethodGoodKey));
  47. }
  48. @Test
  49. public void testDeactivateAPIKey() throws IOException {
  50. ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
  51. if (!page.isJMCEnabled()) {
  52. page.toggleJMCOnOff();
  53. }
  54. // check we can reach JMC... a poll maybe?
  55. final GetMethod pollMethodGoodKey = IssueResourceUtil.makeJMCPollRequest(jira, page.getJMCApiKey(), 0);
  56. final GetMethod pollMethodBadKey = IssueResourceUtil.makeJMCPollRequest(jira, "BADAPIKEY", 0);
  57. final HttpClient client = new HttpClient();
  58. page.deactivateApiKey();
  59. assertEquals(200, client.executeMethod(pollMethodBadKey));
  60. assertEquals(200, client.executeMethod(pollMethodGoodKey));
  61. page.activateApiKey();
  62. assertEquals(403, client.executeMethod(pollMethodBadKey));
  63. assertEquals(200, client.executeMethod(pollMethodGoodKey));
  64. }
  65. }