Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-04-30 23:28:14 +0000
committerSam Davis2014-05-08 20:19:54 +0000
commitdc89720c44f6cfcd6e127bc0fad5c2da9cb965d0 (patch)
tree83108c77b6283b7c6e244822e7f319fc49fcf816 /org.eclipse.mylyn.tasks.tests
parent5fa632424ac4a18d6ccf0cbfa806127d36e902a3 (diff)
downloadorg.eclipse.mylyn.tasks-dc89720c44f6cfcd6e127bc0fad5c2da9cb965d0.tar.gz
org.eclipse.mylyn.tasks-dc89720c44f6cfcd6e127bc0fad5c2da9cb965d0.tar.xz
org.eclipse.mylyn.tasks-dc89720c44f6cfcd6e127bc0fad5c2da9cb965d0.zip
385670: allow connector clients to choose whether subtasks
should be returned by queries Change-Id: I796006923fe6c61f6eb9f290d08452fe67348ef6 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=385670
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/SynchronizeTasksJobTest.java57
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskJobFactoryTest.java91
3 files changed, 134 insertions, 16 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
index 2729cb6a5..2fcfe655c 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
@@ -26,6 +26,7 @@ import org.eclipse.mylyn.tasks.tests.core.RepositoryConnectorContributorTest;
import org.eclipse.mylyn.tasks.tests.core.SynchronizeTasksJobTest;
import org.eclipse.mylyn.tasks.tests.core.TaskAttributeMetaDataTest;
import org.eclipse.mylyn.tasks.tests.core.TaskInitializationDataTest;
+import org.eclipse.mylyn.tasks.tests.core.TaskJobFactoryTest;
import org.eclipse.mylyn.tasks.tests.core.TaskListUnmatchedContainerTest;
import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryLocationTest;
import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryTest;
@@ -166,6 +167,7 @@ public class AllTasksTests {
suite.addTestSuite(TaskDataDiffTest.class);
suite.addTestSuite(TaskEditorExtensionsTest.class);
suite.addTestSuite(AbstractRepositoryConnectorTest.class);
+ suite.addTestSuite(TaskJobFactoryTest.class);
}
}
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 001d68d58..72262af36 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
@@ -523,6 +523,14 @@ public class SynchronizeTasksJobTest extends TestCase {
}
public void testGetSingleTaskDataWithRelationsAndRemoveRelation() throws Exception {
+ getSingleTaskDataWithRelationsAndRemoveRelation(true);
+ }
+
+ public void testGetSingleTaskDataWithRelationsDisabled() throws Exception {
+ getSingleTaskDataWithRelationsAndRemoveRelation(false);
+ }
+
+ private void getSingleTaskDataWithRelationsAndRemoveRelation(boolean fetchSubtasks) {
final List<String> requestedTaskIds = new ArrayList<String>();
AbstractRepositoryConnector connector = new MockRepositoryConnectorWithTaskDataHandler() {
@Override
@@ -540,32 +548,49 @@ public class SynchronizeTasksJobTest extends TestCase {
ArrayList<TaskRelation> relations = new ArrayList<TaskRelation>();
relations.add(TaskRelation.subtask("1.sub"));
relations.add(TaskRelation.subtask("1.sub5"));
+ relations.add(TaskRelation.subtask("taskToBecomeSubtask"));
return relations;
}
};
- final ITask task = new MockTask("1");
- final ITask subtaskToBeGone = new MockTask("1.sub2");
- final ITask subtaskToStay = new MockTask("1.sub5");
+ ITask task = new MockTask("1");
+ ITask subtaskToBeGone = new MockTask("1.sub2");
+ ITask subtaskToStay = new MockTask("1.sub5");
+ ITask taskToBecomeSubtask = new MockTask("taskToBecomeSubtask");
+
taskList.addTask(task);
taskList.addTask(subtaskToBeGone, ((AbstractTaskContainer) task));
taskList.addTask(subtaskToStay, ((AbstractTaskContainer) task));
+ taskList.addTask(taskToBecomeSubtask);
+ Collection<ITask> children = ((AbstractTaskContainer) task).getChildren();
+ assertEquals(2, children.size());
+ assertTrue(children.contains(subtaskToBeGone));
+ assertTrue(children.contains(subtaskToStay));
+
SynchronizeTasksJob job = createSyncJob(connector, Collections.singleton(task));
+ job.setFetchSubtasks(fetchSubtasks);
job.run(new NullProgressMonitor());
- assertEquals(2, requestedTaskIds.size());
+ assertEquals(fetchSubtasks ? 2 : 1, requestedTaskIds.size());
assertTrue(requestedTaskIds.contains("1"));
- assertTrue(requestedTaskIds.contains("1.sub"));
-
- ITask sub1 = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub");
- ITask sub2 = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub2");
- ITask sub5 = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub5");
- assertNotNull(sub1);
- assertNotNull(sub2);
- assertNotNull(sub5);
+ if (fetchSubtasks) {
+ assertTrue(requestedTaskIds.contains("1.sub"));
+ }
- Collection<ITask> children = ((AbstractTaskContainer) task).getChildren();
- assertEquals(2, children.size());
- assertTrue(children.contains(sub1));
- assertTrue(children.contains(sub5));
+ ITask newSubtask = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub");
+ subtaskToBeGone = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub2");
+ subtaskToStay = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "1.sub5");
+ taskToBecomeSubtask = taskList.getTask(MockRepositoryConnector.REPOSITORY_URL, "taskToBecomeSubtask");
+ assertEquals(fetchSubtasks, newSubtask != null);
+ assertNotNull(subtaskToBeGone);
+ assertNotNull(subtaskToStay);
+ assertNotNull(taskToBecomeSubtask);
+
+ children = ((AbstractTaskContainer) task).getChildren();
+ assertEquals(fetchSubtasks ? 3 : 2, children.size());
+ if (fetchSubtasks) {
+ assertTrue(children.contains(newSubtask));
+ }
+ assertTrue(children.contains(subtaskToStay));
+ assertTrue(children.contains(taskToBecomeSubtask));
}
public void testErrorOnRelationRetrieval() throws Exception {
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskJobFactoryTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskJobFactoryTest.java
new file mode 100644
index 000000000..d591cc19f
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskJobFactoryTest.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.core;
+
+import java.util.Collections;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
+import org.eclipse.mylyn.internal.tasks.ui.TaskJobFactory;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.sync.SynchronizationJob;
+
+public class TaskJobFactoryTest extends TestCase {
+ private static abstract class JobCreator {
+ public abstract SynchronizationJob createJob();
+ }
+
+ private TaskJobFactory jobFactory;
+
+ private boolean oldFetchSubtasks;
+
+ @Override
+ protected void setUp() throws Exception {
+ jobFactory = TasksUiPlugin.getTaskJobFactory();
+ oldFetchSubtasks = jobFactory.getFetchSubtasks();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ jobFactory.setFetchSubtasks(oldFetchSubtasks);
+ }
+
+ public void testFetchSubtasksDefaultValue() throws Exception {
+ assertTrue(TasksUiPlugin.getTaskJobFactory().getFetchSubtasks());
+ }
+
+ private void assertFetchSubtasks(JobCreator jobCreator) {
+ jobFactory.setFetchSubtasks(true);
+ assertTrue(jobCreator.createJob().getFetchSubtasks());
+
+ jobFactory.setFetchSubtasks(false);
+ assertFalse(jobCreator.createJob().getFetchSubtasks());
+ }
+
+ public void testCreateSynchronizeTasksJob() {
+ assertFetchSubtasks(new JobCreator() {
+ @Override
+ public SynchronizationJob createJob() {
+ return jobFactory.createSynchronizeTasksJob(null, Collections.<ITask> emptySet());
+ }
+ });
+ assertFetchSubtasks(new JobCreator() {
+ @Override
+ public SynchronizationJob createJob() {
+ return jobFactory.createSynchronizeTasksJob(null, null, Collections.<ITask> emptySet());
+ }
+ });
+ }
+
+ public void testCreateSynchronizeQueriesJob() {
+ assertFetchSubtasks(new JobCreator() {
+ @Override
+ public SynchronizationJob createJob() {
+ return jobFactory.createSynchronizeQueriesJob(null, new TaskRepository("mock", "http://mock"),
+ Collections.<RepositoryQuery> emptySet());
+ }
+ });
+ }
+
+ public void testCreateSynchronizeRepositoriesJob() {
+ assertFetchSubtasks(new JobCreator() {
+ @Override
+ public SynchronizationJob createJob() {
+ return jobFactory.createSynchronizeRepositoriesJob(null);
+ }
+ });
+ }
+
+}

Back to the top