diff options
author | spingel | 2009-09-16 22:16:13 +0000 |
---|---|---|
committer | spingel | 2009-09-16 22:16:13 +0000 |
commit | b091d16e37dc3efe2155e1b666a07b33b2f3f56d (patch) | |
tree | 6f5ba9cf095d4e2cbbdb4ceb34145eca70e556ea /org.eclipse.mylyn.bugzilla.tests | |
parent | efb680390237bc95e4023737514342f4903d23c5 (diff) | |
download | org.eclipse.mylyn.tasks-b091d16e37dc3efe2155e1b666a07b33b2f3f56d.tar.gz org.eclipse.mylyn.tasks-b091d16e37dc3efe2155e1b666a07b33b2f3f56d.tar.xz org.eclipse.mylyn.tasks-b091d16e37dc3efe2155e1b666a07b33b2f3f56d.zip |
NEW - bug 287226: [patch] refactor bugzilla unit tests to test repository passed in from test harness
https://bugs.eclipse.org/bugs/show_bug.cgi?id=287226
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.tests')
5 files changed, 233 insertions, 107 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 2968f373b..afa71866e 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 @@ -17,12 +17,12 @@ import junit.framework.TestSuite; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaClientTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaConfigurationTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaRepositoryConnectorStandaloneTest; -import org.eclipse.mylyn.bugzilla.tests.core.BugzillaTaskHistoryTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaVersionTest; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; /** * @author Steffen Pingel + * @author Thomas Ehrnhoefer */ public class AllBugzillaHeadlessStandaloneTests { @@ -33,7 +33,8 @@ public class AllBugzillaHeadlessStandaloneTests { for (BugzillaFixture fixture : BugzillaFixture.ALL) { TestSuite fixtureSuite = fixture.createSuite(); fixture.add(fixtureSuite, BugzillaClientTest.class); - fixture.add(fixtureSuite, BugzillaTaskHistoryTest.class); + // XXX: re-enable when webservice is used for retrieval of history +// fixture.add(fixtureSuite, BugzillaTaskHistoryTest.class); fixture.add(fixtureSuite, BugzillaRepositoryConnectorStandaloneTest.class); suite.addTest(fixtureSuite); } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java index 06745a639..233fd1ad7 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java @@ -36,10 +36,10 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; -import org.eclipse.mylyn.tasks.ui.TasksUi; /** * @author Robert Elves + * @author Thomas Ehrnhoefer */ public class BugzillaClientTest extends TestCase { @@ -49,7 +49,7 @@ public class BugzillaClientTest extends TestCase { @Override protected void setUp() throws Exception { - repository = BugzillaFixture.current().singleRepository(); + repository = BugzillaFixture.current().repository(); client = BugzillaFixture.current().client(); } @@ -58,20 +58,23 @@ public class BugzillaClientTest extends TestCase { assertNotNull(config); assertEquals(BugzillaFixture.current().getVersion(), config.getInstallVersion().toString()); assertEquals(7, config.getStatusValues().size()); - assertEquals(9, config.getResolutions().size()); - assertEquals(6, config.getPlatforms().size()); - assertEquals(32, config.getOSs().size()); + assertEquals(8, config.getResolutions().size()); + assertEquals(8, config.getPlatforms().size()); + assertEquals(36, config.getOSs().size()); assertEquals(5, config.getPriorities().size()); assertEquals(7, config.getSeverities().size()); - assertTrue(config.getProducts().size() > 50); + assertEquals(3, config.getProducts().size()); assertEquals(4, config.getOpenStatusValues().size()); - assertEquals(14, config.getComponents("Mylyn").size()); - assertEquals(27, config.getKeywords().size()); - assertEquals(1, config.getComponents("TestProduct").size()); - assertEquals(1, config.getVersions("TestProduct").size()); - assertEquals(0, config.getTargetMilestones("TestProduct").size()); - // assertEquals(10, config.getComponents("Hyades").size()); - // assertEquals(1, config.getTargetMilestones("TestProduct").size()); + assertEquals(2, config.getKeywords().size()); + assertEquals(2, config.getComponents("ManualTest").size()); + assertEquals(4, config.getVersions("ManualTest").size()); + assertEquals(4, config.getTargetMilestones("ManualTest").size()); + assertEquals(2, config.getComponents("TestProduct").size()); + assertEquals(4, config.getVersions("TestProduct").size()); + assertEquals(4, config.getTargetMilestones("TestProduct").size()); + assertEquals(2, config.getComponents("Scratch").size()); + assertEquals(4, config.getVersions("Scratch").size()); + assertEquals(4, config.getTargetMilestones("Scratch").size()); } public void testValidate() throws Exception { @@ -90,7 +93,12 @@ public class BugzillaClientTest extends TestCase { client = BugzillaClientFactory.createClient(repository); client = new BugzillaClient(location, repository.getCharacterEncoding(), repository.getProperties(), BugzillaRepositoryConnector.getLanguageSetting(IBugzillaConstants.DEFAULT_LANG)); - client.validate(new NullProgressMonitor()); + try { + client.validate(new NullProgressMonitor()); + fail("invalid proxy did not cause connection error"); + } catch (Exception e) { + // ignore + } } public void testCommentQuery() throws Exception { @@ -98,8 +106,7 @@ public class BugzillaClientTest extends TestCase { TaskData newData = new TaskData(mapper, BugzillaFixture.current().getConnectorKind(), BugzillaFixture.current() .getRepositoryUrl(), ""); - AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(BugzillaFixture.current() - .getConnectorKind()); + AbstractRepositoryConnector connector = BugzillaFixture.current().connector(); connector.getTaskDataHandler().initializeTaskData(repository, newData, null, new NullProgressMonitor()); newData.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).setValue("testCommentQuery()"); newData.getRoot().getMappedAttribute(TaskAttribute.PRODUCT).setValue("TestProduct"); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java index eba762abe..b41b7df76 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaRepositoryConnectorStandaloneTest.java @@ -12,7 +12,9 @@ package org.eclipse.mylyn.bugzilla.tests.core; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import junit.framework.TestCase; @@ -21,13 +23,14 @@ import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.commons.net.AuthenticationCredentials; import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.context.tests.support.TestUtil.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.tasks.core.AbstractTask; import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; import org.eclipse.mylyn.internal.tasks.core.TaskTask; import org.eclipse.mylyn.tasks.core.TaskRepository; -import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; @@ -35,6 +38,8 @@ import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; /** * @author Nathan Hapke * @author Rob Elves + * @author Thomas Ehrnhoefer + * @author Steffen Pingel */ public class BugzillaRepositoryConnectorStandaloneTest extends TestCase { @@ -42,20 +47,16 @@ public class BugzillaRepositoryConnectorStandaloneTest extends TestCase { private BugzillaRepositoryConnector connector; - @SuppressWarnings("unused") - private AbstractTaskDataHandler handler; + private BugzillaClient client; @Override - protected void setUp() throws Exception { + public void setUp() throws Exception { + client = BugzillaFixture.current().client(PrivilegeLevel.USER); repository = BugzillaFixture.current().repository(); - connector = new BugzillaRepositoryConnector(); -// BugzillaLanguageSettings language = BugzillaCorePlugin.getDefault().getLanguageSetting( -// IBugzillaConstants.DEFAULT_LANG); -// BugzillaRepositoryConnector.addLanguageSetting(language); - handler = connector.getTaskDataHandler(); + connector = BugzillaFixture.current().connector(); } - public void testHasChanged() { + public void testHasTaskChanged() { AbstractTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "1"); task.setAttribute(BugzillaAttribute.DELTA_TS.getKey(), "2008-02-02 12:01:12"); TaskData data = new TaskData(connector.getTaskDataHandler().getAttributeMapper(repository), @@ -139,102 +140,126 @@ public class BugzillaRepositoryConnectorStandaloneTest extends TestCase { && auth.getUserName() != null && !auth.getUserName().equals("")); } - public void testGetBug() throws Exception { + public void testGetTaskData() throws Exception { + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); Set<String> taskIds = new HashSet<String>(); - taskIds.add("1"); - final Set<TaskData> changedTaskData = new HashSet<TaskData>(); + taskIds.add(taskData.getTaskId()); + final Set<TaskData> results = new HashSet<TaskData>(); TaskDataCollector collector = new TaskDataCollector() { - @Override public void accept(TaskData taskData) { - changedTaskData.add(taskData); + results.add(taskData); } }; connector.getTaskDataHandler().getMultiTaskData(repository, taskIds, collector, new NullProgressMonitor()); - assertEquals(1, changedTaskData.size()); - for (TaskData taskData : changedTaskData) { - String taskId = taskData.getTaskId(); - if (taskId.equals("1")) { - assertEquals("user@mylar.eclipse.org", taskData.getRoot().getAttribute( - BugzillaAttribute.ASSIGNED_TO.getKey()).getValue()); - assertEquals("foo", taskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); - // You can use the getAttributeValue to pull up the information on any - // part of the bug - assertEquals("P1", taskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue()); - - } else { - fail("Unexpected TaskData returned"); - } - } + assertEquals(1, results.size()); + TaskData updatedTaskData = results.iterator().next(); + String taskId = updatedTaskData.getTaskId(); + assertEquals(taskId, updatedTaskData.getTaskId()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue()); } - public void testGetBugs() throws Exception { + public void testGetMultiTaskData() throws Exception { + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); + TaskData taskData2 = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); + TaskData taskData3 = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); Set<String> taskIds = new HashSet<String>(); - taskIds.add("1"); - taskIds.add("2"); - taskIds.add("4"); - final Set<TaskData> changedTaskData = new HashSet<TaskData>(); + taskIds.add(taskData.getTaskId()); + taskIds.add(taskData2.getTaskId()); + taskIds.add(taskData3.getTaskId()); + final Map<String, TaskData> results = new HashMap<String, TaskData>(); TaskDataCollector collector = new TaskDataCollector() { - @Override public void accept(TaskData taskData) { - changedTaskData.add(taskData); + results.put(taskData.getTaskId(), taskData); } }; connector.getTaskDataHandler().getMultiTaskData(repository, taskIds, collector, new NullProgressMonitor()); - assertEquals(3, changedTaskData.size()); - for (TaskData taskData : changedTaskData) { - String taskId = taskData.getTaskId(); - if (taskId.equals("1")) { - assertEquals("user@mylar.eclipse.org", taskData.getRoot().getAttribute( - BugzillaAttribute.ASSIGNED_TO.getKey()).getValue()); - assertEquals("foo", taskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); - // You can use the getAttributeValue to pull up the information on any - // part of the bug - assertEquals("P1", taskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue()); - - } else if (taskId.equals("2")) { - assertEquals("nhapke@cs.ubc.ca", taskData.getRoot() - .getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()) - .getValue()); - assertEquals("search-match-test 1", taskData.getRoot().getAttribute( - BugzillaAttribute.LONG_DESC.getKey()).getValue()); - } else if (taskId.equals("4")) { - assertEquals("relves@cs.ubc.ca", taskData.getRoot() - .getAttribute(BugzillaAttribute.REPORTER.getKey()) - .getValue()); - assertEquals("Test", taskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); - } else { - fail("Unexpected TaskData returned"); - } - - } + assertEquals(3, results.size()); + + TaskData updatedTaskData = results.get(taskData.getTaskId()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); + assertEquals(taskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue()); + + updatedTaskData = results.get(taskData2.getTaskId()); + assertEquals(taskData2.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue()); + assertEquals(taskData2.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); + + updatedTaskData = results.get(taskData3.getTaskId()); + assertEquals(taskData3.getRoot().getAttribute(BugzillaAttribute.ASSIGNED_TO.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.REPORTER.getKey()).getValue()); + assertEquals(taskData3.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue(), + updatedTaskData.getRoot().getAttribute(BugzillaAttribute.LONG_DESC.getKey()).getValue()); } - public void testQueryViaConnector() throws Exception { - String queryUrlString = repository.getRepositoryUrl() - + "/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0="; + public void testPerformQuery() throws Exception { + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); - // holds onto actual hit objects - BugzillaRepositoryConnector connector = new BugzillaRepositoryConnector(); + // queries for bugs assigned to tests@mylyn.eclipse.org, updated in the last hour, trivial with P1 + String priority = "P1"; + String severity = "trivial"; + String email = "tests%40mylyn.eclipse.org"; + String queryUrlString = repository.getRepositoryUrl() + + "/buglist.cgi?priority=" + + priority + + "&emailassigned_to1=1&query_format=advanced&emailreporter1=1&field0-0-0=bug_status&bug_severity=" + + severity + + "&bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&type0-0-1=equals&value0-0-1=tests%40mylyn.eclipse.org&email1=" + + email + "&type0-0-0=notequals&field0-0-1=reporter&value0-0-0=UNCONFIRMED&emailtype1=exact"; + + // make sure initial task is not P1/trivial + assertFalse(taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRIORITY.getKey()).getValue().equals( + priority)); + assertFalse(taskData.getRoot().getMappedAttribute(BugzillaAttribute.BUG_SEVERITY.getKey()).getValue().equals( + severity)); + + // run query RepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(), "handle-testQueryViaConnector"); query.setUrl(queryUrlString); - - final Set<TaskData> changedTaskData = new HashSet<TaskData>(); + final Map<String, TaskData> changedTaskData = new HashMap<String, TaskData>(); TaskDataCollector collector = new TaskDataCollector() { - @Override public void accept(TaskData taskData) { - changedTaskData.add(taskData); + changedTaskData.put(taskData.getTaskId(), taskData); } }; - connector.performQuery(repository, query, collector, null, new NullProgressMonitor()); - assertEquals(2, changedTaskData.size()); - for (TaskData taskData : changedTaskData) { - assertTrue(taskData.getRoot().getAttribute(BugzillaAttribute.SHORT_DESC.getKey()).getValue().contains( - "search-match-test")); - } + + // set priority and severity on task + taskData.getRoot().getMappedAttribute(BugzillaAttribute.SHORT_DESC.getKey()).setValue( + System.currentTimeMillis() + ""); + taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRIORITY.getKey()).setValue(priority); + taskData.getRoot().getMappedAttribute(BugzillaAttribute.BUG_SEVERITY.getKey()).setValue(severity); + TaskData taskDataNew = BugzillaFixture.current().submitTask(taskData, client); + + // run query again + final Map<String, TaskData> changedTaskData2 = new HashMap<String, TaskData>(); + TaskDataCollector collector2 = new TaskDataCollector() { + @Override + public void accept(TaskData taskData) { + changedTaskData2.put(taskData.getTaskId(), taskData); + } + }; + connector.performQuery(repository, query, collector2, null, new NullProgressMonitor()); + + // compare query results + changedTaskData2.keySet().removeAll(changedTaskData.keySet()); + assertEquals(1, changedTaskData2.size()); + taskData = changedTaskData2.get(taskData.getTaskId()); + assertNotNull(taskData); + assertTrue(taskData.getRoot().getAttribute(BugzillaAttribute.SHORT_DESC.getKey()).getValue().equals( + taskDataNew.getRoot().getAttribute(BugzillaAttribute.SHORT_DESC.getKey()).getValue())); } }
\ No newline at end of file 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 dee41b22e..4227f57d2 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,30 +14,44 @@ package org.eclipse.mylyn.bugzilla.tests.support; import java.io.File; import java.io.IOException; import java.net.URL; +import java.util.Collections; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.mylyn.bugzilla.tests.BugzillaTestConstants; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; +import org.eclipse.mylyn.commons.net.AbstractWebLocation; import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.commons.net.WebLocation; import org.eclipse.mylyn.context.tests.support.TestUtil; import org.eclipse.mylyn.context.tests.support.TestUtil.Credentials; import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClientManager; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; +import org.eclipse.mylyn.tasks.core.RepositoryResponse; import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; +import org.eclipse.mylyn.tasks.core.data.TaskData; +import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; import org.osgi.framework.Bundle; /** * @author Steffen Pingel + * @author Thomas Ehrnhoefer */ public class BugzillaFixture extends TestFixture { private static BugzillaFixture current; + /** + * @deprecated not supported any more + */ + @Deprecated public static BugzillaFixture BUGS_2_18 = new BugzillaFixture(BugzillaTestConstants.TEST_BUGZILLA_218_URL,// "2.18.6", ""); @@ -53,9 +67,17 @@ public class BugzillaFixture extends TestFixture { public static BugzillaFixture BUGS_3_2 = new BugzillaFixture(BugzillaTestConstants.TEST_BUGZILLA_32_URL, // "3.2.4", ""); + /** + * @deprecated use latest 3.2 -> BUGS_3_2 + */ + @Deprecated public static BugzillaFixture BUGS_3_2_2 = new BugzillaFixture(BugzillaTestConstants.TEST_BUGZILLA_322_URL, // "3.2.2", ""); + /** + * @deprecated use latest 3.2 -> BUGS_3_2 + */ + @Deprecated public static BugzillaFixture BUGS_3_2_3 = new BugzillaFixture(BugzillaTestConstants.TEST_BUGZILLA_323_URL, // "3.2.3", ""); @@ -64,8 +86,8 @@ public class BugzillaFixture extends TestFixture { public static BugzillaFixture DEFAULT = BUGS_3_4; - public static final BugzillaFixture[] ALL = new BugzillaFixture[] { BUGS_2_18, BUGS_2_20, BUGS_2_22, BUGS_3_0, - BUGS_3_2_2, BUGS_3_2_3, BUGS_3_2, BUGS_3_4 }; + public static final BugzillaFixture[] ALL = new BugzillaFixture[] { BUGS_2_20, BUGS_2_22, BUGS_3_0, BUGS_3_2, + BUGS_3_4 }; private final String version; @@ -106,21 +128,38 @@ public class BugzillaFixture extends TestFixture { public BugzillaClient client(String hostUrl, String username, String password, String htAuthUser, String htAuthPass, String encoding) throws CoreException, IOException { - TaskRepository taskRepository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, hostUrl); + WebLocation location = new WebLocation(hostUrl); + location.setCredentials(AuthenticationType.REPOSITORY, username, password); + location.setCredentials(AuthenticationType.HTTP, htAuthUser, htAuthPass); + return client(location, encoding); - AuthenticationCredentials credentials = new AuthenticationCredentials(username, password); - taskRepository.setCredentials(AuthenticationType.REPOSITORY, credentials, false); + } + + public BugzillaClient client(AbstractWebLocation location, String encoding) throws CoreException { + + TaskRepository taskRepository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, location.getUrl()); + + taskRepository.setCredentials(AuthenticationType.REPOSITORY, + location.getCredentials(AuthenticationType.REPOSITORY), false); - AuthenticationCredentials webCredentials = new AuthenticationCredentials(htAuthUser, htAuthPass); - taskRepository.setCredentials(AuthenticationType.HTTP, webCredentials, false); + taskRepository.setCredentials(AuthenticationType.HTTP, location.getCredentials(AuthenticationType.HTTP), false); taskRepository.setCharacterEncoding(encoding); - BugzillaClientManager bugzillaClientManager = new BugzillaClientManager(); + BugzillaRepositoryConnector connector = new BugzillaRepositoryConnector(); + super.connector = connector; + BugzillaClientManager bugzillaClientManager = connector.getClientManager(); BugzillaClient client = bugzillaClientManager.getClient(taskRepository, null); - client.getRepositoryConfiguration(new NullProgressMonitor()); + + BugzillaCorePlugin.setConnector(connector); + BugzillaCorePlugin.getRepositoryConfiguration(taskRepository, true, new NullProgressMonitor()); return client; } + public BugzillaClient client(PrivilegeLevel level) throws Exception { + AbstractWebLocation location = location(level); + return client(location, "UTF-8"); + } + public static File getFile(String filename) throws IOException { Bundle bundle = Platform.getBundle("org.eclipse.mylyn.bugzilla.tests"); if (bundle != null) { @@ -133,4 +172,50 @@ public class BugzillaFixture extends TestFixture { return new File(filename); } + /** + * Create and returns a minimal task. + * + * @param summary + * may be <code>null</code> + * @param description + * may be <code>null</code> + * @return The taskData retrieved from updating the task + */ + public TaskData createTask(PrivilegeLevel level, String summary, String description) throws Exception { + if (summary == null) { + summary = "summary"; + } + if (description == null) { + description = "description"; + } + BugzillaClient client = client(level); + AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); + TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository()); + TaskData taskData = new TaskData(mapper, repository().getConnectorKind(), repository().getRepositoryUrl(), ""); + taskDataHandler.initializeTaskData(repository(), taskData, null, null); + taskData.getRoot().createMappedAttribute(TaskAttribute.SUMMARY).setValue(summary); + taskData.getRoot().createMappedAttribute(TaskAttribute.DESCRIPTION).setValue("description"); + return submitTask(taskData, client); + } + + public TaskData submitTask(TaskData taskData, BugzillaClient client) throws IOException, CoreException { + AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler(); + TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository()); + final TaskData[] newData = new TaskData[1]; + RepositoryResponse result = client.postTaskData(taskData, null); + String bugId = result.getTaskId(); + client.getTaskData(Collections.singleton(bugId), new TaskDataCollector() { + @Override + public void accept(TaskData data) { + newData[0] = data; + } + }, mapper, null); + return newData[0]; + } + + @Override + public BugzillaRepositoryConnector connector() { + return (BugzillaRepositoryConnector) connector; + } + } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/TestFixture.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/TestFixture.java index adee4db42..e4ade6cf5 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/TestFixture.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/TestFixture.java @@ -26,10 +26,12 @@ import org.eclipse.mylyn.context.tests.support.TestUtil.Credentials; import org.eclipse.mylyn.context.tests.support.TestUtil.PrivilegeLevel; import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; +import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylyn.tasks.core.TaskRepository; /** * @author Steffen Pingel + * @author Thomas Ehrnhoefer */ public abstract class TestFixture { @@ -39,6 +41,8 @@ public abstract class TestFixture { protected final String repositoryUrl; + protected AbstractRepositoryConnector connector; + public TestFixture(String connectorKind, String repositoryUrl) { this.connectorKind = connectorKind; this.repositoryUrl = repositoryUrl; @@ -126,4 +130,8 @@ public abstract class TestFixture { return repository; } + public AbstractRepositoryConnector connector() { + return connector; + } + } |