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:24:06 UTC

svn commit: r627271 [1/8] - in /incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki: ./ action/ attachment/ auth/ auth/acl/ auth/authorize/ auth/login/ auth/permissions/ auth/user/ dav/ diff/ filters/ htmltowiki/ parser/

Author: ajaquith
Date: Tue Feb 12 22:24:02 2008
New Revision: 627271

URL: http://svn.apache.org/viewvc?rev=627271&view=rev
Log:
Initial commit.

Added:
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/FileUtilTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageRenamerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PropertyReaderTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReleaseTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestAuthorizer.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestEngine.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJDBCDataSource.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJNDIContext.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TextUtilTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/Util.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/VariableManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/WikiEngineTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/WikiSessionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/EventPermissionInfoTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/RenameActionBeanTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/UserPreferencesActionBeanTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/UserProfileActionBeanTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/ViewActionBeanTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/action/WikiActionBeanFactoryTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/attachment/AttachmentManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthenticationManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/GroupManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/SecurityEventTrap.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java   (with props)
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/Users.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclEntryImplTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AclImplTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/acl/DefaultAclManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/GroupTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabaseTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabaseTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/AnonymousLoginModuleTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/CookieAssertionLoginModuleTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/UserDatabaseLoginModuleTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/login/WebContainerLoginModuleTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/AllPermissionCollectionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/AllPermissionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/GroupPermissionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/PagePermissionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/WikiPermissionTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AttachmentDavProviderTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/DavPathTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/HTMLPagesDavProviderTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/RawPagesDavProviderTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/FilterManagerTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/TestFilter.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/HtmlStringToWikiTranslatorTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AllTests.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AndyTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/CreoleToJSPWikiTranslatorTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/MarkupParserTest.java
    incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/creole.properties

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,78 @@
+
+package com.ecyrd.jspwiki;
+
+import java.util.Properties;
+import org.apache.log4j.PropertyConfigurator;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.*;
+
+public class AllTests extends TestCase
+{
+    //
+    //  Ensure everything runs properly and that we can locate all necessary
+    //  thingies.
+    //
+    static
+    {
+        Properties props = new Properties();
+        try
+        {
+            InputStream pin = TestEngine.findTestProperties();
+            if( pin == null )
+            {
+                fail( "No property file found!" );
+            }
+            props.load( pin );
+            PropertyConfigurator.configure(props);
+        }
+        catch( IOException e ) 
+        {
+        }
+    }
+
+    public AllTests( String s )
+    {
+        super( s );
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("JSPWiki Unit Tests");
+
+        suite.addTest( FileUtilTest.suite() );
+        suite.addTest( PageManagerTest.suite() );
+        suite.addTest( PageRenamerTest.suite() );
+        suite.addTest( PropertyReaderTest.suite() );
+        suite.addTest( ReferenceManagerTest.suite() );
+        suite.addTest( ReleaseTest.suite() );
+        suite.addTest( TextUtilTest.suite() );
+        suite.addTest( VariableManagerTest.suite() );
+        // This is obsolete and not maintained anymore
+        // suite.addTest( TranslatorReaderTest.suite() );
+        suite.addTest( WikiSessionTest.suite() );
+        suite.addTest( WikiEngineTest.suite() );
+        suite.addTest( com.ecyrd.jspwiki.action.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.attachment.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.auth.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.dav.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.diff.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.filters.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.htmltowiki.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.parser.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.plugin.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.providers.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.render.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.rss.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.search.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.ui.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.util.AllTests.suite() );
+        // These are not runnable without a running tomcat
+        //suite.addTest( com.ecyrd.jspwiki.web.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.workflow.AllTests.suite() );
+        suite.addTest( com.ecyrd.jspwiki.xmlrpc.AllTests.suite() );
+        
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/FileUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/FileUtilTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/FileUtilTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/FileUtilTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,128 @@
+
+package com.ecyrd.jspwiki;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import org.apache.log4j.*;
+
+public class FileUtilTest extends TestCase
+{
+    public FileUtilTest( String s )
+    {
+        super( s );
+        Properties props = new Properties();
+        try
+        {
+            props.load( TestEngine.findTestProperties() );
+            PropertyConfigurator.configure(props);
+        }
+        catch( IOException e ) {}
+    }
+
+    public void setUp()
+        throws Exception
+    {
+    }
+
+    public void tearDown()
+    {
+    }
+
+    /**
+     *  This test actually checks if your JDK is misbehaving.  On my own Debian
+     *  machine, changing the system to use UTF-8 suddenly broke Java, and I put
+     *  in this test to check for its brokenness.  If your tests suddenly stop
+     *  running, check if this one is failing too.  If it is, your platform is
+     *  broken.  If it's not, seek for the bug in your code.
+     */
+    public void testJDKString()
+        throws Exception
+    {
+        String src = "abc\u00e4\u00e5\u00a6";
+
+        String res = new String( src.getBytes("ISO-8859-1"), "ISO-8859-1" );
+
+        assertEquals( src, res );
+    }
+
+    public void testReadContentsLatin1()
+        throws Exception
+    {
+        String src = "abc\u00e4\u00e5\u00a6";
+
+        String res = FileUtil.readContents( new ByteArrayInputStream( src.getBytes("ISO-8859-1") ),
+                                            "ISO-8859-1" );
+
+        assertEquals( src, res );
+    }
+
+    /**
+     *  Check that fallbacks to ISO-Latin1 still work.
+     */
+    public void testReadContentsLatin1_2()
+        throws Exception
+    {
+        String src = "abc\u00e4\u00e5\u00a6def";
+
+        String res = FileUtil.readContents( new ByteArrayInputStream( src.getBytes("ISO-8859-1") ),
+                                            "UTF-8" );
+
+        assertEquals( src, res );
+    }
+
+    /**
+       ISO Latin 1 from a pipe.
+
+       FIXME: Works only on UNIX systems now.
+    */
+    public void testReadContentsFromPipe()
+        throws Exception
+    {
+        String src = "abc\n123456\n\nfoobar.\n";
+
+        // Make a very long string.
+
+        for( int i = 0; i < 10; i++ )
+        {
+            src += src;
+        }
+
+        src += "\u00e4\u00e5\u00a6";
+
+        File f = FileUtil.newTmpFile( src, "ISO-8859-1" );
+
+        String[] envp = {};
+
+        try
+        {
+            Process process = Runtime.getRuntime().exec( "cat "+f.getAbsolutePath(), 
+                                                         envp, 
+                                                         f.getParentFile() );
+
+            String result = FileUtil.readContents( process.getInputStream(), "UTF-8" );
+
+            f.delete();
+
+            assertEquals( src,
+                          result );
+        }
+        catch( IOException e ) {}
+    }
+
+    public void testReadContentsReader()
+        throws IOException
+    {
+        String data = "ABCDEF";
+
+        String result = FileUtil.readContents( new StringReader( data ) );
+
+        assertEquals( data,
+                      result );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( FileUtilTest.class );
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageManagerTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageManagerTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageManagerTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,57 @@
+
+package com.ecyrd.jspwiki;
+
+import junit.framework.*;
+import java.util.*;
+
+import org.apache.log4j.*;
+
+import com.ecyrd.jspwiki.providers.*;
+
+public class PageManagerTest extends TestCase
+{
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    public PageManagerTest( String s )
+    {
+        super( s );
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+        PropertyConfigurator.configure(props);
+        engine = new TestEngine(props);
+    }
+
+    public void tearDown()
+    {
+    }
+
+    public void testPageCacheExists()
+        throws Exception
+    {
+        props.setProperty( "jspwiki.usePageCache", "true" );
+        PageManager m = new PageManager( engine, props );
+
+        assertTrue( m.getProvider() instanceof CachingProvider );
+    }
+
+    public void testPageCacheNotInUse()
+        throws Exception
+    {
+        props.setProperty( "jspwiki.usePageCache", "false" );
+        PageManager m = new PageManager( engine, props );
+
+        assertTrue( !(m.getProvider() instanceof CachingProvider) );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( PageManagerTest.class );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageRenamerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageRenamerTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageRenamerTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PageRenamerTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,403 @@
+package com.ecyrd.jspwiki;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.action.WikiActionBeanFactory;
+import com.ecyrd.jspwiki.attachment.Attachment;
+
+public class PageRenamerTest extends TestCase
+{
+    TestEngine m_engine;
+    
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+        
+        Properties props = new Properties();
+        
+        props.load( TestEngine.findTestProperties() );
+
+        props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" );
+        
+        TestEngine.emptyWorkDir();
+        m_engine = new TestEngine(props);  
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+        
+        TestEngine.deleteTestPage("TestPage");
+        TestEngine.deleteTestPage("TestPage2");
+        TestEngine.deleteTestPage("FooTest");
+        TestEngine.deleteTestPage("Test");
+        TestEngine.deleteTestPage("CdauthNew");
+        TestEngine.deleteTestPage("Cdauth");
+
+        TestEngine.emptyWorkDir();
+    }
+
+    public void testSimpleRename()
+        throws Exception
+    {
+        // Count the numberof existing references
+        int refCount = m_engine.getReferenceManager().findCreated().size();
+        
+        m_engine.saveText("TestPage", "the big lazy dog thing" );
+        
+        WikiPage p = m_engine.getPage("TestPage");
+        
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+        
+        m_engine.renamePage(context, "TestPage", "FooTest", false);
+        
+        WikiPage newpage = m_engine.getPage("FooTest");
+        
+        assertNotNull( "no new page", newpage );
+        assertNull( "old page not gone", m_engine.getPage("TestPage") );
+        
+        // Refmgr
+        
+        Collection refs = m_engine.getReferenceManager().findCreated();
+        
+        assertEquals( "wrong list size", refCount+1, refs.size() );
+        assertTrue( refs.contains("FooTest") );
+    }
+    
+    public void testReferrerChange()
+       throws Exception
+    {
+        m_engine.saveText("TestPage", "foofoo" );
+        m_engine.saveText("TestPage2", "[TestPage]");
+        
+        WikiPage p = m_engine.getPage("TestPage");
+        
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+        
+        m_engine.renamePage(context, "TestPage", "FooTest", true);
+        
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
+        
+        assertEquals( "no rename", "[FooTest]", data.trim() );
+        
+        Collection refs = m_engine.getReferenceManager().findReferrers("TestPage");
+        
+        assertNull( "oldpage", refs );
+        
+        refs = m_engine.getReferenceManager().findReferrers( "FooTest" );
+        assertEquals( "new size", 1, refs.size() );
+        assertEquals( "wrong ref", "TestPage2", (String)refs.iterator().next() );
+    }
+
+    public void testReferrerChangeCC()
+        throws Exception
+    {
+        m_engine.saveText("TestPage", "foofoo" );
+        m_engine.saveText("TestPage2", "TestPage");
+     
+        WikiPage p = m_engine.getPage("TestPage");
+     
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+     
+        m_engine.renamePage(context, "TestPage", "FooTest", true);
+     
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
+     
+        assertEquals( "no rename", "FooTest", data.trim() );
+        Collection refs = m_engine.getReferenceManager().findReferrers("TestPage");
+        
+        assertNull( "oldpage", refs );
+        
+        refs = m_engine.getReferenceManager().findReferrers( "FooTest" );
+        assertEquals( "new size", 1, refs.size() );
+        assertEquals( "wrong ref", "TestPage2", (String)refs.iterator().next() );
+    }
+    
+    public void testReferrerChangeAnchor()
+        throws Exception
+    {
+        m_engine.saveText("TestPage", "foofoo" );
+        m_engine.saveText("TestPage2", "[TestPage#heading1]");
+     
+        WikiPage p = m_engine.getPage("TestPage");
+     
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+     
+        m_engine.renamePage(context, "TestPage", "FooTest", true);
+     
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
+     
+        assertEquals( "no rename", "[FooTest#heading1]", data.trim() );
+        Collection refs = m_engine.getReferenceManager().findReferrers("TestPage");
+        
+        assertNull( "oldpage", refs );
+        
+        refs = m_engine.getReferenceManager().findReferrers( "FooTest" );
+        assertEquals( "new size", 1, refs.size() );
+        assertEquals( "wrong ref", "TestPage2", (String)refs.iterator().next() );
+    }
+    
+    public void testReferrerChangeMultilink()
+        throws Exception
+    {
+        m_engine.saveText("TestPage", "foofoo" );
+        m_engine.saveText("TestPage2", "[TestPage] [TestPage] [linktext|TestPage] TestPage [linktext|TestPage] [TestPage#Anchor] [TestPage] TestPage [TestPage]");
+     
+        WikiPage p = m_engine.getPage("TestPage");
+     
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+     
+        m_engine.renamePage(context, "TestPage", "FooTest", true);
+     
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
+     
+        assertEquals( "no rename", 
+                      "[FooTest] [FooTest] [linktext|FooTest] FooTest [linktext|FooTest] [FooTest#Anchor] [FooTest] FooTest [FooTest]", 
+                      data.trim() );
+
+        Collection refs = m_engine.getReferenceManager().findReferrers("TestPage");
+        
+        assertNull( "oldpage", refs );
+        
+        refs = m_engine.getReferenceManager().findReferrers( "FooTest" );
+        assertEquals( "new size", 1, refs.size() );
+        assertEquals( "wrong ref", "TestPage2", (String)refs.iterator().next() );
+    }
+    
+    public void testReferrerNoWikiName()
+        throws Exception
+    {
+        m_engine.saveText("Test","foo");
+        m_engine.saveText("TestPage2", "[Test] [Test#anchor] test Test [test] [link|test] [link|test]");
+        
+        WikiPage p = m_engine.getPage("TestPage");
+        
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+     
+        m_engine.renamePage(context, "Test", "TestPage", true);
+        
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION );
+        
+        assertEquals( "wrong data", "[TestPage] [TestPage#anchor] test Test [TestPage] [link|TestPage] [link|TestPage]", data.trim() );
+    }
+
+    public void testAttachmentChange()
+        throws Exception
+    {
+        m_engine.saveText("TestPage", "foofoo" );
+        m_engine.saveText("TestPage2", "[TestPage/foo.txt] [linktext|TestPage/bar.jpg]");
+ 
+        m_engine.addAttachment("TestPage", "foo.txt", "testing".getBytes() );
+        m_engine.addAttachment("TestPage", "bar.jpg", "pr0n".getBytes() );
+        WikiPage p = m_engine.getPage("TestPage");
+ 
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean(p);
+ 
+        m_engine.renamePage(context, "TestPage", "FooTest", true);
+ 
+        String data = m_engine.getPureText("TestPage2", WikiProvider.LATEST_VERSION);
+ 
+        assertEquals( "no rename", 
+                      "[FooTest/foo.txt] [linktext|FooTest/bar.jpg]", 
+                      data.trim() );
+
+        Attachment att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/foo.txt");
+        assertNotNull("footext",att);
+        
+        att = m_engine.getAttachmentManager().getAttachmentInfo("FooTest/bar.jpg");
+        assertNotNull("barjpg",att);
+        
+        att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/bar.jpg");
+        assertNull("testpage/bar.jpg exists",att);
+        
+        att = m_engine.getAttachmentManager().getAttachmentInfo("TestPage/foo.txt");
+        assertNull("testpage/foo.txt exists",att);
+        
+        Collection refs = m_engine.getReferenceManager().findReferrers("TestPage/bar.jpg");
+    
+        assertNull( "oldpage", refs );
+    
+        refs = m_engine.getReferenceManager().findReferrers( "FooTest/bar.jpg" );
+        assertEquals( "new size", 1, refs.size() );
+        assertEquals( "wrong ref", "TestPage2", (String)refs.iterator().next() );
+    }
+
+    public void testSamePage() throws Exception
+    {
+        m_engine.saveText( "TestPage", "[TestPage]");
+        
+        rename( "TestPage", "FooTest" );
+
+        WikiPage p = m_engine.getPage( "FooTest" );
+        
+        assertNotNull( "no page", p );
+        
+        assertEquals("[FooTest]", m_engine.getText("FooTest").trim() );
+    }
+
+    public void testBrokenLink1() throws Exception
+    {
+        m_engine.saveText( "TestPage", "hubbub");
+        m_engine.saveText( "TestPage2", "[TestPage|]" );
+        
+        rename( "TestPage", "FooTest" );
+
+        WikiPage p = m_engine.getPage( "FooTest" );
+        
+        assertNotNull( "no page", p );
+        
+        // Should be no change
+        assertEquals("[TestPage|]", m_engine.getText("TestPage2").trim() );
+    }
+
+    public void testBrokenLink2() throws Exception
+    {
+        m_engine.saveText( "TestPage", "hubbub");
+        m_engine.saveText( "TestPage2", "[|TestPage]" );
+        
+        WikiPage p;
+        rename( "TestPage", "FooTest" );
+
+        p = m_engine.getPage( "FooTest" );
+        
+        assertNotNull( "no page", p );
+        
+        assertEquals("[|FooTest]", m_engine.getText("TestPage2").trim() );
+    }
+
+    private void rename( String src, String dst ) throws WikiException
+    {
+        WikiPage p = m_engine.getPage(src);
+
+        WikiContext context = m_engine.getWikiActionBeanFactory().newViewActionBean( p );
+        
+        m_engine.renamePage(context, src, dst, true);
+    }
+
+    public void testBug25() throws Exception
+    {
+        String src = "[Cdauth/attach.txt] [link|Cdauth/attach.txt] [cdauth|Cdauth/attach.txt]"+
+                     "[CDauth/attach.txt] [link|CDauth/attach.txt] [cdauth|CDauth/attach.txt]"+
+                     "[cdauth/attach.txt] [link|cdauth/attach.txt] [cdauth|cdauth/attach.txt]";
+        
+        String dst = "[CdauthNew/attach.txt] [link|CdauthNew/attach.txt] [cdauth|CdauthNew/attach.txt]"+
+                     "[CDauth/attach.txt] [link|CDauth/attach.txt] [cdauth|CDauth/attach.txt]"+
+                     "[CdauthNew/attach.txt] [link|CdauthNew/attach.txt] [cdauth|CdauthNew/attach.txt]";
+        
+        m_engine.saveText( "Cdauth", "xxx" );
+        m_engine.saveText( "TestPage", src );
+        
+        m_engine.addAttachment( "Cdauth", "attach.txt", "Puppua".getBytes() );
+        
+        rename( "Cdauth", "CdauthNew" );
+        
+        assertEquals( dst, m_engine.getText("TestPage").trim() );
+    }
+    
+    public void testBug21() throws Exception
+    {
+        String src = "[Link to TestPage2|TestPage2]";
+        
+        m_engine.saveText( "TestPage", src );
+        m_engine.saveText( "TestPage2", "foo" );
+        
+        rename ("TestPage2", "Test");
+        
+        assertEquals( "[Link to Test|Test]", m_engine.getText( "TestPage" ).trim() );
+    }
+
+    public void testExtendedLinks() throws Exception
+    {
+        String src = "[Link to TestPage2|TestPage2|target='_new']";
+        
+        m_engine.saveText( "TestPage", src );
+        m_engine.saveText( "TestPage2", "foo" );
+        
+        rename ("TestPage2", "Test");
+        
+        assertEquals( "[Link to Test|Test|target='_new']", m_engine.getText( "TestPage" ).trim() );
+    }
+    
+    public void testBug85_case1() throws Exception 
+    {
+        // renaming a non-existing page
+        // This fails under 2.5.116, cfr. with http://bugs.jspwiki.org/show_bug.cgi?id=85
+        // m_engine.saveText( "TestPage", "blablahblahbla" );
+        try
+        {
+            rename("TestPage123", "Main8887");
+            rename("Main8887", "TestPage123"); 
+        }
+        catch (NullPointerException npe)
+        {
+            npe.printStackTrace();
+            System.out.println("NPE: Bug 85 caught?");
+            fail();
+        }
+    }
+    
+    public void testBug85_case2() throws Exception 
+    {
+        try
+        {
+            // renaming a non-existing page, but we call m_engine.saveText() before renaming 
+            // this does not fail under 2.5.116
+            m_engine.saveText( "TestPage1234", "blablahblahbla" );
+            rename("TestPage1234", "Main8887");
+            rename("Main8887", "TestPage1234");
+        }
+        catch (NullPointerException npe)
+        {
+            npe.printStackTrace();
+            System.out.println("NPE: Bug 85 caught?");
+            fail();
+        }
+    }
+    
+    public void testBug85_case3() throws Exception 
+    {
+        try
+        {
+            // renaming an existing page
+            // this does not fail under 2.5.116
+            // m_engine.saveText( "Main", "blablahblahbla" );
+            rename("Main", "Main8887");
+            rename("Main8887", "Main");
+        }
+        catch (NullPointerException npe)
+        {
+            npe.printStackTrace();
+            System.out.println("NPE: Bug 85 caught?");
+            fail();
+        }
+    }
+    
+    public void testBug85_case4() throws Exception 
+    {
+        try
+        {
+            // renaming an existing page, and we call m_engine.saveText() before renaming
+            // this does not fail under 2.5.116
+            m_engine.saveText( "Main", "blablahblahbla" );
+            rename("Main", "Main8887");
+            rename("Main8887", "Main");
+        }
+        catch (NullPointerException npe)
+        {
+            npe.printStackTrace();
+            System.out.println("NPE: Bug 85 caught?");
+            fail();
+        }
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite( PageRenamerTest.class );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PropertyReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PropertyReaderTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PropertyReaderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/PropertyReaderTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,95 @@
+package com.ecyrd.jspwiki;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class PropertyReaderTest extends TestCase
+{
+    public void testVariableExpansion()
+    {
+        Properties p = new Properties();
+        
+        p.put("var.basedir", "/p/mywiki");
+
+        p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/");
+        p.put("jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/");
+        p.put("jspwiki.workDir", "$basedir/wrk/");
+        p.put("jspwiki.xyz", "test basedir"); //don't touch this
+
+        PropertyReader.expandVars(p);
+        
+        assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.basicAttachmentProvider.storageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.workDir").endsWith("/p/mywiki/wrk/") );
+        assertTrue( p.getProperty("jspwiki.xyz").endsWith("test basedir") ); //don't touch this
+        
+        System.out.println(p.getProperty("jspwiki.workDir"));
+        
+        assertFalse( p.getProperty("jspwiki.workDir").endsWith("$basedir/wrk/") );
+    }
+
+    public void testVariableExpansion2()
+    {
+        Properties p = new Properties();
+        
+        //this time, declare the var at the end... (should overwrite this one);
+        p.put("var.basedir", "xxx");
+        
+        p.put("jspwiki.fileSystemProvider.pageDir", "$basedir/www/");
+        p.put("jspwiki.basicAttachmentProvider.storageDir", "$basedir/www/");
+        p.put("jspwiki.workDir", "$basedir/wrk/");
+        p.put("jspwiki.xyz", "test basedir"); //don't touch this
+        p.put("jspwiki.abc", "test $x2"); //don't touch this
+
+        p.put("var.basedir", " /p/mywiki"); //note that this var has a space at the beginning...
+        p.put("var.x2", " wiki "); //note that this var has a space at the beginning...
+        
+        PropertyReader.expandVars(p);
+        
+        assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.basicAttachmentProvider.storageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.fileSystemProvider.pageDir").equals("/p/mywiki/www/") );
+        assertTrue( p.getProperty("jspwiki.workDir").endsWith("/p/mywiki/wrk/") );
+        assertTrue( p.getProperty("jspwiki.xyz").endsWith("test basedir") ); //don't touch this
+        
+        //System.out.println(p.getProperty("jspwiki.abc"));
+        
+        assertFalse( p.getProperty("jspwiki.workDir").endsWith("$basedir/wrk/") );
+        assertTrue( p.getProperty("jspwiki.abc").endsWith("test wiki") );
+    }
+
+
+    
+    public void testMultipleVariableExpansion()
+    {
+        Properties p = new Properties();
+        
+        //this time, declare the var at the end... (should overwrite this one);
+        p.put("var.x1", "a");
+        p.put("var.x2", "b");
+        
+        p.put("jspwiki.x1", "$x1");
+        p.put("jspwiki.x2", "$x2");
+        p.put("jspwiki.x3", "$x1/$x2");
+        
+        PropertyReader.expandVars(p);
+        
+        //System.out.println(p.getProperty("jspwiki.x1"));
+        //System.out.println(p.getProperty("jspwiki.x2"));
+        //System.out.println(p.getProperty("jspwiki.x3"));
+        
+        assertTrue( p.getProperty("jspwiki.x1").equals("a") );
+        assertTrue( p.getProperty("jspwiki.x2").equals("b") );
+        assertTrue( p.getProperty("jspwiki.x3").equals("a/b") );
+    }
+
+    
+    public static Test suite()
+    {
+        return new TestSuite( PropertyReaderTest.class );
+    }
+}
\ No newline at end of file

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReferenceManagerTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,410 @@
+
+package com.ecyrd.jspwiki;
+
+import junit.framework.*;
+import java.util.*;
+import java.io.*;
+
+import com.ecyrd.jspwiki.providers.FileSystemProvider;
+
+/**
+ *  @author Torsten Hildebrandt.
+ */
+public class ReferenceManagerTest extends TestCase
+{
+    Properties props = new Properties();
+    TestEngine engine;
+    ReferenceManager mgr;
+    
+    public ReferenceManagerTest( String s )
+    {
+        super( s );
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+        props.setProperty( "jspwiki.translatorReader.matchEnglishPlurals", "true");
+
+        //
+        //  We must make sure that the reference manager cache is cleaned first.
+        //
+        String workDir = props.getProperty( "jspwiki.workDir" );
+
+        if( workDir != null )
+        {
+            File refmgrfile = new File( workDir, "refmgr.ser" );
+            if( refmgrfile.exists() ) refmgrfile.delete();
+        }
+
+        String fileDir = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+        
+        if( fileDir != null )
+        {
+            TestEngine.deleteAll( new File(fileDir) );
+        }
+        
+        engine = new TestEngine(props);
+
+        engine.saveText( "TestPage", "Reference to [Foobar]." );
+        engine.saveText( "Foobar", "Reference to [Foobar2], [Foobars], [Foobar]" );
+
+        mgr = engine.getReferenceManager();
+    }
+
+    public void tearDown()
+        throws Exception
+    {
+        engine.deletePage( "TestPage" );
+        engine.deletePage( "Foobar" );
+        engine.deletePage( "Foobars" );
+        engine.deletePage( "Foobar2" );
+        engine.deletePage( "Foobar2s" );
+        engine.deletePage( "BugCommentPreviewDeletesAllComments" );
+        engine.deletePage( "FatalBugs" );
+        engine.deletePage( "RandomPage" );
+        engine.deletePage( "NewBugs" );
+        engine.deletePage( "OpenBug" );
+        engine.deletePage( "OpenBugs" );
+        engine.deletePage( "NewBug" );
+        engine.deletePage( "BugOne" );
+        engine.deletePage( "BugTwo" );
+    }
+
+    public void testNonExistant1()
+        throws Exception
+    {
+        Collection c = mgr.findReferrers("Foobar2");
+        
+        assertTrue( c.size() == 1 && c.contains("Foobar") );
+    }
+    
+    public void testNonExistant2()
+    {
+        Collection c = mgr.findReferrers("TestBug");
+        
+        assertNull( c );
+    }
+    
+    public void testRemove()
+        throws Exception
+    {
+        Collection c = mgr.findReferrers("Foobar2");
+        
+        assertTrue( c.size() == 1 && c.contains("Foobar") );
+
+        engine.deletePage( "Foobar" );
+        
+        c = mgr.findReferrers("Foobar2");
+        
+        assertNull( c );
+        
+        engine.saveText( "Foobar", "[Foobar2]");
+        
+        c = mgr.findReferrers("Foobar2");
+        
+        assertTrue( c.size() == 1 && c.contains("Foobar") );        
+    }
+    
+    public void testUnreferenced()
+        throws Exception
+    {
+        Collection c = mgr.findUnreferenced();
+        assertTrue( "Unreferenced page not found by ReferenceManager",
+                    Util.collectionContains( c, "TestPage" ));
+    }
+
+
+    public void testBecomesUnreferenced()
+        throws Exception
+    {
+        engine.saveText( "Foobar2", "[TestPage]" );
+
+        Collection c = mgr.findUnreferenced();
+        assertEquals( "Wrong # of orphan pages, stage 1", 0, c.size() );
+
+        engine.saveText( "Foobar2", "norefs" );
+        c = mgr.findUnreferenced();
+        assertEquals( "Wrong # of orphan pages", 1, c.size() );
+
+        Iterator i = c.iterator();
+        String first = (String) i.next();
+        assertEquals( "Not correct referrers", "TestPage", first );
+    }
+
+    public void testUncreated()
+        throws Exception
+    {
+        Collection c = mgr.findUncreated();
+        
+        assertTrue( c.size()==1 && ((String) c.iterator().next()).equals("Foobar2") );
+    }
+
+    public void testReferrers()
+        throws Exception
+    {
+        Collection c = mgr.findReferrers( "TestPage" );
+        assertNull( "TestPage referrers", c );
+
+        c = mgr.findReferrers( "Foobar" );
+        assertTrue( "Foobar referrers", c.size()==1 && ((String) c.iterator().next()).equals("TestPage") );
+
+        c = mgr.findReferrers( "Foobar2" );
+        assertTrue( "Foobar2 referrers", c.size()==1 && ((String) c.iterator().next()).equals("Foobar") );
+
+        c = mgr.findReferrers( "Foobars" );
+        assertEquals( "Foobars referrers", 1, c.size() );
+        assertEquals( "Foobars referrer 'TestPage'", "TestPage", (String) c.iterator().next() );
+    }
+
+    public void testRefersTo()
+        throws Exception
+    {
+        Collection s = mgr.findRefersTo( "Foobar" );
+        
+        assertTrue( "does not have Foobar", s.contains("Foobar") );
+        // assertTrue( "does not have Foobars", s.contains("Foobars") );
+        assertTrue( "does not have Foobar2", s.contains("Foobar2") );
+    }
+    
+    /**
+     *  Should fail in 2.2.14-beta
+     * @throws Exception
+     */
+    public void testSingularReferences()
+    throws Exception
+    {
+        engine.saveText( "RandomPage", "FatalBugs" );
+        engine.saveText( "FatalBugs", "<foo>" );
+        engine.saveText( "BugCommentPreviewDeletesAllComments", "FatalBug" );
+        
+        Collection c = mgr.findReferrers( "FatalBugs" );
+        
+        assertEquals( "FatalBugs referrers number", 2, c.size()  );
+    }
+
+    /** 
+     *  Is a page recognized as referenced if only plural form links exist.
+     */
+
+    // NB: Unfortunately, cleaning out self-references in the case there's
+    //     a plural and a singular form of the page becomes nigh impossible, so we
+    //     just don't do it.
+    public void testUpdatePluralOnlyRef()
+        throws Exception
+    {
+        engine.saveText( "TestPage", "Reference to [Foobars]." );
+        Collection c = mgr.findUnreferenced();
+        assertTrue( "Foobar unreferenced", c.size()==1 && ((String) c.iterator().next()).equals("TestPage") );
+
+        c = mgr.findReferrers( "Foobar" );
+        Iterator it = c.iterator();
+        String s1 = (String)it.next();
+        assertTrue( "Foobar referrers", 
+                    c.size()==1 && 
+                    s1.equals("TestPage") );
+    }
+
+
+    /** 
+     *  Opposite to testUpdatePluralOnlyRef(). Is a page with plural form recognized as
+     *  the page referenced by a singular link.
+     */
+
+    public void testUpdateFoobar2s()
+        throws Exception
+    {
+        engine.saveText( "Foobar2s", "qwertz" );
+        assertTrue( "no uncreated", mgr.findUncreated().size()==0 );
+
+        Collection c = mgr.findReferrers( "Foobar2s" );
+        assertTrue( "referrers", c!=null && c.size()==1 && ((String) c.iterator().next()).equals("Foobar") );
+    }
+
+    public void testUpdateBothExist()
+        throws Exception
+    {
+        engine.saveText( "Foobars", "qwertz" );
+        Collection c = mgr.findReferrers( "Foobars" );
+        assertEquals( "Foobars referrers", 1, c.size() );
+        assertEquals( "Foobars referrer is not TestPage", "TestPage", ((String) c.iterator().next()) );
+    }
+
+    public void testUpdateBothExist2()
+        throws Exception
+    {
+        engine.saveText( "Foobars", "qwertz" );
+        engine.saveText( "TestPage", "Reference to [Foobar], [Foobars]." );
+        
+        Collection c = mgr.findReferrers( "Foobars" );
+        assertEquals( "Foobars referrers count", 1, c.size() );
+
+        Iterator i = c.iterator();
+        String first = (String) i.next();
+
+        assertTrue( "Foobars referrers", 
+                    first.equals("TestPage") );
+    }
+
+    public void testCircularRefs()
+        throws Exception
+    {
+        engine.saveText( "Foobar2", "ref to [TestPage]" );
+        
+        assertTrue( "no uncreated", mgr.findUncreated().size()==0 );
+        assertTrue( "no unreferenced", mgr.findUnreferenced().size()==0 );
+    }
+
+    public void testPluralSingularUpdate1()
+        throws Exception
+    {
+        engine.saveText( "BugOne", "NewBug" );
+        engine.saveText( "NewBugs", "foo" );
+        engine.saveText( "OpenBugs", "bar" );
+        
+        engine.saveText( "BugOne", "OpenBug" );
+        
+        Collection ref = mgr.findReferrers( "NewBugs" );
+        assertNull("newbugs",ref); // No referrers must be found
+
+        ref = mgr.findReferrers( "NewBug" );
+        assertNull("newbug",ref); // No referrers must be found
+
+        ref = mgr.findReferrers( "OpenBugs" );
+        assertEquals("openbugs",1,ref.size());
+        assertEquals("openbugs2","BugOne",ref.iterator().next());
+
+        ref = mgr.findReferrers( "OpenBug" );
+        assertEquals("openbug",1,ref.size());
+        assertEquals("openbug2","BugOne",ref.iterator().next());
+
+    }
+
+    public void testPluralSingularUpdate2()
+        throws Exception
+    {
+        engine.saveText( "BugOne", "NewBug" );
+        engine.saveText( "NewBug", "foo" );
+        engine.saveText( "OpenBug", "bar" );
+    
+        engine.saveText( "BugOne", "OpenBug" );
+    
+        Collection ref = mgr.findReferrers( "NewBugs" );
+        assertNull("newbugs",ref); // No referrers must be found
+
+        ref = mgr.findReferrers( "NewBug" );
+        assertNull("newbug",ref); // No referrers must be found
+
+        ref = mgr.findReferrers( "OpenBugs" );
+        assertEquals("openbugs",1,ref.size());
+        assertEquals("openbugs2","BugOne",ref.iterator().next());
+
+        ref = mgr.findReferrers( "OpenBug" );
+        assertEquals("openbug",1,ref.size());
+        assertEquals("openbug2","BugOne",ref.iterator().next());
+
+    }
+
+    public void testPluralSingularUpdate3()
+        throws Exception
+    {
+        engine.saveText( "BugOne", "NewBug" );
+        engine.saveText( "BugTwo", "NewBug" );
+        engine.saveText( "NewBugs", "foo" );
+        engine.saveText( "OpenBugs", "bar" );
+    
+        engine.saveText( "BugOne", "OpenBug" );
+    
+        Collection ref = mgr.findReferrers( "NewBugs" );
+        assertEquals("newbugs",1,ref.size()); 
+        assertEquals("newbugs2","BugTwo",ref.iterator().next()); 
+
+        ref = mgr.findReferrers( "NewBug" );
+        assertEquals("newbugs",1,ref.size()); 
+        assertEquals("newbugs2","BugTwo",ref.iterator().next()); 
+
+        ref = mgr.findReferrers( "OpenBugs" );
+        assertEquals("openbugs",1,ref.size());
+        assertEquals("openbugs2","BugOne",ref.iterator().next());
+
+        ref = mgr.findReferrers( "OpenBug" );
+        assertEquals("openbug",1,ref.size());
+        assertEquals("openbug2","BugOne",ref.iterator().next());
+
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( ReferenceManagerTest.class );
+    }
+    
+    public static void main(String[] args)
+    {
+        junit.textui.TestRunner.main( new String[] { ReferenceManagerTest.class.getName() } );
+    }
+    
+    
+    /**
+     * Test method: dumps the contents of  ReferenceManager link lists to stdout.
+     * This method is NOT synchronized, and should be used in testing
+     * with one user, one WikiEngine only.
+     */
+    public static String dumpReferenceManager( ReferenceManager rm )
+    {
+        StringBuffer buf = new StringBuffer();
+        try
+        {
+            buf.append( "================================================================\n" );
+            buf.append( "Referred By list:\n" );
+            Set keys = rm.getReferredBy().keySet();
+            Iterator it = keys.iterator();
+            while( it.hasNext() )
+            {
+                String key = (String) it.next();
+                buf.append( key + " referred by: " );
+                Set refs = (Set)rm.getReferredBy().get( key );
+                Iterator rit = refs.iterator();
+                while( rit.hasNext() )
+                {
+                    String aRef = (String)rit.next();
+                    buf.append( aRef + " " );
+                }
+                buf.append( "\n" );
+            }
+            
+            
+            buf.append( "----------------------------------------------------------------\n" );
+            buf.append( "Refers To list:\n" );
+            keys = rm.getRefersTo().keySet();
+            it = keys.iterator();
+            while( it.hasNext() )
+            {
+                String key = (String) it.next();
+                buf.append( key + " refers to: " );
+                Collection refs = (Collection)rm.getRefersTo().get( key );
+                if(refs != null)
+                {
+                    Iterator rit = refs.iterator();
+                    while( rit.hasNext() )
+                    {
+                        String aRef = (String)rit.next();
+                        buf.append( aRef + " " );
+                    }
+                    buf.append( "\n" );
+                }
+                else
+                    buf.append("(no references)\n");
+            }
+            buf.append( "================================================================\n" );
+        }
+        catch(Exception e)
+        {
+            buf.append("Problem in dump(): " + e + "\n" );
+        }
+        
+        return( buf.toString() );
+    }
+
+}
+

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReleaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReleaseTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReleaseTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/ReleaseTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,126 @@
+package com.ecyrd.jspwiki;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class ReleaseTest extends TestCase
+{
+    public void testNewer1()
+    {
+        assertTrue( Release.isNewerOrEqual("1.0.100") );
+    }
+
+    public void testNewer2()
+    {
+        assertTrue( Release.isNewerOrEqual("2.0.0-alpha") );
+    }
+    
+    public void testNewer3()
+    {
+        assertFalse( Release.isNewerOrEqual("10.0.0") );
+    }
+    
+    public void testNewer4()
+    {
+        assertTrue( Release.isNewerOrEqual(Release.VERSTR) );
+    }
+    
+    public void testNewer5()
+    {
+        String rel = Release.VERSION+"."+Release.REVISION+"."+(Release.MINORREVISION+1)+"-cvs";
+        
+        assertFalse( Release.isNewerOrEqual(rel) );
+    }
+
+    public void testNewer6()
+    {
+        String rel = null;
+        
+        if( Release.MINORREVISION != 0 )
+            rel = Release.VERSION+"."+Release.REVISION+"."+(Release.MINORREVISION-1)+"-cvs";
+        else
+            rel = Release.VERSION+"."+(Release.REVISION-1)+".9999"+"-cvs";            
+        
+        assertTrue( Release.isNewerOrEqual(rel) );
+    }
+
+    public void testNewer7()
+    {
+        String rel = Release.VERSION+"."+Release.REVISION;
+        
+        assertTrue( Release.isNewerOrEqual(rel) );
+    }
+
+    public void testNewer8()
+    {
+        String rel = Release.VERSION+"";
+        
+        assertTrue( Release.isNewerOrEqual(rel) );
+    }
+
+    public void testOlder1()
+    {
+        assertFalse( Release.isOlderOrEqual("1.0.100") );
+    }
+
+    public void testOlder2()
+    {
+        assertFalse( Release.isOlderOrEqual("2.0.0-alpha") );
+    }
+    
+    public void testOlder3()
+    {
+        assertTrue( Release.isOlderOrEqual("10.0.0") );
+    }
+    
+    public void testOlder4()
+    {
+        assertTrue( Release.isOlderOrEqual(Release.VERSTR) );
+    }
+    
+    public void testOlder5()
+    {
+        String rel = Release.VERSION+"."+Release.REVISION+"."+(Release.MINORREVISION+1)+"-cvs";
+        
+        assertTrue( Release.isOlderOrEqual(rel) );
+    }
+
+    public void testOlder6()
+    {
+        String rel;
+        
+        if( Release.MINORREVISION != 0 )
+            rel = Release.VERSION+"."+Release.REVISION+"."+(Release.MINORREVISION-1)+"-cvs";
+        else
+            rel = Release.VERSION+"."+(Release.REVISION-1)+".9999"+"-cvs";   
+        
+        assertFalse( Release.isOlderOrEqual(rel) );
+    }
+
+    public void testOlder7()
+    {
+        String rel = Release.VERSION+"."+Release.REVISION;
+        
+        assertTrue( Release.isOlderOrEqual(rel) );
+    }
+
+    public void testOlder8()
+    {
+        String rel = Release.VERSION+"";
+        
+        assertTrue( Release.isOlderOrEqual(rel) );
+    }
+
+    public void testOlder9()
+    {
+        String rel = "";
+        
+        assertTrue( Release.isOlderOrEqual(rel) );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( ReleaseTest.class );
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestAuthorizer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestAuthorizer.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestAuthorizer.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestAuthorizer.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,81 @@
+/*
+ * (C) Janne Jalkanen 2005
+ * 
+ */
+package com.ecyrd.jspwiki;
+
+import java.security.Principal;
+import java.util.Properties;
+
+import javax.servlet.http.HttpServletRequest;
+
+import com.ecyrd.jspwiki.auth.authorize.Role;
+import com.ecyrd.jspwiki.auth.authorize.WebAuthorizer;
+
+/**
+ * A very fast authorizer that does almost nothing. The WebContainerAuthorizer module
+ * is very slow, as it parses the web.xml each time, so we use this for most of
+ * the different tests.
+ * @author Janne Jalkanen
+ * @author Andrew R. Jaquith
+ * @since 2.3
+ */
+public class TestAuthorizer implements WebAuthorizer
+{
+    private Role[] m_roles = new Role[]{ 
+            new Role( "Admin" ), 
+            Role.AUTHENTICATED,
+            new Role( "IT" ),
+            new Role( "Finance" ),
+            new Role( "Engineering" ) };
+    
+    public TestAuthorizer()
+    {
+        super();
+    }
+
+    public Principal findRole( String role )
+    {
+        return null;
+    }
+
+    public void initialize( WikiEngine engine, Properties props )
+    {
+    }
+
+    /**
+     * Returns an array of Principal objects containing five elements:
+     * Role "Admin", Role.AUTHENTICATED, Role "IT", Role "Finance" and 
+     * Role "Engineering."
+     */
+    public Principal[] getRoles()
+    {
+        return (Principal[])m_roles.clone();
+    }
+    
+    /**
+     * Returns <code>true</code> if the WikiSession's Subject contains 
+     * a particular role principal.
+     */
+    public boolean isUserInRole( WikiSession session, Principal role )
+    {
+        if ( session == null || role == null )
+        {
+            return false;
+        }
+        
+        return session.hasPrincipal( role );
+    }
+
+    /**
+     * Returns <code>true</code> if the HTTP request contains 
+     * a particular role principal. Delegates to
+     * {@link javax.servlet.http.HttpServletRequest#isUserInRole(String)}.
+     * @see com.ecyrd.jspwiki.auth.authorize.WebAuthorizer#isUserInRole(javax.servlet.http.HttpServletRequest, java.security.Principal)
+     */
+    public boolean isUserInRole( HttpServletRequest request, Principal role )
+    {
+        return request.isUserInRole( role.getName() );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestEngine.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestEngine.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestEngine.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,437 @@
+
+package com.ecyrd.jspwiki;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.io.*;
+
+import net.sourceforge.stripes.controller.DispatcherServlet;
+import net.sourceforge.stripes.controller.StripesFilter;
+import net.sourceforge.stripes.mock.MockHttpServletRequest;
+import net.sourceforge.stripes.mock.MockRoundtrip;
+import net.sourceforge.stripes.mock.MockServletContext;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.action.ViewActionBean;
+import com.ecyrd.jspwiki.action.WikiActionBean;
+import com.ecyrd.jspwiki.action.WikiActionBeanContext;
+import com.ecyrd.jspwiki.attachment.Attachment;
+import com.ecyrd.jspwiki.auth.Users;
+import com.ecyrd.jspwiki.auth.WikiSecurityException;
+import com.ecyrd.jspwiki.providers.*;
+
+/**
+ *  <p>Simple test engine that always assumes pages are found. The version of TestEngine that is part of JSPWiki 3.0
+ *  differs slightly from earlier versions. In particular, it integrates the Stripes framework's mock objects to simulate
+ *  servlet testing.</p>
+ *  <p>Because of its use of Stripes mock objects, TestEngine needs to be able to find the various ActionBean
+ *  implementations provided in JSPWiki. Therefore, it is <em>extremely</em> sensitive to changes in the build
+ *  path. In particular, the mock servlet filter used by TestEngine hard-wires in the relative location
+ *  <code>build</code> for finding ActionBeans. This is the directory (relative to the project root) that the
+ *  Ant build scripts use for placing generated Java class files. The Eclipse project configuration must configure
+ *  itself the same way. To run unit tests in Eclipse, the <code>build</code> directory absolutely <em>must</em>
+ *  place generated class files in this directory, rather than the Eclipse default of <code>classes</code>. If
+ *  unit tests do not run in Eclipse for some reason, this is the likeliest culprit.
+ */
+public class TestEngine extends WikiEngine
+{
+    static Logger log = Logger.getLogger( TestEngine.class );
+
+    /**
+     * Creates WikiSession with the privileges of the administrative user.
+     * For testing purposes, obviously.
+     * @return the wiki session
+     */
+    public WikiSession adminSession() throws WikiSecurityException
+    {
+        MockHttpServletRequest request = guestTrip( ViewActionBean.class ).getRequest();
+        WikiSession session = WikiSession.getWikiSession( this, request );
+        this.getAuthenticationManager().login( session, Users.ADMIN, Users.ADMIN_PASS );
+        return session;
+    }
+
+    /**
+     * Creates guest WikiSession with the no privileges.
+     * For testing purposes, obviously.
+     * @return the wiki session
+     */
+    public WikiSession guestSession()
+    {
+        MockHttpServletRequest request = guestTrip( ViewActionBean.class ).getRequest();
+        return WikiSession.getWikiSession( this, request );
+    }
+   
+    /**
+     * Creates a "round trip" object initialized with a supplied set of credentials. The WikiSession
+     * associated with the created MockRoundtrip object will have privileges appropriate for
+     * the credentials supplied.
+     * @param user the login name
+     * @param password the password
+     * @param beanClass the Stripes action bean to start with
+     * @return the initialized round trip
+     * @throws WikiSecurityException
+     */
+    public MockRoundtrip authenticatedTrip( String user, String password, Class<? extends WikiActionBean> beanClass ) throws WikiSecurityException
+    {
+        MockRoundtrip trip = new MockRoundtrip( getServletContext(), beanClass );
+        MockHttpServletRequest request = trip.getRequest();
+        WikiSession session = WikiSession.getWikiSession( this, request);
+        this.getAuthenticationManager().login( session, Users.ADMIN, Users.ADMIN_PASS );
+        return trip;
+    }
+    
+    /**
+     * Creates a guest "round trip" object that initializes itself with the TestEngine's mock servlet context,
+     * plus a new mock request, mock response and action bean of type {@link com.ecyrd.jspwiki.action.ViewActionBean}.
+     * This method is the preferred way to instantiate request and response objects, which can be
+     * obtained by calling {@link net.sourceforge.stripes.mock.MockRoundtrip#getRequest()} and
+     * {@link net.sourceforge.stripes.mock.MockRoundtrip#getResponse()}.
+     * @param beanClass the Stripes action bean to start with
+     * @return the mock rountrip
+     */
+    public MockRoundtrip guestTrip( Class<? extends WikiActionBean> beanClass )
+    {
+        return new MockRoundtrip( getServletContext(), beanClass );
+    }
+
+    /**
+     * Creates WikiSession with the privileges of the Janne.
+     * For testing purposes, obviously.
+     * @return the wiki session
+     */
+    public WikiSession janneSession() throws WikiSecurityException
+    {
+        MockHttpServletRequest request = guestTrip( ViewActionBean.class ).getRequest();
+        request = guestTrip( ViewActionBean.class ).getRequest();
+        WikiSession session = WikiSession.getWikiSession( this, request );
+        this.getAuthenticationManager().login( session, Users.JANNE, Users.JANNE_PASS );
+        return session;
+    }
+
+    public TestEngine( Properties props )
+        throws WikiException
+    {
+        super( newServletContext( "test" ) , "test", props );
+        
+        // Stash the WikiEngine in the servlet context
+        MockServletContext servletContext = this.getServletContext();
+        servletContext.setAttribute("com.ecyrd.jspwiki.WikiEngine", this);
+    
+        // Add our preferred Stripes startup parameters
+        Map<String, String> filterParams = new HashMap<String, String>();
+        filterParams.put("Configuration.Class", "com.ecyrd.jspwiki.ui.WikiRuntimeConfiguration");
+        filterParams.put("ActionResolver.UrlFilters", "build/");
+        filterParams.put("ActionResolver.PackageFilters", "com.ecyrd.jspwiki");
+        filterParams.put("ActionBeanContext.Class", "com.ecyrd.jspwiki.action.WikiActionBeanContext");
+        filterParams.put("Interceptor.Classes", "com.ecyrd.jspwiki.ui.WikiInterceptor,net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor");
+        filterParams.put("ExceptionHandler.Class", "net.sourceforge.stripes.exception.DefaultExceptionHandler");
+        
+        // Add a captive Stripes Filter and Stripes Dispatcher to the servlet context
+        servletContext.addFilter(StripesFilter.class, "StripesFilter", filterParams);
+        servletContext.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
+    }
+
+    /**
+     * Creates a mock servlet context used to initialize the test WikiEngine.
+     * @return the initialized servlet context
+     */
+    private static MockServletContext newServletContext( String name )
+    {
+        MockServletContext servletContext = new MockServletContext( name );
+        return servletContext;
+    }
+    
+    public static void emptyPageDir()
+    {
+        Properties properties = new Properties();
+
+        try
+        {
+            properties.load( findTestProperties() );
+
+            String pagedir = properties.getProperty( AbstractFileProvider.PROP_PAGEDIR );
+            if( pagedir != null )
+            {
+                File f = new File( pagedir );
+
+                if( f.exists() && f.isDirectory() )
+                {
+                    deleteAll( f );
+                }
+            }
+        }
+        catch( IOException e ) {} // Fine
+    }
+
+    public static void emptyWorkDir()
+    {
+        Properties properties = new Properties();
+
+        try
+        {
+            properties.load( findTestProperties() );
+
+            String workdir = properties.getProperty( WikiEngine.PROP_WORKDIR );
+            if( workdir != null )
+            {
+                File f = new File( workdir );
+
+                if( f.exists() && f.isDirectory() && new File( f, "refmgr.ser" ).exists() )
+                {
+                    deleteAll( f );
+                }
+            }
+        }
+        catch( IOException e ) {} // Fine
+    }
+
+    public static final InputStream findTestProperties()
+    {
+        return findTestProperties( "/jspwiki.properties" );
+    }
+
+    public static final InputStream findTestProperties( String properties )
+    {
+        InputStream in = TestEngine.class.getResourceAsStream( properties );
+
+        if( in == null ) throw new InternalWikiException("Unable to locate test property resource: "+properties);
+
+        return in;
+    }
+
+    /**
+     *  Deletes all files under this directory, and does them recursively.
+     */
+    public static void deleteAll( File file )
+    {
+        if( file != null )
+        {
+            if( file.isDirectory() )
+            {
+                File[] files = file.listFiles();
+
+                if( files != null )
+                {
+                    for( int i = 0; i < files.length; i++ )
+                    {
+                        if( files[i].isDirectory() )
+                        {
+                            deleteAll(files[i]);
+                        }
+
+                        files[i].delete();
+                    }
+                }
+            }
+
+            file.delete();
+        }
+    }
+
+    /**
+     *  Copied from FileSystemProvider
+     */
+    protected static String mangleName( String pagename )
+        throws IOException
+    {
+        Properties properties = new Properties();
+        String m_encoding = properties.getProperty( WikiEngine.PROP_ENCODING,
+                                                    AbstractFileProvider.DEFAULT_ENCODING );
+
+        pagename = TextUtil.urlEncode( pagename, m_encoding );
+        pagename = TextUtil.replaceString( pagename, "/", "%2F" );
+        return pagename;
+    }
+
+    /**
+     *  Removes a page, but not any auxiliary information.  Works only
+     *  with FileSystemProvider.
+     */
+    public static void deleteTestPage( String name )
+    {
+        Properties properties = new Properties();
+
+        try
+        {
+            properties.load( findTestProperties() );
+            String files = properties.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+            File f = new File( files, mangleName(name)+FileSystemProvider.FILE_EXT );
+
+            f.delete();
+
+            // Remove the property file, too
+            f = new File( files, mangleName(name)+".properties" );
+
+            if( f.exists() )
+                f.delete();
+        }
+        catch( Exception e )
+        {
+            log.error("Couldn't delete "+name, e );
+        }
+    }
+
+    /**
+     *  Deletes all attachments related to the given page.
+     */
+    public void deleteAttachments( String page )
+    {
+        try
+        {
+            String files = getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );
+
+            File f = new File( files, TextUtil.urlEncodeUTF8( page ) + BasicAttachmentProvider.DIR_EXTENSION );
+
+            deleteAll( f );
+        }
+        catch( Exception e )
+        {
+            log.error("Could not remove attachments.",e);
+        }
+    }
+
+    /**
+     *  Makes a temporary file with some content, and returns a handle to it.
+     */
+    public File makeAttachmentFile()
+        throws Exception
+    {
+        File tmpFile = File.createTempFile("test","txt");
+        tmpFile.deleteOnExit();
+
+        FileWriter out = new FileWriter( tmpFile );
+
+        FileUtil.copyContents( new StringReader( "asdfa???dfzbvasdjkfbwfkUg783gqdwog" ), out );
+
+        out.close();
+
+        return tmpFile;
+    }
+
+    /**
+     *  Adds an attachment to a page for testing purposes.
+     * @param pageName
+     * @param attachmentName
+     * @param data
+     */
+    public void addAttachment( String pageName, String attachmentName, byte[] data )
+        throws ProviderException, IOException
+    {
+        Attachment att = new Attachment(this,pageName,attachmentName);
+
+        getAttachmentManager().storeAttachment(att, new ByteArrayInputStream(data));
+    }
+
+    /**
+     * Convenience method that saves a wiki page by constructing a fake
+     * WikiContext and HttpServletRequest. We always want to do this using a
+     * WikiContext whose subject contains Role.ADMIN.
+     * @param pageName
+     * @param content
+     * @throws WikiException
+     */
+    public void saveText( String pageName, String content )
+        throws WikiException
+    {
+        // Build new request and associate our admin session
+        MockRoundtrip trip = guestTrip( ViewActionBean.class );
+        MockHttpServletRequest request = trip.getRequest();
+        WikiSession session = WikiSession.getWikiSession( this, request );
+        this.getAuthenticationManager().login( session, Users.ADMIN, Users.ADMIN_PASS );
+
+        // Create page and wiki context
+        WikiPage page = new WikiPage( this, pageName );
+        WikiContext context = this.getWikiActionBeanFactory().newViewActionBean( trip.getRequest(), trip.getResponse(), page );
+        saveText( context, content );
+    }
+
+    public void saveTextAsJanne( String pageName, String content )
+        throws WikiException
+    {
+        // Build new request and associate our Janne session
+        MockRoundtrip trip = guestTrip( ViewActionBean.class );
+        MockHttpServletRequest request = trip.getRequest();
+        WikiSession session = WikiSession.getWikiSession( this, request );
+        this.getAuthenticationManager().login( session, Users.JANNE, Users.JANNE_PASS );
+
+        // Create page and wiki context
+        WikiPage page = new WikiPage( this, pageName );
+        WikiContext context = this.getWikiActionBeanFactory().newViewActionBean( trip.getRequest(), trip.getResponse(), page );
+        saveText( context, content );
+    }
+
+    /**
+     *  Returns the converted HTML of the page using a different
+     *  context than the default context.
+     *
+     *  @param  context A WikiContext in which you wish to render this page in.
+     *  @param  page WikiPage reference.
+     *  @return HTML-rendered version of the page.
+     */
+    @Override
+    public String getHTML( WikiContext context, WikiPage page )
+    {
+        // If needed, inject a mock request/response into the ActionBeanContext
+        WikiActionBeanContext wac = context.getContext();
+        if ( wac.getRequest() == null || wac.getResponse() == null )
+        {
+            MockRoundtrip trip = guestTrip( context.getClass() );
+            wac.setRequest( trip.getRequest() );
+            wac.setResponse( trip.getResponse() );
+        }
+        return super.getHTML( context, page );
+    }
+
+    /**
+     *  Returns the converted HTML of the page.
+     *
+     *  @param page WikiName of the page to convert.
+     *  @return HTML-rendered version of the page.
+     */
+    @Override
+    public String getHTML( String page )
+    {
+        return getHTML( page, WikiPageProvider.LATEST_VERSION );
+    }
+
+    /**
+     *  Returns the converted HTML of the page's specific version.
+     *  The version must be a positive integer, otherwise the current
+     *  version is returned.
+     *
+     *  @param pagename WikiName of the page to convert.
+     *  @param version Version number to fetch
+     *  @return HTML-rendered page text.
+     */
+    @Override
+    public String getHTML( String pagename, int version )
+    {
+        WikiPage page = getPage( pagename, version );
+
+        WikiContext context = getWikiActionBeanFactory().newViewActionBean( page );
+
+        String res = getHTML( context, page );
+
+        return res;
+    }
+    
+    @Override
+    public MockServletContext getServletContext()
+    {
+        return (MockServletContext)super.getServletContext();
+    }
+
+    public static void trace()
+    {
+        try
+        {
+            throw new Exception("Foo");
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+        }
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJDBCDataSource.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJDBCDataSource.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJDBCDataSource.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/TestJDBCDataSource.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,164 @@
+package com.ecyrd.jspwiki;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+/**
+ * Mock JDBC DataSource class that manages JDBC connections to a database whose
+ * driver class, JDBC JAR location and connection details are specified in an
+ * arbitrary propreties file. Gemerally, we pass on any exceptions encountered
+ * as unchecked, since it means that the test case that references this class is
+ * failing somehow.
+ * @author Andrew R. Jaquith
+ */
+public class TestJDBCDataSource implements DataSource
+{
+    private static Driver       m_driver;
+
+    protected static final String PROPERTY_DRIVER_CLASS  = "jdbc.driver.class";
+
+    protected static final String PROPERTY_DRIVER_JAR    = "jdbc.driver.jar";
+
+    protected static final String PROPERTY_DRIVER_URL    = "jdbc.driver.url";
+
+    protected static final String PROPERTY_USER_ID       = "jdbc.user.id";
+
+    protected static final String PROPERTY_USER_PASSWORD = "jdbc.user.password";
+
+    protected String              m_jdbcPassword         = null;
+
+    protected String              m_jdbcURL              = null;
+
+    protected String              m_jdbcUser             = null;
+
+    protected int                 m_timeout              = 0;
+
+    protected PrintWriter         m_writer               = null;
+
+    /**
+     * Constructs a new instance of this class, using a supplied properties
+     * File as the source for JDBC driver properties.
+     * @param file the properties file containing JDBC properties
+     * @throws Exception
+     */
+    public TestJDBCDataSource( File file ) throws Exception
+    {
+        super();
+        initializeJDBC( file );
+    }
+
+    /**
+     * Returns a JDBC connection using the specified username and password.
+     * @return the database connection
+     * @see javax.sql.DataSource#getConnection()
+     */
+    public Connection getConnection() throws SQLException
+    {
+        return getConnection( m_jdbcUser, m_jdbcPassword );
+    }
+
+    /**
+     * Returns a JDBC connection to the database.
+     * @return the database connection
+     * @see javax.sql.DataSource#getConnection(java.lang.String,
+     * java.lang.String)
+     */
+    public Connection getConnection( String username, String password ) throws SQLException
+    {
+        Properties connProperties = new Properties();
+        connProperties.put( "user", m_jdbcUser );
+        connProperties.put( "password", m_jdbcPassword );
+        Connection connection = m_driver.connect( m_jdbcURL, connProperties );
+        return connection;
+    }
+
+    /**
+     * Returns the login timeout for the data source.
+     * @return the login timeout, in seconds
+     * @see javax.sql.DataSource#getLoginTimeout()
+     */
+    public int getLoginTimeout() throws SQLException
+    {
+        return m_timeout;
+    }
+
+    /**
+     * Returns the log writer for the data source.
+     * @return the log writer
+     * @see javax.sql.DataSource#getLogWriter()
+     */
+    public PrintWriter getLogWriter() throws SQLException
+    {
+        return m_writer;
+    }
+
+    /**
+     * Sets the login timeout for the data source. Doesn't do anything, really.
+     * @param seconds the login timeout, in seconds
+     * @see javax.sql.DataSource#setLoginTimeout(int)
+     */
+    public void setLoginTimeout( int seconds ) throws SQLException
+    {
+        this.m_timeout = seconds;
+    }
+
+    /**
+     * Sets the log writer for the data source. Isn't used for anything, really.
+     * @param out the log writer
+     * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter)
+     */
+    public void setLogWriter( PrintWriter out ) throws SQLException
+    {
+        this.m_writer = out;
+    }
+
+    /**
+     * Initialization method that reads a File, and attempts to locate and load
+     * the JDBC driver from properties specified therein.
+     * @throws SQLException
+     * @param file the file containing the JDBC properties
+     */
+    protected void initializeJDBC( File file ) throws Exception
+    {
+        // Load the properties JDBC properties file
+        Properties properties;
+        properties = new Properties();
+        FileInputStream is = new FileInputStream( file );
+        properties.load( is );
+        is.close();
+        m_jdbcURL = properties.getProperty( PROPERTY_DRIVER_URL );
+        m_jdbcUser = properties.getProperty( PROPERTY_USER_ID );
+        m_jdbcPassword = properties.getProperty( PROPERTY_USER_PASSWORD );
+
+        // Identifiy the class and JAR we need to load
+        String clazz = properties.getProperty( PROPERTY_DRIVER_CLASS );
+        String driverFile = properties.getProperty( PROPERTY_DRIVER_JAR );
+
+        // Construct an URL for loading the file
+        final URL driverURL = new URL( "file:" + driverFile );
+
+        // Load the driver using the sytem class loader
+        final ClassLoader parent = ClassLoader.getSystemClassLoader();
+        URLClassLoader loader = (URLClassLoader)AccessController.doPrivileged( new PrivilegedAction() {
+            public Object run() {
+                return new URLClassLoader( new URL[] { driverURL }, parent );
+            }
+        });
+        Class driverClass = loader.loadClass( clazz );
+
+        // Cache the driver
+        m_driver = (Driver) driverClass.newInstance();
+    }
+
+}