You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2008/12/09 20:05:38 UTC
svn commit: r724834 - in /incubator/jspwiki/trunk:
src/com/ecyrd/jspwiki/content/WikiName.java
tests/com/ecyrd/jspwiki/content/AllTests.java
tests/com/ecyrd/jspwiki/content/WikiNameTest.java
Author: jalkanen
Date: Tue Dec 9 11:05:37 2008
New Revision: 724834
URL: http://svn.apache.org/viewvc?rev=724834&view=rev
Log:
Added WikiName.resolve() and tests.
Added:
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/WikiNameTest.java
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/WikiName.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/AllTests.java
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/WikiName.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/WikiName.java?rev=724834&r1=724833&r2=724834&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/WikiName.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/WikiName.java Tue Dec 9 11:05:37 2008
@@ -104,6 +104,26 @@
}
/**
+ * Resolves a path with respect to this WikiName. This is typically used
+ * when figuring out where a subpage should be pointing at.
+ *
+ * @param path Path to resolve
+ * @return A new WikiName
+ */
+ public WikiName resolve( String path )
+ {
+ int colon = path.indexOf( ':' );
+
+ if( colon != -1 )
+ {
+ // It is a FQN, essentially an absolute path, so no resolution necessary
+ return WikiName.valueOf( path );
+ }
+
+ return new WikiName( getSpace(), path );
+ }
+
+ /**
* Returns the FQN format (space:path) of the name.
*
* @return The name in FQN format.
Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/AllTests.java?rev=724834&r1=724833&r2=724834&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/AllTests.java Tue Dec 9 11:05:37 2008
@@ -17,6 +17,7 @@
TestSuite suite = new TestSuite("JSPWiki Content Unit Tests");
suite.addTest( PageRenamerTest.suite() );
+ suite.addTest( WikiNameTest.suite() );
return suite;
}
Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/WikiNameTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/WikiNameTest.java?rev=724834&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/WikiNameTest.java (added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/content/WikiNameTest.java Tue Dec 9 11:05:37 2008
@@ -0,0 +1,48 @@
+package com.ecyrd.jspwiki.content;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class WikiNameTest extends TestCase
+{
+ public void testParse1()
+ {
+ WikiName wn = WikiName.valueOf( "Foo:Bar/Blob 2" );
+
+ assertEquals("space", "Foo", wn.getSpace() );
+ assertEquals("path", "Bar/Blob 2", wn.getPath() );
+ }
+
+ public void testParse2()
+ {
+ WikiName wn = WikiName.valueOf( "BarBrian" );
+
+ assertEquals("space", ContentManager.DEFAULT_SPACE, wn.getSpace() );
+ assertEquals("path", "BarBrian", wn.getPath() );
+ }
+
+ public void testResolve1()
+ {
+ WikiName wn = new WikiName("Test","TestPage");
+
+ WikiName newname = wn.resolve("Barbapapa");
+
+ assertEquals( "Test:Barbapapa", newname.toString() );
+ }
+
+ public void testResolveAbsolute()
+ {
+ WikiName wn = new WikiName("Test","TestPage");
+
+ WikiName newname = wn.resolve("Foo:Barbapapa");
+
+ assertEquals( "Foo:Barbapapa", newname.toString() );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(WikiNameTest.class);
+ }
+
+}