Commits

Don Brown committed 804370d

Add functional test, new container

* Add -Pit to run it
* The test is a bit flaky though I can't figure it out. Will ask
Bob when he gets back

Issue 20

Comments (0)

Files changed (5)

     </description>
 
     <properties>
-        <p3.version>0.6.940</p3.version>
-        <sdk.version>4.1.2</sdk.version>
+        <p3.version>0.6.946</p3.version>
+        <sdk.version>4.1.4</sdk.version>
+        <jira.version>6.0-OD-04</jira.version>
+        <skipITs>true</skipITs>
     </properties>
 
+    <profiles>
+        <profile>
+            <id>it</id>
+            <properties>
+                <skipITs>false</skipITs>
+            </properties>
+        </profile>
+    </profiles>
+
     <dependencies>
         <dependency>
             <groupId>com.atlassian.plugins</groupId>
             <artifactId>remotable-plugins-plugin-api</artifactId>
             <version>${p3.version}</version>
             <scope>provided</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>com.atlassian.labs</groupId>
+                    <artifactId>confluence-xmlrpc-java-client-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>com.atlassian.util.concurrent</groupId>
+            <artifactId>atlassian-util-concurrent</artifactId>
+            <version>2.4.1</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.atlassian.plugins</groupId>
+            <artifactId>remotable-plugins-test</artifactId>
+            <version>${p3.version}</version>
+            <scope>test</scope>
         </dependency>
 
         <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>atlassian-jira-pageobjects</artifactId>
+            <version>${jira.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>com.googlecode.json-simple</groupId>
+            <artifactId>json-simple</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>jira-rest-java-client-core</artifactId>
+            <version>2.0.0-m5</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.jvnet.hudson</groupId>
+            <artifactId>jira-api</artifactId>
+            <version>1.0</version>
+            <scope>test</scope>
+        </dependency>
+
+
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.6</version>
                 <configuration>
                     <extractDependencies>true</extractDependencies>
                     <containerVersion>${p3.version}</containerVersion>
+                    <productVersion>${jira.version}</productVersion>
+                    <productDataVersion>${jira.version}</productDataVersion>
+                    <installPlugin>false</installPlugin>
+                    <product>jira</product>
+                    <skipITs>${skipITs}</skipITs>
                 </configuration>
             </plugin>
             <plugin>

src/main/java/servlets/CreateSubtasksServlet.java

 package servlets;
 
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import services.SubtaskManager;
                 Iterable<String> createdSubtaskKeys = subtaskManager.createSubtasks(parentIssueKey, tasks);
 
                 resp.setStatus(SC_OK);
-                resp.getWriter().write(new JSONArray(newArrayList(createdSubtaskKeys)).toString(2));
+                JSONArray.writeJSONString(newArrayList(createdSubtaskKeys), resp.getWriter());
             }
             catch (Exception ex)
             {
                 log.warn("Unable to create subtasks: " + ex.getMessage());
                 log.error(ex.getMessage(), ex);
                 resp.setStatus(SC_BAD_REQUEST);
-                resp.getWriter().write(new JSONObject(Collections.singletonMap("error", ex.getMessage())).toString(2));
+                JSONObject.writeJSONString(Collections.singletonMap("error", ex.getMessage()), resp.getWriter());
             }
             resp.getWriter().close();
         }
