Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2013-04-18 16:44:02 -0400
committerFrank Becker2013-04-18 16:44:02 -0400
commitdbd66074622e6e6ae3bb01588fe7d5e91418ac05 (patch)
tree6e1232b456f1d617579936d4cd32c5ef60d5efeb /org.eclipse.mylyn.bugzilla.tests/src
parent0d8225e9483fb56e2a1f86af6d6f89a943553ea5 (diff)
downloadorg.eclipse.mylyn.tasks-dbd66074622e6e6ae3bb01588fe7d5e91418ac05.tar.gz
org.eclipse.mylyn.tasks-dbd66074622e6e6ae3bb01588fe7d5e91418ac05.tar.xz
org.eclipse.mylyn.tasks-dbd66074622e6e6ae3bb01588fe7d5e91418ac05.zip
396760: fix standalone tests for Bugzilla
Change-Id: I8bbd8a0f47482cb51559972a48da63da8920a11b Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=396760
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.tests/src')
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java143
1 files changed, 129 insertions, 14 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java
index 57f9f2d5e..3ce6f7ead 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java
@@ -12,19 +12,40 @@
package org.eclipse.mylyn.bugzilla.tests.core;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
-import org.eclipse.mylyn.bugzilla.tests.AbstractBugzillaTest;
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
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.commons.sdk.util.CommonTestUtil.PrivilegeLevel;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion;
+import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.ITaskMapping;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
+import org.eclipse.mylyn.tasks.core.TaskMapping;
+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.eclipse.mylyn.tasks.core.data.TaskMapper;
/**
@@ -33,17 +54,17 @@ import org.eclipse.mylyn.tasks.core.data.TaskMapper;
* @author Frank Becker
* @author Robert Elves
*/
-public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
+public class BugzillaCustomFieldsTest extends TestCase {
private TaskData fruitTaskData;
public void testCustomAttributes() throws Exception {
- String taskId = harness.taskCustomFieldExists();
- if (taskId == null) {
- taskId = harness.createCustomFieldTask();
+ String taskID = taskCustomFieldExists();
+ if (taskID == null) {
+ taskID = createCustomFieldTask();
}
- String taskNumber = taskId;
- TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client);
+ String taskNumber = taskID;
+ TaskData taskData = BugzillaFixture.current().getTask(taskNumber, BugzillaFixture.current().client());
assertNotNull(taskData);
TaskMapper mapper = new TaskMapper(taskData);
assertEquals(taskNumber, taskData.getTaskId());
@@ -51,7 +72,9 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
// SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
// assertEquals(format1.parse("2009-09-16 14:11"), mapper.getCreationDate());
- AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY);
+ AuthenticationCredentials credentials = BugzillaFixture.current()
+ .repository()
+ .getCredentials(AuthenticationType.REPOSITORY);
assertNotNull("credentials are null", credentials);
assertNotNull("Repositor User not set", credentials.getUserName());
assertNotNull("no password for Repository", credentials.getPassword());
@@ -81,7 +104,7 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
}
}
changeCollorAndSubmit(taskData, colorAttribute, red, green, yellow, blue);
- taskData = BugzillaFixture.current().getTask(taskNumber, client);
+ taskData = BugzillaFixture.current().getTask(taskNumber, BugzillaFixture.current().client());
assertNotNull(taskData);
mapper = new TaskMapper(taskData);
@@ -125,7 +148,7 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
changed.add(colorAttribute);
// Submit changes
- BugzillaFixture.current().submitTask(taskData, client);
+ BugzillaFixture.current().submitTask(taskData, BugzillaFixture.current().client());
} else if (red && green && !yellow && !blue) {
List<String> newValue = new ArrayList<String>(2);
newValue.add("Green");
@@ -133,7 +156,7 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
changed.add(colorAttribute);
// Submit changes
- BugzillaFixture.current().submitTask(taskData, client);
+ BugzillaFixture.current().submitTask(taskData, BugzillaFixture.current().client());
}
}
@@ -168,7 +191,7 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
String taskNumber = "1";
- fruitTaskData = BugzillaFixture.current().getTask(taskNumber, client);
+ fruitTaskData = BugzillaFixture.current().getTask(taskNumber, BugzillaFixture.current().client());
assertNotNull(fruitTaskData);
if (fruitTaskData.getRoot().getAttribute("cf_dropdown").getValue().equals("---")) {
@@ -195,9 +218,101 @@ public class BugzillaCustomFieldsTest extends AbstractBugzillaTest {
cf_fruit.setValue(newValue);
assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_dropdown").getValue());
changed.add(cf_fruit);
- BugzillaFixture.current().submitTask(fruitTaskData, client);
- fruitTaskData = BugzillaFixture.current().getTask(fruitTaskData.getTaskId(), client);
+ BugzillaFixture.current().submitTask(fruitTaskData, BugzillaFixture.current().client());
+ fruitTaskData = BugzillaFixture.current()
+ .getTask(fruitTaskData.getTaskId(), BugzillaFixture.current().client());
assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_dropdown").getValue());
}
+ private static TaskData createTaskData(TaskRepository taskRepository, ITaskMapping initializationData,
+ ITaskMapping selectionData, IProgressMonitor monitor) throws CoreException {
+ AbstractRepositoryConnector connector = BugzillaFixture.current().connector();
+ AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
+ TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(taskRepository);
+ TaskData taskData = new TaskData(mapper, taskRepository.getConnectorKind(), taskRepository.getRepositoryUrl(),
+ ""); //$NON-NLS-1$
+ boolean result = taskDataHandler.initializeTaskData(taskRepository, taskData, initializationData, monitor);
+ if (!result) {
+ throw new CoreException(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN,
+ "Initialization of task failed. The provided data is insufficient.")); //$NON-NLS-1$
+ }
+ if (selectionData != null) {
+ connector.getTaskMapping(taskData).merge(selectionData);
+ }
+ return taskData;
+ }
+
+ private String taskCustomFieldExists() {
+ String taskID = null;
+ String queryUrlString = BugzillaFixture.current().repository().getRepositoryUrl() + "/buglist.cgi?"
+ + "short_desc=test%20Bug%20with%20Custom%20Fields&resolution=---&query_format=advanced"
+ + "&short_desc_type=casesubstring&component=ManualC2&product=ManualTest";
+ RepositoryQuery query = new RepositoryQuery(BugzillaFixture.current().repository().getConnectorKind(),
+ "handle-testQueryViaConnector");
+ query.setUrl(queryUrlString);
+ final Map<Integer, TaskData> changedTaskData = new HashMap<Integer, TaskData>();
+ TaskDataCollector collector = new TaskDataCollector() {
+ @Override
+ public void accept(TaskData taskData) {
+ changedTaskData.put(Integer.valueOf(taskData.getTaskId()), taskData);
+ }
+ };
+ BugzillaFixture.current()
+ .connector()
+ .performQuery(BugzillaFixture.current().repository(), query, collector, null, new NullProgressMonitor());
+ if (changedTaskData.size() > 0) {
+ Set<Integer> ks = changedTaskData.keySet();
+ SortedSet<Integer> sks = new TreeSet<Integer>(ks);
+ taskID = sks.last().toString();
+ }
+ return taskID;
+ }
+
+ private String createCustomFieldTask() throws Exception {
+ final TaskMapping taskMappingInit = new TaskMapping() {
+ @Override
+ public String getProduct() {
+ return "ManualTest";
+ }
+ };
+ final TaskMapping taskMappingSelect = new TaskMapping() {
+ @Override
+ public String getComponent() {
+ return "ManualC2";
+ }
+
+ @Override
+ public String getSummary() {
+ return "test Bug with Custom Fields";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The Description of the test with Custom Fields Bug";
+ }
+ };
+ final TaskData[] taskDataNew = new TaskData[1];
+
+ // create Task
+ taskDataNew[0] = createTaskData(BugzillaFixture.current().repository(), taskMappingInit, taskMappingSelect,
+ null);
+
+ RepositoryResponse response = BugzillaFixture.current().submitTask(taskDataNew[0],
+ BugzillaFixture.current().client());
+
+ assertNotNull(response);
+ assertEquals(ResponseKind.TASK_CREATED.toString(), response.getReposonseKind().toString());
+ String taskId = response.getTaskId();
+
+ TaskData taskData = BugzillaFixture.current().getTask(taskId, BugzillaFixture.current().client());
+ assertNotNull(taskData);
+
+ TaskMapper mapper = new TaskMapper(taskData);
+ TaskAttribute cf_multiselect = mapper.getTaskData().getRoot().getAttribute("cf_multiselect");
+ cf_multiselect.setValue("Green");
+ response = BugzillaFixture.current().submitTask(taskData, BugzillaFixture.current().client());
+
+ return taskId;
+ }
+
}

Back to the top