Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/AllBugzillaRestCoreTests.java3
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorNoFixtureTest.java99
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorTest.java18
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java14
4 files changed, 109 insertions, 25 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/AllBugzillaRestCoreTests.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/AllBugzillaRestCoreTests.java
index ca5d011a3..b138d0cc5 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/AllBugzillaRestCoreTests.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/AllBugzillaRestCoreTests.java
@@ -22,7 +22,8 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(ManagedSuite.class)
-@Suite.SuiteClasses({ RepositoryKeyTest.class, BugzillaRestFlagMapperTest.class })
+@Suite.SuiteClasses({ RepositoryKeyTest.class, BugzillaRestFlagMapperTest.class,
+ BugzillaRestConnectorNoFixtureTest.class })
@TestConfigurationProperty()
public class AllBugzillaRestCoreTests {
static {
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorNoFixtureTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorNoFixtureTest.java
new file mode 100644
index 000000000..19c6933dd
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorNoFixtureTest.java
@@ -0,0 +1,99 @@
+package org.eclipse.mylyn.bugzilla.rest.core.tests;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskSchema;
+import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+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.junit.Before;
+import org.junit.Test;
+
+public class BugzillaRestConnectorNoFixtureTest {
+
+ private BugzillaRestConnector connector;
+
+ private TaskRepository repository;
+
+ @Before
+ public void setUp() {
+ connector = new BugzillaRestConnector();
+ repository = new TaskRepository(connector.getConnectorKind(), "http://test.repository.url");
+ }
+
+ @Test
+ public void testGetRepositoryUrlFromTaskUrl() throws Exception {
+ assertNull(connector.getRepositoryUrlFromTaskUrl(repository.getRepositoryUrl() + "/rest/bug/1"));
+ assertThat(connector.getRepositoryUrlFromTaskUrl(repository.getRepositoryUrl() + "/rest.cgi/bug/1"),
+ equalTo(repository.getRepositoryUrl()));
+ }
+
+ @Test
+ public void testGetTaskUrl() throws Exception {
+ assertThat(connector.getTaskUrl(repository.getRepositoryUrl(), "123"),
+ equalTo(repository.getRepositoryUrl() + "/rest.cgi/bug/123"));
+ assertThat(connector.getTaskUrl(repository.getRepositoryUrl(), "Test"),
+ equalTo(repository.getRepositoryUrl() + "/rest.cgi/bug/Test"));
+ }
+
+ @Test
+ public void testHasTaskChanged() {
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), connector.getConnectorKind(),
+ repository.getRepositoryUrl(), "123");
+ TaskTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "123");
+ Date now = new Date();
+ task.setAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey(), "" + now.getTime());
+ taskData.getRoot().createAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey()).setValue(
+ "" + (now.getTime() + 1));
+ assertTrue(connector.hasTaskChanged(repository, task, taskData));
+ }
+
+ @Test
+ public void testHasTaskChangedEmptyModificationDate() {
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), connector.getConnectorKind(),
+ repository.getRepositoryUrl(), "123");
+ TaskTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "123");
+ Date now = new Date();
+ taskData.getRoot().createAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey()).setValue(
+ "" + (now.getTime()));
+ assertTrue(connector.hasTaskChanged(repository, task, taskData));
+ }
+
+ @Test
+ public void testHasNotTaskChanged() {
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), connector.getConnectorKind(),
+ repository.getRepositoryUrl(), "123");
+ TaskTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "123");
+ Date now = new Date();
+ task.setAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey(), "" + now.getTime());
+ taskData.getRoot().createAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey()).setValue(
+ "" + (now.getTime()));
+ assertTrue(!connector.hasTaskChanged(repository, task, taskData));
+ }
+
+ @Test
+ public void testHasNotTaskChangedEmptyModificationDate() {
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), connector.getConnectorKind(),
+ repository.getRepositoryUrl(), "123");
+ TaskTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "123");
+ assertTrue(!connector.hasTaskChanged(repository, task, taskData));
+ }
+
+ @Test
+ public void testTaskDataAndTaskWithodModdate() {
+ TaskData taskData = new TaskData(new TaskAttributeMapper(repository), connector.getConnectorKind(),
+ repository.getRepositoryUrl(), "123");
+ TaskTask task = new TaskTask(repository.getConnectorKind(), repository.getRepositoryUrl(), "123");
+ Date now = new Date();
+ task.setAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey(), "" + now.getTime());
+ assertTrue(connector.hasTaskChanged(repository, task, taskData));
+ }
+
+}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorTest.java
index acf163024..8172b48fd 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestConnectorTest.java
@@ -217,24 +217,6 @@ public class BugzillaRestConnectorTest {
}
@Test
- public void testGetRepositoryUrlFromTaskUrl() throws Exception {
- assertNull(
- connector.getRepositoryUrlFromTaskUrl(actualFixture.repository().getRepositoryUrl() + "/rest/bug/1"));
- assertThat(
- connector
- .getRepositoryUrlFromTaskUrl(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/1"),
- equalTo(actualFixture.repository().getRepositoryUrl()));
- }
-
- @Test
- public void testGetTaskUrl() throws Exception {
- assertThat(connector.getTaskUrl(actualFixture.repository().getRepositoryUrl(), "123"),
- equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/123"));
- assertThat(connector.getTaskUrl(actualFixture.repository().getRepositoryUrl(), "Test"),
- equalTo(actualFixture.repository().getRepositoryUrl() + "/rest.cgi/bug/Test"));
- }
-
- @Test
public void testUpdateTaskFromTaskData() throws Exception {
TaskData taskData = new TaskData(new TaskAttributeMapper(actualFixture.repository()),
connector.getConnectorKind(), actualFixture.repository().getRepositoryUrl(), "123");
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
index 34319faff..e11d503a8 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
@@ -55,6 +55,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
import org.eclipse.mylyn.tasks.core.data.TaskMapper;
import org.eclipse.mylyn.tasks.core.sync.ISynchronizationSession;
+import com.google.common.base.Objects;
import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@@ -230,8 +231,11 @@ public class BugzillaRestConnector extends AbstractRepositoryConnector {
@Override
public boolean hasTaskChanged(TaskRepository taskRepository, ITask task, TaskData taskData) {
- // ignore
- return false;
+ String lastKnownLocalModValue = task
+ .getAttribute(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey());
+ TaskAttribute latestRemoteModAttribute = taskData.getRoot().getMappedAttribute(TaskAttribute.DATE_MODIFICATION);
+ String latestRemoteModValue = latestRemoteModAttribute != null ? latestRemoteModAttribute.getValue() : null;
+ return !Objects.equal(latestRemoteModValue, lastKnownLocalModValue);
}
@Override
@@ -367,10 +371,8 @@ public class BugzillaRestConnector extends AbstractRepositoryConnector {
}
private Map<String, String> convertProperties(TaskRepository repository) {
- return repository.getProperties()
- .entrySet()
- .stream()
- .collect(Collectors.toMap(e -> convertProperty(e.getKey()), Map.Entry::getValue));
+ return repository.getProperties().entrySet().stream().collect(
+ Collectors.toMap(e -> convertProperty(e.getKey()), Map.Entry::getValue));
}
@SuppressWarnings("restriction")

Back to the top