-        catch (JSONException ex)
-        {
-            log.error("JSON error: " + ex.getMessage(), ex);
-            resp.sendError(SC_INTERNAL_SERVER_ERROR);
-        }
         catch (Throwable t)
         {
             log.error(t.getMessage(), t);

src/test/java/it/CreateSubtasksDialog.java

+package it;
+
+import com.atlassian.pageobjects.binder.Init;
+import com.atlassian.plugin.remotable.pageobjects.RemoteDialog;
+import com.atlassian.plugin.remotable.pageobjects.RemotePage;
+import com.google.common.base.Function;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import javax.annotation.Nullable;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+/**
+ */
+public class CreateSubtasksDialog extends RemoteDialog
+{
+    private RemotePage page;
+
+    @Init
+    public void init()
+    {
+        this.page = pageBinder.bind(RemotePage.class, "servlet-quickCreate");
+    }
+
+    public CreateSubtasksDialog addTask(final String title)
+    {
+        page.runInFrame(new Callable<Void>()
+        {
+            public Void call() throws Exception {
+                driver.waitUntilElementIsLocated(By.className("subtask-title"));
+                List<WebElement> titles = driver.findElements(By.className("subtask-title"));
+                titles.get(titles.size() - 1).click();
+                titles.get(titles.size() - 1).sendKeys(title + "\n");
+                driver.waitUntilElementIsLocated(By.className("committed"));
+                return null;
+            }
+        });
+        return this;
+    }
+
+    public String submitWithMessage() {
+        driver.findElement(By.className("ra-dialog-submit")).click();
+        //submit();
+        return page.runInFrame(new Callable<String>() {
+            public String call() throws Exception {
+                driver.waitUntilElementIsLocated(By.className("aui-message"));
+                return driver.findElement(By.className("aui-message")).getText();
+            }
+        });
+    }
+}

src/test/java/it/MoreMenu.java

+package it;
+
+import com.atlassian.pageobjects.PageBinder;
+import com.atlassian.webdriver.AtlassianWebDriver;
+import org.openqa.selenium.By;
+
+import javax.inject.Inject;
+
+/**
+ */
+public class MoreMenu {
+
+    @Inject
+    private AtlassianWebDriver driver;
+
+    @Inject
+    private PageBinder pageBinder;
+
+    public CreateSubtasksDialog openCreateSubtasks() {
+        driver.findElement(By.id("opsbar-operations_more")).click();
+        driver.waitUntilElementIsLocated(By.id("webitem-quickCreate"));
+        driver.findElement(By.id("webitem-quickCreate")).click();
+        return pageBinder.bind(CreateSubtasksDialog.class);
+    }
+}

src/test/java/it/TestCreateSubtasks.java

+package it;
+
+import com.atlassian.jira.pageobjects.JiraTestedProduct;
+import com.atlassian.jira.pageobjects.pages.viewissue.ViewIssuePage;
+import com.atlassian.jira.rest.client.api.JiraRestClient;
+import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
+import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
+import com.atlassian.pageobjects.TestedProduct;
+import com.atlassian.pageobjects.TestedProductFactory;
+import com.atlassian.plugin.remotable.junit.HtmlDumpRule;
+import com.atlassian.plugin.remotable.junit.Mode;
+import com.atlassian.plugin.remotable.junit.UniversalBinaries;
+import com.atlassian.plugin.remotable.junit.UniversalBinariesContainerJUnitRunner;
+import com.atlassian.pageobjects.page.HomePage;
+import com.atlassian.pageobjects.page.LoginPage;
+import com.atlassian.webdriver.pageobjects.WebDriverTester;
+import hudson.plugins.jira.soap.JiraSoapService;
+import hudson.plugins.jira.soap.JiraSoapServiceServiceLocator;
+import hudson.plugins.jira.soap.RemoteIssue;
+import hudson.plugins.jira.soap.RemoteProject;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.*;
+import org.junit.rules.MethodRule;
+import org.junit.runner.RunWith;
+import org.twdata.pkgscanner.ExportPackageListBuilder;
+
+import java.net.URI;
+import java.net.URL;
+import java.rmi.RemoteException;
+import java.util.Locale;
+
+import static org.junit.Assert.*;
+
+@RunWith(UniversalBinariesContainerJUnitRunner.class)
+@UniversalBinaries(value = "${moduleDir}/target/taskmaster-plugin.jar", mode = Mode.CONTAINER)
+public final class TestCreateSubtasks
+{
+
+    private static TestedProduct<WebDriverTester> product = TestedProductFactory.create(JiraTestedProduct.class);
+    private static String token;
+    private static JiraSoapService jiraSoapClient;
+    private static RemoteProject project;
+
+    @BeforeClass
+    public static void before()
+    {
+        Logger.getLogger(ExportPackageListBuilder.class).setLevel(Level.ERROR);
+        try
+        {
+            jiraSoapClient = new JiraSoapServiceServiceLocator().getJirasoapserviceV2(new URL(
+                    product.getProductInstance().getBaseUrl() + "/rpc/soap/jirasoapservice-v2"));
+            token = jiraSoapClient.login("admin", "admin");
+
+            String projectKey = RandomStringUtils.randomAlphabetic(4).toUpperCase(Locale.US);
+            project = jiraSoapClient.createProject(token, projectKey, "Test project " + projectKey,
+                    "This is a test project " + projectKey,
+                    null, "admin", jiraSoapClient.getPermissionSchemes(token)[0], null, null);
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @AfterClass
+    public static void after() {
+        if (jiraSoapClient != null) {
+            try {
+                jiraSoapClient.deleteProject(token, project.getKey());
+            } catch (RemoteException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    @Rule
+    public MethodRule rule = new HtmlDumpRule(product.getTester().getDriver());
+
+    @After
+    public void logout()
+    {
+        product.getTester().getDriver().manage().deleteAllCookies();
+    }
+
+
+
+    @Test
+    public void testCreateSingleTask() throws RemoteException {
+        RemoteIssue issue = new RemoteIssue();
+        issue.setProject(project.getKey());
+        issue.setType("1");
+        issue.setSummary("Sample issue");
+        issue = jiraSoapClient.createIssue(token, issue);
+
+        product.visit(LoginPage.class).login("admin", "admin", HomePage.class);
+        product.visit(ViewIssuePage.class, issue.getKey());
+        String message = product.getPageBinder().bind(MoreMenu.class).
+                openCreateSubtasks().
+                addTask("Test task")
+                .submitWithMessage();
+
+        assertTrue(message.contains("Sub-tasks created"));
+    }
+}