Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2016-10-09 09:33:20 +0000
committerGerrit Code Review @ Eclipse.org2016-10-12 16:12:44 +0000
commitcc702de4c7cf3f0ef719b504459983253ac08f8f (patch)
treed83e694992fa102a65dc66030ce40f2df434540b
parent8aba48a96aaa8d822125d8d8ef11d5b1ca9b9953 (diff)
downloadorg.eclipse.mylyn.tasks-cc702de4c7cf3f0ef719b504459983253ac08f8f.tar.gz
org.eclipse.mylyn.tasks-cc702de4c7cf3f0ef719b504459983253ac08f8f.tar.xz
org.eclipse.mylyn.tasks-cc702de4c7cf3f0ef719b504459983253ac08f8f.zip
505602: cleanup BugzillaRestHarness and BugzillaRestClientTest
Change-Id: I5eb51bb1c6ac81667bf7390a187ac9d00b23a021 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=505602
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java63
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestHarness.java141
2 files changed, 88 insertions, 116 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
index 0dab8d502..f472b0717 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
@@ -60,6 +60,7 @@ import org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor;
import org.eclipse.mylyn.internal.commons.repositories.core.InMemoryCredentialsStore;
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource;
+import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
@@ -588,6 +589,7 @@ public class BugzillaRestClientTest {
@Test
public void testGifAttachment() throws Exception {
+ TaskAttribute attachmentAttribute = null;
TaskRepository repository = actualFixture.repository();
final TaskMapping taskMappingInit = new TaskMapping() {
@@ -616,22 +618,8 @@ public class BugzillaRestClientTest {
return "R1";
}
};
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskData = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskData, taskMappingInit, null);
- taskData.getRoot().getAttribute("cf_dropdown").setValue("one");
- taskData.getRoot()
- .getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
- .setValue("M2");
- RepositoryResponse response = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
- assertEquals(ResponseKind.TASK_CREATED, response.getReposonseKind());
-
- final String taskId = response.getTaskId();
- TaskAttribute attachmentAttribute = null;
- taskData = getTaskData(taskId);
+ String taskId = harness.getNewTaksIdFromInitMapping(taskMappingInit, harness.taskInitializationData);
+ TaskData taskData = harness.getTaskFromServer(taskId);
assertNotNull(taskData);
for (Entry<String, TaskAttribute> entry : taskData.getRoot().getAttributes().entrySet()) {
if (TaskAttribute.TYPE_ATTACHMENT.equals(entry.getValue().getMetaData().getType())) {
@@ -675,6 +663,7 @@ public class BugzillaRestClientTest {
@Test
public void testTextAttachment() throws Exception {
+ TaskAttribute attachmentAttribute = null;
TaskRepository repository = actualFixture.repository();
final TaskMapping taskMappingInit = new TaskMapping() {
@@ -703,22 +692,8 @@ public class BugzillaRestClientTest {
return "R1";
}
};
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskData = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskData, taskMappingInit, null);
- taskData.getRoot().getAttribute("cf_dropdown").setValue("one");
- taskData.getRoot()
- .getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
- .setValue("M2");
- RepositoryResponse response = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
- assertEquals(ResponseKind.TASK_CREATED, response.getReposonseKind());
-
- final String taskId = response.getTaskId();
- TaskAttribute attachmentAttribute = null;
- taskData = getTaskData(taskId);
+ String taskId = harness.getNewTaksIdFromInitMapping(taskMappingInit, harness.taskInitializationData);
+ TaskData taskData = harness.getTaskFromServer(taskId);
assertNotNull(taskData);
for (Entry<String, TaskAttribute> entry : taskData.getRoot().getAttributes().entrySet()) {
if (TaskAttribute.TYPE_ATTACHMENT.equals(entry.getValue().getMetaData().getType())) {
@@ -992,11 +967,7 @@ public class BugzillaRestClientTest {
TaskData taskDataGet = harness.getTaskFromServer(taskId);
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskDataOld = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskDataOld, null, null);
+ TaskData taskDataOld = TaskDataState.createCopy(taskDataGet);
TaskAttribute attribute = taskDataGet.getRoot()
.getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey());
@@ -1043,11 +1014,7 @@ public class BugzillaRestClientTest {
TaskData taskDataGet = harness.getTaskFromServer(taskId);
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskDataOld = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskDataOld, null, null);
+ TaskData taskDataOld = TaskDataState.createCopy(taskDataGet);
TaskAttribute attribute = taskDataGet.getRoot()
.getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey());
@@ -1097,11 +1064,7 @@ public class BugzillaRestClientTest {
TaskData taskDataGet = harness.getTaskFromServer(taskId);
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskDataOld = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskDataOld, null, null);
+ TaskData taskDataOld = TaskDataState.createCopy(taskDataGet);
TaskAttribute attribute = taskDataGet.getRoot()
.getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey());
@@ -1149,11 +1112,7 @@ public class BugzillaRestClientTest {
TaskData taskDataGet = harness.getTaskFromServer(taskId);
Set<TaskAttribute> changed = new HashSet<TaskAttribute>();
- AbstractTaskDataHandler taskDataHandler = connector.getTaskDataHandler();
- TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(actualFixture.repository());
- TaskData taskDataOld = new TaskData(mapper, actualFixture.repository().getConnectorKind(),
- actualFixture.repository().getRepositoryUrl(), "");
- taskDataHandler.initializeTaskData(actualFixture.repository(), taskDataOld, null, null);
+ TaskData taskDataOld = TaskDataState.createCopy(taskDataGet);
TaskAttribute attribute = taskDataGet.getRoot()
.getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey());
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestHarness.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestHarness.java
index 5c20e6ed9..29f92a722 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestHarness.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/test/support/BugzillaRestHarness.java
@@ -38,6 +38,7 @@ import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
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.TaskInitializationData;
import org.eclipse.mylyn.tasks.core.TaskMapping;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
@@ -48,6 +49,51 @@ import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
public class BugzillaRestHarness {
private final BugzillaRestTestFixture fixture;
+ public final TaskMapping taskMappingInitTestProduct = new TaskMapping() {
+ @Override
+ public String getSummary() {
+ return "The Summary";
+ }
+
+ @Override
+ public String getDescription() {
+ return "The Description";
+ }
+
+ @Override
+ public String getProduct() {
+ return "ManualTest";
+ }
+
+ @Override
+ public String getComponent() {
+ return "ManualC1";
+ }
+
+ @Override
+ public String getVersion() {
+ return "R1";
+ }
+ };
+
+ public final TaskInitializationData taskInitializationData = new TaskInitializationData() {
+ private TaskData result;
+
+ @Override
+ public TaskData getTaskData() {
+ if (result == null) {
+ AbstractTaskDataHandler taskDataHandler = connector().getTaskDataHandler();
+ TaskAttributeMapper mapper = taskDataHandler.getAttributeMapper(repository());
+ result = new TaskData(mapper, repository().getConnectorKind(), repository().getRepositoryUrl(), ""); //$NON-NLS-1$
+ result.getRoot().createAttribute("cf_dropdown").setValue("one");
+ result.getRoot()
+ .createAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
+ .setValue("M1");
+ }
+ return result;
+ }
+ };
+
public BugzillaRestHarness(BugzillaRestTestFixture fixture) {
this.fixture = fixture;
}
@@ -94,73 +140,14 @@ public class BugzillaRestHarness {
}
public String getNewTaksId4TestProduct() throws BugzillaRestException, CoreException {
- final TaskMapping taskMappingInit = new TaskMapping() {
- @Override
- public String getSummary() {
- return "The Summary";
- }
-
- @Override
- public String getDescription() {
- return "The Description";
- }
-
- @Override
- public String getProduct() {
- return "ManualTest";
- }
-
- @Override
- public String getComponent() {
- return "ManualC1";
- }
- @Override
- public String getVersion() {
- return "R1";
- }
- };
- TaskData taskData = createTaskData(taskMappingInit, null, null);
- taskData.getRoot().getAttribute("cf_dropdown").setValue("one");
- taskData.getRoot()
- .getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
- .setValue("M1");
- String taskId = submitNewTask(taskData);
- return taskId;
+ return getNewTaksIdFromInitMapping(taskMappingInitTestProduct, taskInitializationData);
}
- public String createTaskWithSummary(final String summary) throws BugzillaRestException, CoreException {
- final TaskMapping taskMappingInit = new TaskMapping() {
- @Override
- public String getSummary() {
- return summary;
- }
+ public String getNewTaksIdFromInitMapping(final ITaskMapping taskMappingInit,
+ final ITaskMapping taskMappingSelection) throws CoreException, BugzillaRestException {
- @Override
- public String getDescription() {
- return "The Description";
- }
-
- @Override
- public String getProduct() {
- return "ManualTest";
- }
-
- @Override
- public String getComponent() {
- return "ManualC1";
- }
-
- @Override
- public String getVersion() {
- return "R1";
- }
- };
- TaskData taskData = createTaskData(taskMappingInit, null, null);
- taskData.getRoot().getAttribute("cf_dropdown").setValue("one");
- taskData.getRoot()
- .getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
- .setValue("M1");
+ TaskData taskData = createTaskData(taskMappingInit, taskMappingSelection, null);
String taskId = submitNewTask(taskData);
return taskId;
}
@@ -195,7 +182,33 @@ public class BugzillaRestHarness {
SortedSet<Integer> sks = new TreeSet<Integer>(ks);
taskID = sks.last().toString();
} else {
- taskID = createTaskWithSummary(summary);
+ final TaskMapping taskMappingInit = new TaskMapping() {
+ @Override
+ public String getSummary() {
+ return summary;
+ }
+
+ @Override
+ public String getDescription() {
+ return "The Description";
+ }
+
+ @Override
+ public String getProduct() {
+ return "ManualTest";
+ }
+
+ @Override
+ public String getComponent() {
+ return "ManualC1";
+ }
+
+ @Override
+ public String getVersion() {
+ return "R1";
+ }
+ };
+ taskID = getNewTaksIdFromInitMapping(taskMappingInit, taskInitializationData);
}
return taskID;

Back to the top