/src/test/java/it/JMCAdminTest.java
Java | 79 lines | 61 code | 14 blank | 4 comment | 5 complexity | ce8b1b5c17bfe0f1c8745dc9f5d5c73d MD5 | raw file
- package it;
- import com.atlassian.jira.pageobjects.JiraTestedProduct;
- import com.atlassian.jira.pageobjects.project.ViewProjectsPage;
- import com.atlassian.pageobjects.TestedProduct;
- import com.atlassian.pageobjects.TestedProductFactory;
- import com.atlassian.pageobjects.page.LoginPage;
- import com.atlassian.webdriver.pageobjects.WebDriverTester;
- import it.page.ProjectSettingsPage;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.methods.GetMethod;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Test;
- import java.io.IOException;
- import static org.junit.Assert.*;
- import static org.junit.Assert.assertEquals;
- /**
- */
- public class JMCAdminTest {
-
- final TestedProduct<WebDriverTester> jira = TestedProductFactory.create(JiraTestedProduct.class);
- @Before
- public void setUp() {
- jira.visit(LoginPage.class).loginAsSysAdmin(ViewProjectsPage.class);
- }
- @After
- public void tearDown() {
- // leave the project in a state we found it... and other projects expect
- ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
- if (!page.isJMCEnabled()) {
- page.toggleJMCOnOff();
- }
- if (page.isJMCEnabled()) {
- page.deactivateApiKey();
- }
- }
- @Test
- public void testEnableJMC() throws IOException {
- ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
- final boolean jmcOn = page.isJMCEnabled();
- assertTrue(jmcOn != page.toggleJMCOnOff().isJMCEnabled());
- if (!page.isJMCEnabled()) {
- page.toggleJMCOnOff();
- }
- final GetMethod pollMethodGoodKey = IssueResourceUtil.makeJMCPollRequest(jira, page.getJMCApiKey(), 0);
- final HttpClient client = new HttpClient();
- assertEquals(pollMethodGoodKey.getResponseBodyAsString(), 200, client.executeMethod(pollMethodGoodKey));
- }
- @Test
- public void testDeactivateAPIKey() throws IOException {
- ProjectSettingsPage page = jira.visit(ProjectSettingsPage.class, IssueResourceUtil.PROJECT_KEY);
- if (!page.isJMCEnabled()) {
- page.toggleJMCOnOff();
- }
- // check we can reach JMC... a poll maybe?
- final GetMethod pollMethodGoodKey = IssueResourceUtil.makeJMCPollRequest(jira, page.getJMCApiKey(), 0);
- final GetMethod pollMethodBadKey = IssueResourceUtil.makeJMCPollRequest(jira, "BADAPIKEY", 0);
- final HttpClient client = new HttpClient();
- page.deactivateApiKey();
- assertEquals(200, client.executeMethod(pollMethodBadKey));
- assertEquals(200, client.executeMethod(pollMethodGoodKey));
- page.activateApiKey();
- assertEquals(403, client.executeMethod(pollMethodBadKey));
- assertEquals(200, client.executeMethod(pollMethodGoodKey));
- }
- }