Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-09-17 22:33:24 -0400
committerspingel2008-09-17 22:33:24 -0400
commit33d17b56b3e5dc96395881e17d2fa76a409cdc72 (patch)
treee73805f286b91a14055d910bb8d50b2e1ffd347e
parent7bb6f24d0bc2f860270d2858237feb9c4f7f6e06 (diff)
downloadorg.eclipse.mylyn.tasks-R_3_0_2.tar.gz
org.eclipse.mylyn.tasks-R_3_0_2.tar.xz
org.eclipse.mylyn.tasks-R_3_0_2.zip
NEW - bug 237552: [api] remove deprecated classesR_3_0_2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=237552
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java16
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java3
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RefactorRepositoryUrlOperationTest.java175
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityListenerTest.java106
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java197
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentTest.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataManagerTest.java (renamed from org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java)395
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java272
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java1006
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListTest.java261
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java11
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java51
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java54
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java117
14 files changed, 1186 insertions, 1480 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 570280fe9..6974664eb 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
@@ -22,8 +22,6 @@ public class AllTasksTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.mylyn.tasks.tests");
-
- // $JUnit-BEGIN$
suite.addTestSuite(LinkProviderTest.class);
suite.addTestSuite(TaskActivationActionTest.class);
suite.addTestSuite(TaskListPresentationTest.class);
@@ -35,9 +33,8 @@ public class AllTasksTests {
suite.addTestSuite(ProjectRepositoryAssociationTest.class);
suite.addTestSuite(TaskList06DataMigrationTest.class);
suite.addTestSuite(TaskPlanningEditorTest.class);
- suite.addTestSuite(TaskListManagerTest.class);
suite.addTestSuite(TaskListExternalizationTest.class);
- suite.addTestSuite(RepositoryTaskSynchronizationTest.class);
+ suite.addTestSuite(TaskDataManagerTest.class);
suite.addTestSuite(TaskRepositoryManagerTest.class);
suite.addTestSuite(TaskRepositoriesExternalizerTest.class);
suite.addTestSuite(TaskListContentProviderTest.class);
@@ -51,13 +48,13 @@ public class AllTasksTests {
suite.addTestSuite(TaskDataExportTest.class);
// XXX: Put back
//suite.addTestSuite(TaskDataImportTest.class);
+ //suite.addTestSuite(QueryExportImportTest.class);
suite.addTestSuite(ScheduledPresentationTest.class);
suite.addTestSuite(TaskActivityTimingTest.class);
suite.addTestSuite(TaskAttachmentTest.class);
suite.addTestSuite(RepositorySettingsPageTest.class);
suite.addTestSuite(CommentQuoterTest.class);
suite.addTestSuite(TaskDataStoreTest.class);
- suite.addTestSuite(QueryExportImportTest.class);
suite.addTestSuite(TaskExportImportTest.class);
suite.addTestSuite(PersonProposalProviderTest.class);
suite.addTestSuite(TaskRepositoryLocationTest.class);
@@ -66,18 +63,19 @@ public class AllTasksTests {
suite.addTestSuite(OrphanedTasksTest.class);
suite.addTestSuite(TaskWorkingSetTest.class);
suite.addTestSuite(TaskActivationHistoryTest.class);
- // $JUnit-END$
+ suite.addTestSuite(TaskActivityManagerTest.class);
+ suite.addTestSuite(TaskRepositoryFilterTests.class);
+ suite.addTestSuite(TaskDiffUtilTest.class);
+ suite.addTestSuite(RefactorRepositoryUrlOperationTest.class);
// suite.addTestSuite(BackgroundSaveTest.class);
// suite.addTestSuite(RetrieveTitleFromUrlTest.class);
+ // web connector tests
suite.addTestSuite(org.eclipse.mylyn.tasks.tests.web.NamedPatternTest.class);
suite.addTestSuite(org.eclipse.mylyn.tasks.tests.web.HtmlDecodeEntityTest.class);
suite.addTestSuite(org.eclipse.mylyn.tasks.tests.web.WebRepositoryTest.class);
- suite.addTestSuite(TaskActivityListenerTest.class);
- suite.addTestSuite(TaskRepositoryFilterTests.class);
- suite.addTestSuite(TaskDiffUtilTest.class);
return suite;
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java
index 092e694b6..f55d1694a 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/QueryExportImportTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2008 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
@@ -37,6 +37,7 @@ import org.eclipse.mylyn.tasks.tests.connector.MockTaskListFactory;
/**
* @author Jevgeni Holodkov
*/
+// FIXME speed up test
public class QueryExportImportTest extends TestCase {
private File dest;
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RefactorRepositoryUrlOperationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RefactorRepositoryUrlOperationTest.java
new file mode 100644
index 000000000..29b09111a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RefactorRepositoryUrlOperationTest.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 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;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
+import org.eclipse.mylyn.internal.context.core.InteractionContext;
+import org.eclipse.mylyn.internal.context.core.InteractionContextManager;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.internal.tasks.ui.RefactorRepositoryUrlOperation;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.monitor.core.InteractionEvent;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+import org.eclipse.mylyn.tasks.ui.TasksUi;
+
+/**
+ * @author Robert Elves
+ * @author Steffen Pingel
+ */
+public class RefactorRepositoryUrlOperationTest extends TestCase {
+
+ private TaskList taskList;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ taskList = TasksUiPlugin.getTaskList();
+ TaskTestUtil.resetTaskList();
+ }
+
+ private void runRepositoryUrlOperation(String oldUrl, String newUrl) {
+ try {
+ new RefactorRepositoryUrlOperation(oldUrl, newUrl).run(new NullProgressMonitor());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ public void testMigrateTaskContextFiles() throws IOException {
+ File fileA = ContextCorePlugin.getContextStore().getFileForContext("http://a-1");
+ fileA.createNewFile();
+ fileA.deleteOnExit();
+ assertTrue(fileA.exists());
+ runRepositoryUrlOperation("http://a", "http://b");
+ File fileB = ContextCorePlugin.getContextStore().getFileForContext("http://b-1");
+ assertTrue(fileB.exists());
+ assertFalse(fileA.exists());
+ }
+
+ public void testMigrateQueryUrlHandles() {
+ RepositoryQuery query = new MockRepositoryQuery("mquery");
+ query.setRepositoryUrl("http://foo.bar");
+ query.setUrl("http://foo.bar/b");
+ taskList.addQuery(query);
+ assertTrue(taskList.getRepositoryQueries("http://foo.bar").size() > 0);
+ runRepositoryUrlOperation("http://foo.bar", "http://bar.baz");
+ assertTrue(taskList.getRepositoryQueries("http://foo.bar").size() == 0);
+ assertTrue(taskList.getRepositoryQueries("http://bar.baz").size() > 0);
+ IRepositoryQuery changedQuery = taskList.getRepositoryQueries("http://bar.baz").iterator().next();
+ assertEquals("http://bar.baz/b", changedQuery.getUrl());
+ }
+
+ public void testMigrateQueryHandles() {
+ RepositoryQuery query = new MockRepositoryQuery("mquery");
+ query.setRepositoryUrl("http://a");
+ taskList.addQuery(query);
+ runRepositoryUrlOperation("http://a", "http://b");
+ assertFalse(taskList.getRepositoryQueries("http://b").isEmpty());
+ assertTrue(taskList.getRepositoryQueries("http://a").isEmpty());
+ }
+
+ public void testMigrateTaskHandles() throws Exception {
+ AbstractTask task = new MockTask("http://a", "123");
+ AbstractTask task2 = new MockTask("http://other", "other");
+ taskList.addTask(task);
+ taskList.addTask(task2);
+
+ TaskRepository repository = new TaskRepository("kind", "http://a");
+ TaskRepository repository2 = new TaskRepository("kind", "http://other");
+
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), task.getConnectorKind(),
+ task.getRepositoryUrl(), task.getTaskId());
+ TasksUiPlugin.getTaskDataManager().putUpdatedTaskData(task, taskData, true);
+
+ TaskData taskData2 = new TaskData(new TaskAttributeMapper(repository2), task2.getConnectorKind(),
+ task2.getRepositoryUrl(), task2.getTaskId());
+ taskData2.getRoot().createAttribute("comment").setValue("TEST");
+ TasksUiPlugin.getTaskDataManager().putUpdatedTaskData(task2, taskData2, true);
+
+ runRepositoryUrlOperation("http://a", "http://b");
+ assertNull(taskList.getTask("http://a-123"));
+ assertNotNull(taskList.getTask("http://b-123"));
+ assertNotNull(TasksUi.getTaskDataManager().getTaskData(task));
+ TaskData otherData = TasksUi.getTaskDataManager().getTaskData(task2);
+ assertNotNull(otherData);
+ assertEquals("TEST", otherData.getRoot().getAttribute("comment").getValue());
+ }
+
+ public void testMigrateTaskHandlesWithExplicitSet() {
+ AbstractTask task = new MockTask("http://a", "123");
+ task.setUrl("http://a/task/123");
+ taskList.addTask(task);
+ runRepositoryUrlOperation("http://a", "http://b");
+ assertNull(taskList.getTask("http://a-123"));
+ assertNotNull(taskList.getTask("http://b-123"));
+ assertEquals("http://b/task/123", task.getUrl());
+ }
+
+ public void testRefactorMetaContextHandles() {
+ String firstUrl = "http://repository1.com/bugs";
+ String secondUrl = "http://repository2.com/bugs";
+ AbstractTask task1 = new MockTask(firstUrl, "1");
+ AbstractTask task2 = new MockTask(firstUrl, "2");
+ taskList.addTask(task1);
+ taskList.addTask(task2);
+ Calendar startDate = Calendar.getInstance();
+ Calendar endDate = Calendar.getInstance();
+ endDate.add(Calendar.MINUTE, 5);
+
+ Calendar startDate2 = Calendar.getInstance();
+ startDate2.add(Calendar.MINUTE, 15);
+ Calendar endDate2 = Calendar.getInstance();
+ endDate2.add(Calendar.MINUTE, 25);
+
+ ContextCorePlugin.getContextManager().resetActivityMetaContext();
+ InteractionContext metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
+ assertEquals(0, metaContext.getInteractionHistory().size());
+
+ ContextCorePlugin.getContextManager().processActivityMetaContextEvent(
+ new InteractionEvent(InteractionEvent.Kind.ATTENTION,
+ InteractionContextManager.ACTIVITY_STRUCTUREKIND_TIMING, task1.getHandleIdentifier(), "origin",
+ null, InteractionContextManager.ACTIVITY_DELTA_ADDED, 1f, startDate.getTime(),
+ endDate.getTime()));
+
+ ContextCorePlugin.getContextManager().processActivityMetaContextEvent(
+ new InteractionEvent(InteractionEvent.Kind.ATTENTION,
+ InteractionContextManager.ACTIVITY_STRUCTUREKIND_TIMING, task2.getHandleIdentifier(), "origin",
+ null, InteractionContextManager.ACTIVITY_DELTA_ADDED, 1f, startDate2.getTime(),
+ endDate2.getTime()));
+
+ assertEquals(2, metaContext.getInteractionHistory().size());
+ assertEquals(60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(task1));
+ assertEquals(2 * 60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(task2));
+ runRepositoryUrlOperation(firstUrl, secondUrl);
+ metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
+ assertEquals(2, metaContext.getInteractionHistory().size());
+ assertEquals(60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(new MockTask(secondUrl, "1")));
+ assertEquals(2 * 60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(
+ new MockTask(secondUrl, "2")));
+ assertEquals(secondUrl + "-1", metaContext.getInteractionHistory().get(0).getStructureHandle());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityListenerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityListenerTest.java
deleted file mode 100644
index e665caa02..000000000
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityListenerTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 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;
-
-import junit.framework.TestCase;
-
-import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.core.ITaskActivityManager;
-import org.eclipse.mylyn.tasks.core.TaskActivationAdapter;
-import org.eclipse.mylyn.tasks.tests.connector.MockTask;
-import org.eclipse.mylyn.tasks.ui.TasksUi;
-
-/**
- * @author Shawn Minto
- */
-public class TaskActivityListenerTest extends TestCase {
-
- private class MockTaskActivationListener extends TaskActivationAdapter {
-
- private boolean hasActivated = false;
-
- private boolean hasPreActivated = false;
-
- private boolean hasDeactivated = false;
-
- private boolean hasPreDeactivated = false;
-
- public void reset() {
- hasActivated = false;
- hasPreActivated = false;
-
- hasDeactivated = false;
- hasPreDeactivated = false;
-
- }
-
- @Override
- public void preTaskActivated(ITask task) {
- assertFalse(hasActivated);
- hasPreActivated = true;
- }
-
- @Override
- public void preTaskDeactivated(ITask task) {
- assertFalse(hasDeactivated);
- hasPreDeactivated = true;
- }
-
- @Override
- public void taskActivated(ITask task) {
- assertTrue(hasPreActivated);
- hasActivated = true;
- }
-
- @Override
- public void taskDeactivated(ITask task) {
- assertTrue(hasPreDeactivated);
- hasDeactivated = true;
- }
-
- }
-
- private ITaskActivityManager taskActivityManager;
-
- @Override
- protected void setUp() throws Exception {
- taskActivityManager = TasksUi.getTaskActivityManager();
- taskActivityManager.deactivateActiveTask();
- }
-
- public void testTaskActivation() {
- MockTask task = new MockTask("test:activation");
- MockTaskActivationListener listener = new MockTaskActivationListener();
- try {
- taskActivityManager.addActivationListener(listener);
- try {
- taskActivityManager.activateTask(task);
- assertTrue(listener.hasPreActivated);
- assertTrue(listener.hasActivated);
- assertFalse(listener.hasPreDeactivated);
- assertFalse(listener.hasDeactivated);
-
- listener.reset();
- } finally {
- taskActivityManager.deactivateTask(task);
- }
- assertFalse(listener.hasPreActivated);
- assertFalse(listener.hasActivated);
- assertTrue(listener.hasPreDeactivated);
- assertTrue(listener.hasDeactivated);
- } finally {
- TasksUiPlugin.getTaskActivityManager().removeActivationListener(listener);
- }
- }
-
-} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
new file mode 100644
index 000000000..1fc5e8b62
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskActivityManagerTest.java
@@ -0,0 +1,197 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 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;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.LocalTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
+import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskActivationAdapter;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+
+/**
+ * @author Shawn Minto
+ * @author Robert Elves
+ */
+public class TaskActivityManagerTest extends TestCase {
+
+ private class MockTaskActivationListener extends TaskActivationAdapter {
+
+ private boolean hasActivated = false;
+
+ private boolean hasPreActivated = false;
+
+ private boolean hasDeactivated = false;
+
+ private boolean hasPreDeactivated = false;
+
+ public void reset() {
+ hasActivated = false;
+ hasPreActivated = false;
+
+ hasDeactivated = false;
+ hasPreDeactivated = false;
+
+ }
+
+ @Override
+ public void preTaskActivated(ITask task) {
+ assertFalse(hasActivated);
+ hasPreActivated = true;
+ }
+
+ @Override
+ public void preTaskDeactivated(ITask task) {
+ assertFalse(hasDeactivated);
+ hasPreDeactivated = true;
+ }
+
+ @Override
+ public void taskActivated(ITask task) {
+ assertTrue(hasPreActivated);
+ hasActivated = true;
+ }
+
+ @Override
+ public void taskDeactivated(ITask task) {
+ assertTrue(hasPreDeactivated);
+ hasDeactivated = true;
+ }
+
+ }
+
+ private TaskActivityManager taskActivityManager;
+
+ private TaskList taskList;
+
+ private TaskRepository repository;
+
+ @Override
+ protected void setUp() throws Exception {
+ taskActivityManager = TasksUiPlugin.getTaskActivityManager();
+ taskActivityManager.deactivateActiveTask();
+ taskList = TasksUiPlugin.getTaskList();
+
+ TaskTestUtil.resetTaskList();
+
+ repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND, MockRepositoryConnector.REPOSITORY_URL);
+ TasksUiPlugin.getRepositoryManager().addRepository(repository);
+ }
+
+ public void testTaskActivation() {
+ MockTask task = new MockTask("test:activation");
+ MockTaskActivationListener listener = new MockTaskActivationListener();
+ try {
+ taskActivityManager.addActivationListener(listener);
+ try {
+ taskActivityManager.activateTask(task);
+ assertTrue(listener.hasPreActivated);
+ assertTrue(listener.hasActivated);
+ assertFalse(listener.hasPreDeactivated);
+ assertFalse(listener.hasDeactivated);
+
+ listener.reset();
+ } finally {
+ taskActivityManager.deactivateTask(task);
+ }
+ assertFalse(listener.hasPreActivated);
+ assertFalse(listener.hasActivated);
+ assertTrue(listener.hasPreDeactivated);
+ assertTrue(listener.hasDeactivated);
+ } finally {
+ taskActivityManager.removeActivationListener(listener);
+ }
+ }
+
+ public void testIsActiveToday() {
+ AbstractTask task = new LocalTask("1", "task-1");
+ assertFalse(taskActivityManager.isScheduledForToday(task));
+
+ task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday());
+ assertTrue(taskActivityManager.isScheduledForToday(task));
+
+ task.setReminded(true);
+ assertTrue(taskActivityManager.isScheduledForToday(task));
+ task.setReminded(true);
+
+// Calendar inAnHour = Calendar.getInstance();
+// inAnHour.set(Calendar.HOUR_OF_DAY, inAnHour.get(Calendar.HOUR_OF_DAY) + 1);
+// inAnHour.getTime();
+// task.setScheduledForDate(inAnHour.getTime());
+// Calendar tomorrow = Calendar.getInstance();
+// TaskActivityUtil.snapToNextDay(tomorrow);
+// assertEquals(-1, inAnHour.compareTo(tomorrow));
+// assertTrue(taskActivityManager.isScheduledForToday(task));
+ }
+
+ public void testScheduledForToday() {
+ AbstractTask task = new LocalTask("1", "task-1");
+ task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday());
+ assertTrue(taskActivityManager.isScheduledForToday(task));
+ task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday().next());
+ assertFalse(taskActivityManager.isScheduledForToday(task));
+ }
+
+ public void testSchedulePastEndOfMonth() {
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
+ calendar.set(Calendar.DAY_OF_MONTH, 30);
+ TaskActivityUtil.snapForwardNumDays(calendar, 1);
+ assertEquals("Should be October", Calendar.OCTOBER, calendar.get(Calendar.MONTH));
+ }
+
+ public void testIsCompletedToday() {
+ ITask task = new LocalTask("1", "task 1");
+ task.setCompletionDate(new Date());
+ assertTrue(taskActivityManager.isCompletedToday(task));
+
+ MockTask mockTask = new MockTask("1");
+ mockTask.setOwner("unknown");
+ taskList.addTask(mockTask);
+ mockTask.setCompletionDate(new Date());
+ assertFalse("completed: " + mockTask.getCompletionDate(), taskActivityManager.isCompletedToday(mockTask));
+
+ mockTask = new MockTask("2");
+ taskList.addTask(mockTask);
+ mockTask.setCompletionDate(new Date());
+ mockTask.setOwner("testUser");
+ repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials("testUser", ""), false);
+ assertTrue(taskActivityManager.isCompletedToday(mockTask));
+ }
+
+ public void testAllTasksDeactivation() {
+ AbstractTask task1 = new LocalTask("task1", "description1");
+ AbstractTask task2 = new LocalTask("task2", "description2");
+ taskList.addTask(task1);
+ taskList.addTask(task2);
+ assertNull(taskActivityManager.getActiveTask());
+
+ taskActivityManager.activateTask(task2);
+ assertEquals(task2, taskActivityManager.getActiveTask());
+
+ taskActivityManager.deactivateActiveTask();
+ assertNull(taskActivityManager.getActiveTask());
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentTest.java
index a5081b58b..b0e134b39 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskAttachmentTest.java
@@ -62,7 +62,7 @@ public class TaskAttachmentTest extends TestCase {
attachmentHandler = new MockAttachmentHandler();
connector = new MockRepositoryConnector();
- connector.setAttachmentHandler(attachmentHandler);
+ connector.setTaskAttachmentHandler(attachmentHandler);
manager.addRepositoryConnector(connector);
TaskData taskData = new TaskData(new TaskAttributeMapper(repository), MockRepositoryConnector.REPOSITORY_KIND,
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataManagerTest.java
index 96a249a4e..72c427c95 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskDataManagerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2008 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
@@ -12,10 +12,8 @@
package org.eclipse.mylyn.tasks.tests;
import java.util.Collections;
-import java.util.Date;
import java.util.HashSet;
import java.util.Set;
-import java.util.Stack;
import junit.framework.TestCase;
@@ -29,14 +27,14 @@ import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
-import org.eclipse.mylyn.tasks.tests.connector.MockAttributeFactory;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
/**
* @author Rob Elves
+ * @author Steffen Pingel
*/
-public class RepositoryTaskSynchronizationTest extends TestCase {
+public class TaskDataManagerTest extends TestCase {
private static final String DATE_STAMP_3 = "2006-06-21 15:29:42";
@@ -54,61 +52,61 @@ public class RepositoryTaskSynchronizationTest extends TestCase {
private RepositoryTaskData newData;
- public void testHasIncoming() {
- MockTask task = new MockTask(MOCCK_ID);
- RepositoryTaskData taskData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
- MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
- task.setLastReadTimeStamp("never");
-
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, "2006-06-21 15:29:39");
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- task.setLastReadTimeStamp("2006-06-21 15:29:39");
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- task.setLastReadTimeStamp(DATE_STAMP_1);
- assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- }
-
- public void testHasIncomingDateComparison() {
- final Stack<Date> dates = new Stack<Date>();
- MockTask task = new MockTask(MOCCK_ID);
- RepositoryTaskData taskData = new RepositoryTaskData(new MockAttributeFactory() {
- private static final long serialVersionUID = 1L;
-
- @Override
- public Date getDateForAttributeType(String attributeKey, String dateString) {
- return dates.pop();
- }
- }, connector.getConnectorKind(), MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
- task.setLastReadTimeStamp("never");
-
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
-
- // strings and dates mismatch
- dates.push(new Date(1));
- dates.push(new Date(2));
- taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, "2006-06-21 15:29:39");
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
-
- dates.push(null);
- dates.push(new Date(2));
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
-
- dates.push(new Date());
- dates.push(null);
- assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
-
- // strings mismatch but dates match
- dates.push(new Date(1));
- dates.push(new Date(1));
- assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
-
- // strings match, dates should not be checked
- task.setLastReadTimeStamp("2006-06-21 15:29:39");
- assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
- }
+// public void testHasIncoming() {
+// MockTask task = new MockTask(MOCCK_ID);
+// RepositoryTaskData taskData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
+// MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
+// task.setLastReadTimeStamp("never");
+//
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, "2006-06-21 15:29:39");
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// task.setLastReadTimeStamp("2006-06-21 15:29:39");
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// task.setLastReadTimeStamp(DATE_STAMP_1);
+// assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// }
+
+// public void testHasIncomingDateComparison() {
+// final Stack<Date> dates = new Stack<Date>();
+// MockTask task = new MockTask(MOCCK_ID);
+// RepositoryTaskData taskData = new RepositoryTaskData(new MockAttributeFactory() {
+// private static final long serialVersionUID = 1L;
+//
+// @Override
+// public Date getDateForAttributeType(String attributeKey, String dateString) {
+// return dates.pop();
+// }
+// }, connector.getConnectorKind(), MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
+// task.setLastReadTimeStamp("never");
+//
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+//
+// // strings and dates mismatch
+// dates.push(new Date(1));
+// dates.push(new Date(2));
+// taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, "2006-06-21 15:29:39");
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+//
+// dates.push(null);
+// dates.push(new Date(2));
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+//
+// dates.push(new Date());
+// dates.push(null);
+// assertTrue(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+//
+// // strings mismatch but dates match
+// dates.push(new Date(1));
+// dates.push(new Date(1));
+// assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+//
+// // strings match, dates should not be checked
+// task.setLastReadTimeStamp("2006-06-21 15:29:39");
+// assertFalse(TasksUiPlugin.getTaskDataManager().checkHasIncoming(task, taskData));
+// }
public void testIncomingToIncoming() {
/*
@@ -118,38 +116,38 @@ public class RepositoryTaskSynchronizationTest extends TestCase {
* to 2nd occurrence of new incoming data
*/
- // Test unforced
- AbstractTask task = primeTaskAndRepository(SynchronizationState.INCOMING, SynchronizationState.INCOMING);
- RepositoryTaskData taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(),
- task.getTaskId());
- assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
- assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
- assertEquals(DATE_STAMP_2, newData.getLastModified());
- TasksUiPlugin.getTaskDataManager().saveIncoming(task, newData, false);
- assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
- assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
- // TasksUiPlugin.getSynchronizationManager().setTaskRead(task, true);
- // assertEquals(DATE_STAMP_2, task.getLastSyncDateStamp());
- // and again...
-
- RepositoryTaskData taskData3 = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
- MockRepositoryConnector.REPOSITORY_URL, "1");
- taskData3.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_3);
- TasksUiPlugin.getTaskDataManager().saveIncoming(task, taskData3, false);
- // last modified stamp not updated until user synchronizes (newdata ==
- // olddata)
- assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
- assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
- taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(), task.getTaskId());
- assertEquals(DATE_STAMP_3, taskData.getLastModified());
-
- // Should keep INCOMING state state since new data has same date samp
- // and sych is not forced.
- TasksUiPlugin.getTaskDataManager().saveIncoming(task, taskData3, false);
- assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
- assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
- taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(), task.getTaskId());
- assertEquals(DATE_STAMP_3, taskData.getLastModified());
+// // Test unforced
+// AbstractTask task = primeTaskAndRepository(SynchronizationState.INCOMING, SynchronizationState.INCOMING);
+// RepositoryTaskData taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(),
+// task.getTaskId());
+// assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
+// assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
+// assertEquals(DATE_STAMP_2, newData.getLastModified());
+// TasksUiPlugin.getTaskDataManager().saveIncoming(task, newData, false);
+// assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
+// assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
+// // TasksUiPlugin.getSynchronizationManager().setTaskRead(task, true);
+// // assertEquals(DATE_STAMP_2, task.getLastSyncDateStamp());
+// // and again...
+//
+// RepositoryTaskData taskData3 = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
+// MockRepositoryConnector.REPOSITORY_URL, "1");
+// taskData3.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_3);
+// TasksUiPlugin.getTaskDataManager().saveIncoming(task, taskData3, false);
+// // last modified stamp not updated until user synchronizes (newdata ==
+// // olddata)
+// assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
+// assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
+// taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(), task.getTaskId());
+// assertEquals(DATE_STAMP_3, taskData.getLastModified());
+//
+// // Should keep INCOMING state state since new data has same date samp
+// // and sych is not forced.
+// TasksUiPlugin.getTaskDataManager().saveIncoming(task, taskData3, false);
+// assertEquals(SynchronizationState.INCOMING, task.getSynchronizationState());
+// assertEquals(DATE_STAMP_1, task.getLastReadTimeStamp());
+// taskData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(), task.getTaskId());
+// assertEquals(DATE_STAMP_3, taskData.getLastModified());
}
// Invalid state change. Test that this can't happen.
@@ -333,28 +331,28 @@ public class RepositoryTaskSynchronizationTest extends TestCase {
}
public void testClearOutgoing() {
- AbstractTask task = primeTaskAndRepository(SynchronizationState.SYNCHRONIZED, SynchronizationState.SYNCHRONIZED);
- RepositoryTaskData taskData1 = new RepositoryTaskData(new MockAttributeFactory(),
- MockRepositoryConnector.REPOSITORY_KIND, MockRepositoryConnector.REPOSITORY_URL, "1");
- TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData1);
- taskData1 = TasksUiPlugin.getTaskDataStorageManager()
- .getEditableCopy(task.getRepositoryUrl(), task.getTaskId());
-
- taskData1.setNewComment("Testing");
- Set<RepositoryTaskAttribute> edits = new HashSet<RepositoryTaskAttribute>();
- edits.add(taskData1.getAttribute(RepositoryTaskAttribute.COMMENT_NEW));
- TasksUiPlugin.getTaskDataStorageManager().saveEdits(task.getRepositoryUrl(), task.getTaskId(), edits);
-
- RepositoryTaskData editedData = TasksUiPlugin.getTaskDataStorageManager().getEditableCopy(
- task.getRepositoryUrl(), task.getTaskId());
- assertEquals("Testing", editedData.getNewComment());
-
- TasksUiPlugin.getTaskDataManager().discardOutgoing(task);
-
- assertTrue(task.getSynchronizationState().equals(SynchronizationState.SYNCHRONIZED));
- RepositoryTaskData taskData = TasksUiPlugin.getTaskDataStorageManager().getEditableCopy(
- task.getRepositoryUrl(), task.getTaskId());
- assertEquals("", taskData.getNewComment());
+// AbstractTask task = primeTaskAndRepository(SynchronizationState.SYNCHRONIZED, SynchronizationState.SYNCHRONIZED);
+// RepositoryTaskData taskData1 = new RepositoryTaskData(new MockAttributeFactory(),
+// MockRepositoryConnector.REPOSITORY_KIND, MockRepositoryConnector.REPOSITORY_URL, "1");
+// TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData1);
+// taskData1 = TasksUiPlugin.getTaskDataStorageManager()
+// .getEditableCopy(task.getRepositoryUrl(), task.getTaskId());
+//
+// taskData1.setNewComment("Testing");
+// Set<RepositoryTaskAttribute> edits = new HashSet<RepositoryTaskAttribute>();
+// edits.add(taskData1.getAttribute(RepositoryTaskAttribute.COMMENT_NEW));
+// TasksUiPlugin.getTaskDataStorageManager().saveEdits(task.getRepositoryUrl(), task.getTaskId(), edits);
+//
+// RepositoryTaskData editedData = TasksUiPlugin.getTaskDataStorageManager().getEditableCopy(
+// task.getRepositoryUrl(), task.getTaskId());
+// assertEquals("Testing", editedData.getNewComment());
+//
+// TasksUiPlugin.getTaskDataManager().discardOutgoing(task);
+//
+// assertTrue(task.getSynchronizationState().equals(SynchronizationState.SYNCHRONIZED));
+// RepositoryTaskData taskData = TasksUiPlugin.getTaskDataStorageManager().getEditableCopy(
+// task.getRepositoryUrl(), task.getTaskId());
+// assertEquals("", taskData.getNewComment());
}
@@ -422,57 +420,142 @@ public class RepositoryTaskSynchronizationTest extends TestCase {
private class TestRepositoryConnector extends MockRepositoryConnector {
- @Override
- public AbstractTaskDataHandler getLegacyTaskDataHandler() {
- return handler;
- }
-
- // @Override
- // protected void removeOfflineTaskData(RepositoryTaskData bug) {
- // // ignore
- // }
- //
- // @Override
- // public void saveOffline(RepositoryTaskData taskData) {
- // // ignore
- // }
-
- // @Override
- // protected RepositoryTaskData
- // loadOfflineTaskData(AbstractTask repositoryTask) {
- // return repositoryTask.getTaskData();
- // }
-
}
private AbstractTask primeTaskAndRepository(SynchronizationState localState, SynchronizationState remoteState) {
RepositoryTaskData taskData = null;
AbstractTask task = new MockTask(MOCCK_ID);
- taskData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
- MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
- taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
- task.setLastReadTimeStamp(DATE_STAMP_1);
- task.setSynchronizationState(localState);
- TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData);
- newData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
- MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
-
- switch (remoteState) {
- case CONFLICT:
- case INCOMING:
- newData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_2);
- break;
- case SYNCHRONIZED:
- newData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
- break;
- default:
- fail("Remote repository can only be INCOMING or SYNCHRONIZED wrt the local task.");
-
- }
+// taskData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
+// MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
+// taskData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
+// task.setLastReadTimeStamp(DATE_STAMP_1);
+// task.setSynchronizationState(localState);
+// TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData);
+// newData = new RepositoryTaskData(new MockAttributeFactory(), connector.getConnectorKind(),
+// MockRepositoryConnector.REPOSITORY_URL, MOCCK_ID);
+//
+// switch (remoteState) {
+// case CONFLICT:
+// case INCOMING:
+// newData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_2);
+// break;
+// case SYNCHRONIZED:
+// newData.setAttributeValue(RepositoryTaskAttribute.DATE_MODIFIED, DATE_STAMP_1);
+// break;
+// default:
+// fail("Remote repository can only be INCOMING or SYNCHRONIZED wrt the local task.");
+//
+// }
return task;
+ }
+ public void testMarkTaskRead() {
+ // TODO reimplement
+// String repositoryUrl = "http://mylyn.eclipse.org/bugs222";
+// MockTask task1 = new MockTask(repositoryUrl, "1");
+// MockTask task2 = new MockTask(repositoryUrl, "2");
+// task1.setSynchronizationState(SynchronizationState.INCOMING);
+// task2.setSynchronizationState(SynchronizationState.INCOMING);
+// List<ITaskElement> elements = new ArrayList<ITaskElement>();
+// elements.add(task1);
+// elements.add(task2);
+// MarkTaskReadAction readAction = new MarkTaskReadAction(elements);
+// readAction.run();
+// assertEquals(SynchronizationState.SYNCHRONIZED, task1.getSynchronizationState());
+// assertEquals(SynchronizationState.SYNCHRONIZED, task2.getSynchronizationState());
+//
+// taskList.reset();
+// MockTask hit1 = new MockTask("1");
+// MockTask hit2 = new MockTask("2");
+// MockRepositoryQuery query = new MockRepositoryQuery("summary");
+// taskList.addQuery(query);
+// taskList.addTask(hit1, query);
+// taskList.addTask(hit2, query);
+//
+// elements.clear();
+// elements.add(query);
+// readAction = new MarkTaskReadAction(elements);
+// readAction.run();
+// assertEquals(2, query.getChildren().size());
+// for (ITaskElement element : query.getChildren()) {
+// if (element instanceof MockTask) {
+// MockTask mockTask = (MockTask) element;
+// assertEquals(SynchronizationState.SYNCHRONIZED, mockTask.getSynchronizationState());
+// }
+// }
+
+ }
+
+ public void testMarkUnRead() {
+ // TODO reimplement
+// String repositoryUrl = "http://mylyn.eclipse.org/bugs222";
+// MockTask task1 = new MockTask(repositoryUrl, "1");
+// MockTask task2 = new MockTask(repositoryUrl, "2");
+// assertEquals(SynchronizationState.SYNCHRONIZED, task1.getSynchronizationState());
+// assertEquals(SynchronizationState.SYNCHRONIZED, task2.getSynchronizationState());
+// List<ITaskElement> elements = new ArrayList<ITaskElement>();
+// elements.add(task1);
+// elements.add(task2);
+// MarkTaskUnreadAction unreadAction = new MarkTaskUnreadAction(elements);
+// unreadAction.run();
+// assertEquals(SynchronizationState.INCOMING, task1.getSynchronizationState());
+// assertEquals(SynchronizationState.INCOMING, task2.getSynchronizationState());
+//
+// taskList.reset();
+// MockTask hit1 = new MockTask("1");
+// MockTask hit2 = new MockTask("2");
+// MockRepositoryQuery query = new MockRepositoryQuery("summary");
+// taskList.addQuery(query);
+// taskList.addTask(hit1, query);
+// taskList.addTask(hit2, query);
+//
+// elements.clear();
+// elements.add(query);
+// MarkTaskReadAction readAction = new MarkTaskReadAction(elements);
+// readAction.run();
+// assertEquals(2, query.getChildren().size());
+// for (ITaskElement element : query.getChildren()) {
+// if (element instanceof MockTask) {
+// MockTask mockTask = (MockTask) element;
+// assertEquals(SynchronizationState.SYNCHRONIZED, mockTask.getSynchronizationState());
+// } else {
+// fail();
+// }
+// }
+//
+// unreadAction = new MarkTaskUnreadAction(elements);
+// unreadAction.run();
+// assertEquals(2, query.getChildren().size());
+// for (ITaskElement element : query.getChildren()) {
+// if (element instanceof MockTask) {
+// MockTask mockTask = (MockTask) element;
+// assertEquals(SynchronizationState.INCOMING, mockTask.getSynchronizationState());
+// } else {
+// fail();
+// }
+// }
}
+// public void testQueryHitsNotDropped() {
+// MockTask task1 = new MockTask("1");
+// MockTask task2 = new MockTask("2");
+// task1.setLastReadTimeStamp("today");
+// task2.setLastReadTimeStamp("today");
+// MockRepositoryQuery query = new MockRepositoryQuery("summary");
+// taskList.addQuery(query);
+// taskList.addTask(task1, query);
+// taskList.addTask(task2, query);
+// //assertEquals(0, taskList.getArchiveContainer().getChildren().size());
+// assertEquals(2, query.getChildren().size());
+// TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
+// MockRepositoryConnector.REPOSITORY_URL);
+// Set<RepositoryQuery> queries = new HashSet<RepositoryQuery>();
+// queries.add(query);
+// TasksUiInternal.synchronizeQueries(new MockRepositoryConnector(), repository, queries, null, true);
+// //assertEquals(2, taskList.getArchiveContainer().getChildren().size());
+// assertEquals(0, query.getChildren().size());
+// }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
index ddbbdea7a..01ab8a688 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListExternalizationTest.java
@@ -11,16 +11,29 @@
package org.eclipse.mylyn.tasks.tests;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
import junit.framework.TestCase;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
+import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
+import org.eclipse.mylyn.internal.tasks.core.LocalTask;
+import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.ITaskContainer;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
/**
* @author Steffen Pingel
@@ -31,7 +44,7 @@ public class TaskListExternalizationTest extends TestCase {
private TaskRepository repository;
- private void reloadTaskList() throws CoreException {
+ private void reloadTaskList() throws Exception {
taskList.notifyElementsChanged(null);
TasksUiPlugin.getExternalizationManager().requestSave();
TasksUiPlugin.getDefault().reloadDataDirectory();
@@ -55,7 +68,7 @@ public class TaskListExternalizationTest extends TestCase {
TaskTestUtil.resetTaskList();
}
- public void testTaskAttributes() throws CoreException {
+ public void testTaskAttributes() throws Exception {
AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
task1.setAttribute("key", "value");
assertEquals(1, task1.getAttributes().size());
@@ -68,7 +81,7 @@ public class TaskListExternalizationTest extends TestCase {
assertEquals("value", task1.getAttribute("key"));
}
- public void testTaskAttributeDelete() throws CoreException {
+ public void testTaskAttributeDelete() throws Exception {
AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
task1.setAttribute("key", "value");
task1.setAttribute("key", null);
@@ -83,4 +96,255 @@ public class TaskListExternalizationTest extends TestCase {
assertEquals(null, task1.getAttribute("key"));
}
+ public void testUncategorizedTasksNotLost() throws Exception {
+ MockRepositoryQuery query = new MockRepositoryQuery("Test");
+ taskList.addQuery(query);
+ MockTask task = new MockTask("1");
+ taskList.addTask(task, query);
+ taskList.addTask(task, taskList.getDefaultCategory());
+ assertTrue(query.contains(task.getHandleIdentifier()));
+ assertTrue(taskList.getDefaultCategory().contains(task.getHandleIdentifier()));
+
+ reloadTaskList();
+
+ assertTrue(taskList.getDefaultCategory().contains(task.getHandleIdentifier()));
+ }
+
+ public void testUniqueTaskId() throws Exception {
+ LocalTask task1 = TasksUiInternal.createNewLocalTask("label");
+ taskList.addTask(task1);
+ LocalTask task2 = TasksUiInternal.createNewLocalTask("label");
+ taskList.addTask(task2);
+ assertEquals(2, taskList.getLastLocalTaskId());
+ taskList.deleteTask(task2);
+ LocalTask task3 = TasksUiInternal.createNewLocalTask("label");
+ taskList.addTask(task3);
+ assertTrue(task3.getHandleIdentifier() + " should end with 3", task3.getHandleIdentifier().endsWith("3"));
+ assertEquals(3, taskList.getLastLocalTaskId());
+ assertEquals(2, taskList.getAllTasks().size());
+
+ reloadTaskList();
+ assertEquals(2, taskList.getAllTasks().size());
+ assertEquals(3, taskList.getLastLocalTaskId());
+ ITask task4 = TasksUiInternal.createNewLocalTask("label");
+ assertTrue(task4.getHandleIdentifier() + " should end with 4", task4.getHandleIdentifier().endsWith("4"));
+ }
+
+ public void testSingleTaskDeletion() throws Exception {
+ MockTask task = new MockTask("1");
+ taskList.addTask(task, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
+ assertEquals(1, taskList.getAllTasks().size());
+ taskList.deleteTask(task);
+ assertEquals(0, taskList.getAllTasks().size());
+ taskList.addTask(task, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
+ assertEquals(1, taskList.getAllTasks().size());
+
+ reloadTaskList();
+ assertEquals(1, taskList.getAllTasks().size());
+
+ taskList.deleteTask(task);
+ assertEquals(0, taskList.getAllTasks().size());
+
+ reloadTaskList();
+ assertEquals(0, taskList.getAllTasks().size());
+ }
+
+ public void testCategoryPersistance() throws Exception {
+ MockTask task = new MockTask("1");
+ TaskCategory category = new TaskCategory("cat");
+ taskList.addCategory(category);
+ taskList.addTask(task, category);
+ assertNotNull(taskList);
+ assertEquals(2, taskList.getCategories().size());
+
+ reloadTaskList();
+ assertEquals("" + taskList.getCategories(), 2, taskList.getCategories().size());
+ assertEquals(1, taskList.getAllTasks().size());
+ }
+
+ public void testCreate() throws Exception {
+ MockTask repositoryTask = new MockTask("1");
+ taskList.addTask(repositoryTask, taskList.getDefaultCategory());
+ assertEquals(1, taskList.getDefaultCategory().getChildren().size());
+
+ reloadTaskList();
+ assertEquals(1, taskList.getAllTasks().size());
+ }
+
+ public void testCreateAndMove() throws Exception {
+ MockTask repositoryTask = new MockTask("1");
+ taskList.addTask(repositoryTask);
+ assertEquals(1, taskList.getAllTasks().size());
+
+ reloadTaskList();
+ assertEquals(1, taskList.getAllTasks().size());
+ assertEquals(1, taskList.getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL).getChildren().size());
+ }
+
+ public void testArchiveRepositoryTaskExternalization() throws Exception {
+ MockTask repositoryTask = new MockTask("1");
+ taskList.addTask(repositoryTask);
+ assertEquals(1, taskList.getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL).getChildren().size());
+
+ reloadTaskList();
+ assertEquals(1, taskList.getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL).getChildren().size());
+ }
+
+ public void testRepositoryTasksAndCategoriesMultiRead() throws Exception {
+ TaskCategory cat1 = new TaskCategory("Category 1");
+ taskList.addCategory(cat1);
+
+ MockTask reportInCat1 = new MockTask("123");
+ taskList.addTask(reportInCat1, cat1);
+ assertEquals(cat1, TaskCategory.getParentTaskCategory(reportInCat1));
+
+ reloadTaskList();
+
+ // read once
+ Set<AbstractTaskCategory> readCats = taskList.getTaskCategories();
+ assertTrue(taskList.getCategories().contains(cat1));
+ Iterator<AbstractTaskCategory> iterator = readCats.iterator();
+
+ boolean found = false;
+ while (iterator.hasNext()) {
+ ITaskContainer readCat1 = iterator.next();
+ if (cat1.equals(readCat1)) {
+ found = true;
+ assertEquals(1, readCat1.getChildren().size());
+ }
+ }
+ if (!found) {
+ fail(" Category not found afer tasklist read");
+ }
+
+ reloadTaskList();
+
+ // read again
+ readCats = taskList.getTaskCategories();
+ assertTrue(taskList.getCategories().contains(cat1));
+
+ iterator = readCats.iterator();
+ found = false;
+ while (iterator.hasNext()) {
+ ITaskContainer readCat1 = iterator.next();
+ if (cat1.equals(readCat1)) {
+ found = true;
+ assertEquals(1, readCat1.getChildren().size());
+ }
+ }
+ if (!found) {
+ fail(" Category not found afer tasklist read");
+ }
+ }
+
+ public void testSubTaskExternalization() throws Exception {
+ Set<AbstractTask> rootTasks = new HashSet<AbstractTask>();
+ AbstractTask task1 = new LocalTask("1", "task1");
+ taskList.addTask(task1);
+ rootTasks.add(task1);
+
+ AbstractTask sub2 = new LocalTask("2", "sub 2");
+ taskList.addTask(sub2, task1);
+ assertEquals(1, task1.getChildren().size());
+ assertTrue(rootTasks.containsAll(taskList.getDefaultCategory().getChildren()));
+
+ reloadTaskList();
+
+ // XXX: This should pass once sub tasks are handled properly
+// assertTrue(rootTasks.containsAll(taskList.getOrphanContainer(
+// LocalRepositoryConnector.REPOSITORY_URL).getChildren()));
+
+ Collection<ITask> readList = taskList.getDefaultCategory().getChildren();
+ for (ITask task : readList) {
+ if (task.equals(task1)) {
+ assertEquals(task1.getSummary(), task.getSummary());
+ assertEquals(1, ((ITaskContainer) task).getChildren().size());
+ }
+ }
+ }
+
+ public void testCreationAndExternalization() throws Exception {
+ Set<AbstractTask> rootTasks = new HashSet<AbstractTask>();
+ AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
+ rootTasks.add(task1);
+ assertEquals(1, taskList.getAllTasks().size());
+
+ AbstractTask sub1 = TasksUiInternal.createNewLocalTask("sub 1");
+ taskList.addTask(sub1, task1);
+ assertEquals(4, taskList.getRootElements().size());
+
+ //taskList.moveToContainer(sub1, taskList.getArchiveContainer());
+
+ AbstractTask task2 = TasksUiInternal.createNewLocalTask("task 2");
+ rootTasks.add(task2);
+ assertEquals(3, taskList.getAllTasks().size());
+
+ Set<TaskCategory> categories = new HashSet<TaskCategory>();
+ Set<AbstractTask> cat1Contents = new HashSet<AbstractTask>();
+ TaskCategory cat1 = new TaskCategory("Category 1");
+ taskList.addCategory(cat1);
+ categories.add(cat1);
+ assertEquals(5, taskList.getRootElements().size());
+
+ AbstractTask task3 = TasksUiInternal.createNewLocalTask("task 3");
+ taskList.addTask(task3, cat1);
+ cat1Contents.add(task3);
+ assertEquals(4, taskList.getAllTasks().size());
+ assertEquals(cat1, TaskCategory.getParentTaskCategory(task3));
+ AbstractTask sub2 = TasksUiInternal.createNewLocalTask("sub 2");
+ assertEquals(5, taskList.getAllTasks().size());
+ taskList.addTask(sub2, task3);
+ //taskList.moveToContainer(sub2, taskList.getArchiveContainer());
+
+ AbstractTask task4 = TasksUiInternal.createNewLocalTask("task 4");
+ taskList.addTask(task4, cat1);
+ cat1Contents.add(task4);
+ assertEquals(6, taskList.getAllTasks().size());
+
+ MockTask reportInCat1 = new MockTask("123");
+ taskList.addTask(reportInCat1, cat1);
+ assertEquals(cat1, TaskCategory.getParentTaskCategory(reportInCat1));
+ cat1Contents.add(reportInCat1);
+ assertEquals(7, taskList.getAllTasks().size());
+
+ assertEquals(5, taskList.getRootElements().size());
+
+ TasksUiPlugin.getExternalizationManager().requestSave();
+ TasksUiPlugin.getDefault().reloadDataDirectory();
+
+ Collection<ITask> readList = taskList.getDefaultCategory().getChildren();
+ for (ITask task : readList) {
+ if (task.equals(task1)) {
+ assertEquals(task1.getSummary(), task.getSummary());
+ assertEquals(1, ((AbstractTaskContainer) task).getChildren().size());
+ }
+ }
+
+ Set<AbstractTaskCategory> readCats = taskList.getTaskCategories();
+ assertTrue(taskList.getCategories().contains(cat1));
+ Iterator<AbstractTaskCategory> iterator = readCats.iterator();
+ boolean found = false;
+ while (iterator.hasNext()) {
+ ITaskContainer readCat1 = iterator.next();
+ if (cat1.equals(readCat1)) {
+ found = true;
+ for (ITask task : readCat1.getChildren()) {
+ assertTrue(cat1Contents.contains(task));
+ }
+ }
+ }
+ if (!found) {
+ fail(" Category not found afer tasklist read");
+ }
+ }
+
+ public void testExternalizationOfHandlesWithDash() throws Exception {
+ AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
+ taskList.addTask(task1, taskList.getDefaultCategory());
+
+ TasksUiPlugin.getExternalizationManager().requestSave();
+ TasksUiPlugin.getDefault().reloadDataDirectory();
+ assertTrue(taskList.getDefaultCategory().getChildren().contains(task1));
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java
deleted file mode 100644
index f44f0b8f3..000000000
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java
+++ /dev/null
@@ -1,1006 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2004, 2008 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;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.mylyn.internal.context.core.ContextCorePlugin;
-import org.eclipse.mylyn.internal.context.core.InteractionContext;
-import org.eclipse.mylyn.internal.context.core.InteractionContextManager;
-import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
-import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
-import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
-import org.eclipse.mylyn.internal.tasks.core.ITaskList;
-import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
-import org.eclipse.mylyn.internal.tasks.core.LocalTask;
-import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery;
-import org.eclipse.mylyn.internal.tasks.core.TaskActivityUtil;
-import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
-import org.eclipse.mylyn.internal.tasks.core.TaskList;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData;
-import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants;
-import org.eclipse.mylyn.internal.tasks.ui.RefactorRepositoryUrlOperation;
-import org.eclipse.mylyn.internal.tasks.ui.TaskListManager;
-import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
-import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
-import org.eclipse.mylyn.monitor.core.InteractionEvent;
-import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
-import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.core.ITaskContainer;
-import org.eclipse.mylyn.tasks.core.TaskRepository;
-import org.eclipse.mylyn.tasks.tests.connector.MockAttributeFactory;
-import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
-import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
-import org.eclipse.mylyn.tasks.tests.connector.MockTask;
-
-/**
- * @author Mik Kersten
- */
-public class TaskListManagerTest extends TestCase {
-
- private TaskListManager manager;
-
- private TaskRepository repository;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- TasksUiPlugin.getDefault().getPreferenceStore().setValue(
- ITasksUiPreferenceConstants.REPOSITORY_SYNCH_SCHEDULE_ENABLED, false);
- manager = TasksUiPlugin.getTaskListManager();
- for (TaskRepository repository : TasksUiPlugin.getRepositoryManager().getAllRepositories()) {
- TasksUiPlugin.getRepositoryManager().removeRepository(repository,
- TasksUiPlugin.getDefault().getRepositoriesFilePath());
- }
- manager.resetTaskList();
- assertEquals(0, manager.getTaskList().getAllTasks().size());
-// manager.readExistingOrCreateNewList();
- TasksUiPlugin.getExternalizationManager().save(true);
- TasksUiPlugin.getDefault().reloadDataDirectory();
-
- repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND, MockRepositoryConnector.REPOSITORY_URL);
- TasksUiPlugin.getRepositoryManager().addRepository(repository);
-
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- TasksUiPlugin.getRepositoryManager().removeRepository(repository,
- TasksUiPlugin.getDefault().getRepositoriesFilePath());
- manager.resetTaskList();
- TasksUiPlugin.getExternalizationManager().save(true);
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- }
-
- public void testUncategorizedTasksNotLost() throws CoreException {
- MockRepositoryQuery query = new MockRepositoryQuery("Test");
- manager.getTaskList().addQuery(query);
- MockTask task = new MockTask("1");
- manager.getTaskList().addTask(task, query);
- manager.getTaskList().addTask(task, manager.getTaskList().getDefaultCategory());
- assertTrue(query.contains(task.getHandleIdentifier()));
- assertTrue(manager.getTaskList().getDefaultCategory().contains(task.getHandleIdentifier()));
-
- TasksUiPlugin.getExternalizationManager().requestSave();
- manager.resetTaskList();
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertFalse(manager.getTaskList().getDefaultCategory().contains(task.getHandleIdentifier()));
- TasksUiPlugin.getDefault().reloadDataDirectory();
-
- assertTrue(manager.getTaskList().getDefaultCategory().contains(task.getHandleIdentifier()));
-
- }
-
- public void testQueryAndCategoryNameClash() {
- TaskCategory category = new TaskCategory("TestClash");
- manager.getTaskList().addCategory(category);
- assertTrue(manager.getTaskList().getCategories().contains(category));
- assertEquals(2, manager.getTaskList().getCategories().size());
-
- MockRepositoryQuery query = new MockRepositoryQuery("TestClash");
- manager.getTaskList().addQuery(query);
- assertTrue(manager.getTaskList().getCategories().contains(category));
- assertEquals(2, manager.getTaskList().getCategories().size());
-
- manager.getTaskList().deleteCategory(category);
- }
-
- public void testUniqueTaskID() {
- LocalTask task1 = TasksUiInternal.createNewLocalTask("label");
- manager.getTaskList().addTask(task1);
- LocalTask task2 = TasksUiInternal.createNewLocalTask("label");
- manager.getTaskList().addTask(task2);
- assertEquals(2, manager.getTaskList().getLastLocalTaskId());
- manager.getTaskList().deleteTask(task2);
- LocalTask task3 = TasksUiInternal.createNewLocalTask("label");
- manager.getTaskList().addTask(task3);
- assertTrue(task3.getHandleIdentifier() + " should end with 3", task3.getHandleIdentifier().endsWith("3"));
- assertEquals(3, manager.getTaskList().getLastLocalTaskId());
-
- assertEquals(2, manager.getTaskList().getAllTasks().size());
- manager.saveTaskList();
- manager.resetTaskList();
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertEquals(0, manager.getTaskList().getLastLocalTaskId());
- manager.readExistingOrCreateNewList();
- assertEquals(2, manager.getTaskList().getAllTasks().size());
- assertEquals(3, manager.getTaskList().getLastLocalTaskId());
- ITask task4 = TasksUiInternal.createNewLocalTask("label");
- assertTrue(task4.getHandleIdentifier() + " should end with 4", task4.getHandleIdentifier().endsWith("4"));
- }
-
- public void testSingleTaskDeletion() {
- MockTask task = new MockTask("1");
- task.setLastReadTimeStamp("now");
- manager.getTaskList().addTask(task,
- manager.getTaskList().getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
- assertEquals(1, manager.getTaskList().getAllTasks().size());
- manager.getTaskList().deleteTask(task);
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- manager.getTaskList().addTask(task,
- manager.getTaskList().getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
- assertEquals(1, manager.getTaskList().getAllTasks().size());
-
- manager.saveTaskList();
-
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
- assertEquals(1, manager.getTaskList().getAllTasks().size());
-
- manager.getTaskList().deleteTask(task);
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- manager.saveTaskList();
- assertEquals(0, manager.getTaskList().getAllTasks().size());
-
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- }
-
- private void runRepositoryUrlOperation(String oldUrl, String newUrl) {
- try {
- new RefactorRepositoryUrlOperation(oldUrl, newUrl).run(new NullProgressMonitor());
- } catch (Exception e) {
- fail();
- }
- }
-
- public void testMigrateTaskContextFiles() throws IOException {
- File fileA = ContextCorePlugin.getContextStore().getFileForContext("http://a-1");
- fileA.createNewFile();
- fileA.deleteOnExit();
- assertTrue(fileA.exists());
- runRepositoryUrlOperation("http://a", "http://b");
- File fileB = ContextCorePlugin.getContextStore().getFileForContext("http://b-1");
- assertTrue(fileB.exists());
- assertFalse(fileA.exists());
- }
-
- public void testMigrateQueryUrlHandles() {
- RepositoryQuery query = new MockRepositoryQuery("mquery");
- query.setRepositoryUrl("http://foo.bar");
- query.setUrl("http://foo.bar/b");
- manager.getTaskList().addQuery(query);
- assertTrue(manager.getTaskList().getRepositoryQueries("http://foo.bar").size() > 0);
- runRepositoryUrlOperation("http://foo.bar", "http://bar.baz");
- assertTrue(manager.getTaskList().getRepositoryQueries("http://foo.bar").size() == 0);
- assertTrue(manager.getTaskList().getRepositoryQueries("http://bar.baz").size() > 0);
- IRepositoryQuery changedQuery = manager.getTaskList().getRepositoryQueries("http://bar.baz").iterator().next();
- assertEquals("http://bar.baz/b", changedQuery.getUrl());
- }
-
- public void testMigrateQueryHandles() {
- RepositoryQuery query = new MockRepositoryQuery("mquery");
- query.setRepositoryUrl("http://a");
- manager.getTaskList().addQuery(query);
- runRepositoryUrlOperation("http://a", "http://b");
- assertFalse(manager.getTaskList().getRepositoryQueries("http://b").isEmpty());
- assertTrue(manager.getTaskList().getRepositoryQueries("http://a").isEmpty());
- }
-
-// public void testMigrateQueryHits() {
-// AbstractRepositoryQuery query = new MockRepositoryQuery("mquery",
-// manager.getTaskList());
-// query.setRepositoryUrl("http://a");
-// manager.getTaskList().addQuery(query);
-// AbstractQueryHit hit = new MockQueryHit(manager.getTaskList(), "http://a",
-// "", "123");
-// query.addHit(hit);
-// runRepositoryUrlOperation("http://a", "http://b");
-// assertNotNull(manager.getTaskList().getQueryHit("http://b-123"));
-// assertEquals("http://b-123", hit.getHandleIdentifier());
-// }
-
- public void testMigrateTaskHandles() {
- AbstractTask task = new MockTask("http://a", "123");
- AbstractTask task2 = new MockTask("http://other", "other");
- manager.getTaskList().addTask(task);
- manager.getTaskList().addTask(task2);
-
- RepositoryTaskData taskData = new RepositoryTaskData(new MockAttributeFactory(), task.getConnectorKind(),
- task.getRepositoryUrl(), task.getTaskId(), task.getTaskKind());
- TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData);
- assertNotNull(TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task.getRepositoryUrl(),
- task.getTaskId()));
-
- RepositoryTaskData taskData2 = new RepositoryTaskData(new MockAttributeFactory(), task2.getConnectorKind(),
- task2.getRepositoryUrl(), task2.getTaskId(), task2.getTaskKind());
- taskData2.setNewComment("TEST");
- TasksUiPlugin.getTaskDataStorageManager().setNewTaskData(taskData2);
- assertNotNull(TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task2.getRepositoryUrl(),
- task2.getTaskId()));
- assertEquals("TEST", TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(task2.getRepositoryUrl(),
- task2.getTaskId()).getNewComment());
-
- runRepositoryUrlOperation("http://a", "http://b");
- assertNull(manager.getTaskList().getTask("http://a-123"));
- assertNotNull(manager.getTaskList().getTask("http://b-123"));
- assertNotNull(TasksUiPlugin.getTaskDataStorageManager().getNewTaskData("http://b", "123"));
- RepositoryTaskData otherData = TasksUiPlugin.getTaskDataStorageManager().getNewTaskData(
- task2.getRepositoryUrl(), task2.getTaskId());
- assertNotNull(otherData);
- assertEquals("TEST", otherData.getNewComment());
- }
-
- public void testMigrateTaskHandlesWithExplicitSet() {
- AbstractTask task = new MockTask("http://a", "123");
- task.setUrl("http://a/task/123");
- manager.getTaskList().addTask(task);
- runRepositoryUrlOperation("http://a", "http://b");
- assertNull(manager.getTaskList().getTask("http://a-123"));
- assertNotNull(manager.getTaskList().getTask("http://b-123"));
- assertEquals("http://b/task/123", task.getUrl());
- }
-
- public void testRefactorMetaContextHandles() {
- String firstUrl = "http://repository1.com/bugs";
- String secondUrl = "http://repository2.com/bugs";
- AbstractTask task1 = new MockTask(firstUrl, "1");
- AbstractTask task2 = new MockTask(firstUrl, "2");
- manager.getTaskList().addTask(task1);
- manager.getTaskList().addTask(task2);
- Calendar startDate = Calendar.getInstance();
- Calendar endDate = Calendar.getInstance();
- endDate.add(Calendar.MINUTE, 5);
-
- Calendar startDate2 = Calendar.getInstance();
- startDate2.add(Calendar.MINUTE, 15);
- Calendar endDate2 = Calendar.getInstance();
- endDate2.add(Calendar.MINUTE, 25);
-
- ContextCorePlugin.getContextManager().resetActivityMetaContext();
- InteractionContext metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
- assertEquals(0, metaContext.getInteractionHistory().size());
-
- ContextCorePlugin.getContextManager().processActivityMetaContextEvent(
- new InteractionEvent(InteractionEvent.Kind.ATTENTION,
- InteractionContextManager.ACTIVITY_STRUCTUREKIND_TIMING, task1.getHandleIdentifier(), "origin",
- null, InteractionContextManager.ACTIVITY_DELTA_ADDED, 1f, startDate.getTime(),
- endDate.getTime()));
-
- ContextCorePlugin.getContextManager().processActivityMetaContextEvent(
- new InteractionEvent(InteractionEvent.Kind.ATTENTION,
- InteractionContextManager.ACTIVITY_STRUCTUREKIND_TIMING, task2.getHandleIdentifier(), "origin",
- null, InteractionContextManager.ACTIVITY_DELTA_ADDED, 1f, startDate2.getTime(),
- endDate2.getTime()));
-
- assertEquals(2, metaContext.getInteractionHistory().size());
- assertEquals(60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(task1));
- assertEquals(2 * 60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(task2));
- runRepositoryUrlOperation(firstUrl, secondUrl);
- metaContext = ContextCorePlugin.getContextManager().getActivityMetaContext();
- assertEquals(2, metaContext.getInteractionHistory().size());
- assertEquals(60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(new MockTask(secondUrl, "1")));
- assertEquals(2 * 60 * 1000 * 5, TasksUiPlugin.getTaskActivityManager().getElapsedTime(
- new MockTask(secondUrl, "2")));
- assertEquals(secondUrl + "-1", metaContext.getInteractionHistory().get(0).getStructureHandle());
- }
-
- public void testIsActiveToday() {
- AbstractTask task = new LocalTask("1", "task-1");
- assertFalse(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
-
- task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday());
- assertTrue(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
-
- task.setReminded(true);
- assertTrue(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
- task.setReminded(true);
-
-// Calendar inAnHour = Calendar.getInstance();
-// inAnHour.set(Calendar.HOUR_OF_DAY, inAnHour.get(Calendar.HOUR_OF_DAY) + 1);
-// inAnHour.getTime();
-// task.setScheduledForDate(inAnHour.getTime());
-// Calendar tomorrow = Calendar.getInstance();
-// TaskActivityUtil.snapToNextDay(tomorrow);
-// assertEquals(-1, inAnHour.compareTo(tomorrow));
-// assertTrue(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
- }
-
- public void testScheduledForToday() {
- AbstractTask task = new LocalTask("1", "task-1");
- task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday());
- assertTrue(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
- task.setScheduledForDate(TaskActivityUtil.getCurrentWeek().getToday().next());
- assertFalse(TasksUiPlugin.getTaskActivityManager().isScheduledForToday(task));
- }
-
- public void testSchedulePastEndOfMonth() {
- Calendar calendar = Calendar.getInstance();
- calendar.set(Calendar.MONTH, Calendar.SEPTEMBER);
- calendar.set(Calendar.DAY_OF_MONTH, 30);
- TaskActivityUtil.snapForwardNumDays(calendar, 1);
- assertEquals("Should be October", Calendar.OCTOBER, calendar.get(Calendar.MONTH));
- }
-
- public void testIsCompletedToday() {
- ITask task = new LocalTask("1", "task 1");
- task.setCompletionDate(new Date());
- assertTrue(TasksUiPlugin.getTaskActivityManager().isCompletedToday(task));
-
- MockTask mockTask = new MockTask("1");
- mockTask.setOwner("unknown");
- manager.getTaskList().addTask(mockTask);
- mockTask.setCompletionDate(new Date());
- assertFalse("completed: " + mockTask.getCompletionDate(), TasksUiPlugin.getTaskActivityManager()
- .isCompletedToday(mockTask));
-
- mockTask = new MockTask("2");
- manager.getTaskList().addTask(mockTask);
- mockTask.setCompletionDate(new Date());
- repository.setAuthenticationCredentials("testUser", "testPassword");
- mockTask.setOwner("testUser");
- assertTrue(TasksUiPlugin.getTaskActivityManager().isCompletedToday(mockTask));
-
- }
-
- public void testMoveCategories() {
-// assertEquals(0, manager.getTaskList()
-// .getOrphanContainer(LocalRepositoryConnector.REPOSITORY_URL)
-// .getChildren()
-// .size());
-
- assertTrue(manager.getTaskList().getDefaultCategory().isEmpty());
-
- AbstractTask task1 = new LocalTask("t1", "t1");
-
- TaskCategory cat1 = new TaskCategory("cat1");
- manager.getTaskList().addCategory(cat1);
- TaskCategory cat2 = new TaskCategory("cat2");
- manager.getTaskList().addCategory(cat2);
-
- manager.getTaskList().addTask(task1, cat1);
- assertEquals(1, manager.getTaskList().getContainerForHandle("cat1").getChildren().size());
- assertEquals(0, manager.getTaskList().getContainerForHandle("cat2").getChildren().size());
-
- manager.getTaskList().addTask(task1, cat2);
- assertEquals(0, manager.getTaskList().getContainerForHandle("cat1").getChildren().size());
- assertEquals(1, manager.getTaskList().getContainerForHandle("cat2").getChildren().size());
- }
-
- public void testMoveToRoot() {
-// assertEquals(0, manager.getTaskList()
-// .getOrphanContainer(LocalRepositoryConnector.REPOSITORY_URL)
-// .getChildren()
-// .size());
- assertTrue(manager.getTaskList().getDefaultCategory().isEmpty());
-
- AbstractTask task1 = new LocalTask("t1", "t1");
- manager.getTaskList().addTask(task1,
- manager.getTaskList().getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
- assertEquals(1, manager.getTaskList().getDefaultCategory().getChildren().size());
- assertEquals(manager.getTaskList().getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));
-
- TaskCategory cat1 = new TaskCategory("c1");
- manager.getTaskList().addCategory(cat1);
-
- manager.getTaskList().addTask(task1, cat1);
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- assertEquals(cat1, TaskCategory.getParentTaskCategory(task1));
-
- manager.getTaskList().addTask(task1,
- manager.getTaskList().getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
- assertEquals(1, manager.getTaskList().getDefaultCategory().getChildren().size());
- assertEquals(0, cat1.getChildren().size());
- assertEquals(manager.getTaskList().getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));
- }
-
- public void testCategoryPersistance() {
- MockTask task = new MockTask("1");
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- manager.getTaskList().addTask(task, category);
- assertNotNull(manager.getTaskList());
- assertEquals(2, manager.getTaskList().getCategories().size());
-
- manager.saveTaskList();
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
- assertEquals("" + manager.getTaskList().getCategories(), 2, manager.getTaskList().getCategories().size());
- assertEquals(1, manager.getTaskList().getAllTasks().size());
- }
-
- public void testDeleteCategory() {
- assertNotNull(manager.getTaskList());
- assertEquals(1, manager.getTaskList().getCategories().size());
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- assertEquals(2, manager.getTaskList().getCategories().size());
- manager.getTaskList().deleteCategory(category);
- assertEquals(1, manager.getTaskList().getCategories().size());
- }
-
- public void testDeleteCategoryMovesTasksToRoot() {
- AbstractTask task = new MockTask("delete");
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- manager.getTaskList().addTask(task, category);
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- manager.getTaskList().deleteCategory(category);
- manager.getTaskList().getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL);
- }
-
- public void testRenameCategory() {
-
- assertNotNull(manager.getTaskList());
-
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- assertEquals(2, manager.getTaskList().getCategories().size());
- String newDesc = "newDescription";
- manager.getTaskList().renameContainer(category, newDesc);
- AbstractTaskCategory container = manager.getTaskList().getContainerForHandle(newDesc);
- assertNotNull(container);
- assertEquals(newDesc, container.getSummary());
- manager.getTaskList().deleteCategory(container);
- assertEquals(1, manager.getTaskList().getCategories().size());
- }
-
- public void testDeleteCategoryAfterRename() {
- String newDesc = "newDescription";
- assertNotNull(manager.getTaskList());
- assertEquals(1, manager.getTaskList().getCategories().size());
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- assertEquals(2, manager.getTaskList().getCategories().size());
- manager.getTaskList().renameContainer(category, newDesc);
- manager.getTaskList().deleteCategory(category);
- assertEquals(1, manager.getTaskList().getCategories().size());
- }
-
- public void testCreateSameCategoryName() {
- assertNotNull(manager.getTaskList());
- assertEquals(1, manager.getTaskList().getCategories().size());
- TaskCategory category = new TaskCategory("cat");
- manager.getTaskList().addCategory(category);
- assertEquals(2, manager.getTaskList().getCategories().size());
- TaskCategory category2 = new TaskCategory("cat");
- manager.getTaskList().addCategory(category2);
- assertEquals(2, manager.getTaskList().getCategories().size());
- ITaskContainer container = manager.getTaskList().getContainerForHandle("cat");
- assertEquals(container, category);
- }
-
- public void testDeleteRootTask() {
- AbstractTask task = new LocalTask("1", "label");
- manager.getTaskList().addTask(task);
- manager.getTaskList().deleteTask(task);
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- }
-
- public void testDeleteFromCategory() {
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- //assertEquals(0, manager.getTaskList().getArchiveContainer().getChildren().size());
- assertEquals(1, manager.getTaskList().getCategories().size());
-
- AbstractTask task = new LocalTask("1", "label");
- TaskCategory category = new TaskCategory("handleAndDescription");
- manager.getTaskList().addTask(task);
- assertEquals(1, manager.getTaskList().getDefaultCategory().getChildren().size());
-
- manager.getTaskList().addCategory(category);
- manager.getTaskList().addTask(task, category);
- assertEquals(2, manager.getTaskList().getCategories().size());
- assertEquals(1, category.getChildren().size());
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- assertEquals(1, manager.getTaskList().getAllTasks().size());
-
- manager.getTaskList().deleteTask(task);
- assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- assertEquals(0, category.getChildren().size());
- }
-
- public void testDeleteRepositoryTask() {
- String repositoryUrl = "http://somewhere.com";
- repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND, repositoryUrl);
- TasksUiPlugin.getRepositoryManager().addRepository(repository);
- MockTask task = new MockTask(repositoryUrl, "1");
- TaskList taskList = TasksUiPlugin.getTaskList();
- taskList.addTask(task, manager.getTaskList().getDefaultCategory());
- MockRepositoryQuery query = new MockRepositoryQuery("query");
- taskList.addQuery(query);
- taskList.addTask(task, query);
- assertEquals(1, taskList.getAllTasks().size());
- assertEquals(1, manager.getTaskList().getDefaultCategory().getChildren().size());
- taskList.deleteTask(task);
- assertEquals(0, taskList.getAllTasks().size());
- assertEquals(0, manager.getTaskList().getDefaultCategory().getChildren().size());
- }
-
- public void testCreate() {
- MockTask repositoryTask = new MockTask("1");
- repositoryTask.setLastReadTimeStamp("now");
- manager.getTaskList().addTask(repositoryTask, manager.getTaskList().getDefaultCategory());
- assertEquals(1, manager.getTaskList().getDefaultCategory().getChildren().size());
- manager.saveTaskList();
-
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
- assertEquals(1, manager.getTaskList().getAllTasks().size());
- }
-
- public void testCreateAndMove() throws CoreException {
- MockTask repositoryTask = new MockTask("1");
- repositoryTask.setLastReadTimeStamp("now");
- manager.getTaskList().addTask(repositoryTask);
- assertEquals(1, manager.getTaskList().getAllTasks().size());
- TasksUiPlugin.getExternalizationManager().requestSave();
- TasksUiPlugin.getDefault().reloadDataDirectory();
- assertEquals(1, manager.getTaskList().getAllTasks().size());
- assertEquals(1, manager.getTaskList()
- .getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL)
- .getChildren()
- .size());
-
- }
-
- public void testArchiveRepositoryTaskExternalization() {
- MockTask repositoryTask = new MockTask("1");
- repositoryTask.setLastReadTimeStamp("now");
- manager.getTaskList().addTask(repositoryTask);
- assertEquals(1, manager.getTaskList()
- .getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL)
- .getChildren()
- .size());
- manager.saveTaskList();
-
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
- assertEquals(1, manager.getTaskList()
- .getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL)
- .getChildren()
- .size());
- }
-
- public void testRepositoryTasksAndCategoriesMultiRead() {
- TaskCategory cat1 = new TaskCategory("Category 1");
- manager.getTaskList().addCategory(cat1);
-
- MockTask reportInCat1 = new MockTask("123");
- manager.getTaskList().addTask(reportInCat1, cat1);
- assertEquals(cat1, TaskCategory.getParentTaskCategory(reportInCat1));
-
- manager.saveTaskList();
- assertNotNull(manager.getTaskList());
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
-
- // read once
- Set<AbstractTaskCategory> readCats = manager.getTaskList().getTaskCategories();
- assertTrue(manager.getTaskList().getCategories().contains(cat1));
- Iterator<AbstractTaskCategory> iterator = readCats.iterator();
-
- boolean found = false;
- while (iterator.hasNext()) {
- ITaskContainer readCat1 = iterator.next();
- if (cat1.equals(readCat1)) {
- found = true;
- assertEquals(1, readCat1.getChildren().size());
- }
- }
- if (!found) {
- fail(" Category not found afer tasklist read");
- }
-
- manager.saveTaskList();
- assertNotNull(manager.getTaskList());
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
-
- // read again
- readCats = manager.getTaskList().getTaskCategories();
- assertTrue(manager.getTaskList().getCategories().contains(cat1));
-
- iterator = readCats.iterator();
- found = false;
- while (iterator.hasNext()) {
- ITaskContainer readCat1 = iterator.next();
- if (cat1.equals(readCat1)) {
- found = true;
- assertEquals(1, readCat1.getChildren().size());
- }
- }
- if (!found) {
- fail(" Category not found afer tasklist read");
- }
- }
-
- public void testSubTaskExternalization() {
- Set<AbstractTask> rootTasks = new HashSet<AbstractTask>();
- AbstractTask task1 = new LocalTask("1", "task1");
- manager.getTaskList().addTask(task1);
- rootTasks.add(task1);
-
- AbstractTask sub2 = new LocalTask("2", "sub 2");
- manager.getTaskList().addTask(sub2, task1);
- assertEquals(1, task1.getChildren().size());
- assertTrue(rootTasks.containsAll(manager.getTaskList().getDefaultCategory().getChildren()));
-
- manager.saveTaskList();
- assertNotNull(manager.getTaskList());
- manager.resetTaskList();
- manager.readExistingOrCreateNewList();
-
- assertNotNull(manager.getTaskList());
-
- // XXX: This should pass once sub tasks are handled properly
-// assertTrue(rootTasks.containsAll(manager.getTaskList().getOrphanContainer(
-// LocalRepositoryConnector.REPOSITORY_URL).getChildren()));
-
- Collection<ITask> readList = manager.getTaskList().getDefaultCategory().getChildren();
- for (ITask task : readList) {
- if (task.equals(task1)) {
- assertEquals(task1.getSummary(), task.getSummary());
- assertEquals(1, ((ITaskContainer) task).getChildren().size());
- }
- }
- }
-
- public void testCreationAndExternalization() throws CoreException {
- Set<AbstractTask> rootTasks = new HashSet<AbstractTask>();
- AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
- rootTasks.add(task1);
- assertEquals(1, manager.getTaskList().getAllTasks().size());
-
- AbstractTask sub1 = TasksUiInternal.createNewLocalTask("sub 1");
- manager.getTaskList().addTask(sub1, task1);
- assertEquals(4, manager.getTaskList().getRootElements().size());
-
- //manager.getTaskList().moveToContainer(sub1, manager.getTaskList().getArchiveContainer());
-
- AbstractTask task2 = TasksUiInternal.createNewLocalTask("task 2");
- rootTasks.add(task2);
- assertEquals(3, manager.getTaskList().getAllTasks().size());
-
- Set<TaskCategory> categories = new HashSet<TaskCategory>();
- Set<AbstractTask> cat1Contents = new HashSet<AbstractTask>();
- TaskCategory cat1 = new TaskCategory("Category 1");
- manager.getTaskList().addCategory(cat1);
- categories.add(cat1);
- assertEquals(5, manager.getTaskList().getRootElements().size());
-
- AbstractTask task3 = TasksUiInternal.createNewLocalTask("task 3");
- manager.getTaskList().addTask(task3, cat1);
- cat1Contents.add(task3);
- assertEquals(4, manager.getTaskList().getAllTasks().size());
- assertEquals(cat1, TaskCategory.getParentTaskCategory(task3));
- AbstractTask sub2 = TasksUiInternal.createNewLocalTask("sub 2");
- assertEquals(5, manager.getTaskList().getAllTasks().size());
- manager.getTaskList().addTask(sub2, task3);
- //manager.getTaskList().moveToContainer(sub2, manager.getTaskList().getArchiveContainer());
-
- AbstractTask task4 = TasksUiInternal.createNewLocalTask("task 4");
- manager.getTaskList().addTask(task4, cat1);
- cat1Contents.add(task4);
- assertEquals(6, manager.getTaskList().getAllTasks().size());
-
- MockTask reportInCat1 = new MockTask("123");
- manager.getTaskList().addTask(reportInCat1, cat1);
- assertEquals(cat1, TaskCategory.getParentTaskCategory(reportInCat1));
- cat1Contents.add(reportInCat1);
- assertEquals(7, manager.getTaskList().getAllTasks().size());
-
- assertEquals(5, manager.getTaskList().getRootElements().size());
-
- TasksUiPlugin.getExternalizationManager().requestSave();
- TasksUiPlugin.getDefault().reloadDataDirectory();
-
- Collection<ITask> readList = manager.getTaskList().getDefaultCategory().getChildren();
- for (ITask task : readList) {
- if (task.equals(task1)) {
- assertEquals(task1.getSummary(), task.getSummary());
- assertEquals(1, ((AbstractTaskContainer) task).getChildren().size());
- }
- }
-
- Set<AbstractTaskCategory> readCats = manager.getTaskList().getTaskCategories();
- assertTrue(manager.getTaskList().getCategories().contains(cat1));
- Iterator<AbstractTaskCategory> iterator = readCats.iterator();
- boolean found = false;
- while (iterator.hasNext()) {
- ITaskContainer readCat1 = iterator.next();
- if (cat1.equals(readCat1)) {
- found = true;
- for (ITask task : readCat1.getChildren()) {
- assertTrue(cat1Contents.contains(task));
- }
- }
- }
- if (!found) {
- fail(" Category not found afer tasklist read");
- }
- }
-
- public void testExternalizationOfHandlesWithDash() throws CoreException {
- AbstractTask task1 = TasksUiInternal.createNewLocalTask("task 1");
- manager.getTaskList().addTask(task1, manager.getTaskList().getDefaultCategory());
-
- TasksUiPlugin.getExternalizationManager().requestSave();
- TasksUiPlugin.getDefault().reloadDataDirectory();
- assertTrue(manager.getTaskList().getDefaultCategory().getChildren().contains(task1));
- }
-
- public void testgetQueriesAndHitsForHandle() {
- TaskList taskList = manager.getTaskList();
-
- MockTask hit1 = new MockTask("1");
- MockTask hit2 = new MockTask("2");
- MockTask hit3 = new MockTask("3");
-
- MockTask hit1twin = new MockTask("1");
- MockTask hit2twin = new MockTask("2");
- MockTask hit3twin = new MockTask("3");
-
- MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
- MockRepositoryQuery query2 = new MockRepositoryQuery("query2");
-
- taskList.addQuery(query1);
- taskList.addQuery(query2);
- taskList.addTask(hit1, query1);
- taskList.addTask(hit2, query1);
- taskList.addTask(hit3, query1);
-
- assertEquals(3, query1.getChildren().size());
-
- taskList.addTask(hit1twin, query2);
- taskList.addTask(hit2twin, query2);
- taskList.addTask(hit3twin, query2);
-
- assertEquals(3, query2.getChildren().size());
-
- Set<AbstractTaskContainer> queriesReturned = hit1.getParentContainers();
- assertNotNull(queriesReturned);
- assertEquals(2, queriesReturned.size());
- assertTrue(queriesReturned.contains(query1));
- assertTrue(queriesReturned.contains(query2));
- }
-
-// public void testQueryHitHasParent() {
-// TaskList taskList = manager.getTaskList();
-//
-// MockQueryHit hit1 = new MockQueryHit(taskList,
-// MockRepositoryConnector.REPOSITORY_URL, "description1", "1");
-// assertNull(hit1.getParent());
-// MockRepositoryQuery query1 = new MockRepositoryQuery("query1",
-// manager.getTaskList());
-// query1.addHit(hit1);
-// assertEquals(query1, hit1.getParent());
-//
-// }
-
- public void testUpdateQueryHits() {
- ITaskList taskList = manager.getTaskList();
-
- MockTask hit1 = new MockTask("1");
- MockTask hit2 = new MockTask("2");
- MockTask hit3 = new MockTask("3");
-
- MockTask hit1twin = new MockTask("1");
- MockTask hit2twin = new MockTask("2");
- MockTask hit3twin = new MockTask("3");
-
- MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
- taskList.addQuery(query1);
-
- taskList.addTask(hit1, query1);
- taskList.addTask(hit2, query1);
- taskList.addTask(hit3, query1);
-
- taskList.addTask(hit1twin, query1);
- taskList.addTask(hit2twin, query1);
- taskList.addTask(hit3twin, query1);
-
- assertEquals(3, query1.getChildren().size());
- for (ITask child : query1.getChildren()) {
- taskList.removeFromContainer(query1, child);
- }
- assertEquals(0, query1.getChildren().size());
- taskList.addTask(hit1, query1);
- taskList.addTask(hit2, query1);
- assertEquals(2, query1.getChildren().size());
- hit1.setNotified(true);
-
- taskList.addTask(hit1twin, query1);
- taskList.addTask(hit2twin, query1);
- taskList.addTask(hit3twin, query1);
- assertEquals(3, query1.getChildren().size());
- assertTrue(query1.getChildren().contains(hit1twin));
- assertTrue(query1.getChildren().contains(hit2twin));
- assertTrue(query1.getChildren().contains(hit3twin));
- for (ITask hit : query1.getChildren()) {
- if (hit.equals(hit1twin)) {
- assertTrue(((AbstractTask) hit).isNotified());
- } else {
- assertFalse(((AbstractTask) hit).isNotified());
- }
- }
- }
-
- public void testgetRepositoryTasks() {
-
- String repositoryUrl = "https://bugs.eclipse.org/bugs";
-
- String bugNumber = "106939";
-
- MockTask task1 = new MockTask(repositoryUrl, bugNumber);
- manager.getTaskList().addTask(task1);
-
- MockTask task2 = new MockTask("https://unresolved", bugNumber);
- manager.getTaskList().addTask(task2);
-
- TaskList taskList = manager.getTaskList();
- assertEquals(2, taskList.getAllTasks().size());
- Set<ITask> tasksReturned = taskList.getTasks(repositoryUrl);
- assertNotNull(tasksReturned);
- assertEquals(1, tasksReturned.size());
- assertTrue(tasksReturned.contains(task1));
- }
-
- public void testAllTasksDeactivation() {
- AbstractTask task1 = new LocalTask("task1", "description1");
- AbstractTask task2 = new LocalTask("task2", "description2");
- TaskList taskList = manager.getTaskList();
- taskList.addTask(task1);
- taskList.addTask(task2);
- assertNull(manager.getActiveTask());
-
- manager.activateTask(task2);
- assertEquals(task2, manager.getActiveTask());
-
- manager.deactivateAllTasks();
- assertNull(manager.getActiveTask());
- }
-
- public void testMarkTaskRead() {
- // TODO reimplement
-// String repositoryUrl = "http://mylyn.eclipse.org/bugs222";
-// MockTask task1 = new MockTask(repositoryUrl, "1");
-// MockTask task2 = new MockTask(repositoryUrl, "2");
-// task1.setSynchronizationState(SynchronizationState.INCOMING);
-// task2.setSynchronizationState(SynchronizationState.INCOMING);
-// List<ITaskElement> elements = new ArrayList<ITaskElement>();
-// elements.add(task1);
-// elements.add(task2);
-// MarkTaskReadAction readAction = new MarkTaskReadAction(elements);
-// readAction.run();
-// assertEquals(SynchronizationState.SYNCHRONIZED, task1.getSynchronizationState());
-// assertEquals(SynchronizationState.SYNCHRONIZED, task2.getSynchronizationState());
-//
-// manager.getTaskList().reset();
-// MockTask hit1 = new MockTask("1");
-// MockTask hit2 = new MockTask("2");
-// MockRepositoryQuery query = new MockRepositoryQuery("summary");
-// manager.getTaskList().addQuery(query);
-// manager.getTaskList().addTask(hit1, query);
-// manager.getTaskList().addTask(hit2, query);
-//
-// elements.clear();
-// elements.add(query);
-// readAction = new MarkTaskReadAction(elements);
-// readAction.run();
-// assertEquals(2, query.getChildren().size());
-// for (ITaskElement element : query.getChildren()) {
-// if (element instanceof MockTask) {
-// MockTask mockTask = (MockTask) element;
-// assertEquals(SynchronizationState.SYNCHRONIZED, mockTask.getSynchronizationState());
-// }
-// }
-
- }
-
- public void testMarkUnRead() {
- // TODO reimplement
-// String repositoryUrl = "http://mylyn.eclipse.org/bugs222";
-// MockTask task1 = new MockTask(repositoryUrl, "1");
-// MockTask task2 = new MockTask(repositoryUrl, "2");
-// assertEquals(SynchronizationState.SYNCHRONIZED, task1.getSynchronizationState());
-// assertEquals(SynchronizationState.SYNCHRONIZED, task2.getSynchronizationState());
-// List<ITaskElement> elements = new ArrayList<ITaskElement>();
-// elements.add(task1);
-// elements.add(task2);
-// MarkTaskUnreadAction unreadAction = new MarkTaskUnreadAction(elements);
-// unreadAction.run();
-// assertEquals(SynchronizationState.INCOMING, task1.getSynchronizationState());
-// assertEquals(SynchronizationState.INCOMING, task2.getSynchronizationState());
-//
-// manager.getTaskList().reset();
-// MockTask hit1 = new MockTask("1");
-// MockTask hit2 = new MockTask("2");
-// MockRepositoryQuery query = new MockRepositoryQuery("summary");
-// manager.getTaskList().addQuery(query);
-// manager.getTaskList().addTask(hit1, query);
-// manager.getTaskList().addTask(hit2, query);
-//
-// elements.clear();
-// elements.add(query);
-// MarkTaskReadAction readAction = new MarkTaskReadAction(elements);
-// readAction.run();
-// assertEquals(2, query.getChildren().size());
-// for (ITaskElement element : query.getChildren()) {
-// if (element instanceof MockTask) {
-// MockTask mockTask = (MockTask) element;
-// assertEquals(SynchronizationState.SYNCHRONIZED, mockTask.getSynchronizationState());
-// } else {
-// fail();
-// }
-// }
-//
-// unreadAction = new MarkTaskUnreadAction(elements);
-// unreadAction.run();
-// assertEquals(2, query.getChildren().size());
-// for (ITaskElement element : query.getChildren()) {
-// if (element instanceof MockTask) {
-// MockTask mockTask = (MockTask) element;
-// assertEquals(SynchronizationState.INCOMING, mockTask.getSynchronizationState());
-// } else {
-// fail();
-// }
-// }
- }
-
- public void testQueryHitsNotDropped() {
- MockTask task1 = new MockTask("1");
- MockTask task2 = new MockTask("2");
- task1.setLastReadTimeStamp("today");
- task2.setLastReadTimeStamp("today");
- MockRepositoryQuery query = new MockRepositoryQuery("summary");
- manager.getTaskList().addQuery(query);
- manager.getTaskList().addTask(task1, query);
- manager.getTaskList().addTask(task2, query);
- //assertEquals(0, manager.getTaskList().getArchiveContainer().getChildren().size());
- assertEquals(2, query.getChildren().size());
- TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
- MockRepositoryConnector.REPOSITORY_URL);
- Set<RepositoryQuery> queries = new HashSet<RepositoryQuery>();
- queries.add(query);
- TasksUiInternal.synchronizeQueries(new MockRepositoryConnector(), repository, queries, null, true);
- //assertEquals(2, manager.getTaskList().getArchiveContainer().getChildren().size());
- assertEquals(0, query.getChildren().size());
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListTest.java
index 6ddd5abd7..fedeb6c19 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2008 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
@@ -11,12 +11,22 @@
package org.eclipse.mylyn.tasks.tests;
+import java.util.Set;
+
import junit.framework.TestCase;
-import org.eclipse.mylyn.internal.tasks.core.ITaskList;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskCategory;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTaskContainer;
+import org.eclipse.mylyn.internal.tasks.core.LocalRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.core.TaskCategory;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.ITaskContainer;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryQuery;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
/**
* @author Mik Kersten
@@ -25,14 +35,19 @@ import org.eclipse.mylyn.internal.tasks.core.TaskList;
*/
public class TaskListTest extends TestCase {
+ private TaskList taskList;
+
+ @Override
+ protected void setUp() throws Exception {
+ taskList = new TaskList();
+ }
+
public void testGetCategories() {
- TaskList taskList = new TaskList();
taskList.addCategory(new TaskCategory("a"));
assertEquals(2, taskList.getCategories().size());
}
public void testLocalSubTaskAdd() {
- ITaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
LocalTask subTask = new LocalTask("2", "subTask");
@@ -44,7 +59,6 @@ public class TaskListTest extends TestCase {
}
public void testLocalTaskAddToSelf() {
- ITaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
taskList.addTask(task);
@@ -54,7 +68,6 @@ public class TaskListTest extends TestCase {
}
public void testLocalSubTaskAddCycle() {
- TaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
LocalTask subTask = new LocalTask("2", "subTask");
@@ -71,7 +84,6 @@ public class TaskListTest extends TestCase {
}
public void testLocalSubTaskAddDeepCycle() {
- TaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
LocalTask subTask1 = new LocalTask("2", "subTask");
LocalTask subTask2 = new LocalTask("3", "subTask");
@@ -135,7 +147,6 @@ public class TaskListTest extends TestCase {
}
public void testLocalSubTaskAddMaxSubTaskDepthDeepCycle() {
- TaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
LocalTask subTask1 = new LocalTask("2", "subTask");
LocalTask subTask2 = new LocalTask("3", "subTask");
@@ -204,7 +215,6 @@ public class TaskListTest extends TestCase {
}
public void testLocalSubTaskAddReallyDeepCycle() {
- TaskList taskList = new TaskList();
LocalTask task = new LocalTask("1", "summary");
LocalTask subTask1 = new LocalTask("2", "subTask");
LocalTask subTask2 = new LocalTask("3", "subTask");
@@ -309,4 +319,237 @@ public class TaskListTest extends TestCase {
assertEquals(0, subTask18.getChildren().size());
}
+
+ public void testQueryAndCategoryNameClash() {
+ TaskCategory category = new TaskCategory("TestClash");
+ taskList.addCategory(category);
+ assertTrue(taskList.getCategories().contains(category));
+ assertEquals(2, taskList.getCategories().size());
+
+ MockRepositoryQuery query = new MockRepositoryQuery("TestClash");
+ taskList.addQuery(query);
+ assertTrue(taskList.getCategories().contains(category));
+ assertEquals(2, taskList.getCategories().size());
+ }
+
+ public void testMoveToRoot() {
+ AbstractTask task1 = new LocalTask("t1", "t1");
+ taskList.addTask(task1, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
+ assertEquals(1, taskList.getDefaultCategory().getChildren().size());
+ assertEquals(taskList.getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));
+
+ TaskCategory cat1 = new TaskCategory("c1");
+ taskList.addCategory(cat1);
+
+ taskList.addTask(task1, cat1);
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ assertEquals(cat1, TaskCategory.getParentTaskCategory(task1));
+
+ taskList.addTask(task1, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
+ assertEquals(1, taskList.getDefaultCategory().getChildren().size());
+ assertEquals(0, cat1.getChildren().size());
+ assertEquals(taskList.getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));
+ }
+
+ public void testDeleteCategory() {
+ assertEquals(1, taskList.getCategories().size());
+ TaskCategory category = new TaskCategory("cat");
+ taskList.addCategory(category);
+ assertEquals(2, taskList.getCategories().size());
+ taskList.deleteCategory(category);
+ assertEquals(1, taskList.getCategories().size());
+ }
+
+ public void testDeleteCategoryMovesTasksToRoot() {
+ AbstractTask task = new MockTask("delete");
+ TaskCategory category = new TaskCategory("cat");
+ taskList.addCategory(category);
+ taskList.addTask(task, category);
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ taskList.deleteCategory(category);
+ taskList.getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testRenameCategory() {
+ TaskCategory category = new TaskCategory("handle", "cat");
+ taskList.addCategory(category);
+ assertEquals(2, taskList.getCategories().size());
+ taskList.renameContainer(category, "newDescription");
+ AbstractTaskCategory container = taskList.getContainerForHandle("handle");
+ assertNotNull(container);
+ assertEquals("newDescription", container.getSummary());
+ taskList.deleteCategory(container);
+ assertEquals(1, taskList.getCategories().size());
+ }
+
+ @SuppressWarnings("deprecation")
+ public void testDeleteCategoryAfterRename() {
+ String newDesc = "newDescription";
+ assertNotNull(taskList);
+ assertEquals(1, taskList.getCategories().size());
+ TaskCategory category = new TaskCategory("cat");
+ taskList.addCategory(category);
+ assertEquals(2, taskList.getCategories().size());
+ taskList.renameContainer(category, newDesc);
+ taskList.deleteCategory(category);
+ assertEquals(1, taskList.getCategories().size());
+ }
+
+ public void testCreateSameCategoryName() {
+ assertEquals(1, taskList.getCategories().size());
+ TaskCategory category = new TaskCategory("cat");
+ taskList.addCategory(category);
+ assertEquals(2, taskList.getCategories().size());
+ TaskCategory category2 = new TaskCategory("cat");
+ try {
+ taskList.addCategory(category2);
+ fail("expected IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ }
+ assertEquals(2, taskList.getCategories().size());
+ ITaskContainer container = taskList.getContainerForHandle("cat");
+ assertEquals(container, category);
+ }
+
+ public void testDeleteRootTask() {
+ AbstractTask task = new LocalTask("1", "label");
+ taskList.addTask(task);
+ taskList.deleteTask(task);
+ assertEquals(0, taskList.getAllTasks().size());
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ }
+
+ public void testDeleteFromCategory() {
+ assertEquals(0, taskList.getAllTasks().size());
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ //assertEquals(0, taskList.getArchiveContainer().getChildren().size());
+ assertEquals(1, taskList.getCategories().size());
+
+ AbstractTask task = new LocalTask("1", "label");
+ TaskCategory category = new TaskCategory("handleAndDescription");
+ taskList.addTask(task);
+ assertEquals(1, taskList.getDefaultCategory().getChildren().size());
+
+ taskList.addCategory(category);
+ taskList.addTask(task, category);
+ assertEquals(2, taskList.getCategories().size());
+ assertEquals(1, category.getChildren().size());
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ assertEquals(1, taskList.getAllTasks().size());
+
+ taskList.deleteTask(task);
+ assertEquals(0, taskList.getAllTasks().size());
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ assertEquals(0, category.getChildren().size());
+ }
+
+ public void testDeleteRepositoryTask() {
+ String repositoryUrl = "http://somewhere.com";
+ MockTask task = new MockTask(repositoryUrl, "1");
+ taskList.addTask(task, taskList.getDefaultCategory());
+ MockRepositoryQuery query = new MockRepositoryQuery("query");
+ taskList.addQuery(query);
+ taskList.addTask(task, query);
+ assertEquals(1, taskList.getAllTasks().size());
+ assertEquals(1, taskList.getDefaultCategory().getChildren().size());
+ taskList.deleteTask(task);
+ assertEquals(0, taskList.getAllTasks().size());
+ assertEquals(0, taskList.getDefaultCategory().getChildren().size());
+ }
+
+ public void testgetQueriesAndHitsForHandle() {
+ MockTask hit1 = new MockTask("1");
+ MockTask hit2 = new MockTask("2");
+ MockTask hit3 = new MockTask("3");
+
+ MockTask hit1twin = new MockTask("1");
+ MockTask hit2twin = new MockTask("2");
+ MockTask hit3twin = new MockTask("3");
+
+ MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
+ MockRepositoryQuery query2 = new MockRepositoryQuery("query2");
+
+ taskList.addQuery(query1);
+ taskList.addQuery(query2);
+ taskList.addTask(hit1, query1);
+ taskList.addTask(hit2, query1);
+ taskList.addTask(hit3, query1);
+
+ assertEquals(3, query1.getChildren().size());
+
+ taskList.addTask(hit1twin, query2);
+ taskList.addTask(hit2twin, query2);
+ taskList.addTask(hit3twin, query2);
+
+ assertEquals(3, query2.getChildren().size());
+
+ Set<AbstractTaskContainer> queriesReturned = hit1.getParentContainers();
+ assertNotNull(queriesReturned);
+ assertEquals(2, queriesReturned.size());
+ assertTrue(queriesReturned.contains(query1));
+ assertTrue(queriesReturned.contains(query2));
+ }
+
+ public void testUpdateQueryHits() {
+ MockTask hit1 = new MockTask("1");
+ MockTask hit2 = new MockTask("2");
+ MockTask hit3 = new MockTask("3");
+
+ MockTask hit1twin = new MockTask("1");
+ MockTask hit2twin = new MockTask("2");
+ MockTask hit3twin = new MockTask("3");
+
+ MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
+ taskList.addQuery(query1);
+
+ taskList.addTask(hit1, query1);
+ taskList.addTask(hit2, query1);
+ taskList.addTask(hit3, query1);
+
+ taskList.addTask(hit1twin, query1);
+ taskList.addTask(hit2twin, query1);
+ taskList.addTask(hit3twin, query1);
+
+ assertEquals(3, query1.getChildren().size());
+ for (ITask child : query1.getChildren()) {
+ taskList.removeFromContainer(query1, child);
+ }
+ assertEquals(0, query1.getChildren().size());
+ taskList.addTask(hit1, query1);
+ taskList.addTask(hit2, query1);
+ assertEquals(2, query1.getChildren().size());
+ hit1.setNotified(true);
+
+ taskList.addTask(hit1twin, query1);
+ taskList.addTask(hit2twin, query1);
+ taskList.addTask(hit3twin, query1);
+ assertEquals(3, query1.getChildren().size());
+ assertTrue(query1.getChildren().contains(hit1twin));
+ assertTrue(query1.getChildren().contains(hit2twin));
+ assertTrue(query1.getChildren().contains(hit3twin));
+ for (ITask hit : query1.getChildren()) {
+ if (hit.equals(hit1twin)) {
+ assertTrue(((AbstractTask) hit).isNotified());
+ } else {
+ assertFalse(((AbstractTask) hit).isNotified());
+ }
+ }
+ }
+
+ public void testGetRepositoryTasks() {
+ String repositoryUrl = "https://bugs.eclipse.org/bugs";
+ String bugNumber = "106939";
+ MockTask task1 = new MockTask(repositoryUrl, bugNumber);
+ taskList.addTask(task1);
+ MockTask task2 = new MockTask("https://unresolved", bugNumber);
+ taskList.addTask(task2);
+
+ assertEquals(2, taskList.getAllTasks().size());
+ Set<ITask> tasksReturned = taskList.getTasks(repositoryUrl);
+ assertNotNull(tasksReturned);
+ assertEquals(1, tasksReturned.size());
+ assertTrue(tasksReturned.contains(task1));
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
index e31d41b4b..58bf8e2bf 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2008 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
@@ -23,8 +23,8 @@ import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.RepositoryTaskHandleUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractLegacyRepositoryConnector;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
@@ -121,7 +121,7 @@ public class TaskRepositoryManagerTest extends TestCase {
}
public void testConnectorAddition() {
- AbstractLegacyRepositoryConnector connector = new MockRepositoryConnector();
+ AbstractRepositoryConnector connector = new MockRepositoryConnector();
manager.addRepositoryConnector(connector);
assertNotNull(manager.getRepositoryConnector(connector.getConnectorKind()));
}
@@ -203,14 +203,13 @@ public class TaskRepositoryManagerTest extends TestCase {
}
public void testRepositoryWithCustomAttributes() throws Exception {
-
// Note: if a connector doesn't exist the associated repositories are not loaded (orphaned)
// causing this test to fail.
- AbstractLegacyRepositoryConnector connector = new MockRepositoryConnector();
+ AbstractRepositoryConnector connector = new MockRepositoryConnector();
manager.addRepositoryConnector(connector);
TaskRepository repository = new TaskRepository(MockRepositoryConnector.REPOSITORY_KIND,
- "http://jroller.com/page/eu");
+ "http://mylyn.eclipse.org/");
repository.setProperty("owner", "euxx");
manager.addRepository(repository);
TasksUiPlugin.getDefault();
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java
index ffacda184..ec2fe6364 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttachmentHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2004, 2008 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
@@ -12,73 +12,46 @@
package org.eclipse.mylyn.tasks.tests.connector;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttachmentHandler;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.ITaskAttachment;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryAttachment;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
/**
* @author Steffen Pingel
*/
-public class MockAttachmentHandler extends AbstractAttachmentHandler {
+public class MockAttachmentHandler extends AbstractTaskAttachmentHandler {
private byte[] data;
- @Override
- public boolean canDeprecate(TaskRepository repository, RepositoryAttachment attachment) {
- // ignore
- return false;
+ public void setAttachmentData(byte[] data) {
+ this.data = data;
}
@Override
- public boolean canDownloadAttachment(TaskRepository repository, ITask task) {
- // ignore
+ public boolean canGetContent(TaskRepository repository, ITask task) {
return true;
}
@Override
- public boolean canUploadAttachment(TaskRepository repository, ITask task) {
- // ignore
+ public boolean canPostContent(TaskRepository repository, ITask task) {
return true;
}
@Override
- public void downloadAttachment(TaskRepository repository, RepositoryAttachment attachment, OutputStream target,
- IProgressMonitor monitor) throws CoreException {
- try {
- target.write(data);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public InputStream getAttachmentAsStream(TaskRepository repository, RepositoryAttachment attachment,
+ public InputStream getContent(TaskRepository repository, ITask task, TaskAttribute attachmentAttribute,
IProgressMonitor monitor) throws CoreException {
- // ignore
return new ByteArrayInputStream(data);
}
@Override
- public void updateAttachment(TaskRepository repository, RepositoryAttachment attachment) throws CoreException {
- // ignore
- }
-
- @Override
- public void uploadAttachment(TaskRepository repository, ITask task, ITaskAttachment attachment, String comment,
- IProgressMonitor monitor) throws CoreException {
- // ignore
- }
-
- public void setAttachmentData(byte[] data) {
- this.data = data;
+ public void postContent(TaskRepository repository, ITask task, AbstractTaskAttachmentSource source, String comment,
+ TaskAttribute attachmentAttribute, IProgressMonitor monitor) throws CoreException {
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java
deleted file mode 100644
index 776ab6a81..000000000
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockAttributeFactory.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2004, 2008 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 org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttributeFactory;
-
-/**
- * @author Rob Elves
- */
-public class MockAttributeFactory extends AbstractAttributeFactory {
-
- private static final long serialVersionUID = 7713746838934802731L;
-
- @Override
- public boolean isHidden(String key) {
- // ignore
- return false;
- }
-
- @Override
- public String getName(String key) {
- // ignore
- return key;
- }
-
- @Override
- public boolean isReadOnly(String key) {
- // ignore
- return false;
- }
-
- @Override
- public String mapCommonAttributeKey(String key) {
- return key;
- }
-
- @Override
- public Date getDateForAttributeType(String attributeKey, String dateString) {
- // ignore
- return null;
- }
-
-}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
index 37eed63d7..96e5bc235 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
@@ -11,24 +11,16 @@
package org.eclipse.mylyn.tasks.tests.connector;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttachmentHandler;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractAttributeFactory;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractLegacyRepositoryConnector;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.AbstractTaskDataHandler;
-import org.eclipse.mylyn.internal.tasks.core.deprecated.RepositoryTaskData;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITask;
-import org.eclipse.mylyn.tasks.core.RepositoryTemplate;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentHandler;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
@@ -36,15 +28,16 @@ import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
* @author Mik Kersten
* @author Rob Elves
* @author Shawn Minto
+ * @author Steffen Pingel
*/
-public class MockRepositoryConnector extends AbstractLegacyRepositoryConnector {
+public class MockRepositoryConnector extends AbstractRepositoryConnector {
// TODO 3.1 rename to CONNECTOR_KIND
public static final String REPOSITORY_KIND = "mock";
public static final String REPOSITORY_URL = "http://mockrepository.test";
- private AbstractAttachmentHandler attachmentHandler;
+ private AbstractTaskAttachmentHandler attachmentHandler;
private boolean canQuery = false;
@@ -86,63 +79,11 @@ public class MockRepositoryConnector extends AbstractLegacyRepositoryConnector {
}
@Override
- public AbstractAttachmentHandler getAttachmentHandler() {
- return attachmentHandler;
- }
-
- @Override
public String getLabel() {
return "Mock Repository (for unit tests)";
}
@Override
- public AbstractTaskDataHandler getLegacyTaskDataHandler() {
- // ignore
- return new AbstractTaskDataHandler() {
-
- @Override
- public AbstractAttributeFactory getAttributeFactory(String repositoryUrl, String repositoryKind,
- String taskKind) {
- // we don't care about the repository information right now
- return new MockAttributeFactory();
- }
-
- @Override
- public RepositoryTaskData getTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
- throws CoreException {
- // ignore
- return null;
- }
-
- @Override
- public String postTaskData(TaskRepository repository, RepositoryTaskData taskData, IProgressMonitor monitor)
- throws CoreException {
- // ignore
- return null;
- }
-
- @Override
- public boolean initializeTaskData(TaskRepository repository, RepositoryTaskData data,
- IProgressMonitor monitor) throws CoreException {
- // ignore
- return false;
- }
-
- @Override
- public AbstractAttributeFactory getAttributeFactory(RepositoryTaskData taskData) {
- // ignore
- return new MockAttributeFactory();
- }
-
- @Override
- public Set<String> getSubTaskIds(RepositoryTaskData taskData) {
- return Collections.emptySet();
- }
-
- };
- }
-
- @Override
public String getConnectorKind() {
return REPOSITORY_KIND;
}
@@ -170,44 +111,42 @@ public class MockRepositoryConnector extends AbstractLegacyRepositoryConnector {
}
@Override
- public void updateTaskFromRepository(TaskRepository repository, ITask repositoryTask, IProgressMonitor monitor) {
- // ignore
+ public IStatus performQuery(TaskRepository repository, IRepositoryQuery query, TaskDataCollector resultCollector,
+ ISynchronizationSession event, IProgressMonitor monitor) {
+ return Status.OK_STATUS;
}
@Override
- public AbstractTask createTask(String repositoryUrl, String id, String summary) {
- // ignore
- return null;
+ public AbstractTaskAttachmentHandler getTaskAttachmentHandler() {
+ return attachmentHandler;
}
- @Override
- public boolean updateTaskFromTaskData(TaskRepository repository, ITask repositoryTask, RepositoryTaskData taskData) {
- return false;
+ public void setTaskAttachmentHandler(MockAttachmentHandler attachmentHandler) {
+ this.attachmentHandler = attachmentHandler;
}
@Override
- public IStatus performQuery(TaskRepository repository, IRepositoryQuery query, TaskDataCollector resultCollector,
- ISynchronizationSession event, IProgressMonitor monitor) {
- return Status.OK_STATUS;
- }
-
- public void setAttachmentHandler(AbstractAttachmentHandler attachmentHandler) {
- this.attachmentHandler = attachmentHandler;
+ public TaskData getTaskData(TaskRepository taskRepository, String taskId, IProgressMonitor monitor)
+ throws CoreException {
+ return null;
}
@Override
- public Set<RepositoryTemplate> getTemplates() {
- Set<RepositoryTemplate> templates = new HashSet<RepositoryTemplate>();
- RepositoryTemplate template = new RepositoryTemplate("Mock Template", REPOSITORY_URL, "utf-8", "1", "new",
- "prefix", "query", "newAccountUrl", false, true);
- templates.add(template);
- return templates;
+ public boolean hasTaskChanged(TaskRepository taskRepository, ITask task, TaskData taskData) {
+ return false;
}
@Override
- public RepositoryTaskData getLegacyTaskData(TaskRepository repository, String taskId, IProgressMonitor monitor)
- throws CoreException {
- return null;
+ public void updateTaskFromTaskData(TaskRepository taskRepository, ITask task, TaskData taskData) {
}
+// @Override
+// public Set<RepositoryTemplate> getTemplates() {
+// Set<RepositoryTemplate> templates = new HashSet<RepositoryTemplate>();
+// RepositoryTemplate template = new RepositoryTemplate("Mock Template", REPOSITORY_URL, "utf-8", "1", "new",
+// "prefix", "query", "newAccountUrl", false, true);
+// templates.add(template);
+// return templates;
+// }
+
}

Back to the top