You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/13 07:22:49 UTC
svn commit: r627269 [1/3] - in
/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com: ./ ecyrd/
ecyrd/jspwiki/ ecyrd/jspwiki/plugin/ ecyrd/jspwiki/providers/
ecyrd/jspwiki/render/ ecyrd/jspwiki/rss/ ecyrd/jspwiki/search/
ecyrd/jspwiki/ui/ ecyrd/...
Author: ajaquith
Date: Tue Feb 12 22:22:45 2008
New Revision: 627269
URL: http://svn.apache.org/viewvc?rev=627269&view=rev
Log:
Initial commit.
Added:
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/GroupsTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/InsertPageTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/JavaScriptPlugin.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/SamplePlugin.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/TableOfContentsTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/BasicAttachmentProviderTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CachingProviderTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CounterProvider.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/FileSystemProviderTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/RCSFileProviderTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/VersioningFileProviderTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/VerySimpleProvider.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/render/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/render/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/render/CreoleRendererTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/render/RenderingManagerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/render/WysiwygEditingRendererTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/rss/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/rss/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/rss/RSSGeneratorTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/search/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/search/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/search/SearchManagerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ui/InputValidatorTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/ClassUtilTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/MailUtilTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/PriorityListTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/TextUtilTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CommonContainerTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CommonCustomTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CommonTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/ContainerJDBCTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/ContainerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CustomAbsoluteTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CustomJDBCTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/CustomTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/ApprovalWorkflowTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/DecisionQueueTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/FactTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/OutcomeTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/SimpleDecisionTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/TaskTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/WorkflowManagerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/WorkflowTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/AllTests.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/RPCHandlerTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/foo/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/foo/SamplePlugin3.java
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/AllTests.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/AllTests.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,31 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+
+public class AllTests extends TestCase
+{
+ public AllTests( String s )
+ {
+ super( s );
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("JSPWiki plugins");
+
+ suite.addTest( CounterPluginTest.suite() );
+ suite.addTest( GroupsTest.suite() );
+ suite.addTest( InsertPageTest.suite() );
+ suite.addTest( PluginManagerTest.suite() );
+ suite.addTest( ReferringPagesPluginTest.suite() );
+ suite.addTest( TableOfContentsTest.suite() );
+ suite.addTest( UndefinedPagesPluginTest.suite() );
+
+ return suite;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/CounterPluginTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,94 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Properties;
+
+import javax.servlet.ServletException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.NoRequiredPropertyException;
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.parser.JSPWikiMarkupParser;
+import com.ecyrd.jspwiki.parser.MarkupParser;
+import com.ecyrd.jspwiki.parser.WikiDocument;
+import com.ecyrd.jspwiki.render.WikiRenderer;
+import com.ecyrd.jspwiki.render.XHTMLRenderer;
+
+public class CounterPluginTest extends TestCase
+{
+ Properties props = new Properties();
+ TestEngine testEngine;
+
+ public CounterPluginTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ testEngine = new TestEngine(props);
+ }
+
+ public void tearDown()
+ {
+ }
+
+ private String translate( String src )
+ throws IOException,
+ NoRequiredPropertyException,
+ ServletException
+ {
+ WikiContext context = testEngine.getWikiActionBeanFactory().newViewActionBean(
+ new WikiPage(testEngine, "TestPage") );
+
+ MarkupParser p = new JSPWikiMarkupParser( context, new StringReader(src) );
+
+ WikiDocument dom = p.parse();
+
+ WikiRenderer r = new XHTMLRenderer( context, dom );
+
+ return r.getString();
+ }
+
+ public void testSimpleCount()
+ throws Exception
+ {
+ String src = "[{Counter}], [{Counter}]";
+
+ assertEquals( "1, 2",
+ translate(src) );
+ }
+
+ public void testSimpleVar()
+ throws Exception
+ {
+ String src = "[{Counter}], [{Counter}], [{$counter}]";
+
+ assertEquals( "1, 2, 2",
+ translate(src) );
+ }
+
+ public void testTwinVar()
+ throws Exception
+ {
+ String src = "[{Counter}], [{Counter name=aa}], [{$counter-aa}]";
+
+ assertEquals( "1, 1, 1",
+ translate(src) );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( CounterPluginTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/GroupsTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/GroupsTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/GroupsTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/GroupsTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,56 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.TestEngine;
+
+public class GroupsTest extends TestCase
+{
+ Properties props = new Properties();
+ TestEngine testEngine;
+
+ public GroupsTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ testEngine = new TestEngine(props);
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ testEngine.deletePage( "Test" );
+ }
+
+ public void testTag() throws Exception
+ {
+ String src="[{Groups}]";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ assertEquals( "<a href=\"/Group.action?group=Admin\">Admin</a>, "
+ + "<a href=\"/Group.action?group=Art\">Art</a>, "
+ + "<a href=\"/Group.action?group=Literature\">Literature</a>, "
+ + "<a href=\"/Group.action?group=TV\">TV</a>\n"
+ , res );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( GroupsTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/InsertPageTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/InsertPageTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/InsertPageTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/InsertPageTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,86 @@
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class InsertPageTest extends TestCase
+{
+ protected TestEngine testEngine;
+ protected Properties props = new Properties();
+
+ protected void setUp() throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ testEngine = new TestEngine(props);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ TestEngine.deleteTestPage( "ThisPage" );
+ TestEngine.deleteTestPage( "ThisPage2" );
+ TestEngine.deleteTestPage( "Test_Page" );
+ }
+
+ public void testRecursive() throws Exception
+ {
+ String src = "[{InsertPage page='ThisPage'}] [{ALLOW view Anonymous}]";
+
+ testEngine.saveText("ThisPage",src);
+
+ // Just check that it contains a proper error message; don't bother do HTML
+ // checking.
+ String res = testEngine.getHTML("ThisPage");
+ assertTrue( res.indexOf("Circular reference") != -1 );
+ }
+
+ public void testRecursive2() throws Exception
+ {
+ String src = "[{InsertPage page='ThisPage2'}]";
+ String src2 = "[{InsertPage page='ThisPage'}]";
+
+ testEngine.saveText("ThisPage",src);
+ testEngine.saveText("ThisPage2",src2);
+
+ // Just check that it contains a proper error message; don't bother do HTML
+ // checking.
+ assertTrue( testEngine.getHTML("ThisPage").indexOf("Circular reference") != -1 );
+ }
+
+ public void testMultiInvocation() throws Exception
+ {
+ String src = "[{InsertPage page='ThisPage2'}] [{InsertPage page='ThisPage2'}]";
+ String src2 = "foo[{ALLOW view Anonymous}]";
+
+ testEngine.saveText("ThisPage",src);
+ testEngine.saveText("ThisPage2",src2);
+
+ assertTrue( "got circ ref", testEngine.getHTML("ThisPage").indexOf("Circular reference") == -1 );
+
+ assertEquals( "found != 2", "<div style=\"\">foo\n</div> <div style=\"\">foo\n</div>\n", testEngine.getHTML("ThisPage") );
+
+ }
+
+ public void testUnderscore() throws Exception
+ {
+ String src = "[{InsertPage page='Test_Page'}]";
+ String src2 = "foo[{ALLOW view Anonymous}]";
+
+ testEngine.saveText("ThisPage",src);
+ testEngine.saveText("Test_Page",src2);
+
+ assertTrue( "got circ ref", testEngine.getHTML("ThisPage").indexOf("Circular reference") == -1 );
+
+ assertEquals( "found != 1", "<div style=\"\">foo\n</div>\n", testEngine.getHTML("ThisPage") );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( InsertPageTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/JavaScriptPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/JavaScriptPlugin.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/JavaScriptPlugin.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/JavaScriptPlugin.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,30 @@
+package com.ecyrd.jspwiki.plugin;
+
+import com.ecyrd.jspwiki.*;
+
+import java.util.*;
+
+/**
+ * Implements a simple plugin that just returns a piece of Javascript
+ * <P>
+ * Parameters: text - text to return.
+ *
+ * @author Janne Jalkanen
+ */
+public class JavaScriptPlugin
+ implements WikiPlugin, InitializablePlugin
+{
+ protected static boolean c_inited = false;
+
+ public String execute( WikiContext context, Map params )
+ throws PluginException
+ {
+ return "<script language=\"JavaScript\"><!--\nfoo='';\n--></script>\n";
+ }
+
+ public void initialize(WikiEngine engine) throws PluginException
+ {
+ c_inited = true;
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/PluginManagerTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,205 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+public class PluginManagerTest extends TestCase
+{
+ public static final String NAME1 = "Test1";
+
+ Properties props = new Properties();
+
+ WikiEngine engine;
+
+ WikiContext context;
+
+ PluginManager manager;
+
+ public PluginManagerTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ engine = new TestEngine(props);
+ context = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine, "Testpage") );
+ manager = new PluginManager( engine, props );
+ }
+
+ public void tearDown() throws ProviderException
+ {
+ engine.deletePage("Testpage");
+ }
+
+ public void testSimpleInsert()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text=foobar}");
+
+ assertEquals( "foobar",
+ res );
+ }
+
+ public void testSimpleInsertNoPackage()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT SamplePlugin WHERE text=foobar}");
+
+ assertEquals( "foobar",
+ res );
+ }
+
+
+ public void testSimpleInsertNoPackage2()
+ throws Exception
+ {
+ props.setProperty( PluginManager.PROP_SEARCHPATH, "com.foo" );
+ PluginManager m = new PluginManager( engine, props );
+ String res = m.execute( context,
+ "{INSERT SamplePlugin2 WHERE text=foobar}");
+
+ assertEquals( "foobar",
+ res );
+ }
+
+ public void testSimpleInsertNoPackage3()
+ throws Exception
+ {
+ props.setProperty( PluginManager.PROP_SEARCHPATH, "com.foo" );
+ PluginManager m = new PluginManager( engine, props );
+ String res = m.execute( context,
+ "{INSERT SamplePlugin3 WHERE text=foobar}");
+
+ assertEquals( "foobar",
+ res );
+ }
+
+ /** Check that in all cases com.ecyrd.jspwiki.plugin is searched. */
+ public void testSimpleInsertNoPackage4()
+ throws Exception
+ {
+ props.setProperty( PluginManager.PROP_SEARCHPATH, "com.foo,blat.blaa" );
+ PluginManager m = new PluginManager( engine, props );
+ String res = m.execute( context,
+ "{INSERT SamplePlugin WHERE text=foobar}");
+
+ assertEquals( "foobar",
+ res );
+ }
+
+
+ public void testSimpleInsert2()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text = foobar2, moo=blat}");
+
+ assertEquals( "foobar2",
+ res );
+ }
+
+ /** Missing closing brace */
+ public void testSimpleInsert3()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text = foobar2, moo=blat");
+
+ assertEquals( "foobar2",
+ res );
+ }
+
+ public void testQuotedArgs()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT SamplePlugin WHERE text='this is a space'}");
+
+ assertEquals( "this is a space",
+ res );
+ }
+
+ public void testQuotedArgs2()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT SamplePlugin WHERE text='this \\'is a\\' space'}");
+
+ assertEquals( "this 'is a' space",
+ res );
+ }
+
+ public void testNumberArgs()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT SamplePlugin WHERE text=15}");
+
+ assertEquals( "15",
+ res );
+ }
+
+ public void testNoInsert()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{SamplePlugin WHERE text=15}");
+
+ assertEquals( "15",
+ res );
+ }
+
+ // This should be read from tests/etc/ini/jspwiki_module.xml
+ public void testAlias()
+ throws Exception
+ {
+ String res = manager.execute( context, "{samplealias text=15}");
+
+ assertEquals( "15", res );
+ }
+
+ public void testAlias2()
+ throws Exception
+ {
+ String res = manager.execute( context, "{samplealias2 text=xyzzy}");
+
+ assertEquals( "xyzzy", res );
+ }
+
+ public void testInitPlugin() throws Exception
+ {
+ manager.execute( context, "{JavaScriptPlugin}");
+
+ assertTrue( JavaScriptPlugin.c_inited );
+ }
+
+ public void testParserPlugin() throws Exception
+ {
+ engine.saveText(context, "[{SamplePlugin render=true}]");
+
+ engine.getHTML( "Testpage" );
+
+ assertTrue( SamplePlugin.c_rendered );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( PluginManagerTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/ReferringPagesPluginTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,170 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+
+public class ReferringPagesPluginTest extends TestCase
+{
+ Properties props = new Properties();
+ TestEngine engine;
+ WikiContext context;
+ PluginManager manager;
+
+ public ReferringPagesPluginTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ props.setProperty( "jspwiki.breakTitleWithSpaces", "false" );
+ engine = new TestEngine(props);
+
+ engine.saveText( "TestPage", "Reference to [Foobar]." );
+ engine.saveText( "Foobar", "Reference to [TestPage]." );
+ engine.saveText( "Foobar2", "Reference to [TestPage]." );
+ engine.saveText( "Foobar3", "Reference to [TestPage]." );
+ engine.saveText( "Foobar4", "Reference to [TestPage]." );
+ engine.saveText( "Foobar5", "Reference to [TestPage]." );
+ engine.saveText( "Foobar6", "Reference to [TestPage]." );
+ engine.saveText( "Foobar7", "Reference to [TestPage]." );
+
+ context = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine,"TestPage") );
+ manager = new PluginManager( engine, props );
+ }
+
+ public void tearDown()
+ {
+ TestEngine.deleteTestPage( "TestPage" );
+ TestEngine.deleteTestPage( "Foobar" );
+ TestEngine.deleteTestPage( "Foobar2" );
+ TestEngine.deleteTestPage( "Foobar3" );
+ TestEngine.deleteTestPage( "Foobar4" );
+ TestEngine.deleteTestPage( "Foobar5" );
+ TestEngine.deleteTestPage( "Foobar6" );
+ TestEngine.deleteTestPage( "Foobar7" );
+ }
+
+ private String mkLink( String page )
+ {
+ return mkFullLink( page, page );
+ }
+
+ private String mkFullLink( String page, String link )
+ {
+ return "<a class=\"wikipage\" href=\"/Wiki.jsp?page="+link+"\">"+page+"</a>";
+ }
+
+ public void testSingleReferral()
+ throws Exception
+ {
+ WikiContext context2 = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine, "Foobar") );
+
+ String res = manager.execute( context2,
+ "{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=5}");
+
+ assertEquals( mkLink( "TestPage" )+"<br />",
+ res );
+ }
+
+ public void testMaxReferences()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=5}");
+
+ int count = 0;
+ int index = -1;
+
+ // Count the number of hyperlinks. We could check their
+ // correctness as well, though.
+
+ while( (index = res.indexOf("<a",index+1)) != -1 )
+ {
+ count++;
+ }
+
+ assertEquals( 5, count );
+
+ String expected = "...and 2 more<br />";
+
+ assertEquals( "End", expected,
+ res.substring( res.length()-expected.length() ) );
+ }
+
+ public void testReferenceWidth()
+ throws Exception
+ {
+ WikiContext context2 = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine, "Foobar") );
+
+ String res = manager.execute( context2,
+ "{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE maxwidth=5}");
+
+ assertEquals( mkFullLink( "TestP...", "TestPage" )+"<br />",
+ res );
+ }
+
+ public void testInclude()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{ReferringPagesPlugin include='*7'}" );
+
+ assertTrue( "7", res.indexOf("Foobar7") != -1 );
+ assertTrue( "6", res.indexOf("Foobar6") == -1 );
+ assertTrue( "5", res.indexOf("Foobar5") == -1 );
+ assertTrue( "4", res.indexOf("Foobar4") == -1 );
+ assertTrue( "3", res.indexOf("Foobar3") == -1 );
+ assertTrue( "2", res.indexOf("Foobar2") == -1 );
+ }
+
+ public void testExclude()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{ReferringPagesPlugin exclude='*'}");
+
+ assertEquals( "...nobody",
+ res );
+ }
+
+ public void testExclude2()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{ReferringPagesPlugin exclude='*7'}");
+
+ assertTrue( res.indexOf("Foobar7") == -1 );
+ }
+
+ public void testExclude3()
+ throws Exception
+ {
+ String res = manager.execute( context,
+ "{ReferringPagesPlugin exclude='*7,*5,*4'}");
+
+ assertTrue( "7", res.indexOf("Foobar7") == -1 );
+ assertTrue( "6", res.indexOf("Foobar6") != -1 );
+ assertTrue( "5", res.indexOf("Foobar5") == -1 );
+ assertTrue( "4", res.indexOf("Foobar4") == -1 );
+ assertTrue( "3", res.indexOf("Foobar3") != -1 );
+ assertTrue( "2", res.indexOf("Foobar2") != -1 );
+ }
+
+
+ public static Test suite()
+ {
+ return new TestSuite( ReferringPagesPluginTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/SamplePlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/SamplePlugin.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/SamplePlugin.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/SamplePlugin.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,47 @@
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Map;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.parser.PluginContent;
+
+/**
+ * Implements a simple plugin that just returns its text.
+ * <P>
+ * Parameters: text - text to return.
+ * Any _body content gets appended between brackets.
+ *
+ * @author Janne Jalkanen
+ */
+public class SamplePlugin
+ implements WikiPlugin, ParserStagePlugin
+{
+ protected static boolean c_rendered = false;
+
+ public String execute( WikiContext context, Map params )
+ throws PluginException
+ {
+ StringBuffer sb = new StringBuffer();
+
+ String text = (String) params.get("text");
+
+ if( text != null )
+ {
+ sb.append( text );
+ }
+
+ String body = (String)params.get("_body");
+ if( body != null )
+ {
+ sb.append( " ("+body.replace('\n','+')+")" );
+ }
+
+ return sb.toString();
+ }
+
+ public void executeParser(PluginContent element, WikiContext context, Map params)
+ {
+ if( element.getParameter("render") != null ) c_rendered = true;
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/TableOfContentsTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/TableOfContentsTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/TableOfContentsTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/TableOfContentsTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,225 @@
+/*
+ * (C) Janne Jalkanen 2005
+ *
+ */
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class TableOfContentsTest extends TestCase
+{
+ TestEngine testEngine;
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ Properties props = new Properties();
+
+ props.load(TestEngine.findTestProperties());
+
+ testEngine = new TestEngine( props );
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ testEngine.deletePage( "Test" );
+ }
+
+ public void testHeadingVariables()
+ throws Exception
+ {
+ String src="[{SET foo=bar}]\n\n[{TableOfContents}]\n\n!!!Heading [{$foo}]";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ // FIXME: The <p> should not be here.
+ assertEquals( "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"+
+ "<h4>Table of Contents</h4>\n"+
+ "<ul>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">Heading bar</a></li>\n"+
+ "</ul>\n</div>\n</div>\n\n</p>"+
+ "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>\n",
+ res );
+ }
+
+ public void testNumberedItems()
+ throws Exception
+ {
+ String src="[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ // FIXME: The <p> should not be here.
+ String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"+
+ "<h4>Table of Contents</h4>\n"+
+ "<ul>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">3 Heading bar</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">3.1 Subheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">3.1.1 Subsubheading</a></li>\n"+
+ "</ul>\n</div>\n</div>\n\n</p>"+
+ "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"+
+ "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>\n";
+
+ assertEquals(expecting,
+ res );
+ }
+
+ public void testNumberedItemsComplex()
+ throws Exception
+ {
+ String src="[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading\n\n!Subsubheading2\n\n!!Subheading2\n\n!Subsubheading3\n\n!!!Heading\n\n!!Subheading3";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ // FIXME: The <p> should not be here.
+ String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"+
+ "<h4>Table of Contents</h4>\n"+
+ "<ul>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">3 Heading bar</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">3.1 Subheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">3.1.1 Subsubheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading2\">3.1.2 Subsubheading2</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading2\">3.2 Subheading2</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading3\">3.2.1 Subsubheading3</a></li>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Heading\">4 Heading</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading3\">4.1 Subheading3</a></li>\n"+
+ "</ul>\n</div>\n</div>\n\n</p>"+
+ "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"+
+ "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>"+
+ "\n<h4 id=\"section-Test-Subsubheading2\">Subsubheading2</h4>"+
+ "\n<h3 id=\"section-Test-Subheading2\">Subheading2</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading3\">Subsubheading3</h4>"+
+ "\n<h2 id=\"section-Test-Heading\">Heading</h2>"+
+ "\n<h3 id=\"section-Test-Subheading3\">Subheading3</h3>\n";
+
+ assertEquals(expecting,
+ res );
+ }
+
+ public void testNumberedItemsComplex2()
+ throws Exception
+ {
+ String src="[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3}]\n\n!!Subheading0\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading\n\n!Subsubheading2\n\n!!Subheading2\n\n!Subsubheading3\n\n!!!Heading\n\n!!Subheading3";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ // FIXME: The <p> should not be here.
+ String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"+
+ "<h4>Table of Contents</h4>\n"+
+ "<ul>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading0\">3.1 Subheading0</a></li>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">4 Heading bar</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">4.1 Subheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">4.1.1 Subsubheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading2\">4.1.2 Subsubheading2</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading2\">4.2 Subheading2</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading3\">4.2.1 Subsubheading3</a></li>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Heading\">5 Heading</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading3\">5.1 Subheading3</a></li>\n"+
+ "</ul>\n</div>\n</div>\n\n</p>"+
+ "\n<h3 id=\"section-Test-Subheading0\">Subheading0</h3>"+
+ "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"+
+ "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>"+
+ "\n<h4 id=\"section-Test-Subsubheading2\">Subsubheading2</h4>"+
+ "\n<h3 id=\"section-Test-Subheading2\">Subheading2</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading3\">Subsubheading3</h4>"+
+ "\n<h2 id=\"section-Test-Heading\">Heading</h2>"+
+ "\n<h3 id=\"section-Test-Subheading3\">Subheading3</h3>\n";
+
+ assertEquals(expecting,
+ res );
+ }
+
+ public void testNumberedItemsWithPrefix()
+ throws Exception
+ {
+ String src="[{SET foo=bar}]\n\n[{INSERT TableOfContents WHERE numbered=true,start=3,prefix=FooBar-}]\n\n!!!Heading [{$foo}]\n\n!!Subheading\n\n!Subsubheading";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ // FIXME: The <p> should not be here.
+ String expecting = "<p><div class=\"toc\">\n<div class=\"collapsebox\">\n"+
+ "<h4>Table of Contents</h4>\n"+
+ "<ul>\n"+
+ "<li class=\"toclevel-1\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-HeadingBar\">FooBar-3 Heading bar</a></li>\n"+
+ "<li class=\"toclevel-2\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subheading\">FooBar-3.1 Subheading</a></li>\n"+
+ "<li class=\"toclevel-3\"><a class=\"wikipage\" href=\"/Wiki.jsp?page=Test#section-Test-Subsubheading\">FooBar-3.1.1 Subsubheading</a></li>\n"+
+ "</ul>\n</div>\n</div>\n\n</p>"+
+ "\n<h2 id=\"section-Test-HeadingBar\">Heading bar</h2>"+
+ "\n<h3 id=\"section-Test-Subheading\">Subheading</h3>"+
+ "\n<h4 id=\"section-Test-Subsubheading\">Subsubheading</h4>\n";
+
+ assertEquals(expecting,
+ res );
+ }
+
+ /**
+ * Tests BugTableOfContentsCausesHeapdump
+ *
+ * @throws Exception
+ */
+ public void testSelfReference()
+ throws Exception
+ {
+ String src = "!!![{TableOfContents}]";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ assertTrue( res.indexOf("Table of Contents") != -1 );
+ }
+
+ public void testHTML()
+ throws Exception
+ {
+ String src = "[{TableOfContents}]\n\n!<i>test</i>";
+
+ testEngine.saveText( "Test", src );
+
+ String res = testEngine.getHTML( "Test" );
+
+ assertTrue( "<i>", res.indexOf("<i>") == -1 ); // Check that there is no HTML left
+ assertTrue( "</i>", res.indexOf("</i>") == -1 ); // Check that there is no HTML left
+
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( TableOfContentsTest.class );
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/plugin/UndefinedPagesPluginTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,75 @@
+
+package com.ecyrd.jspwiki.plugin;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.framework.Test;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+
+public class UndefinedPagesPluginTest extends TestCase
+{
+ Properties props = new Properties();
+ TestEngine engine;
+ WikiContext context;
+ PluginManager manager;
+
+ public UndefinedPagesPluginTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ engine = new TestEngine(props);
+
+ engine.saveText( "TestPage", "Reference to [Foobar]." );
+ engine.saveText( "Foobar", "Reference to [Foobar 2], [Foobars]" );
+
+ context = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine, "TestPage") );
+ manager = new PluginManager( engine, props );
+ }
+
+ public void tearDown()
+ {
+ TestEngine.deleteTestPage( "TestPage" );
+ TestEngine.deleteTestPage( "Foobar" );
+ TestEngine.emptyPageDir();
+ TestEngine.emptyWorkDir();
+ }
+
+ private String wikitize( String s )
+ {
+ return engine.textToHTML( context, s );
+ }
+
+ /**
+ * Tests that only correct undefined links are found.
+ * We also check against plural forms here, which should not
+ * be listed as non-existant.
+ */
+ public void testSimpleUndefined()
+ throws Exception
+ {
+ WikiContext context2 = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine, "Foobar") );
+
+ String res = manager.execute( context2,
+ "{INSERT com.ecyrd.jspwiki.plugin.UndefinedPagesPlugin");
+
+ String exp = "[Foobar 2]\\\\";
+
+ assertEquals( wikitize(exp), res );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( UndefinedPagesPluginTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/AllTests.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/AllTests.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,25 @@
+
+package com.ecyrd.jspwiki.providers;
+
+import junit.framework.*;
+
+public class AllTests extends TestCase
+{
+ public AllTests( String s )
+ {
+ super( s );
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Providers suite");
+
+ suite.addTest( BasicAttachmentProviderTest.suite() );
+ suite.addTest( CachingProviderTest.suite() );
+ suite.addTest( FileSystemProviderTest.suite() );
+ suite.addTest( RCSFileProviderTest.suite() );
+ suite.addTest( VersioningFileProviderTest.suite() );
+
+ return suite;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/BasicAttachmentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/BasicAttachmentProviderTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/BasicAttachmentProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/BasicAttachmentProviderTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,340 @@
+
+package com.ecyrd.jspwiki.providers;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.attachment.*;
+
+public class BasicAttachmentProviderTest extends TestCase
+{
+ public static final String NAME1 = "TestPage";
+ public static final String NAME2 = "TestPageToo";
+
+ Properties props = new Properties();
+
+ TestEngine m_engine;
+
+ BasicAttachmentProvider m_provider;
+
+ /**
+ * This is the sound of my head hitting the keyboard.
+ */
+ private static final String c_fileContents = "gy th tgyhgthygyth tgyfgftrfgvtgfgtr";
+
+ public BasicAttachmentProviderTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+
+ m_engine = new TestEngine(props);
+
+ m_provider = new BasicAttachmentProvider();
+ m_provider.initialize( m_engine, props );
+
+ m_engine.saveText( NAME1, "Foobar" );
+ m_engine.saveText( NAME2, "Foobar2" );
+ }
+
+ private File makeAttachmentFile()
+ throws Exception
+ {
+ File tmpFile = File.createTempFile("test","txt");
+ tmpFile.deleteOnExit();
+
+ FileWriter out = new FileWriter( tmpFile );
+
+ FileUtil.copyContents( new StringReader( c_fileContents ), out );
+
+ out.close();
+
+ return tmpFile;
+ }
+
+ private File makeExtraFile( File directory, String name )
+ throws Exception
+ {
+ File tmpFile = new File( directory, name );
+ FileWriter out = new FileWriter( tmpFile );
+
+ FileUtil.copyContents( new StringReader( c_fileContents ), out );
+
+ out.close();
+
+ return tmpFile;
+ }
+
+
+ public void tearDown()
+ {
+ TestEngine.deleteTestPage( NAME1 );
+ TestEngine.deleteTestPage( NAME2 );
+
+ String tmpfiles = props.getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );
+
+ File f = new File( tmpfiles, NAME1+BasicAttachmentProvider.DIR_EXTENSION );
+
+ TestEngine.deleteAll( f );
+
+ f = new File( tmpfiles, NAME2+BasicAttachmentProvider.DIR_EXTENSION );
+
+ TestEngine.deleteAll( f );
+
+ TestEngine.emptyWorkDir();
+ }
+
+ public void testExtension()
+ {
+ String s = "test.png";
+
+ assertEquals( BasicAttachmentProvider.getFileExtension(s), "png" );
+ }
+
+ public void testExtension2()
+ {
+ String s = ".foo";
+
+ assertEquals( "foo", BasicAttachmentProvider.getFileExtension(s) );
+ }
+
+ public void testExtension3()
+ {
+ String s = "test.png.3";
+
+ assertEquals( "3", BasicAttachmentProvider.getFileExtension(s) );
+ }
+
+ public void testExtension4()
+ {
+ String s = "testpng";
+
+ assertEquals( "bin", BasicAttachmentProvider.getFileExtension(s) );
+ }
+
+
+ public void testExtension5()
+ {
+ String s = "test.";
+
+ assertEquals( "bin", BasicAttachmentProvider.getFileExtension(s) );
+ }
+
+ public void testExtension6()
+ {
+ String s = "test.a";
+
+ assertEquals( "a", BasicAttachmentProvider.getFileExtension(s) );
+ }
+
+ /**
+ * Can we save attachments with names in UTF-8 range?
+ */
+ public void testPutAttachmentUTF8()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ Attachment att = new Attachment( m_engine, NAME1, "\u3072\u3048\u308båäötest.füü" );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ Attachment a0 = (Attachment) res.get(0);
+
+ assertEquals( "name", att.getName(), a0.getName() );
+ }
+
+ public void testListAll()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ Thread.sleep( 2000L ); // So that we get a bit of granularity.
+
+ Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
+
+ m_provider.putAttachmentData( att2, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ assertEquals( "list size", 2, res.size() );
+
+ Attachment a2 = (Attachment) res.get(0); // Most recently changed
+ Attachment a1 = (Attachment) res.get(1); // Least recently changed
+
+ assertEquals( "a1 name", att.getName(), a1.getName() );
+ assertEquals( "a2 name", att2.getName(), a2.getName() );
+ }
+
+
+ /**
+ * Check that the system does not fail if there are extra files in the directory.
+ */
+ public void testListAllExtrafile()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ File sDir = new File(m_engine.getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR ));
+ File extrafile = makeExtraFile( sDir, "foobar.blob" );
+
+ try
+ {
+ Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ Thread.sleep( 2000L ); // So that we get a bit of granularity.
+
+ Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
+
+ m_provider.putAttachmentData( att2, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ assertEquals( "list size", 2, res.size() );
+
+ Attachment a2 = (Attachment) res.get(0); // Most recently changed
+ Attachment a1 = (Attachment) res.get(1); // Least recently changed
+
+ assertEquals( "a1 name", att.getName(), a1.getName() );
+ assertEquals( "a2 name", att2.getName(), a2.getName() );
+ }
+ finally
+ {
+ extrafile.delete();
+ }
+ }
+
+ /**
+ * Check that the system does not fail if there are extra files in the
+ * attachment directory.
+ */
+ public void testListAllExtrafileInAttachmentDir()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ File sDir = new File(m_engine.getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR ));
+ File attDir = new File( sDir, NAME1+"-att" );
+
+
+ Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ File extrafile = makeExtraFile( attDir, "ping.pong" );
+
+ try
+ {
+ Thread.sleep( 2000L ); // So that we get a bit of granularity.
+
+ Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
+
+ m_provider.putAttachmentData( att2, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ assertEquals( "list size", 2, res.size() );
+
+ Attachment a2 = (Attachment) res.get(0); // Most recently changed
+ Attachment a1 = (Attachment) res.get(1); // Least recently changed
+
+ assertEquals( "a1 name", att.getName(), a1.getName() );
+ assertEquals( "a2 name", att2.getName(), a2.getName() );
+ }
+ finally
+ {
+ extrafile.delete();
+ }
+ }
+
+ /**
+ * Check that the system does not fail if there are extra dirs in the
+ * attachment directory.
+ */
+ public void testListAllExtradirInAttachmentDir()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ File sDir = new File(m_engine.getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR ));
+ File attDir = new File( sDir, NAME1+"-att" );
+
+ Attachment att = new Attachment( m_engine, NAME1, "test1.txt" );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ // This is our extraneous directory.
+ File extrafile = new File( attDir, "ping.pong" );
+ extrafile.mkdir();
+
+ try
+ {
+ Thread.sleep( 2000L ); // So that we get a bit of granularity.
+
+ Attachment att2 = new Attachment( m_engine, NAME2, "test2.txt" );
+
+ m_provider.putAttachmentData( att2, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ assertEquals( "list size", 2, res.size() );
+
+ Attachment a2 = (Attachment) res.get(0); // Most recently changed
+ Attachment a1 = (Attachment) res.get(1); // Least recently changed
+
+ assertEquals( "a1 name", att.getName(), a1.getName() );
+ assertEquals( "a2 name", att2.getName(), a2.getName() );
+ }
+ finally
+ {
+ extrafile.delete();
+ }
+ }
+
+ public void testListAllNoExtension()
+ throws Exception
+ {
+ File in = makeAttachmentFile();
+
+ Attachment att = new Attachment( m_engine, NAME1, "test1." );
+
+ m_provider.putAttachmentData( att, new FileInputStream(in) );
+
+ Thread.sleep( 2000L ); // So that we get a bit of granularity.
+
+ Attachment att2 = new Attachment( m_engine, NAME2, "test2." );
+
+ m_provider.putAttachmentData( att2, new FileInputStream(in) );
+
+ List res = m_provider.listAllChanged( new Date(0L) );
+
+ assertEquals( "list size", 2, res.size() );
+
+ Attachment a2 = (Attachment) res.get(0); // Most recently changed
+ Attachment a1 = (Attachment) res.get(1); // Least recently changed
+
+ assertEquals( "a1 name", att.getName(), a1.getName() );
+ assertEquals( "a2 name", att2.getName(), a2.getName() );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( BasicAttachmentProviderTest.class );
+ }
+
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CachingProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CachingProviderTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CachingProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CachingProviderTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,104 @@
+
+package com.ecyrd.jspwiki.providers;
+
+import junit.framework.*;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.io.File;
+import java.io.StringReader;
+import java.util.*;
+
+import org.apache.log4j.*;
+
+import com.ecyrd.jspwiki.*;
+
+public class CachingProviderTest extends TestCase
+{
+ public CachingProviderTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ TestEngine.emptyWorkDir();
+
+ Properties props2 = new Properties();
+
+ props2.load( TestEngine.findTestProperties() );
+ PropertyConfigurator.configure(props2);
+ }
+
+ public void tearDown()
+ {
+ TestEngine.emptyWorkDir();
+ TestEngine.deleteTestPage("Testi");
+ }
+
+ /**
+ * Checks that at startup we call the provider once, and once only.
+ */
+ public void testInitialization()
+ throws Exception
+ {
+ Properties props = new Properties();
+ props.load( TestEngine.findTestProperties() );
+
+ props.setProperty( "jspwiki.usePageCache", "true" );
+ props.setProperty( "jspwiki.pageProvider", "com.ecyrd.jspwiki.providers.CounterProvider" );
+ props.setProperty( "jspwiki.cachingProvider.capacity", "100" );
+
+ TestEngine engine = new TestEngine( props );
+
+ CounterProvider p = (CounterProvider)((CachingProvider)engine.getPageManager().getProvider()).getRealProvider();
+
+ assertEquals("init", 1, p.m_initCalls);
+ assertEquals("getAllPages", 1, p.m_getAllPagesCalls);
+ assertEquals("pageExists", 0, p.m_pageExistsCalls);
+ assertEquals("getPage", 2, p.m_getPageCalls); // These two are for non-existant pages (with and without s)
+ assertEquals("getPageText", 4, p.m_getPageTextCalls);
+
+ engine.getPage( "Foo" );
+
+ assertEquals("pageExists2", 0, p.m_pageExistsCalls);
+ assertEquals("getPage2", 2, p.m_getPageCalls);
+ }
+
+ public void testSneakyAdd()
+ throws Exception
+ {
+ Properties props = new Properties();
+ props.load( TestEngine.findTestProperties() );
+
+ props.setProperty( "jspwiki.cachingProvider.cacheCheckInterval", "2" );
+
+ TestEngine engine = new TestEngine( props );
+
+ String dir = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( dir, "Testi.txt" );
+ String content = "[fuufaa]";
+
+ PrintWriter out = new PrintWriter( new FileWriter(f) );
+ FileUtil.copyContents( new StringReader(content), out );
+ out.close();
+
+ Thread.sleep( 4000L ); // Make sure we wait long enough
+
+ WikiPage p = engine.getPage( "Testi" );
+ assertNotNull( "page did not exist?", p );
+
+ String text = engine.getText( "Testi");
+ assertEquals("text", "[fuufaa]", text );
+
+ // TODO: ReferenceManager check as well
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( CachingProviderTest.class );
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CounterProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CounterProvider.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CounterProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/CounterProvider.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,166 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.providers;
+
+import java.util.*;
+
+import org.apache.log4j.*;
+
+import com.ecyrd.jspwiki.*;
+
+/**
+ * A provider who counts the hits to different parts.
+ */
+public class CounterProvider
+ implements WikiPageProvider
+{
+ public int m_getPageCalls = 0;
+ public int m_pageExistsCalls = 0;
+ public int m_getPageTextCalls = 0;
+ public int m_getAllPagesCalls = 0;
+ public int m_initCalls = 0;
+
+ static Logger log = Logger.getLogger( CounterProvider.class );
+
+ WikiPage[] m_pages = new WikiPage[0];
+
+ String m_defaultText = "[Foo], [Bar], [Blat], [Blah]";
+
+
+ public void initialize( WikiEngine engine, Properties props )
+ {
+ m_pages = new WikiPage[]
+ { new WikiPage(engine, "Foo"),
+ new WikiPage(engine, "Bar"),
+ new WikiPage(engine, "Blat"),
+ new WikiPage(engine, "Blaa") };
+
+ m_initCalls++;
+
+ for( int i = 0; i < m_pages.length; i++ )
+ {
+ m_pages[i].setAuthor("Unknown");
+ m_pages[i].setLastModified( new Date(0L) );
+ m_pages[i].setVersion(1);
+ }
+ }
+
+ public String getProviderInfo()
+ {
+ return "Very Simple Provider.";
+ }
+
+ public void putPageText( WikiPage page, String text )
+ throws ProviderException
+ {
+ }
+
+ public boolean pageExists( String page )
+ {
+ m_pageExistsCalls++;
+
+ //System.out.println("PAGE="+page);
+ //TestEngine.trace();
+
+ return findPage( page ) != null;
+ }
+
+ public Collection findPages( QueryItem[] query )
+ {
+ return null;
+ }
+
+ private WikiPage findPage( String page )
+ {
+ for( int i = 0; i < m_pages.length; i++ )
+ {
+ if( m_pages[i].getName().equals(page) )
+ return m_pages[i];
+ }
+
+ return null;
+ }
+
+ public WikiPage getPageInfo( String page, int version )
+ {
+ m_getPageCalls++;
+
+ //System.out.println("GETPAGEINFO="+page);
+ //TestEngine.trace();
+
+ WikiPage p = findPage(page);
+
+ return p;
+ }
+
+ public Collection getAllPages()
+ {
+ m_getAllPagesCalls++;
+
+ Vector v = new Vector();
+
+ for( int i = 0; i < m_pages.length; i++ )
+ {
+ v.add( m_pages[i] );
+ }
+
+ return v;
+ }
+
+ public Collection getAllChangedSince( Date date )
+ {
+ return new Vector();
+ }
+
+ public int getPageCount()
+ {
+ return m_pages.length;
+ }
+
+ public List getVersionHistory( String page )
+ {
+ return new Vector();
+ }
+
+ public String getPageText( String page, int version )
+ {
+ m_getPageTextCalls++;
+ return m_defaultText;
+ }
+
+ public void deleteVersion( String page, int version )
+ {
+ }
+
+ public void deletePage( String page )
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see com.ecyrd.jspwiki.providers.WikiPageProvider#movePage(java.lang.String, java.lang.String)
+ */
+ public void movePage( String from, String to ) throws ProviderException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/FileSystemProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/FileSystemProviderTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/FileSystemProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/FileSystemProviderTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,256 @@
+
+package com.ecyrd.jspwiki.providers;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+
+import org.apache.log4j.*;
+
+import com.ecyrd.jspwiki.*;
+
+public class FileSystemProviderTest extends TestCase
+{
+ FileSystemProvider m_provider;
+ FileSystemProvider m_providerUTF8;
+ String m_pagedir;
+ Properties props = new Properties();
+
+ TestEngine m_engine;
+
+ public FileSystemProviderTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ m_pagedir = System.getProperties().getProperty("java.io.tmpdir");
+
+ Properties props2 = new Properties();
+
+ props.setProperty( PageManager.PROP_PAGEPROVIDER, "FileSystemProvider" );
+ props.setProperty( FileSystemProvider.PROP_PAGEDIR,
+ m_pagedir );
+
+ props2.load( TestEngine.findTestProperties() );
+ PropertyConfigurator.configure(props2);
+
+ m_engine = new TestEngine(props);
+
+ m_provider = new FileSystemProvider();
+
+ m_provider.initialize( m_engine, props );
+
+ props.setProperty( WikiEngine.PROP_ENCODING, "UTF-8" );
+ m_providerUTF8 = new FileSystemProvider();
+ m_providerUTF8.initialize( m_engine, props );
+ }
+
+ public void tearDown()
+ {
+ TestEngine.deleteAll( new File(m_pagedir) );
+ }
+
+ public void testScandinavianLetters()
+ throws Exception
+ {
+ WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
+
+ m_provider.putPageText( page, "test" );
+
+ File resultfile = new File( m_pagedir, "%C5%E4Test.txt" );
+
+ assertTrue("No such file", resultfile.exists());
+
+ String contents = FileUtil.readContents( new FileInputStream(resultfile),
+ "ISO-8859-1" );
+
+ assertEquals("Wrong contents", contents, "test");
+ }
+
+ public void testScandinavianLettersUTF8()
+ throws Exception
+ {
+ WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
+
+ m_providerUTF8.putPageText( page, "test\u00d6" );
+
+ File resultfile = new File( m_pagedir, "%C3%85%C3%A4Test.txt" );
+
+ assertTrue("No such file", resultfile.exists());
+
+ String contents = FileUtil.readContents( new FileInputStream(resultfile),
+ "UTF-8" );
+
+ assertEquals("Wrong contents", contents, "test\u00d6");
+ }
+
+ /**
+ * This should never happen, but let's check that we're protected anyway.
+ * @throws Exception
+ */
+ public void testSlashesInPageNamesUTF8()
+ throws Exception
+ {
+ WikiPage page = new WikiPage(m_engine, "Test/Foobar");
+
+ m_providerUTF8.putPageText( page, "test" );
+
+ File resultfile = new File( m_pagedir, "Test%2FFoobar.txt" );
+
+ assertTrue("No such file", resultfile.exists());
+
+ String contents = FileUtil.readContents( new FileInputStream(resultfile),
+ "UTF-8" );
+
+ assertEquals("Wrong contents", contents, "test");
+ }
+
+ public void testSlashesInPageNames()
+ throws Exception
+ {
+ WikiPage page = new WikiPage(m_engine, "Test/Foobar");
+
+ m_provider.putPageText( page, "test" );
+
+ File resultfile = new File( m_pagedir, "Test%2FFoobar.txt" );
+
+ assertTrue("No such file", resultfile.exists());
+
+ String contents = FileUtil.readContents( new FileInputStream(resultfile),
+ "ISO-8859-1" );
+
+ assertEquals("Wrong contents", contents, "test");
+ }
+
+ public void testAuthor()
+ throws Exception
+ {
+ try
+ {
+ WikiPage page = new WikiPage(m_engine, "\u00c5\u00e4Test");
+ page.setAuthor("Min\u00e4");
+
+ m_provider.putPageText( page, "test" );
+
+ WikiPage page2 = m_provider.getPageInfo( "\u00c5\u00e4Test", 1 );
+
+ assertEquals( "Min\u00e4", page2.getAuthor() );
+ }
+ finally
+ {
+ File resultfile = new File( m_pagedir,
+ "%C5%E4Test.txt" );
+ try
+ {
+ resultfile.delete();
+ }
+ catch(Exception e) {}
+
+ resultfile = new File( m_pagedir,
+ "%C5%E4Test.properties" );
+ try
+ {
+ resultfile.delete();
+ }
+ catch(Exception e) {}
+ }
+ }
+
+ public void testNonExistantDirectory()
+ throws Exception
+ {
+ String tmpdir = m_pagedir;
+ String dirname = "non-existant-directory";
+
+ String newdir = tmpdir + File.separator + dirname;
+
+ Properties pr = new Properties();
+
+ pr.setProperty( FileSystemProvider.PROP_PAGEDIR,
+ newdir );
+
+ FileSystemProvider test = new FileSystemProvider();
+
+ test.initialize( m_engine, pr );
+
+ File f = new File( newdir );
+
+ assertTrue( "didn't create it", f.exists() );
+ assertTrue( "isn't a dir", f.isDirectory() );
+
+ f.delete();
+ }
+
+ public void testDirectoryIsFile()
+ throws Exception
+ {
+ File tmpFile = null;
+
+ try
+ {
+ tmpFile = FileUtil.newTmpFile("foobar"); // Content does not matter.
+
+ Properties pr = new Properties();
+
+ pr.setProperty( FileSystemProvider.PROP_PAGEDIR,
+ tmpFile.getAbsolutePath() );
+
+ FileSystemProvider test = new FileSystemProvider();
+
+ try
+ {
+ test.initialize( m_engine, pr );
+
+ fail( "Wiki did not warn about wrong property." );
+ }
+ catch( IOException e )
+ {
+ // This is okay.
+ }
+ }
+ finally
+ {
+ if( tmpFile != null )
+ {
+ tmpFile.delete();
+ }
+ }
+ }
+
+ public void testDelete()
+ throws Exception
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ WikiPage p = new WikiPage(m_engine,"Test");
+ p.setAuthor("AnonymousCoward");
+
+ m_provider.putPageText( p, "v1" );
+
+ File f = new File( files, "Test"+FileSystemProvider.FILE_EXT );
+
+ assertTrue( "file does not exist", f.exists() );
+
+ f = new File( files, "Test.properties" );
+
+ assertTrue( "property file does not exist", f.exists() );
+
+ m_provider.deletePage( "Test" );
+
+ f = new File( files, "Test"+FileSystemProvider.FILE_EXT );
+
+ assertFalse( "file exists", f.exists() );
+
+ f = new File( files, "Test.properties" );
+
+ assertFalse( "properties exist", f.exists() );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( FileSystemProviderTest.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/RCSFileProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/RCSFileProviderTest.java?rev=627269&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/RCSFileProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/providers/RCSFileProviderTest.java Tue Feb 12 22:22:45 2008
@@ -0,0 +1,237 @@
+
+package com.ecyrd.jspwiki.providers;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import com.ecyrd.jspwiki.*;
+
+/**
+ * Tests the RCSFileProvider. If you are getting strange errors, please check that you
+ * actually <i>have</i> RCS installed and in your path...
+ *
+ * @author jalkanen
+ *
+ * @since forever
+ */
+public class RCSFileProviderTest extends TestCase
+{
+ public static final String NAME1 = "Test1";
+
+ Properties props = new Properties();
+
+ TestEngine engine;
+
+ public RCSFileProviderTest( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties("/jspwiki_rcs.properties") );
+
+ engine = new TestEngine(props);
+ }
+
+ /**
+ * Remove NAME1 + all RCS directories for it.
+ */
+ public void tearDown()
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+
+ f.delete();
+
+ f = new File( files+File.separator+"RCS", NAME1+FileSystemProvider.FILE_EXT+",v" );
+
+ f.delete();
+
+ f = new File( files, "RCS" );
+
+ f.delete();
+ }
+
+ /**
+ * Bug report by Anon: RCS under Windows 2k:
+ * <PRE>
+ * In getPageInfo of RCSFileProvider:
+ *
+ * Problem:
+ *
+ * With a longer rlog result, the break clause in the last "else if"
+ * breaks out of the reading loop before all the lines in the full
+ * rlog have been read in. This causes the process.wait() to hang.
+ *
+ * Suggested quick fix:
+ *
+ * Always read all the contents of the rlog, even if it is slower.
+ * </PRE>
+ *
+ */
+
+ public void testMillionChanges()
+ throws Exception
+ {
+ String text = "";
+ String name = NAME1;
+ int maxver = 100; // Save 100 versions.
+
+ for( int i = 0; i < maxver; i++ )
+ {
+ text = text + ".";
+ engine.saveText( name, text );
+ }
+
+ WikiPage pageinfo = engine.getPage( NAME1 );
+
+ assertEquals( "wrong version", maxver, pageinfo.getVersion() );
+ // +2 comes from \r\n at the end of each file.
+ assertEquals( "wrong text", maxver+2, engine.getText(NAME1).length() );
+ }
+
+ /**
+ * Checks if migration from FileSystemProvider to VersioningFileProvider
+ * works by creating a dummy file without corresponding content in OLD/
+ */
+ public void testMigration()
+ throws IOException
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+
+ Writer out = new FileWriter( f );
+ FileUtil.copyContents( new StringReader("foobar"), out );
+ out.close();
+
+ String res = engine.getText( NAME1 );
+
+ assertEquals( "latest did not work", "foobar", res );
+
+ res = engine.getText( NAME1, 1 ); // Should be the first version.
+
+ assertEquals( "fetch by direct version did not work", "foobar", res );
+ }
+
+ public void testGetByVersion()
+ throws Exception
+ {
+ String text = "diddo\r\n";
+
+ engine.saveText( NAME1, text );
+
+ WikiPage page = engine.getPage( NAME1, 1 );
+
+ assertEquals( "name", NAME1, page.getName() );
+ assertEquals( "version", 1, page.getVersion() );
+ }
+
+ public void testGetByLatestVersion()
+ throws Exception
+ {
+ String text = "diddo\r\n";
+
+ engine.saveText( NAME1, text );
+
+ WikiPage page = engine.getPage( NAME1, WikiProvider.LATEST_VERSION );
+
+ assertEquals( "name", NAME1, page.getName() );
+ assertEquals( "version", 1, page.getVersion() );
+ }
+
+ public void testDelete()
+ throws Exception
+ {
+ engine.saveText( NAME1, "v1" );
+ engine.saveText( NAME1, "v2" );
+ engine.saveText( NAME1, "v3" );
+
+ PageManager mgr = engine.getPageManager();
+ WikiPageProvider provider = mgr.getProvider();
+
+ provider.deletePage( NAME1 );
+
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+
+ assertFalse( "file exists", f.exists() );
+
+ f = new File( files+File.separator+"RCS", NAME1+FileSystemProvider.FILE_EXT+",v" );
+
+ assertFalse( "RCS file exists", f.exists() );
+ }
+
+ public void testDeleteVersion()
+ throws Exception
+ {
+ engine.saveText( NAME1, "v1\r\n" );
+ engine.saveText( NAME1, "v2\r\n" );
+ engine.saveText( NAME1, "v3\r\n" );
+
+ PageManager mgr = engine.getPageManager();
+ WikiPageProvider provider = mgr.getProvider();
+
+ provider.deleteVersion( NAME1, 2 );
+
+ List l = provider.getVersionHistory( NAME1 );
+
+ assertEquals( "wrong # of versions", 2, l.size() );
+
+ assertEquals( "v1", "v1\r\n", provider.getPageText( NAME1, 1 ) );
+ assertEquals( "v3", "v3\r\n", provider.getPageText( NAME1, 3 ) );
+
+ try
+ {
+ provider.getPageText( NAME1, 2 );
+ fail( "v2" );
+ }
+ catch( NoSuchVersionException e )
+ {
+ // This is expected
+ }
+ }
+
+ public void testChangeNote()
+ throws Exception
+ {
+ WikiPage p = new WikiPage( engine, NAME1 );
+ p.setAttribute(WikiPage.CHANGENOTE, "Test change" );
+ WikiContext context = engine.getWikiActionBeanFactory().newViewActionBean(p);
+
+ engine.saveText( context, "test" );
+
+ WikiPage p2 = engine.getPage( NAME1 );
+
+ assertEquals( "Test change", p2.getAttribute(WikiPage.CHANGENOTE) );
+ }
+
+ public void testChangeNoteOldVersion()
+ throws Exception
+ {
+ WikiPage p = new WikiPage( engine, NAME1 );
+ WikiContext context = engine.getWikiActionBeanFactory().newViewActionBean(p);
+
+ context.getPage().setAttribute(WikiPage.CHANGENOTE, "Test change" );
+ engine.saveText( context, "test" );
+
+ context.getPage().setAttribute(WikiPage.CHANGENOTE, "Change 2" );
+ engine.saveText( context, "test2" );
+
+ WikiPage p2 = engine.getPage( NAME1, 1 );
+
+ assertEquals( "Test change", p2.getAttribute(WikiPage.CHANGENOTE) );
+
+ WikiPage p3 = engine.getPage( NAME1, 2 );
+
+ assertEquals( "Change 2", p3.getAttribute(WikiPage.CHANGENOTE) );
+ }
+ public static Test suite()
+ {
+ return new TestSuite( RCSFileProviderTest.class );
+ }
+}