Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-16 11:10:41 -0400
committerGerrit Code Review @ Eclipse.org2013-04-21 19:07:54 -0400
commita4275ac930f94ddaa2e75dc8dff860c51b43c775 (patch)
tree1fee82f5cb060cbca7691d8e4b03a81cae09954e /org.eclipse.mylyn.bugzilla.tests/src
parent72f3117a1c2e325d823bd44c9a0c23843d93d99e (diff)
downloadorg.eclipse.mylyn.tasks-a4275ac930f94ddaa2e75dc8dff860c51b43c775.tar.gz
org.eclipse.mylyn.tasks-a4275ac930f94ddaa2e75dc8dff860c51b43c775.tar.xz
org.eclipse.mylyn.tasks-a4275ac930f94ddaa2e75dc8dff860c51b43c775.zip
399803: simplify Bugzilla fixture discovery
* Discover all fixtures dynamically and remove hard coded URLs. Change-Id: I23197e708b31a9996cf3b53558771fb06c92e77c Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=399803
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.tests/src')
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java11
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java15
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskDataHandlerTest.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaConfigurationTest.java72
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java148
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaSearchPageTest.java2
6 files changed, 74 insertions, 178 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java
index 3a953193e..ed07e4278 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java
@@ -12,6 +12,8 @@
package org.eclipse.mylyn.bugzilla.tests;
+import java.util.List;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -49,12 +51,9 @@ public class AllBugzillaHeadlessStandaloneTests {
// network tests
suite.addTestSuite(BugzillaTaskCompletionTest.class);
// tests that run against all repository versions
- if (configuration.isDefaultOnly()) {
- addTests(suite, BugzillaFixture.DEFAULT);
- } else {
- for (BugzillaFixture fixture : BugzillaFixture.ALL) {
- addTests(suite, fixture);
- }
+ List<BugzillaFixture> fixtures = configuration.discover(BugzillaFixture.class, "bugzilla");
+ for (BugzillaFixture fixture : fixtures) {
+ addTests(suite, fixture);
}
}
return suite;
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java
index 7fad7a747..fa4737627 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java
@@ -12,6 +12,8 @@
package org.eclipse.mylyn.bugzilla.tests;
+import java.util.List;
+
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -24,7 +26,6 @@ import org.eclipse.mylyn.bugzilla.tests.ui.BugzillaTaskEditorTest;
import org.eclipse.mylyn.bugzilla.tests.ui.BugzillaTaskHyperlinkDetectorTest;
import org.eclipse.mylyn.commons.sdk.util.ManagedTestSuite;
import org.eclipse.mylyn.commons.sdk.util.TestConfiguration;
-import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion;
/**
* @author Mik Kersten
@@ -58,12 +59,9 @@ public class AllBugzillaTests {
suite.addTestSuite(BugzillaTaskEditorTest.class);
suite.addTestSuite(BugzillaSearchPageTest.class);
suite.addTestSuite(BugzillaRepositorySettingsPageTest.class);
- if (configuration.isDefaultOnly()) {
- addTests(suite, BugzillaFixture.DEFAULT);
- } else {
- for (BugzillaFixture fixture : BugzillaFixture.ALL) {
- addTests(suite, fixture);
- }
+ List<BugzillaFixture> fixtures = configuration.discover(BugzillaFixture.class, "bugzilla");
+ for (BugzillaFixture fixture : fixtures) {
+ addTests(suite, fixture);
}
}
}
@@ -83,8 +81,7 @@ public class AllBugzillaTests {
fixture.add(BugzillaAttachmentHandlerTest.class);
// Only run this if we have custom status and Workflow
- if (BugzillaVersion.BUGZILLA_3_6.compareTo(fixture.getBugzillaVersion()) == 0
- && BugzillaFixture.CUSTOM_WF_AND_STATUS.equals(fixture.getDescription())) {
+ if (fixture.isCustomWorkflowAndStatus()) {
fixture.add(BugzillaCustomRepositoryTest.class);
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskDataHandlerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskDataHandlerTest.java
index 06381dbb3..d99d53f95 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskDataHandlerTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskDataHandlerTest.java
@@ -16,7 +16,6 @@ import junit.framework.TestCase;
import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.PrivilegeLevel;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
-import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.internal.tasks.core.DefaultTaskMapping;
@@ -38,12 +37,9 @@ public class BugzillaTaskDataHandlerTest extends TestCase {
private BugzillaRepositoryConnector connector;
- private BugzillaClient client;
-
@Override
public void setUp() throws Exception {
repository = BugzillaFixture.current().repository();
- client = BugzillaFixture.current().client();
connector = BugzillaFixture.current().connector();
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaConfigurationTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaConfigurationTest.java
index 4a233ae83..be0e1af87 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaConfigurationTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaConfigurationTest.java
@@ -109,46 +109,50 @@ public class BugzillaConfigurationTest extends TestCase {
* included (rdfconfig218.txt) is from mylyn.eclipse.org/bugs218
*/
public void testRepositoryConfigurationFromFile() throws Exception {
- InputStream stream = BugzillaFixture.getResource("testdata/configuration/rdfconfig218.txt");
- BufferedReader in = new BufferedReader(new InputStreamReader(stream));
-
- if (true) {
+ BufferedReader inCleaned = null;
+ try {
File tempFile = File.createTempFile("XmlCleaner-", "tmp");
tempFile.deleteOnExit();
- in = XmlCleaner.clean(in, tempFile);
- if (tempFile != null) {
- tempFile.delete();
- }
-
- }
-
- SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
- final XMLReader reader = XMLReaderFactory.createXMLReader();
- reader.setContentHandler(contentHandler);
- reader.setErrorHandler(new ErrorHandler() {
-
- public void error(SAXParseException exception) throws SAXException {
- throw exception;
- }
- public void fatalError(SAXParseException exception) throws SAXException {
- throw exception;
+ InputStream stream = BugzillaFixture.getResource("testdata/configuration/rdfconfig218.txt");
+ BufferedReader in = new BufferedReader(new InputStreamReader(stream));
+ try {
+ inCleaned = XmlCleaner.clean(in, tempFile);
+ if (tempFile != null) {
+ tempFile.delete();
+ }
+ } finally {
+ in.close();
}
- public void warning(SAXParseException exception) throws SAXException {
- throw exception;
+ SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
+ final XMLReader reader = XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(contentHandler);
+ reader.setErrorHandler(new ErrorHandler() {
+ public void error(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+
+ public void warning(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
+ });
+ reader.parse(new InputSource(inCleaned));
+
+ RepositoryConfiguration config = contentHandler.getConfiguration();
+ assertNotNull(config);
+
+ assertTrue(config.getOptionValues(BugzillaAttribute.PRODUCT).contains(
+ "Test-Long-Named-Product-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
+ } finally {
+ if (inCleaned != null) {
+ inCleaned.close();
}
- });
- reader.parse(new InputSource(in));
-
- RepositoryConfiguration config = contentHandler.getConfiguration();
- assertNotNull(config);
-
- assertTrue(config.getOptionValues(BugzillaAttribute.PRODUCT).contains(
- "Test-Long-Named-Product-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
-
- // Add your additional checking for valid data here if necessary
-
+ }
}
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java
index 6d85d9185..acb6951f2 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java
@@ -14,9 +14,7 @@ package org.eclipse.mylyn.bugzilla.tests.support;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
import junit.framework.AssertionFailedError;
@@ -51,25 +49,10 @@ import org.eclipse.osgi.util.NLS;
/**
* @author Steffen Pingel
* @author Thomas Ehrnhoefer
+ * @author Frank Becker
*/
public class BugzillaFixture extends TestFixture {
- public static final String TEST_BUGZILLA_34_URL = getServerUrl("bugs34");
-
- public static final String TEST_BUGZILLA_36_URL = getServerUrl("bugs36");
-
- public static final String TEST_BUGZILLA_40_URL = getServerUrl("bugs40");
-
- public static final String TEST_BUGZILLA_42_URL = getServerUrl("bugs42");
-
- public static final String TEST_BUGZILLA_44_URL = getServerUrl("bugs44");
-
- public static final String TEST_BUGZILLA_HEAD_URL = getServerUrl("bugshead");
-
- private static final String getServerUrl(String version) {
- return TestConfiguration.getRepositoryUrl(version);
- }
-
public static final String CUSTOM_WF = "Custom Workflow";
public static final String CUSTOM_WF_AND_STATUS = "Custom Workflow and Status";
@@ -78,47 +61,14 @@ public class BugzillaFixture extends TestFixture {
private static BugzillaFixture current;
- /**
- * @deprecated not supported any more
- */
- @Deprecated
- private static BugzillaFixture BUGS_3_4 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_34_URL, //
- "3.4.14", "");
-
- private static BugzillaFixture BUGS_3_6 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_36_URL, //
- "3.6", "");
-
- private static BugzillaFixture BUGS_3_6_CUSTOM_WF = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_36_URL
- + "-custom-wf", "3.6", CUSTOM_WF);
-
- private static BugzillaFixture BUGS_3_6_CUSTOM_WF_AND_STATUS = new BugzillaFixture(
- BugzillaFixture.TEST_BUGZILLA_36_URL + "-custom-wf-and-status", "3.6", CUSTOM_WF_AND_STATUS);
-
- private static BugzillaFixture BUGS_3_6_XML_RPC_DISABLED = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_36_URL
- + "-xml-rpc-disabled", "3.6", XML_RPC_DISABLED);
-
- private static BugzillaFixture BUGS_4_0 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_40_URL, //
- "4.0", "");
-
- private static BugzillaFixture BUGS_4_2 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_42_URL, //
- "4.2", "");
-
- private static BugzillaFixture BUGS_4_4 = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_44_URL, //
- "4.4", "");
-
- private static BugzillaFixture BUGS_HEAD = new BugzillaFixture(BugzillaFixture.TEST_BUGZILLA_HEAD_URL, //
- "4.5", "");
-
- public static BugzillaFixture DEFAULT;
-
- public static final List<BugzillaFixture> ALL;
-
private final String version;
private final BugzillaVersion bugzillaVersion;
private final Map<String, String> properties;
+ private BugzillaRepositoryConnector connector;
+
public BugzillaFixture(FixtureConfiguration config) {
super(BugzillaCorePlugin.CONNECTOR_KIND, config.getUrl());
this.version = config.getVersion();
@@ -146,17 +96,14 @@ public class BugzillaFixture extends TestFixture {
public static void cleanup010() throws Exception {
}
- public static BugzillaFixture current(BugzillaFixture fixture) {
+ public static BugzillaFixture current() {
if (current == null) {
- fixture.activate();
+ current = TestConfiguration.getDefault().discoverDefault(BugzillaFixture.class, "bugzilla");
+ current.activate();
}
return current;
}
- public static BugzillaFixture current() {
- return current(DEFAULT);
- }
-
@Override
public BugzillaFixture activate() {
current = this;
@@ -166,7 +113,7 @@ public class BugzillaFixture extends TestFixture {
@Override
protected TestFixture getDefault() {
- return DEFAULT;
+ return TestConfiguration.getDefault().discoverDefault(BugzillaFixture.class, "bugzilla");
}
public String getVersion() {
@@ -190,16 +137,18 @@ public class BugzillaFixture extends TestFixture {
public BugzillaClient client(AbstractWebLocation location, String encoding) throws CoreException {
TaskRepository taskRepository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, location.getUrl());
- String filepath = "testdata/repository/" + getRepositoryName(location.getUrl()) + "/DesciptorFile.txt";
- try {
- File file = BugzillaFixture.getFile(filepath);
- if (file != null) {
- taskRepository.setProperty(IBugzillaConstants.BUGZILLA_DESCRIPTOR_FILE, file.getCanonicalPath());
+ if (properties.get("desciptorfile") != null) {
+ String filepath = "testdata/repository/" + properties.get("desciptorfile");
+ try {
+ File file = BugzillaFixture.getFile(filepath);
+ if (file != null) {
+ taskRepository.setProperty(IBugzillaConstants.BUGZILLA_DESCRIPTOR_FILE, file.getCanonicalPath());
+ }
+ } catch (AssertionFailedError a) {
+ // ignore the Exception. The BUGZILLA_DESCRIPTOR_FILE does not exist so the property is null
+ } catch (IOException e) {
+ // ignore the Exception. The BUGZILLA_DESCRIPTOR_FILE does not exist so the property is null
}
- } catch (AssertionFailedError a) {
- // ignore the Exception. The BUGZILLA_DESCRIPTOR_FILE does not exist so the property is null
- } catch (IOException e) {
- // ignore the Exception. The BUGZILLA_DESCRIPTOR_FILE does not exist so the property is null
}
taskRepository.setCredentials(AuthenticationType.REPOSITORY,
@@ -208,8 +157,7 @@ public class BugzillaFixture extends TestFixture {
taskRepository.setCredentials(AuthenticationType.HTTP, location.getCredentials(AuthenticationType.HTTP), false);
taskRepository.setCharacterEncoding(encoding);
- BugzillaRepositoryConnector connector = new BugzillaRepositoryConnector();
- super.connector = connector;
+ connector = new BugzillaRepositoryConnector();
BugzillaClientManager bugzillaClientManager = connector.getClientManager();
BugzillaClient client = bugzillaClientManager.getClient(taskRepository, null);
@@ -256,7 +204,7 @@ public class BugzillaFixture extends TestFixture {
description = "description";
}
BugzillaClient client = client(level);
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
+ AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
TaskData taskData = new TaskData(mapper, repository().getConnectorKind(), repository().getRepositoryUrl(), "");
taskDataHandler.initializeTaskData(repository(), taskData, null, null);
@@ -279,7 +227,7 @@ public class BugzillaFixture extends TestFixture {
* @throws Exception
*/
public TaskData getTask(String id, BugzillaClient client) throws Exception {
- final AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
+ final AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
final TaskData[] newData = new TaskData[1];
client.getTaskData(Collections.singleton(id), new TaskDataCollector() {
@@ -299,15 +247,7 @@ public class BugzillaFixture extends TestFixture {
@Override
public BugzillaRepositoryConnector connector() {
- return (BugzillaRepositoryConnector) connector;
- }
-
- private static final String getServerUrl() {
- String url = TestConfiguration.getRepositoryUrl("");
- if (url.endsWith("/")) {
- return url.substring(0, url.length() - 1);
- }
- return url;
+ return connector;
}
public String getProperty(String key) {
@@ -317,48 +257,8 @@ public class BugzillaFixture extends TestFixture {
return null;
}
- private static BugzillaFixture getDefaultFixture(List<BugzillaFixture> fixtureList) {
- if (fixtureList != null && fixtureList.size() > 0) {
- String defaultFixture = System.getProperty("mylyn.test.default", "");
- for (BugzillaFixture fixture : fixtureList) {
- if (!"".equals(defaultFixture)) {
- if (defaultFixture.equals(fixture.getRepositoryUrl())) {
- return fixture;
- }
- } else {
- Map<String, String> property = fixture.getProperties();
- if (property != null) {
- String defaultProperty = property.get("default");
- if (defaultProperty != null && "1".equals(defaultProperty)) {
- return fixture;
- }
- }
- }
- }
- }
- return BUGS_4_2;
+ public boolean isCustomWorkflowAndStatus() {
+ return Boolean.parseBoolean(properties.get("custom_wf_and_status"));
}
- private static List<BugzillaFixture> getAll(List<BugzillaFixture> fixtureList) {
- if (fixtureList != null && fixtureList.size() > 0) {
- return fixtureList;
- }
- List<BugzillaFixture> result = new ArrayList<BugzillaFixture>(9);
- result.add(BUGS_3_4);
- result.add(BUGS_3_6);
- result.add(BUGS_3_6_XML_RPC_DISABLED);
- result.add(BUGS_3_6_CUSTOM_WF);
- result.add(BUGS_3_6_CUSTOM_WF_AND_STATUS);
- result.add(BUGS_4_0);
- result.add(BUGS_4_2);
- result.add(BUGS_4_4);
- result.add(BUGS_HEAD);
- return result;
- }
-
- static {
- List<BugzillaFixture> fixtureList = TestConfiguration.getDefault().discover(BugzillaFixture.class, "bugzilla");
- DEFAULT = getDefaultFixture(fixtureList);
- ALL = getAll(fixtureList);
- }
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaSearchPageTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaSearchPageTest.java
index 1f9f7152d..018ff03e2 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaSearchPageTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaSearchPageTest.java
@@ -31,7 +31,7 @@ public class BugzillaSearchPageTest extends TestCase {
@Override
public void setUp() throws Exception {
- repository = BugzillaFixture.DEFAULT.singleRepository();
+ repository = BugzillaFixture.current().singleRepository();
}
/**

Back to the top