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.java4
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/CopyDetailsActionTest.java42
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java52
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/MockRepositoryConnectorTestCase.java141
4 files changed, 238 insertions, 1 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 176d26f7f..2729cb6a5 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
@@ -17,6 +17,7 @@ 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;
+import org.eclipse.mylyn.tasks.tests.core.AbstractRepositoryConnectorTest;
import org.eclipse.mylyn.tasks.tests.core.FileTaskAttachmentSourceTest;
import org.eclipse.mylyn.tasks.tests.core.ITasksCoreConstantsTest;
import org.eclipse.mylyn.tasks.tests.core.PriorityLevelTest;
@@ -43,11 +44,11 @@ import org.eclipse.mylyn.tasks.tests.ui.TaskListSynchronizationSchedulerTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskListViewTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskRelationHyperlinkDetectorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.AttachmentTableLabelProviderTest;
-import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorExtensionsTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.EditorUtilTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.PlanningPartTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.RegionComparatorTest;
import org.eclipse.mylyn.tasks.tests.ui.editor.RepositoryCompletionProcessorTest;
+import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorExtensionsTest;
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;
@@ -164,6 +165,7 @@ public class AllTasksTests {
suite.addTestSuite(TaskInitializationDataTest.class);
suite.addTestSuite(TaskDataDiffTest.class);
suite.addTestSuite(TaskEditorExtensionsTest.class);
+ suite.addTestSuite(AbstractRepositoryConnectorTest.class);
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/CopyDetailsActionTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/CopyDetailsActionTest.java
index f29dad897..9b6bad614 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/CopyDetailsActionTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/CopyDetailsActionTest.java
@@ -11,6 +11,9 @@
package org.eclipse.mylyn.tasks.tests;
+import java.net.MalformedURLException;
+import java.net.URL;
+
import junit.framework.TestCase;
import org.eclipse.mylyn.commons.ui.ClipboardCopier;
@@ -18,6 +21,8 @@ import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyTaskDetailsAction;
import org.eclipse.mylyn.internal.tasks.ui.actions.CopyTaskDetailsAction.Mode;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryElement;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
import org.eclipse.mylyn.tasks.ui.TasksUi;
@@ -89,4 +94,41 @@ public class CopyDetailsActionTest extends TestCase {
}
}
+ public void testGetBrowseableUrl() {
+ MockTask task = new MockTask("123");
+ task.setSummary("Ticket 123");
+ MockRepositoryConnector connector = new MockRepositoryConnector() {
+
+ @Override
+ public String getTaskUrl(String repositoryUrl, String taskId) {
+ return "URI://mock-repo/id/123";
+ }
+
+ @Override
+ public URL getBrowserUrl(TaskRepository repository, IRepositoryElement element) {
+ try {
+ return new URL("http://mock-repo-evolved.com/tickets/123");
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ };
+
+ AbstractRepositoryConnector oldConnector = TasksUi.getRepositoryManager().getRepositoryConnector(
+ MockRepositoryConnector.CONNECTOR_KIND);
+ try {
+ ((TaskRepositoryManager) TasksUi.getRepositoryManager()).addRepositoryConnector(connector);
+ assertEquals("123: Ticket 123" + ClipboardCopier.LINE_SEPARATOR
+ + "http://mock-repo-evolved.com/tickets/123",
+ CopyTaskDetailsAction.getTextForTask(task, Mode.SUMMARY_URL));
+ assertEquals("http://mock-repo-evolved.com/tickets/123",
+ CopyTaskDetailsAction.getTextForTask(task, Mode.URL));
+ } finally {
+ if (oldConnector != null) {
+ ((TaskRepositoryManager) TasksUi.getRepositoryManager()).addRepositoryConnector(oldConnector);
+ }
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java
new file mode 100644
index 000000000..c7b4d190c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests.core;
+
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+import org.eclipse.mylyn.tasks.tests.util.MockRepositoryConnectorTestCase;
+
+public class AbstractRepositoryConnectorTest extends MockRepositoryConnectorTestCase {
+
+ public void testGetTaskUrl() {
+ assertEquals("http://mock-repo.com/tickets/123",
+ connectorWithUrl.getTaskUrl(repositoryWithUrl.getRepositoryUrl(), taskWithUrl.getTaskId()));
+ assertEquals(
+ "URI://mock-repo/id/123",
+ connectorWithBrowserUrl.getTaskUrl(repositoryWithBrowserUrl.getRepositoryUrl(),
+ taskWithBrowserUrl.getTaskId()));
+ }
+
+ public void testGetBrowserUrl() {
+ assertNull(connectorWithUrl.getBrowserUrl(repositoryWithUrl, taskWithUrl));
+ assertEquals("http://mock-repo-evolved.com/tickets/123",
+ connectorWithBrowserUrl.getBrowserUrl(repositoryWithBrowserUrl, taskWithBrowserUrl).toString());
+ }
+
+ public void testGetTaskByUrl() {
+ MockTask taskWithBrowserUrl2 = createMockTaskForRepository(repositoryWithBrowserUrl, "234");
+ TasksUiPlugin.getTaskList().addTask(taskWithBrowserUrl2);
+
+ MockTask taskWithUrl2 = createMockTaskForRepository(repositoryWithUrl, "234");
+ TasksUiPlugin.getTaskList().addTask(taskWithUrl2);
+
+ assertEquals(taskWithBrowserUrl2, TasksUiInternal.getTaskByUrl("http://mock-repo-evolved.com/tickets/234"));
+ assertEquals(taskWithUrl2, TasksUiInternal.getTaskByUrl("http://mock-repo.com/tickets/234"));
+ assertEquals(taskWithUrl, TasksUiInternal.getTaskByUrl("http://mock-repo.com/tickets/123"));
+ assertEquals(taskWithBrowserUrl, TasksUiInternal.getTaskByUrl("http://mock-repo-evolved.com/tickets/123"));
+ assertEquals(taskWithBrowserUrl, TasksUiInternal.getTaskByUrl("URI://mock-repo/id/123"));
+ assertNull(TasksUiInternal.getTaskByUrl(null));
+ assertNull(TasksUiInternal.getTaskByUrl(""));
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/MockRepositoryConnectorTestCase.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/MockRepositoryConnectorTestCase.java
new file mode 100644
index 000000000..0ade95344
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/util/MockRepositoryConnectorTestCase.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.tasks.tests.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.IRepositoryElement;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+
+public class MockRepositoryConnectorTestCase extends TestCase {
+
+ protected AbstractRepositoryConnector connectorWithUrl;
+
+ protected AbstractRepositoryConnector connectorWithBrowserUrl;
+
+ protected TaskRepository repositoryWithUrl;
+
+ protected TaskRepository repositoryWithBrowserUrl;
+
+ protected MockTask taskWithUrl;
+
+ protected MockTask taskWithBrowserUrl;
+
+ protected class MockRepositoryWithUrl extends MockRepositoryConnector {
+
+ public static final String CONNECTOR_KIND = "mock-with-url";
+
+ public static final String REPOSITORY_URL = "http://mock-repo.com";
+
+ @Override
+ public String getConnectorKind() {
+ return CONNECTOR_KIND;
+ }
+
+ @Override
+ public String getTaskUrl(String repositoryUrl, String taskId) {
+ return repositoryUrl + "/tickets/" + taskId;
+ }
+
+ }
+
+ protected class MockRepositoryWithBrowserUrl extends MockRepositoryConnector {
+
+ public static final String CONNECTOR_KIND = "mock-with-browser";
+
+ public static final String REPOSITORY_URL = "http://mock-repo-evolved.com";
+
+ @Override
+ public String getConnectorKind() {
+ return CONNECTOR_KIND;
+ }
+
+ @Override
+ public String getTaskUrl(String repositoryUrl, String taskId) {
+ return "URI://mock-repo/id/" + taskId;
+ }
+
+ @Override
+ public URL getBrowserUrl(TaskRepository repository, IRepositoryElement element) {
+ if (element instanceof ITask) {
+ try {
+ return new URL(repository.getRepositoryUrl() + "/tickets/" + ((ITask) element).getTaskId());
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ }
+
+ protected MockTask createMockTaskForRepository(final TaskRepository repository, String taskId) {
+ return new MockTask(repository.getRepositoryUrl(), taskId) {
+
+ @Override
+ public String getConnectorKind() {
+ return repository.getConnectorKind();
+ }
+
+ @Override
+ public String getUrl() {
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
+ getConnectorKind());
+ return connector.getTaskUrl(getRepositoryUrl(), getTaskId());
+ }
+
+ };
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ TaskRepositoryManager manager = TasksUiPlugin.getRepositoryManager();
+ connectorWithUrl = new MockRepositoryWithUrl();
+ connectorWithBrowserUrl = new MockRepositoryWithBrowserUrl();
+
+ manager.addRepositoryConnector(connectorWithUrl);
+ manager.addRepositoryConnector(connectorWithBrowserUrl);
+
+ repositoryWithUrl = new TaskRepository(MockRepositoryWithUrl.CONNECTOR_KIND,
+ MockRepositoryWithUrl.REPOSITORY_URL);
+ repositoryWithBrowserUrl = new TaskRepository(MockRepositoryWithBrowserUrl.CONNECTOR_KIND,
+ MockRepositoryWithBrowserUrl.REPOSITORY_URL);
+
+ manager.addRepository(repositoryWithUrl);
+ manager.addRepository(repositoryWithBrowserUrl);
+
+ taskWithUrl = createMockTaskForRepository(repositoryWithUrl, "123");
+ TasksUiPlugin.getTaskList().addTask(taskWithUrl);
+
+ taskWithBrowserUrl = createMockTaskForRepository(repositoryWithBrowserUrl, "123");
+ TasksUiPlugin.getTaskList().addTask(taskWithBrowserUrl);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TaskRepositoryManager manager = TasksUiPlugin.getRepositoryManager();
+ manager.removeRepository(repositoryWithUrl);
+ manager.removeRepository(repositoryWithBrowserUrl);
+ manager.removeRepositoryConnector(MockRepositoryWithUrl.CONNECTOR_KIND);
+ manager.removeRepositoryConnector(MockRepositoryWithBrowserUrl.CONNECTOR_KIND);
+ }
+
+}

Back to the top