summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2012-07-24 08:16:04 (EDT)
committer Benjamin Muskalla2012-07-31 04:33:11 (EDT)
commit9019b02f9090cf6fa7afd26401e44c86e6fb2a40 (patch)
tree1e6f3e59e9e6339cb5f00eb3b892ce32e291ce98
parentfc0f2cca939b9b3d347ff033fff94ef2a1ec59cf (diff)
downloadorg.eclipse.mylyn.tasks-9019b02f9090cf6fa7afd26401e44c86e6fb2a40.zip
org.eclipse.mylyn.tasks-9019b02f9090cf6fa7afd26401e44c86e6fb2a40.tar.gz
org.eclipse.mylyn.tasks-9019b02f9090cf6fa7afd26401e44c86e6fb2a40.tar.bz2
Additional testcases multitaskdata handling in SynchronizeTasksJobrefs/changes/37/6937/3
task relations https://bugs.eclipse.org/bugs/show_bug.cgi?id=385828 Added more tests around task relations Change-Id: I7bfc50d9443d67958cb7ae129799a5d5d4170f57
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java248
1 files changed, 248 insertions, 0 deletions
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 e21a8d0..e75a98f 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,10 +11,15 @@
package org.eclipse.mylyn.tasks.tests.core;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
import junit.framework.TestCase;
@@ -28,20 +33,27 @@ 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.RepositoryModel;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
import org.eclipse.mylyn.internal.tasks.core.TaskContainerDelta;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.internal.tasks.core.data.SynchronizationManger;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataManager;
import org.eclipse.mylyn.internal.tasks.core.data.TaskDataStore;
+import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizationSession;
import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizeTasksJob;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
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.ITask.SynchronizationState;
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.core.data.TaskRelation;
+import org.eclipse.mylyn.tasks.core.data.TaskRelation.Direction;
import org.eclipse.mylyn.tasks.tests.connector.AssertionProgressMonitor;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnectorWithTaskDataHandler;
@@ -274,10 +286,246 @@ public class SynchronizeTasksJobTest extends TestCase {
assertEquals(ITasksCoreConstants.ID_PLUGIN, status.getPlugin());
}
+ public void testGetSingleTaskData() throws Exception {
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ return createTaskData("x");
+ }
+ };
+ final ITask task = new MockTask("1");
+ final AtomicBoolean putTaskData = new AtomicBoolean();
+ final SynchronizationSession synchronizationSession = new SynchronizationSession();
+ TaskDataManager customTaskDataManager = new TaskDataManager(taskDataStore, TasksUi.getRepositoryManager(),
+ taskList, (TaskActivityManager) TasksUi.getTaskActivityManager(), new SynchronizationManger(
+ (RepositoryModel) TasksUi.getRepositoryModel())) {
+ @Override
+ public void putUpdatedTaskData(ITask itask, TaskData taskData, boolean user, Object token,
+ IProgressMonitor monitor) throws CoreException {
+ putTaskData.set(true);
+ assertEquals(task, itask);
+ assertNotNull(taskData);
+ assertFalse(user);
+ assertEquals(synchronizationSession, token);
+ assertNotNull(monitor);
+ }
+ };
+ SynchronizeTasksJob job = createSyncJobWithManager(connector, Collections.singleton(task),
+ customTaskDataManager);
+ job.setSession(synchronizationSession);
+ job.run(new NullProgressMonitor());
+ assertTrue(putTaskData.get());
+ }
+
+ public void testGetSingleTaskDataPutFails() throws Exception {
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ return createTaskData("x");
+ }
+ };
+ final ITask task = new MockTask("1");
+ TaskDataStore taskDataStore = new TaskDataStore(TasksUi.getRepositoryManager());
+ final Status status = new Status(IStatus.ERROR, "bundle", "error");
+ TaskDataManager customTaskDataManager = new TaskDataManager(taskDataStore, TasksUi.getRepositoryManager(),
+ taskList, (TaskActivityManager) TasksUi.getTaskActivityManager(), new SynchronizationManger(
+ (RepositoryModel) TasksUi.getRepositoryModel())) {
+ @Override
+ public void putUpdatedTaskData(ITask itask, TaskData taskData, boolean user, Object token,
+ IProgressMonitor monitor) throws CoreException {
+ throw new CoreException(status);
+ }
+ };
+ SynchronizeTasksJob job = createSyncJobWithManager(connector, Collections.singleton(task),
+ customTaskDataManager);
+ job.run(new NullProgressMonitor());
+ assertEquals(status, ((AbstractTask) task).getStatus());
+ }
+
+ public void testGetMultiTaskData() throws Exception {
+ final AtomicBoolean multiGotCalled = new AtomicBoolean();
+ DeltaCountingTaskListChangeListener listener = new DeltaCountingTaskListChangeListener();
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ fail("Should use canGetMultiTaskData");
+ return null;
+ }
+
+ @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 {
+ multiGotCalled.set(true);
+ assertEquals(3, taskIds.size());
+ assertTrue(taskIds.contains("1"));
+ assertTrue(taskIds.contains("2"));
+ assertTrue(taskIds.contains("3"));
+ assertNotNull(collector);
+ }
+ };
+ }
+ };
+ final ITask task = new MockTask("1");
+ final ITask task2 = new MockTask("2");
+ final ITask task3 = new MockTask("3");
+ ((AbstractTask) task).setStatus(new Status(IStatus.WARNING, "bundle", ""));
+ ((AbstractTask) task2).setStatus(new Status(IStatus.WARNING, "bundle", ""));
+ ((AbstractTask) task3).setStatus(new Status(IStatus.WARNING, "bundle", ""));
+ 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(3, listener.getDeltasFired());
+ assertTrue(multiGotCalled.get());
+ listener.tearDown();
+ }
+
+ public void testGetMultiTaskDataPutIntoManager() throws Exception {
+ final MockRepositoryConnector 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 {
+ collector.accept(createTaskData("1"));
+ collector.accept(createTaskData("2"));
+ collector.failed("3", new Status(IStatus.ERROR, "bundle", "error"));
+ }
+ };
+ }
+ };
+ final ITask task = new MockTask("1");
+ final ITask task2 = new MockTask("2");
+ final ITask task3 = new MockTask("3");
+ HashSet<ITask> tasks = new HashSet<ITask>();
+ tasks.add(task);
+ tasks.add(task2);
+ tasks.add(task3);
+
+ final AtomicInteger taskDataPut = new AtomicInteger();
+ TaskDataManager customTaskDataManager = new TaskDataManager(taskDataStore, TasksUi.getRepositoryManager(),
+ taskList, (TaskActivityManager) TasksUi.getTaskActivityManager(), new SynchronizationManger(
+ (RepositoryModel) TasksUi.getRepositoryModel())) {
+ @Override
+ public void putUpdatedTaskData(ITask itask, TaskData taskData, boolean user, Object token,
+ IProgressMonitor monitor) throws CoreException {
+ taskDataPut.incrementAndGet();
+ }
+ };
+ SynchronizeTasksJob job = createSyncJobWithManager(connector, tasks, customTaskDataManager);
+ job.run(new NullProgressMonitor());
+ assertEquals(2, taskDataPut.get());
+ assertEquals("error", ((AbstractTask) task3).getStatus().getMessage());
+ }
+
+ public void testGetMultiTaskDataFails() throws Exception {
+ final Status errorStatus = new Status(IStatus.ERROR, "bundle", "error");
+ 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 {
+ throw new CoreException(errorStatus);
+ }
+ };
+ }
+ };
+ final ITask task = new MockTask("1");
+ final ITask task2 = new MockTask("2");
+ HashSet<ITask> tasks = new HashSet<ITask>();
+ tasks.add(task);
+ tasks.add(task2);
+ SynchronizeTasksJob job = createSyncJob(connector, tasks);
+ job.run(new NullProgressMonitor());
+ assertEquals(errorStatus, ((AbstractTask) task).getStatus());
+ assertEquals(errorStatus, ((AbstractTask) task2).getStatus());
+ }
+
+ public void testGetSingleTaskDataWithRelations() throws Exception {
+ final AtomicReference<List<String>> requestedTaskIds = new AtomicReference<List<String>>();
+ requestedTaskIds.set(new ArrayList<String>());
+ AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
+ @Override
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ requestedTaskIds.get().add(taskId);
+ return createTaskData(taskId);
+ }
+
+ @Override
+ public Collection<TaskRelation> getTaskRelations(TaskData taskData) {
+ if (!taskData.getTaskId().equals("1")) {
+ return null;
+ }
+ ArrayList<TaskRelation> relations = new ArrayList<TaskRelation>();
+ relations.add(TaskRelation.dependency("1.dep.in", Direction.INWARD));
+ relations.add(TaskRelation.dependency("1.dep.out", Direction.OUTWARD));
+ relations.add(TaskRelation.parentTask("1.par"));
+ relations.add(TaskRelation.subtask("1.sub"));
+ relations.add(TaskRelation.subtask("1.sub2"));
+ return relations;
+ }
+ };
+ final ITask task = new MockTask("1");
+ taskList.addTask(task);
+ SynchronizeTasksJob job = createSyncJob(connector, Collections.singleton(task));
+ job.run(new NullProgressMonitor());
+ assertEquals(3, requestedTaskIds.get().size());
+ assertTrue(requestedTaskIds.get().contains("1"));
+ assertTrue(requestedTaskIds.get().contains("1.sub"));
+ assertTrue(requestedTaskIds.get().contains("1.sub2"));
+
+ ITask sub1 = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub");
+ assertNotNull(sub1);
+ ITask sub2 = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub2");
+ assertNotNull(sub2);
+ assertEquals(SynchronizationState.INCOMING_NEW, ((AbstractTask) sub1).getSynchronizationState());
+ assertEquals(SynchronizationState.INCOMING_NEW, ((AbstractTask) sub2).getSynchronizationState());
+
+ // same again but this time we already got them in the task list
+ requestedTaskIds.get().clear();
+ job = createSyncJob(connector, Collections.singleton(task));
+ job.run(new NullProgressMonitor());
+ assertEquals(1, requestedTaskIds.get().size());
+ assertTrue(requestedTaskIds.get().contains("1"));
+ }
+
private SynchronizeTasksJob createSyncJob(AbstractRepositoryConnector connector, Set<ITask> tasks) {
return new SynchronizeTasksJob(taskList, taskDataManager, tasksModel, connector, repository, tasks);
}
+ private SynchronizeTasksJob createSyncJobWithManager(AbstractRepositoryConnector connector, Set<ITask> tasks,
+ TaskDataManager customTaskDataManager) {
+ return new SynchronizeTasksJob(taskList, customTaskDataManager, tasksModel, connector, repository, tasks);
+ }
+
private TaskData createTaskData(String taskId) {
return new TaskData(new TaskAttributeMapper(repository), MockRepositoryConnector.CONNECTOR_KIND,
MockRepositoryConnector.REPOSITORY_URL, taskId);