summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2012-07-24 08:13:42 (EDT)
committer Benjamin Muskalla2012-07-31 04:33:11 (EDT)
commitfc0f2cca939b9b3d347ff033fff94ef2a1ec59cf (patch)
tree31de710f59f09446e6720f58c6bd42b95bd78649
parentea4770bcde0e3600637a2bbd0ac5c2eb5a1e5f3a (diff)
downloadorg.eclipse.mylyn.tasks-fc0f2cca939b9b3d347ff033fff94ef2a1ec59cf.zip
org.eclipse.mylyn.tasks-fc0f2cca939b9b3d347ff033fff94ef2a1ec59cf.tar.gz
org.eclipse.mylyn.tasks-fc0f2cca939b9b3d347ff033fff94ef2a1ec59cf.tar.bz2
TaskDataHandler related tests for SynchronizeTasksJobrefs/changes/36/6936/3
https://bugs.eclipse.org/bugs/show_bug.cgi?id=385828 Change-Id: Ic08041a96f631c8f4815dbc75b6b373363998ac4
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorWithTaskDataHandler.java40
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockTaskDataHandler.java71
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java112
3 files changed, 184 insertions, 39 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorWithTaskDataHandler.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorWithTaskDataHandler.java
index fe36414..6c25e84 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorWithTaskDataHandler.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnectorWithTaskDataHandler.java
@@ -12,19 +12,12 @@
package org.eclipse.mylyn.tasks.tests.connector;
import java.util.Date;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.tasks.core.ITask;
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.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.TaskMapper;
@@ -61,38 +54,7 @@ public class MockRepositoryConnectorWithTaskDataHandler extends MockRepositoryCo
@Override
public AbstractTaskDataHandler getTaskDataHandler() {
- return new AbstractTaskDataHandler() {
-
- @Override
- public RepositoryResponse postTaskData(TaskRepository repository, TaskData taskData,
- Set<TaskAttribute> oldAttributes, IProgressMonitor monitor) throws CoreException {
- if (taskData.getTaskId() == null || taskData.getTaskId().length() == 0) {
- return new RepositoryResponse(ResponseKind.TASK_UPDATED, String.valueOf(idSeed.incrementAndGet()));
- } else {
- return new RepositoryResponse(ResponseKind.TASK_UPDATED, taskData.getTaskId());
- }
- }
-
- @Override
- public boolean initializeTaskData(TaskRepository repository, TaskData data,
- ITaskMapping initializationData, IProgressMonitor monitor) throws CoreException {
- TaskMapper mapper = getTaskMapping(data);
- mapper.setCreationDate(new Date());
- mapper.setDescription("");
- mapper.setModificationDate(mapper.getCreationDate());
- mapper.setOwner("");
- mapper.setProduct("Product1");
- mapper.setReporter("");
- mapper.setStatus("NEW");
- mapper.setSummary("");
- return true;
- }
-
- @Override
- public TaskAttributeMapper getAttributeMapper(TaskRepository repository) {
- return new TaskAttributeMapper(repository);
- }
- };
+ return new MockTaskDataHandler(this);
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockTaskDataHandler.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockTaskDataHandler.java
new file mode 100644
index 0000000..bfa2141
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockTaskDataHandler.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests.connector;
+
+import java.util.Date;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+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.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.TaskMapper;
+
+/**
+ * @author Frank Becker
+ * @author Benjamin Muskalla
+ */
+public class MockTaskDataHandler extends AbstractTaskDataHandler {
+
+ private final MockRepositoryConnectorWithTaskDataHandler connector;
+
+ public MockTaskDataHandler(MockRepositoryConnectorWithTaskDataHandler connector) {
+ this.connector = connector;
+ }
+
+ @Override
+ public RepositoryResponse postTaskData(TaskRepository repository, TaskData taskData,
+ Set<TaskAttribute> oldAttributes, IProgressMonitor monitor) throws CoreException {
+ if (taskData.getTaskId() == null || taskData.getTaskId().length() == 0) {
+ return new RepositoryResponse(ResponseKind.TASK_UPDATED,
+ String.valueOf(this.connector.idSeed.incrementAndGet()));
+ } else {
+ return new RepositoryResponse(ResponseKind.TASK_UPDATED, taskData.getTaskId());
+ }
+ }
+
+ @Override
+ public boolean initializeTaskData(TaskRepository repository, TaskData data, ITaskMapping initializationData,
+ IProgressMonitor monitor) throws CoreException {
+ TaskMapper mapper = this.connector.getTaskMapping(data);
+ mapper.setCreationDate(new Date());
+ mapper.setDescription("");
+ mapper.setModificationDate(mapper.getCreationDate());
+ mapper.setOwner("");
+ mapper.setProduct("Product1");
+ mapper.setReporter("");
+ mapper.setStatus("NEW");
+ mapper.setSummary("");
+ return true;
+ }
+
+ @Override
+ public TaskAttributeMapper getAttributeMapper(TaskRepository repository) {
+ return new TaskAttributeMapper(repository);
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java
index 3784755..e21a8d0 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java
@@ -11,6 +11,7 @@
package org.eclipse.mylyn.tasks.tests.core;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -25,6 +26,7 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.ITaskListChangeListener;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants.MutexSchedulingRule;
import org.eclipse.mylyn.internal.tasks.core.TaskContainerDelta;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
@@ -36,10 +38,15 @@ import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryModel;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
+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.tests.connector.AssertionProgressMonitor;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnectorWithTaskDataHandler;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+import org.eclipse.mylyn.tasks.tests.connector.MockTaskDataHandler;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tests.util.TestFixture;
@@ -166,8 +173,113 @@ public class SynchronizeTasksJobTest extends TestCase {
listener.tearDown();
}
+ public void testMonitorWithMultiTaskData() throws Exception {
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public AbstractTaskDataHandler getTaskDataHandler() {
+ return new MockTaskDataHandler(this) {
+ @Override
+ public boolean canGetMultiTaskData(TaskRepository repository) {
+ return true;
+ }
+
+ @Override
+ public void getMultiTaskData(TaskRepository repository, Set<String> taskIds,
+ TaskDataCollector collector, IProgressMonitor monitor) throws CoreException {
+ }
+ };
+ }
+ };
+ ITask task = new MockTask("1");
+ ITask task2 = new MockTask("2");
+ HashSet<ITask> tasks = new HashSet<ITask>();
+ tasks.add(task);
+ tasks.add(task2);
+ SynchronizeTasksJob job = createSyncJob(connector, tasks);
+ AssertionProgressMonitor monitor = new AssertionProgressMonitor();
+ job.run(monitor);
+ assertEquals("beginTask|subTask|done", monitor.getProgressLog());
+ }
+
+ public void testGetSingleTaskDataError() throws Exception {
+ final IStatus status = new Status(IStatus.WARNING, "bundle", "error");
+ AbstractRepositoryConnector connector = new MockRepositoryConnector() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ throw new CoreException(status);
+ }
+ };
+ ITask task = new MockTask("1");
+ SynchronizeTasksJob job = createSyncJob(connector, Collections.singleton(task));
+ job.run(new NullProgressMonitor());
+ assertEquals(status, ((AbstractTask) task).getStatus());
+ }
+
+ public void testMultipleErrors() throws Exception {
+ final IStatus status = new Status(IStatus.WARNING, "bundle", "error");
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ if (!taskId.equals("3")) {
+ throw new CoreException(status);
+ }
+ return createTaskData("x");
+ }
+ };
+ DeltaCountingTaskListChangeListener listener = new DeltaCountingTaskListChangeListener();
+ ITask task = new MockTask("1");
+ ITask task2 = new MockTask("2");
+ ITask task3 = new MockTask("3");
+ HashSet<ITask> tasks = new HashSet<ITask>();
+ tasks.add(task);
+ tasks.add(task2);
+ tasks.add(task3);
+ SynchronizeTasksJob job = createSyncJob(connector, tasks);
+ job.run(new NullProgressMonitor());
+ assertEquals(status, ((AbstractTask) task).getStatus());
+ assertFalse(((AbstractTask) task).isSynchronizing());
+ assertEquals(status, ((AbstractTask) task2).getStatus());
+ assertFalse(((AbstractTask) task2).isSynchronizing());
+ assertNull(((AbstractTask) task3).getStatus());
+ Collection<IStatus> statuses = job.getStatuses();
+ assertEquals(2, statuses.size());
+
+ try {
+ statuses.add(status);
+ fail("Should not be modifiable");
+ } catch (Exception e) {
+ // expected
+ }
+ assertEquals(2, listener.getDeltasFired());
+ listener.tearDown();
+ }
+
+ public void testGetSingleTaskDataNull() throws Exception {
+ AbstractRepositoryConnector connector = new MockRepositoryConnector() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ return null;
+ }
+ };
+ ITask task = new MockTask("1");
+ SynchronizeTasksJob job = createSyncJob(connector, Collections.singleton(task));
+ job.run(new NullProgressMonitor());
+ IStatus status = ((AbstractTask) task).getStatus();
+ assertEquals("Connector failed to return task data for task \"Mock Task: http://mockrepository.test-1\"",
+ status.getMessage());
+ assertEquals(IStatus.ERROR, status.getSeverity());
+ assertEquals(ITasksCoreConstants.ID_PLUGIN, status.getPlugin());
+ }
+
private SynchronizeTasksJob createSyncJob(AbstractRepositoryConnector connector, Set<ITask> tasks) {
return new SynchronizeTasksJob(taskList, taskDataManager, tasksModel, connector, repository, tasks);
}
+ private TaskData createTaskData(String taskId) {
+ return new TaskData(new TaskAttributeMapper(repository), MockRepositoryConnector.CONNECTOR_KIND,
+ MockRepositoryConnector.REPOSITORY_URL, taskId);
+ }
} \ No newline at end of file