Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java8
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/SynchronizationMangerTest.java190
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java8
3 files changed, 198 insertions, 8 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 a819eb752..72def97b5 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
@@ -11,9 +11,6 @@
package org.eclipse.mylyn.tasks.tests;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
import org.eclipse.mylyn.commons.sdk.util.ManagedTestSuite;
import org.eclipse.mylyn.commons.sdk.util.TestConfiguration;
import org.eclipse.mylyn.tasks.tests.bugs.SupportHandlerManagerTest;
@@ -30,6 +27,7 @@ import org.eclipse.mylyn.tasks.tests.core.TaskJobFactoryTest;
import org.eclipse.mylyn.tasks.tests.core.TaskListUnmatchedContainerTest;
import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryLocationTest;
import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryTest;
+import org.eclipse.mylyn.tasks.tests.data.SynchronizationMangerTest;
import org.eclipse.mylyn.tasks.tests.data.TaskAttributeMapperTest;
import org.eclipse.mylyn.tasks.tests.data.TaskAttributeTest;
import org.eclipse.mylyn.tasks.tests.data.TaskDataDiffTest;
@@ -54,6 +52,9 @@ import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorPartDescriptorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.TaskMigratorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.TaskUrlHyperlinkDetectorTest;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
/**
* @author Mik Kersten
* @author Shawn Minto
@@ -166,6 +167,7 @@ public class AllTasksTests {
suite.addTestSuite(RepositoryConnectorContributorTest.class);
suite.addTestSuite(TaskInitializationDataTest.class);
suite.addTestSuite(TaskDataDiffTest.class);
+ suite.addTestSuite(SynchronizationMangerTest.class);
suite.addTestSuite(TaskEditorExtensionsTest.class);
suite.addTestSuite(AbstractRepositoryConnectorTest.class);
suite.addTestSuite(TaskJobFactoryTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/SynchronizationMangerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/SynchronizationMangerTest.java
new file mode 100644
index 000000000..063a49d0c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/SynchronizationMangerTest.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2016 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.data;
+
+import java.util.Collections;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.internal.tasks.core.RepositoryModel;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+import org.eclipse.mylyn.internal.tasks.core.data.SynchronizationManger;
+import org.eclipse.mylyn.internal.tasks.core.data.TaskAttributeDiff;
+import org.eclipse.mylyn.internal.tasks.core.data.TaskDataDiff;
+import org.eclipse.mylyn.tasks.core.IRepositoryManager;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+import junit.framework.TestCase;
+
+public class SynchronizationMangerTest extends TestCase {
+
+ private SynchronizationManger manager;
+
+ private RepositoryModel model;
+
+ private TaskRepository repository;
+
+ private TaskAttributeMapper mapper;
+
+ private TaskData newData;
+
+ private TaskData oldData;
+
+ @Override
+ protected void setUp() throws Exception {
+ ITask task = new TaskTask("kind", "url", "1");
+ repository = new TaskRepository(task.getConnectorKind(), task.getRepositoryUrl());
+ mapper = new TaskAttributeMapper(repository);
+ IRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(repository);
+ TaskList taskList = new TaskList();
+ taskList.addTask(task);
+ model = new RepositoryModel(taskList, repositoryManager);
+
+ newData = new TaskData(mapper, repository.getConnectorKind(), repository.getUrl(), "1");
+ oldData = new TaskData(mapper, repository.getConnectorKind(), repository.getUrl(), "1");
+ manager = new SynchronizationManger(model);
+ }
+
+ @Test
+ public void testHasChangedAttributes() {
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertFalse(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithoutKind() {
+ TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom");
+ attributeCustom.setValue("1");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertFalse(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithKind() {
+ TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom");
+ attributeCustom.setValue("1");
+ attributeCustom.getMetaData().setKind("kind");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithChangedValues() {
+ TaskAttribute attributeOld = oldData.getRoot().createAttribute(TaskAttribute.SUMMARY);
+ attributeOld.setValue("1");
+ TaskAttribute attributeNew = newData.getRoot().createAttribute(TaskAttribute.SUMMARY);
+ attributeNew.setValue("2");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithChangedCustomValues() {
+ TaskAttribute attributeOld = oldData.getRoot().createAttribute("custom");
+ attributeOld.setValue("1");
+ attributeOld.getMetaData().setKind("kind");
+ TaskAttribute attributeNew = newData.getRoot().createAttribute("custom");
+ attributeNew.setValue("2");
+ attributeNew.getMetaData().setKind("kind");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithUnchangedCustomValues() {
+ TaskAttribute attributeOld = oldData.getRoot().createAttribute("custom");
+ attributeOld.setValue("1");
+ attributeOld.getMetaData().setKind("kind");
+ TaskAttribute attributeNew = newData.getRoot().createAttribute("custom");
+ attributeNew.setValue("1");
+ attributeNew.getMetaData().setKind("kind");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertFalse(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesMultiple() {
+ TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom");
+ attributeCustom.setValue("1");
+ TaskAttribute attributeSummary = newData.getRoot().createAttribute(TaskAttribute.SUMMARY);
+ attributeSummary.setValue("1");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithComments() {
+ TaskAttribute attributeComment = newData.getRoot().createAttribute("custom");
+ attributeComment.setValue("1");
+ attributeComment.getMetaData().setType(TaskAttribute.TYPE_COMMENT);
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testGetChangedAttributesWithComments() {
+ TaskAttribute attributeComment = newData.getRoot().createAttribute("custom");
+ attributeComment.setValue("1");
+ attributeComment.getMetaData().setType(TaskAttribute.TYPE_COMMENT);
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertEquals(1, diff.getNewComments().size());
+ assertEquals(attributeComment, diff.getNewComments().iterator().next().getTaskAttribute());
+ }
+
+ @Test
+ public void testHasChangedAttributesWithAttachments() {
+ TaskAttribute attributeAttachment = newData.getRoot().createAttribute("custom");
+ attributeAttachment.setValue("1");
+ attributeAttachment.getMetaData().setType(TaskAttribute.TYPE_ATTACHMENT);
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testGetChangedAttributesWithAttachments() {
+ TaskAttribute attributeAttachment = newData.getRoot().createAttribute("custom");
+ attributeAttachment.setValue("1");
+ attributeAttachment.getMetaData().setType(TaskAttribute.TYPE_ATTACHMENT);
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertEquals(Collections.singleton(attributeAttachment), diff.getNewAttachments());
+ }
+
+ @Test
+ public void testGetChangedAttributesMultipleKind() {
+ TaskAttribute attributeCustom = newData.getRoot().createAttribute("custom");
+ attributeCustom.setValue("1");
+ attributeCustom.getMetaData().setKind("kind");
+ TaskAttribute attributeSummary = newData.getRoot().createAttribute(TaskAttribute.SUMMARY);
+ attributeSummary.setValue("1");
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertEquals(ImmutableSet.of(new TaskAttributeDiff(null, attributeSummary),
+ new TaskAttributeDiff(null, attributeCustom)), diff.getChangedAttributes());
+ assertTrue(diff.hasChanged());
+ }
+
+ @Test
+ public void testHasChangedAttributesSummaryEmptyValue() {
+ newData.getRoot().createAttribute(TaskAttribute.SUMMARY);
+ TaskDataDiff diff = manager.createDiff(newData, oldData, new NullProgressMonitor());
+ assertFalse(diff.hasChanged());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java
index 56b141fe2..f9efe2377 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/data/TaskDataDiffTest.java
@@ -16,8 +16,6 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.mylyn.internal.tasks.core.RepositoryModel;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
@@ -33,6 +31,8 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.junit.Test;
+import junit.framework.TestCase;
+
/**
* @author Steffen Pingel
*/
@@ -110,7 +110,7 @@ public class TaskDataDiffTest extends TestCase {
@Test
public void testHasChanges() {
TaskDataDiff diff = new TaskDataDiff(model, newData, oldData);
- assertTrue(diff.hasChanged());
+ assertFalse(diff.hasChanged());
}
@Test
@@ -118,7 +118,5 @@ public class TaskDataDiffTest extends TestCase {
newData.getRoot().createAttribute(TaskAttribute.SUMMARY).setValue("text");
TaskDataDiff diff = new TaskDataDiff(model, newData, oldData);
assertTrue(diff.hasChanged());
- diff.setHasChanged(false);
- assertFalse(diff.hasChanged());
}
}

Back to the top