Commits

Adam Jakubowski committed 62dd74a

Step 11 Write integration tests

  • Participants
  • Parent commits a958714

Comments (0)

Files changed (5)

 			<version>${jim.version}</version>
 			<scope>provided</scope>
 		</dependency>
+        <dependency>
+            <groupId>com.atlassian.jira</groupId>
+            <artifactId>atlassian-jira-pageobjects</artifactId>
+            <version>${jira.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.jira.plugins</groupId>
+            <artifactId>jira-importers-plugin</artifactId>
+            <version>${jim.version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.atlassian.jira.tests</groupId>
+            <artifactId>jira-testkit-client</artifactId>
+            <version>${testkit.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-core-asl</artifactId>
+            <version>1.9.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-xc</artifactId>
+            <version>1.9.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-jaxrs</artifactId>
+            <version>1.9.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.jackson</groupId>
+            <artifactId>jackson-mapper-asl</artifactId>
+            <version>1.9.1</version>
+        </dependency>
 	</dependencies>
 
 	<build>
 	</build>
 
 	<properties>
-		<jira.version>5.0</jira.version>
+		<jira.version>5.0.2</jira.version>
 		<amps.version>4.0</amps.version>
-		<jim.version>5.0.1</jim.version>
-        <plugins>com.atlassian.jira.plugins:jira-importers-plugin:${jim.version}</plugins>
+        <jim.version>5.0.1</jim.version>
+		<testkit.version>5.0-m13</testkit.version>
+        <plugins>com.atlassian.jira.plugins:jira-importers-plugin:${jim.version},com.atlassian.jira.tests:jira-testkit-plugin:${testkit.version}</plugins>
 	</properties>
 
 </project>

File src/test/java/com/example/plugins/jira/csvimport/po/SimpleCsvSetupPage.java

+package com.example.plugins.jira.csvimport.po;
+
+import com.atlassian.jira.plugins.importer.po.common.AbstractImporterWizardPage;
+import com.atlassian.jira.plugins.importer.po.common.ImporterProjectsMappingsPage;
+import org.junit.Assert;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.FindBy;
+
+public class SimpleCsvSetupPage extends AbstractImporterWizardPage {
+
+    @FindBy(id = "filePath")
+    WebElement filePath;
+
+
+    public SimpleCsvSetupPage setFilePath(String filePath) {
+        this.filePath.sendKeys(filePath);
+        return this;
+    }
+
+    @Override
+    public String getUrl() {
+        return "/secure/admin/views/SimpleCsvSetupPage!default.jspa?externalSystem=" +
+                "com.example.plugins.tutorial.jira.simple-csv-importer:SimpleCSVImporterKey";
+    }
+
+    public ImporterProjectsMappingsPage next() {
+        Assert.assertTrue(nextButton.isEnabled());
+        nextButton.click();
+        return pageBinder.bind(ImporterProjectsMappingsPage.class);
+    }
+}

File src/test/java/it/com/example/plugins/jira/csvimport/TestSimpleCsvImporter.java

+package it.com.example.plugins.jira.csvimport;
+
+import com.atlassian.jira.pageobjects.JiraTestedProduct;
+import com.atlassian.jira.pageobjects.config.EnvironmentBasedProductInstance;
+import com.atlassian.jira.plugins.importer.po.ExternalImportPage;
+import com.atlassian.jira.plugins.importer.po.common.ImporterLinksPage;
+import com.atlassian.jira.plugins.importer.po.common.ImporterProjectsMappingsPage;
+import com.atlassian.jira.testkit.client.Backdoor;
+import com.atlassian.jira.testkit.client.restclient.SearchRequest;
+import com.atlassian.jira.testkit.client.restclient.SearchResult;
+import com.atlassian.jira.testkit.client.util.TestKitLocalEnvironmentData;
+import com.example.plugins.jira.csvimport.po.SimpleCsvSetupPage;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.hasItem;
+
+public class TestSimpleCsvImporter {
+	private JiraTestedProduct jira;
+	private Backdoor backdoor;
+
+	@Before
+	public void setUp() {
+		backdoor = new Backdoor(new TestKitLocalEnvironmentData());
+		backdoor.restoreBlankInstance();
+		jira = new JiraTestedProduct(null, new EnvironmentBasedProductInstance());
+	}
+
+	@Test
+	public void testSimpleCsvImporterAttachedToConfigPage() {
+		assertThat(jira.gotoLoginPage().loginAsSysAdmin(ExternalImportPage.class).getImportersOrder(),
+				hasItem("SimpleCSVImporter"));
+	}
+
+	@Test
+	public void testSimpleCsvImporterWizard() {
+		backdoor.issueLinking().enable();
+		backdoor.issueLinking().createIssueLinkType("Related", "related", "related to");
+		final SimpleCsvSetupPage setupPage = jira.gotoLoginPage().loginAsSysAdmin(SimpleCsvSetupPage.class);
+		final String file = getClass().getResource("/test.csv").getFile();
+		final ImporterProjectsMappingsPage projectsPage = setupPage.setFilePath(file).next();
+		projectsPage.createProject("project", "JIRA Project", "PRJ");
+		final ImporterLinksPage linksPage = projectsPage.next().next().next().next();
+		linksPage.setSelect("link", "Related");
+		assertTrue(linksPage.next().waitUntilFinished().isSuccess());
+		final SearchResult search = backdoor.search().getSearch(new SearchRequest().jql(""));
+		assertEquals((Integer) 4, search.total);
+	}
+}

File src/test/resources/test.csv

+1,summary 1,Low,user1,value1,2
+2,summary 2,High,user1,value2,3
+3,summary 3,Low,user2,value1,
+4,summary 4,Unknown,user3,value3,

File src/test/xml/empty.xml

+This is an empty file. It is required because without it xml directory is not created by git,
+and xml directory is required by