Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-10-12 05:08:47 +0000
committerspingel2008-10-12 05:08:47 +0000
commit6055ae0057839ca6f12637bad029e518484a0531 (patch)
tree6f6ca89e4c4d31832b5223cd7919ebcf876cb0bd /org.eclipse.mylyn.trac.tests
parente1a393760cd47d1918fb922571b5ba6d244501a6 (diff)
downloadorg.eclipse.mylyn.tasks-6055ae0057839ca6f12637bad029e518484a0531.tar.gz
org.eclipse.mylyn.tasks-6055ae0057839ca6f12637bad029e518484a0531.tar.xz
org.eclipse.mylyn.tasks-6055ae0057839ca6f12637bad029e518484a0531.zip
NEW - bug 248798: implement new hyperlink detection API for Trac
https://bugs.eclipse.org/bugs/show_bug.cgi?id=248798
Diffstat (limited to 'org.eclipse.mylyn.trac.tests')
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracHyperlinkUtilTest.java81
1 files changed, 42 insertions, 39 deletions
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracHyperlinkUtilTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracHyperlinkUtilTest.java
index adf6a452e..b113b6b0b 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracHyperlinkUtilTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracHyperlinkUtilTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2006, 2008 Steffen Pingel and others.
+ * Copyright (c) 2006, 2008 Steffen Pingel 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,6 +12,8 @@
package org.eclipse.mylyn.trac.tests;
+import java.util.List;
+
import junit.framework.TestCase;
import org.eclipse.jface.text.Region;
@@ -33,13 +35,11 @@ public class TracHyperlinkUtilTest extends TestCase {
@Override
protected void setUp() throws Exception {
- super.setUp();
-
repository = new TaskRepository(TracCorePlugin.CONNECTOR_KIND, "http://localhost");
}
public void testFindHyperlinksComment() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "comment:ticket:12:34", 0, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "comment:ticket:12:34", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals(new Region(0, 20), links[0].getHyperlinkRegion());
@@ -66,88 +66,86 @@ public class TracHyperlinkUtilTest extends TestCase {
}
public void testFindHyperlinksReport() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "report:123", 0, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "report:123", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 10), links[0].getHyperlinkRegion());
assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "{123}", 0, 0);
+ links = findTracHyperlinks(repository, "{123}", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 5), links[0].getHyperlinkRegion());
assertEquals("http://localhost/report/123", ((WebHyperlink) links[0]).getURLString());
}
public void testFindHyperlinksChangeset() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "r123", 0, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "r123", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 4), links[0].getHyperlinkRegion());
assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "[123]", 0, 0);
+ links = findTracHyperlinks(repository, "[123]", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 5), links[0].getHyperlinkRegion());
assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "![123]", 0, 0);
+ links = findTracHyperlinks(repository, "![123]", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "![123]", 1, 0);
+ links = findTracHyperlinks(repository, "![123]", 1, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "changeset:123", 0, 0);
+ links = findTracHyperlinks(repository, "changeset:123", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 13), links[0].getHyperlinkRegion());
assertEquals("http://localhost/changeset/123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "[123/trunk]", 0, 0);
+ links = findTracHyperlinks(repository, "[123/trunk]", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 11), links[0].getHyperlinkRegion());
assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "changeset:123/trunk", 0, 0);
+ links = findTracHyperlinks(repository, "changeset:123/trunk", 0, 0);
assertEquals(1, links.length);
assertEquals(new Region(0, 19), links[0].getHyperlinkRegion());
assertEquals("http://localhost/changeset/123/trunk", ((WebHyperlink) links[0]).getURLString());
}
public void testFindHyperlinksRevisionLog() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "r123:456", 0, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "r123:456", 0, 0);
assertEquals(2, links.length);
assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(0, 8), links[0].getHyperlinkRegion());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "[123:456]", 0, 0);
+ links = findTracHyperlinks(repository, "[123:456]", 0, 0);
assertEquals(1, links.length);
assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(0, 9), links[0].getHyperlinkRegion());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "log:@123:456", 0, 0);
+ links = findTracHyperlinks(repository, "log:@123:456", 0, 0);
assertEquals(1, links.length);
assertEquals("http://localhost/log/?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(0, 12), links[0].getHyperlinkRegion());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "log:trunk@123:456", 0, 0);
+ links = findTracHyperlinks(repository, "log:trunk@123:456", 0, 0);
assertEquals(1, links.length);
assertEquals("http://localhost/log/trunk?rev=123&stop_rev=456", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(0, 17), links[0].getHyperlinkRegion());
}
public void testFindHyperlinksDiff() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "diff:@123:456", 0, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "diff:@123:456", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/changeset/?new=456&old=123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository,
- "diff:trunk/trac@3538//sandbox/vc-refactoring/trac@3539", 0, 0);
+ links = findTracHyperlinks(repository, "diff:trunk/trac@3538//sandbox/vc-refactoring/trac@3539", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals(
"http://localhost/changeset/?new_path=sandbox%2Fvc-refactoring%2Ftrac&old_path=trunk%2Ftrac&new=3539&old=3538",
((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository,
- "diff:tags/trac-0.9.2/wiki-default//tags/trac-0.9.3/wiki-default", 0, 0);
+ links = findTracHyperlinks(repository, "diff:tags/trac-0.9.2/wiki-default//tags/trac-0.9.3/wiki-default", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals(
@@ -156,83 +154,88 @@ public class TracHyperlinkUtilTest extends TestCase {
}
public void testFindHyperlinksWiki() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "[wiki:page]", 1, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "[wiki:page]", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "wiki:page", 0, 0);
+ links = findTracHyperlinks(repository, "wiki:page", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/wiki/page", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "Page", 0, 0);
+ links = findTracHyperlinks(repository, "Page", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "!Page", 0, 0);
+ links = findTracHyperlinks(repository, "!Page", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "ab Page dc", 0, 0);
+ links = findTracHyperlinks(repository, "ab Page dc", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "paGe", 0, 0);
+ links = findTracHyperlinks(repository, "paGe", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "WikiPage", 0, 0);
+ links = findTracHyperlinks(repository, "WikiPage", 0, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/wiki/WikiPage", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(0, 8), links[0].getHyperlinkRegion());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "!WikiPage", 0, 0);
+ links = findTracHyperlinks(repository, "!WikiPage", 0, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "!WikiPage", 1, 0);
+ links = findTracHyperlinks(repository, "!WikiPage", 1, 0);
assertNull(links);
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "a WikiPage is here", 4, 0);
+ links = findTracHyperlinks(repository, "a WikiPage is here", 4, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/wiki/WikiPage", ((WebHyperlink) links[0]).getURLString());
assertEquals(new Region(2, 8), links[0].getHyperlinkRegion());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "a !WikiPage is here", 4, 0);
+ links = findTracHyperlinks(repository, "a !WikiPage is here", 4, 0);
assertNull(links);
}
public void testFindHyperlinksMilestone() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "milestone:1.0", 1, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "milestone:1.0", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/milestone/1.0", ((WebHyperlink) links[0]).getURLString());
}
public void testFindHyperlinksAttachment() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "attachment:ticket:123:foo.bar", 1, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "attachment:ticket:123:foo.bar", 1, 0);
assertNotNull(links);
assertEquals("123", ((TaskHyperlink) links[0]).getTaskId());
}
public void testFindHyperlinksFiles() {
- IHyperlink[] links = TracHyperlinkUtil.findTracHyperlinks(repository, "source:trunk/foo", 1, 0);
+ IHyperlink[] links = findTracHyperlinks(repository, "source:trunk/foo", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/browser/trunk/foo", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "source:trunk/foo@123", 1, 0);
+ links = findTracHyperlinks(repository, "source:trunk/foo@123", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/browser/trunk/foo?rev=123", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "source:trunk/foo@123#L456", 1, 0);
+ links = findTracHyperlinks(repository, "source:trunk/foo@123#L456", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/browser/trunk/foo?rev=123#L456", ((WebHyperlink) links[0]).getURLString());
- links = TracHyperlinkUtil.findTracHyperlinks(repository, "source:/tags/foo_bar-1.1", 1, 0);
+ links = findTracHyperlinks(repository, "source:/tags/foo_bar-1.1", 1, 0);
assertNotNull(links);
assertEquals(1, links.length);
assertEquals("http://localhost/browser/tags/foo_bar-1.1", ((WebHyperlink) links[0]).getURLString());
}
+ private IHyperlink[] findTracHyperlinks(TaskRepository repository, String text, int offsetInText, int textOffset) {
+ List<IHyperlink> links = TracHyperlinkUtil.findTracHyperlinks(repository, text, offsetInText, textOffset);
+ return (links.isEmpty()) ? null : links.toArray(new IHyperlink[0]);
+ }
+
}

Back to the top