jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r627271 [6/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/
Date Wed, 13 Feb 2008 06:24:06 GMT
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/PagePermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/PagePermissionTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/PagePermissionTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/PagePermissionTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,351 @@
+package com.ecyrd.jspwiki.auth.permissions;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Andrew R. Jaquith
+ */
+public class PagePermissionTest extends TestCase
+{
+
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( PagePermissionTest.class );
+    }
+
+    /*
+     * Class under test for boolean equals(java.lang.Object)
+     */
+    public final void testEqualsObject()
+    {
+        PagePermission p1 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        PagePermission p2 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        PagePermission p3 = new PagePermission( "mywiki:Main", "delete,view,edit" );
+        PagePermission p4 = new PagePermission( "mywiki:Main*", "delete,view,edit" );
+        assertEquals( p1, p2 );
+        assertEquals( p1, p3 );
+        assertFalse( p3.equals( p4 ) );
+    }
+
+    public final void testCreateMask()
+    {
+        assertEquals( 1, PagePermission.createMask( "view" ) );
+        assertEquals( 19, PagePermission.createMask( "view,edit,delete" ) );
+        assertEquals( 19, PagePermission.createMask( "edit,delete,view" ) );
+        assertEquals( 14, PagePermission.createMask( "edit,comment,upload" ) );
+    }
+
+    /*
+     * Class under test for java.lang.String toString()
+     */
+    public final void testToString()
+    {
+        PagePermission p;
+        p = new PagePermission( "Main", "view,edit,delete" );
+        assertEquals( "(\"com.ecyrd.jspwiki.auth.permissions.PagePermission\",\":Main\",\"delete,edit,view\")", p
+                .toString() );
+        p = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        assertEquals( "(\"com.ecyrd.jspwiki.auth.permissions.PagePermission\",\"mywiki:Main\",\"delete,edit,view\")", p
+                .toString() );
+    }
+
+    /**
+     * Tests wiki name support.
+     */
+    public final void testWikiNames()
+    {
+        PagePermission p1;
+        PagePermission p2;
+
+        // Permissions without prepended wiki name should never imply themselves
+        // or others
+        p1 = new PagePermission( "Main", "edit" );
+        p2 = new PagePermission( "Main", "edit" );
+        assertFalse( p1.implies( p1 ) );
+        assertFalse( p1.implies( p2 ) );
+
+        // Permissions with a wildcard wiki should imply other wikis
+        p1 = new PagePermission( "*:Main", "edit" );
+        p2 = new PagePermission( "mywiki:Main", "edit" );
+        assertTrue( p1.implies( p2 ) );
+        assertFalse( p2.implies( p1 ) );
+
+        // Permissions that start with ":" are just like null
+        p1 = new PagePermission( ":Main", "edit" );
+        p2 = new PagePermission( "Main", "edit" );
+        assertFalse( p1.implies( p1 ) );
+        assertFalse( p1.implies( p2 ) );
+    }
+
+    public final void testImpliesAttachments()
+    {
+        PagePermission p1;
+        PagePermission p2;
+        
+        // A page should imply its attachment and vice-versa
+        p1 = new PagePermission( "mywiki:Main", "view" );
+        p2 = new PagePermission( "mywiki:Main/test.png", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p2.implies( p1 ) );
+    }
+    
+    /*
+     * Class under test for boolean implies(java.security.Permission)
+     */
+    public final void testImpliesPermission()
+    {
+        PagePermission p1;
+        PagePermission p2;
+        PagePermission p3;
+
+        // The same permission should imply itself
+        p1 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        p2 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p2.implies( p1 ) );
+
+        // The same permission should imply itself for wildcard wikis
+        p1 = new PagePermission( "Main", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view,edit,delete" );
+        p3 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        assertFalse( p1.implies( p2 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p1.implies( p3 ) );
+        assertTrue( p2.implies( p3 ) );
+        assertFalse( p3.implies( p1 ) );
+        assertFalse( p3.implies( p2 ) );
+
+        // Actions on collection should imply permission for page with same
+        // actions
+        p1 = new PagePermission( "*:*", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view,edit,delete" );
+        p3 = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertTrue( p2.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Actions on single page should imply subset of those actions
+        p1 = new PagePermission( "*:Main", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+        assertFalse( p3.implies( p2 ) );
+
+        // Actions on collection should imply subset of actions on single page
+        p1 = new PagePermission( "*:*", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p1 = new PagePermission( "*:Mai*", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p1 = new PagePermission( "*:*in", "view,edit,delete" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Delete action on collection should imply modify/edit/upload/comment/view on
+        // single page
+        p1 = new PagePermission( "*:*in", "delete" );
+        p2 = new PagePermission( "*:Main", "edit" );
+        p3 = new PagePermission( "mywiki:Main", "edit" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p2 = new PagePermission( "*:Main", "modify" );
+        p3 = new PagePermission( "mywiki:Main", "modify" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+        
+        p2 = new PagePermission( "*:Main", "upload" );
+        p3 = new PagePermission( "mywiki:Main", "upload" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p2 = new PagePermission( "*:Main", "comment" );
+        p3 = new PagePermission( "mywiki:Main", "comment" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Rename action on collection should imply edit on single page
+        p1 = new PagePermission( "*:*in", "rename" );
+        p2 = new PagePermission( "*:Main", "edit" );
+        p3 = new PagePermission( "mywiki:Main", "edit" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Modify action on collection should imply upload/comment/view on single
+        // page
+        p1 = new PagePermission( "*:*in", "modify" );
+        p2 = new PagePermission( "*:Main", "upload" );
+        p3 = new PagePermission( "mywiki:Main", "upload" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p2 = new PagePermission( "*:Main", "comment" );
+        p3 = new PagePermission( "mywiki:Main", "comment" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Upload action on collection should imply view on single page
+        p1 = new PagePermission( "*:*in", "upload" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Comment action on collection should imply view on single page
+        p1 = new PagePermission( "*:*in", "comment" );
+        p2 = new PagePermission( "*:Main", "view" );
+        p3 = new PagePermission( "mywiki:Main", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // View action on wildcard collection SHOULD imply view on
+        // GroupConfiguration page
+        p1 = new PagePermission( "*:*", "view" );
+        p2 = new PagePermission( "*:GroupConfiguration", "view" );
+        p3 = new PagePermission( "mywiki:GroupConfiguration", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        // Pre- and post- wildcards should also be fine
+        p1 = new PagePermission( "*:Group*", "view" );
+        p2 = new PagePermission( "*:GroupConfiguration", "view" );
+        p3 = new PagePermission( "mywiki:GroupConfiguration", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+
+        p1 = new PagePermission( "*:*Configuration", "view" );
+        p2 = new PagePermission( "*:GroupConfiguration", "view" );
+        p3 = new PagePermission( "mywiki:GroupConfiguration", "view" );
+        assertTrue( p1.implies( p2 ) );
+        assertTrue( p1.implies( p3 ) );
+        assertFalse( p2.implies( p1 ) );
+        assertFalse( p3.implies( p1 ) );
+    }
+    
+    public final void testImplies()
+    {
+        assertFalse(PagePermission.RENAME.implies( PagePermission.MODIFY ) );
+        assertTrue( PagePermission.RENAME.implies( PagePermission.EDIT ) );
+        assertFalse(PagePermission.RENAME.implies( PagePermission.UPLOAD ) );
+        assertTrue( PagePermission.RENAME.implies( PagePermission.COMMENT ) );
+        assertTrue( PagePermission.RENAME.implies( PagePermission.VIEW ) );
+        
+        assertTrue( PagePermission.DELETE.implies( PagePermission.MODIFY ) );
+        assertTrue( PagePermission.DELETE.implies( PagePermission.EDIT ) );
+        assertTrue( PagePermission.DELETE.implies( PagePermission.UPLOAD ) );
+        assertTrue( PagePermission.DELETE.implies( PagePermission.COMMENT ) );
+        assertTrue( PagePermission.DELETE.implies( PagePermission.VIEW ) );
+        
+        assertTrue( PagePermission.MODIFY.implies( PagePermission.EDIT ) );
+        assertTrue( PagePermission.MODIFY.implies( PagePermission.UPLOAD ) );
+        assertTrue( PagePermission.MODIFY.implies( PagePermission.COMMENT ) );
+        assertTrue( PagePermission.MODIFY.implies( PagePermission.VIEW ) );
+        
+        assertTrue( PagePermission.EDIT.implies( PagePermission.VIEW ) );
+        assertTrue( PagePermission.EDIT.implies( PagePermission.COMMENT ) );
+        
+        assertTrue( PagePermission.UPLOAD.implies( PagePermission.VIEW ) );
+        
+        assertTrue( PagePermission.COMMENT.implies( PagePermission.VIEW ) );
+    }
+
+    public final void testImpliedMask()
+    {
+        int result = ( PagePermission.DELETE_MASK | PagePermission.MODIFY_MASK | PagePermission.EDIT_MASK 
+                | PagePermission.COMMENT_MASK | PagePermission.UPLOAD_MASK | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.DELETE_MASK ) );
+
+        result = ( PagePermission.RENAME_MASK | PagePermission.EDIT_MASK | PagePermission.COMMENT_MASK 
+                | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.RENAME_MASK ) );
+        
+        result = ( PagePermission.MODIFY_MASK | PagePermission.EDIT_MASK | PagePermission.COMMENT_MASK
+                | PagePermission.UPLOAD_MASK | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.MODIFY_MASK ) );
+
+        result = ( PagePermission.EDIT_MASK | PagePermission.COMMENT_MASK | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.EDIT_MASK ) );
+        
+        result = ( PagePermission.COMMENT_MASK | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.COMMENT_MASK ) );
+
+        result = ( PagePermission.UPLOAD_MASK | PagePermission.VIEW_MASK );
+        assertEquals( result, PagePermission.impliedMask( PagePermission.UPLOAD_MASK ) );
+    }
+
+    public final void testGetName()
+    {
+        PagePermission p;
+        p = new PagePermission( "Main", "view,edit,delete" );
+        assertEquals( "Main", p.getName() );
+        p = new PagePermission( "mywiki:Main", "view,edit,delete" );
+        assertEquals( "mywiki:Main", p.getName() );
+        assertNotSame( "*:Main", p.getName() );
+    }
+
+    /*
+     * Class under test for java.lang.String getActions()
+     */
+    public final void testGetActions()
+    {
+        PagePermission p = new PagePermission( "Main", "VIEW,edit,delete" );
+        assertEquals( "delete,edit,view", p.getActions() );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/WikiPermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/WikiPermissionTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/WikiPermissionTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/permissions/WikiPermissionTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,157 @@
+package com.ecyrd.jspwiki.auth.permissions;
+
+import junit.framework.TestCase;
+
+
+/**
+ * @author Andrew Jaquith
+ */
+public class WikiPermissionTest extends TestCase
+{
+
+  public void testHashCode()
+  {
+  }
+
+  public void testWikiPermission()
+  {
+      WikiPermission p = new WikiPermission("*", "createPages");
+      assertEquals("*", p.getName());
+      assertEquals("*", p.getWiki());
+      assertEquals("createpages", p.getActions());
+  }
+
+  /*
+   * Class under test for boolean equals(Object)
+   */
+  public void testEqualsObject()
+  {
+      WikiPermission p1 = new WikiPermission("*", "createPages");
+      WikiPermission p2 = new WikiPermission("*", "createPages");
+      WikiPermission p3 = new WikiPermission("*", "createGroups");
+      assertTrue(p1.equals(p2));
+      assertTrue(p2.equals(p1));
+      assertFalse(p1.equals(p3));
+      assertFalse(p3.equals(p1));
+      WikiPermission p4 = new WikiPermission("*", "createPages,createGroups");
+      WikiPermission p5 = new WikiPermission("*", "createGroups,createPages");
+      assertTrue(p4.equals(p5));
+  }
+
+  /*
+   * Class under test for boolean equals(Object)
+   */
+  public void testEqualsObjectNSi()
+  {
+      WikiPermission p1 = new WikiPermission("mywiki", "createPages");
+      WikiPermission p2 = new WikiPermission("*",      "createPages");
+      WikiPermission p3 = new WikiPermission("mywiki", "createGroups");
+      assertFalse(p1.equals(p2));
+      assertFalse(p2.equals(p1));
+      assertFalse(p1.equals(p3));
+      assertFalse(p3.equals(p1));
+      WikiPermission p4 = new WikiPermission("mywiki", "createPages,createGroups");
+      WikiPermission p5 = new WikiPermission("*",      "createGroups,createPages");
+      assertFalse(p4.equals(p5));
+  }
+
+  /*
+   * Class under test for String getActions()
+   */
+  public void testGetActions()
+  {
+      WikiPermission p1 = new WikiPermission("*", "createPages,createGroups,editProfile");
+      assertEquals("creategroups,createpages,editprofile", p1.getActions());
+      WikiPermission p2 = new WikiPermission("*", "createGroups,editProfile,createPages");
+      assertEquals("creategroups,createpages,editprofile", p2.getActions());
+  }
+
+  /*
+   * Class under test for boolean implies(Permission)
+   */
+  public void testImpliesPermission()
+  {
+      // Superset of actions implies all individual actions
+      WikiPermission p1 = new WikiPermission("*", "createPages,createGroups,editProfile");
+      WikiPermission p2 = new WikiPermission("*", "createPages");
+      WikiPermission p3 = new WikiPermission("*", "createGroups");
+      WikiPermission p5 = new WikiPermission("*", "editPreferences");
+      WikiPermission p6 = new WikiPermission("*", "editProfile");
+      assertTrue(p1.implies(p2));
+      assertFalse(p2.implies(p1));
+      assertTrue(p1.implies(p3));
+      assertFalse(p3.implies(p1));
+      assertTrue(p1.implies(p6));
+      assertFalse(p6.implies(p1));
+
+      // createGroups implies createPages
+      assertTrue(p3.implies(p2));
+      assertFalse(p2.implies(p3));
+
+      // editProfile implies nothing
+      assertFalse(p6.implies(p5));
+      assertFalse(p6.implies(p3));
+      assertFalse(p6.implies(p3));
+      assertFalse(p6.implies(p1));
+  }
+
+  /*
+   * Class under test for boolean implies(Permission)
+   */
+  public void testImpliesPermissionNS()
+  {
+      // Superset of actions implies all individual actions
+      WikiPermission p1 = new WikiPermission("*",      "createPages,createGroups,editProfile");
+      WikiPermission p2 = new WikiPermission("mywiki", "createPages");
+      WikiPermission p3 = new WikiPermission("mywiki", "createGroups");
+      WikiPermission p4 = new WikiPermission("urwiki", "editProfile");
+      WikiPermission p5 = new WikiPermission("*",      "editPreferences");
+      assertTrue(p1.implies(p2));
+      assertFalse(p2.implies(p1));
+      assertTrue(p1.implies(p3));
+      assertFalse(p3.implies(p1));
+      assertTrue(p1.implies(p4));
+      assertFalse(p4.implies(p1));
+
+      // createGroups implies createPages
+      assertTrue(p3.implies(p2));
+      assertFalse(p2.implies(p3));
+
+      // editPreferences does not imply editProfile
+      assertFalse(p5.implies(p4));
+      assertFalse(p4.implies(p5));
+  }
+
+  /*
+   * Class under test for String toString()
+   */
+  public void testToString()
+  {
+      WikiPermission p1 = new WikiPermission("*", "createPages,createGroups,editProfile");
+      String result = "(\"com.ecyrd.jspwiki.auth.permissions.WikiPermission\",\"*\",\"creategroups,createpages,editprofile\")";
+      assertEquals(result, p1.toString());
+  }
+
+  public void testImpliedMask()
+  {
+      assertEquals(3, WikiPermission.impliedMask(1));
+      assertEquals(2, WikiPermission.impliedMask(2));
+      assertEquals(4, WikiPermission.impliedMask(4));
+  }
+
+  public void testCreateMask()
+  {
+      assertEquals(1, WikiPermission.createMask("createGroups"));
+      assertEquals(2, WikiPermission.createMask("createPages"));
+      assertEquals(3, WikiPermission.createMask("createGroups,createPages"));
+      assertEquals(4, WikiPermission.createMask("editPreferences"));
+      assertEquals(5, WikiPermission.createMask("createGroups,editPreferences"));
+      assertEquals(6, WikiPermission.createMask("createPages,editPreferences"));
+      assertEquals(7, WikiPermission.createMask("createGroups,createPages,editPreferences"));
+      assertEquals(8, WikiPermission.createMask("editProfile"));
+      assertEquals(9, WikiPermission.createMask("createGroups,editProfile"));
+      assertEquals(16, WikiPermission.createMask("login"));
+      assertEquals(24, WikiPermission.createMask("login,editProfile"));
+  }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,25 @@
+package com.ecyrd.jspwiki.auth.user;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * @author Andrew R. Jaquith
+ */
+public class AllTests extends TestCase
+{
+    public AllTests( String s )
+    {
+        super( s );
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite( "User profile and database tests" );
+        suite.addTestSuite( UserProfileTest.class );
+        suite.addTestSuite( JDBCUserDatabaseTest.class );
+        suite.addTestSuite( XMLUserDatabaseTest.class );
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,358 @@
+package com.ecyrd.jspwiki.auth.user;
+
+import java.io.File;
+import java.security.Principal;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Timestamp;
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import junit.framework.TestCase;
+
+import com.ecyrd.jspwiki.TestJDBCDataSource;
+import com.ecyrd.jspwiki.TestJNDIContext;
+import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
+import com.ecyrd.jspwiki.auth.WikiSecurityException;
+
+/**
+ * @author Andrew Jaquith
+ */
+public class JDBCUserDatabaseTest extends TestCase
+{
+    private JDBCUserDatabase m_db   = null;
+
+    private static final String INSERT_JANNE = "INSERT INTO users (" +
+          JDBCUserDatabase.DEFAULT_DB_EMAIL + "," +
+          JDBCUserDatabase.DEFAULT_DB_FULL_NAME + "," +
+          JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," +
+          JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," +
+          JDBCUserDatabase.DEFAULT_DB_WIKI_NAME + "," +
+          JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES (" +
+          "'janne@ecyrd.com'," + "'Janne Jalkanen'," + "'janne'," +
+          "'{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee'," +
+          "'JanneJalkanen'," +
+          "'" + new Timestamp( new Timestamp( System.currentTimeMillis() ).getTime() ).toString() + "'" + ");";
+
+    private static final String INSERT_USER = "INSERT INTO users (" +
+        JDBCUserDatabase.DEFAULT_DB_EMAIL + "," +
+        JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," +
+        JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," +
+        JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES (" +
+        "'user@example.com'," + "'user'," +
+        "'{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'," +
+        "'" + new Timestamp( new Timestamp( System.currentTimeMillis() ).getTime() ).toString() + "'" + ");";
+
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        // Set up the mock JNDI initial context
+        TestJNDIContext.initialize();
+        Context initCtx = new InitialContext();
+        initCtx.bind( "java:comp/env", new TestJNDIContext() );
+        Context ctx = (Context) initCtx.lookup( "java:comp/env" );
+        DataSource ds = new TestJDBCDataSource( new File( "build.properties" ) );
+        ctx.bind( JDBCUserDatabase.DEFAULT_DB_JNDI_NAME, ds );
+
+        // Get the JDBC connection and init tables
+        try
+        {
+            Connection conn = ds.getConnection();
+            Statement stmt = conn.createStatement();
+            String sql;
+
+            sql = "DELETE FROM " + JDBCUserDatabase.DEFAULT_DB_TABLE + ";";
+            stmt.executeUpdate( sql );
+
+            // Create a new test user 'janne'
+            stmt.executeUpdate( INSERT_JANNE );
+
+            // Create a new test user 'user'
+            stmt.executeUpdate( INSERT_USER );
+            stmt.close();
+
+            conn.close();
+
+            // Initialize the user database
+            m_db = new JDBCUserDatabase();
+            m_db.initialize( null, new Properties() );
+        }
+        catch( SQLException e )
+        {
+            System.err.println("Looks like your database could not be connected to - "+
+                               "please make sure that you have started your database "+
+                               "(e.g. by running ant hsql-start)");
+
+            throw (SQLException) e.fillInStackTrace();
+        }
+    }
+
+    public void testDeleteByLoginName() throws WikiSecurityException
+    {
+        // First, count the number of users in the db now.
+        int oldUserCount = m_db.getWikiNames().length;
+
+        // Create a new user with random name
+        String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
+        UserProfile profile = new DefaultUserProfile();
+        profile.setEmail("testuser@testville.com");
+        profile.setLoginName( loginName );
+        profile.setFullname( "FullName"+loginName );
+        profile.setPassword("password");
+        m_db.save(profile);
+
+        // Make sure the profile saved successfully
+        profile = m_db.findByLoginName( loginName );
+        assertEquals( loginName, profile.getLoginName() );
+        assertEquals( oldUserCount+1, m_db.getWikiNames().length );
+
+        // Now delete the profile; should be back to old count
+        m_db.deleteByLoginName( loginName );
+        assertEquals( oldUserCount, m_db.getWikiNames().length );
+    }
+
+    public void testFindByEmail()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByEmail( "janne@ecyrd.com" );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword() );
+            assertEquals( "janne@ecyrd.com", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "foo@bar.org" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testFindByFullName()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByFullName( "Janne Jalkanen" );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword() );
+            assertEquals( "janne@ecyrd.com", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "foo@bar.org" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testFindByWikiName()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByWikiName( "JanneJalkanen" );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword() );
+            assertEquals( "janne@ecyrd.com", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "foo" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testFindByLoginName()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByLoginName( "janne" );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword() );
+            assertEquals( "janne@ecyrd.com", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "FooBar" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testGetWikiName() throws WikiSecurityException
+    {
+        Principal[] principals = m_db.getWikiNames();
+        assertEquals( 1, principals.length );
+    }
+
+    public void testRename() throws Exception
+    {
+        // Try renaming a non-existent profile; it should fail
+        try
+        {
+            m_db.rename( "nonexistentname", "renameduser" );
+            fail( "Should not have allowed rename..." );
+        }
+        catch ( NoSuchPrincipalException e )
+        {
+            // Cool; that's what we expect
+        }
+
+        // Create new user & verify it saved ok
+        UserProfile profile = new DefaultUserProfile();
+        profile.setEmail( "renamed@example.com" );
+        profile.setFullname( "Renamed User" );
+        profile.setLoginName( "olduser" );
+        profile.setPassword( "password" );
+        m_db.save( profile );
+        profile = m_db.findByLoginName( "olduser" );
+        assertNotNull( profile );
+
+        // Try renaming to a login name that's already taken; it should fail
+        try
+        {
+            m_db.rename( "olduser", "janne" );
+            fail( "Should not have allowed rename..." );
+        }
+        catch ( DuplicateUserException e )
+        {
+            // Cool; that's what we expect
+        }
+
+        // Now, rename it to an unused name
+        m_db.rename( "olduser", "renameduser" );
+
+        // The old user shouldn't be found
+        try
+        {
+            profile = m_db.findByLoginName( "olduser" );
+            fail( "Old user was found, but it shouldn't have been." );
+        }
+        catch ( NoSuchPrincipalException e )
+        {
+            // Cool, it's gone
+        }
+
+        // The new profile should be found, and its properties should match the old ones
+        profile = m_db.findByLoginName( "renameduser" );
+        assertEquals( "renamed@example.com", profile.getEmail() );
+        assertEquals( "Renamed User", profile.getFullname() );
+        assertEquals( "renameduser", profile.getLoginName() );
+        assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+
+        // Delete the user
+        m_db.deleteByLoginName( "renameduser" );
+    }
+
+    public void testSave()
+    {
+        try
+        {
+            // Overwrite existing user
+            UserProfile profile = new DefaultUserProfile();
+            profile.setEmail( "user@example.com" );
+            profile.setFullname( "Test User" );
+            profile.setLoginName( "user" );
+            profile.setPassword( "password" );
+            m_db.save( profile );
+            profile = m_db.findByEmail( "user@example.com" );
+            assertEquals( "user@example.com", profile.getEmail() );
+            assertEquals( "Test User", profile.getFullname() );
+            assertEquals( "user", profile.getLoginName() );
+            assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+            assertEquals( "TestUser", profile.getWikiName() );
+            assertNotNull( profile.getCreated() );
+            assertNotNull( profile.getLastModified() );
+            assertNotSame( profile.getCreated(), profile.getLastModified() );
+
+            // Create new user
+            profile = new DefaultUserProfile();
+            profile.setEmail( "user2@example.com" );
+            profile.setFullname( "Test User 2" );
+            profile.setLoginName( "user2" );
+            profile.setPassword( "password" );
+            m_db.save( profile );
+            profile = m_db.findByEmail( "user2@example.com" );
+            assertEquals( "user2@example.com", profile.getEmail() );
+            assertEquals( "Test User 2", profile.getFullname() );
+            assertEquals( "user2", profile.getLoginName() );
+            assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+            assertEquals( "TestUser2", profile.getWikiName() );
+            assertNotNull( profile.getCreated() );
+            assertNotNull( profile.getLastModified() );
+            assertEquals( profile.getCreated(), profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        catch( WikiSecurityException e )
+        {
+            assertTrue( false );
+        }
+    }
+
+    public void testValidatePassword()
+    {
+        assertFalse( m_db.validatePassword( "janne", "test" ) );
+        assertTrue( m_db.validatePassword( "janne", "myP@5sw0rd" ) );
+        assertTrue( m_db.validatePassword( "user", "password" ) );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,67 @@
+package com.ecyrd.jspwiki.auth.user;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.PropertyConfigurator;
+
+import com.ecyrd.jspwiki.TestEngine;
+
+/**
+ *  Tests the DefaultUserProfile class.
+ *  @author Janne Jalkanen
+ */
+public class UserProfileTest extends TestCase
+{
+    public UserProfileTest( 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()
+    {
+    }
+
+    public void testEquals()
+    {
+        UserProfile p = new DefaultUserProfile();
+        UserProfile p2 = new DefaultUserProfile();
+
+        p.setFullname("Alice");
+        p2.setFullname("Bob");
+
+        assertFalse( p.equals( p2 ) );
+    }
+
+    public void testEquals2()
+    {
+        UserProfile p = new DefaultUserProfile();
+        UserProfile p2 = new DefaultUserProfile();
+
+        p.setFullname("Alice");
+        p2.setFullname("Alice");
+
+        assertTrue( p.equals( p2 ) );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( UserProfileTest.class );
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,249 @@
+package com.ecyrd.jspwiki.auth.user;
+import java.security.Principal;
+import java.util.Properties;
+
+import org.apache.commons.lang.ArrayUtils;
+
+import junit.framework.TestCase;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.auth.NoSuchPrincipalException;
+import com.ecyrd.jspwiki.auth.Users;
+import com.ecyrd.jspwiki.auth.WikiPrincipal;
+import com.ecyrd.jspwiki.auth.WikiSecurityException;
+
+
+
+/**
+ * @author Andrew Jaquith
+ */
+public class XMLUserDatabaseTest extends TestCase
+{
+
+  private XMLUserDatabase m_db;
+
+  /**
+   * @see junit.framework.TestCase#setUp()
+   */
+  protected void setUp() throws Exception
+  {
+      super.setUp();
+      Properties props = new Properties();
+      props.load( TestEngine.findTestProperties() );
+      props.put(XMLUserDatabase.PROP_USERDATABASE, "tests/etc/userdatabase.xml");
+      WikiEngine engine  = new TestEngine(props);
+      m_db = new XMLUserDatabase();
+      m_db.initialize(engine, props);
+  }
+
+  public void testDeleteByLoginName() throws WikiSecurityException
+  {
+      // First, count the number of users in the db now.
+      int oldUserCount = m_db.getWikiNames().length;
+
+      // Create a new user with random name
+      String loginName = "TestUser" + String.valueOf( System.currentTimeMillis() );
+      UserProfile profile = new DefaultUserProfile();
+      profile.setEmail("testuser@testville.com");
+      profile.setLoginName( loginName );
+      profile.setFullname( "FullName"+loginName );
+      profile.setPassword("password");
+      m_db.save(profile);
+
+      // Make sure the profile saved successfully
+      profile = m_db.findByLoginName( loginName );
+      assertEquals( loginName, profile.getLoginName() );
+      assertEquals( oldUserCount+1, m_db.getWikiNames().length );
+
+      // Now delete the profile; should be back to old count
+      m_db.deleteByLoginName( loginName );
+      assertEquals( oldUserCount, m_db.getWikiNames().length );
+  }
+
+  public void testFindByEmail()
+  {
+    try
+    {
+        UserProfile profile = m_db.findByEmail("janne@ecyrd.com");
+        assertEquals("janne",           profile.getLoginName());
+        assertEquals("Janne Jalkanen",  profile.getFullname());
+        assertEquals("JanneJalkanen",   profile.getWikiName());
+        assertEquals("{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword());
+        assertEquals("janne@ecyrd.com", profile.getEmail());
+    }
+    catch (NoSuchPrincipalException e)
+    {
+        assertTrue(false);
+    }
+    try
+    {
+        m_db.findByEmail("foo@bar.org");
+        // We should never get here
+        assertTrue(false);
+    }
+    catch (NoSuchPrincipalException e)
+    {
+        assertTrue(true);
+    }
+  }
+
+  public void testFindByWikiName()
+  {
+      try
+      {
+          UserProfile profile = m_db.findByWikiName("JanneJalkanen");
+          assertEquals("janne",           profile.getLoginName());
+          assertEquals("Janne Jalkanen",  profile.getFullname());
+          assertEquals("JanneJalkanen",   profile.getWikiName());
+          assertEquals("{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword());
+          assertEquals("janne@ecyrd.com", profile.getEmail());
+      }
+      catch (NoSuchPrincipalException e)
+      {
+          assertTrue(false);
+      }
+      try
+      {
+          m_db.findByEmail("foo");
+          // We should never get here
+          assertTrue(false);
+      }
+      catch (NoSuchPrincipalException e)
+      {
+          assertTrue(true);
+      }
+    }
+
+  public void testFindByLoginName()
+  {
+      try
+      {
+          UserProfile profile = m_db.findByLoginName("janne");
+          assertEquals("janne",           profile.getLoginName());
+          assertEquals("Janne Jalkanen",  profile.getFullname());
+          assertEquals("JanneJalkanen",   profile.getWikiName());
+          assertEquals("{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", profile.getPassword());
+          assertEquals("janne@ecyrd.com", profile.getEmail());
+      }
+      catch (NoSuchPrincipalException e)
+      {
+          assertTrue(false);
+      }
+      try
+      {
+          m_db.findByEmail("FooBar");
+          // We should never get here
+          assertTrue(false);
+      }
+      catch (NoSuchPrincipalException e)
+      {
+          assertTrue(true);
+      }
+    }
+
+  public void testGetWikiNames() throws WikiSecurityException
+  {
+      // There are 8 test users in the database
+      Principal[] p = m_db.getWikiNames();
+      assertEquals( 8, p.length );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( "JanneJalkanen", WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( "", WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( "Administrator", WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( Users.ALICE, WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( Users.BOB, WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( Users.CHARLIE, WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( "FredFlintstone", WikiPrincipal.WIKI_NAME ) ) );
+      assertTrue( ArrayUtils.contains( p, new WikiPrincipal( Users.BIFF, WikiPrincipal.WIKI_NAME ) ) );
+  }
+
+  public void testRename() throws Exception
+  {
+      // Try renaming a non-existent profile; it should fail
+      try
+      {
+          m_db.rename( "nonexistentname", "renameduser" );
+          fail( "Should not have allowed rename..." );
+      }
+      catch ( NoSuchPrincipalException e )
+      {
+          // Cool; that's what we expect
+      }
+
+      // Create new user & verify it saved ok
+      UserProfile profile = new DefaultUserProfile();
+      profile.setEmail( "renamed@example.com" );
+      profile.setFullname( "Renamed User" );
+      profile.setLoginName( "olduser" );
+      profile.setPassword( "password" );
+      m_db.save( profile );
+      profile = m_db.findByLoginName( "olduser" );
+      assertNotNull( profile );
+
+      // Try renaming to a login name that's already taken; it should fail
+      try
+      {
+          m_db.rename( "olduser", "janne" );
+          fail( "Should not have allowed rename..." );
+      }
+      catch ( DuplicateUserException e )
+      {
+          // Cool; that's what we expect
+      }
+
+      // Now, rename it to an unused name
+      m_db.rename( "olduser", "renameduser" );
+
+      // The old user shouldn't be found
+      try
+      {
+          profile = m_db.findByLoginName( "olduser" );
+          fail( "Old user was found, but it shouldn't have been." );
+      }
+      catch ( NoSuchPrincipalException e )
+      {
+          // Cool, it's gone
+      }
+
+      // The new profile should be found, and its properties should match the old ones
+      profile = m_db.findByLoginName( "renameduser" );
+      assertEquals( "renamed@example.com", profile.getEmail() );
+      assertEquals( "Renamed User", profile.getFullname() );
+      assertEquals( "renameduser", profile.getLoginName() );
+      assertEquals( "{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword() );
+
+      // Delete the user
+      m_db.deleteByLoginName( "renameduser" );
+  }
+
+  public void testSave()
+  {
+      try
+      {
+          UserProfile profile = new DefaultUserProfile();
+          profile.setEmail("user@example.com");
+          profile.setLoginName("user");
+          profile.setPassword("password");
+          m_db.save(profile);
+          profile = m_db.findByEmail("user@example.com");
+          assertEquals("user@example.com", profile.getEmail());
+          assertEquals("{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8", profile.getPassword());
+      }
+      catch (NoSuchPrincipalException e)
+      {
+          assertTrue(false);
+      }
+      catch (WikiSecurityException e)
+      {
+          assertTrue(false);
+      }
+  }
+
+  public void testValidatePassword()
+  {
+      assertFalse(m_db.validatePassword("janne", "test"));
+      assertTrue(m_db.validatePassword("janne", "myP@5sw0rd"));
+      assertTrue(m_db.validatePassword("user", "password"));
+  }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,23 @@
+/*
+ * (C) Janne Jalkanen 2005
+ * 
+ */
+package com.ecyrd.jspwiki.dav;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AllTests extends TestCase
+{
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("DAV tests");
+
+        suite.addTest( DavPathTest.suite() );
+        suite.addTest( RawPagesDavProviderTest.suite() );
+        suite.addTest( HTMLPagesDavProviderTest.suite() );
+        suite.addTest( AttachmentDavProviderTest.suite() );
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AttachmentDavProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AttachmentDavProviderTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AttachmentDavProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/AttachmentDavProviderTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,82 @@
+package com.ecyrd.jspwiki.dav;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.attachment.Attachment;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.DirectoryItem;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AttachmentDavProviderTest extends TestCase
+{
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    AttachmentDavProvider m_provider;
+    
+    protected void setUp() throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        engine = new TestEngine(props);
+
+        m_provider = new AttachmentDavProvider(engine);
+    }
+
+    protected void tearDown() throws Exception
+    {
+        engine.deleteAttachments( "TestPage" );
+        TestEngine.deleteTestPage("TestPage");
+    }
+
+    public void testGetPageURL()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+        Attachment att = new Attachment(engine,"TestPage","deceit of the tribbles.txt");
+        
+        engine.getAttachmentManager().storeAttachment( att, engine.makeAttachmentFile() );
+        
+        DavItem di = m_provider.getItem( new DavPath("TestPage/deceit of the tribbles.txt") );
+        
+        assertNotNull( "No di", di );
+        assertEquals("URL", "http://localhost/attach/TestPage/deceit+of+the+tribbles.txt", 
+                     di.getHref() );
+    }
+
+    public void testDirURL()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+    
+        DavItem di = m_provider.getItem( new DavPath("") );
+    
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/attach/", di.getHref() );
+    }
+
+    public void testDirURL2()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+
+        DavItem di = m_provider.getItem( new DavPath("TestPage/") );
+
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/attach/TestPage/", di.getHref() );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( RawPagesDavProviderTest.class );
+    }
+
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/DavPathTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/DavPathTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/DavPathTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/DavPathTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,165 @@
+/*
+ * (C) Janne Jalkanen 2005
+ * 
+ */
+package com.ecyrd.jspwiki.dav;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class DavPathTest extends TestCase
+{
+    public void testCreate1()
+    {
+        String src = "/";
+        
+        DavPath dp = new DavPath( src );
+        
+        assertEquals( "path", "/", dp.pathPart() );
+        assertEquals( "file", "", dp.filePart() );
+    }
+
+    public void testCreate2()
+    {
+        String src = "/test/foo/bar.txt";
+        
+        DavPath dp = new DavPath( src );
+        
+        assertEquals( "path", "/test/foo/", dp.pathPart() );
+        assertEquals( "file", "bar.txt", dp.filePart() );        
+    }
+
+    public void testCreate3()
+    {
+        String src = "/test/foo/";
+        
+        DavPath dp = new DavPath( src );
+        
+        assertEquals( "path", "/test/foo/", dp.pathPart() );
+        assertEquals( "file", "", dp.filePart() );        
+    }
+
+    public void testCreate4()
+    {
+        String src = "";
+        
+        DavPath dp = new DavPath( src );
+        
+        assertEquals( "path", "", dp.pathPart() );
+        assertEquals( "file", "", dp.filePart() );        
+    }
+
+    public void testCreate5()
+    {
+        String src = "/foo//bar///goo";
+        
+        DavPath dp = new DavPath( src );
+        
+        assertEquals( "path", "/foo/bar/", dp.pathPart() );
+        assertEquals( "file", "goo", dp.filePart() );        
+    }
+    
+    public void testSubPath()
+    {
+        String src = "/foo/bar/goo/blot";
+        
+        DavPath dp = new DavPath( src );
+        
+        DavPath subdp = dp.subPath( 2 );
+        
+        assertEquals( "goo/blot", subdp.getPath() );
+    }
+
+    public void testSubPath2()
+    {
+        String src = "/foo/bar/goo/blot";
+        
+        DavPath dp = new DavPath( src );
+        
+        DavPath subdp = dp.subPath( 0 );
+        
+        assertEquals( "/foo/bar/goo/blot", subdp.getPath() );
+    }
+
+    public void testSubPath3()
+    {
+        String src = "/foo/bar/goo/blot";
+        
+        DavPath dp = new DavPath( src );
+        
+        DavPath subdp = dp.subPath( 3 );
+        
+        assertEquals( "blot", subdp.getPath() );
+    }
+
+    public void testGetPath()
+    {
+        String src = "/foo/bar/goo/blot";
+        
+        DavPath dp = new DavPath( src );
+                
+        assertEquals( "/foo/bar/goo/blot", dp.getPath() );
+    }
+
+    public void testRoot1()
+    {
+        String src = "";
+        
+        DavPath dp = new DavPath( src );
+                
+        assertTrue( dp.isRoot() );
+    }
+
+    public void testRoot2()
+    {
+        String src = "/";
+        
+        DavPath dp = new DavPath( src );
+                
+        assertTrue( dp.isRoot() );
+    }
+
+    public void testRoot3()
+    {
+        String src = "foo";
+        
+        DavPath dp = new DavPath( src );
+                
+        assertFalse( dp.isRoot() );
+    }
+
+    public void testRoot4()
+    {
+        String src = "/foo";
+        
+        DavPath dp = new DavPath( src );
+                
+        assertFalse( dp.isRoot() );
+    }
+    
+    public void testAppend1()
+    {
+        DavPath dp = new DavPath("/foo/bar/");
+        
+        dp.append("/zorp");
+        
+        assertEquals( "/foo/bar/zorp", dp.getPath() );
+    }
+
+    public void testAppend2()
+    {
+        DavPath dp = new DavPath("/foo/bar/");
+        
+        dp.append("zorp/grub/");
+        
+        assertEquals( "/foo/bar/zorp/grub/", dp.getPath() );
+    }
+
+    
+    public static Test suite()
+    {
+        return new TestSuite( DavPathTest.class );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/HTMLPagesDavProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/HTMLPagesDavProviderTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/HTMLPagesDavProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/HTMLPagesDavProviderTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,77 @@
+package com.ecyrd.jspwiki.dav;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.DirectoryItem;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class HTMLPagesDavProviderTest extends TestCase
+{
+
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    HTMLPagesDavProvider m_provider;
+        
+    protected void setUp() throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        engine = new TestEngine(props);
+
+        m_provider = new HTMLPagesDavProvider(engine);
+    }
+
+    protected void tearDown() throws Exception
+    {
+        TestEngine.deleteTestPage("TestPage");
+    }
+
+    public void testGetPageURL()
+    throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+            
+        DavItem di = m_provider.getItem( new DavPath("t/TestPage.html") );
+            
+        assertNotNull( "No di", di );
+        assertEquals("URL", "http://localhost/dav/html/t/TestPage.html", di.getHref() );
+    }
+
+    public void testDirURL()
+    throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+        
+        DavItem di = m_provider.getItem( new DavPath("") );
+        
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/dav/html/", di.getHref() );
+    }
+
+    public void testDirURL2()
+    throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+
+        DavItem di = m_provider.getItem( new DavPath("t/") );
+
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/dav/html/t/", di.getHref() );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( HTMLPagesDavProviderTest.class );
+    }
+
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/RawPagesDavProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/RawPagesDavProviderTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/RawPagesDavProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/dav/RawPagesDavProviderTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,76 @@
+package com.ecyrd.jspwiki.dav;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.DirectoryItem;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class RawPagesDavProviderTest extends TestCase
+{
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    RawPagesDavProvider m_provider;
+    
+    protected void setUp() throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        engine = new TestEngine(props);
+
+        m_provider = new RawPagesDavProvider(engine);
+    }
+
+    protected void tearDown() throws Exception
+    {
+        TestEngine.deleteTestPage("TestPage");
+    }
+
+    public void testGetPageURL()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+        
+        DavItem di = m_provider.getItem( new DavPath("t/TestPage.txt") );
+        
+        assertNotNull( "No di", di );
+        assertEquals("URL", "http://localhost/dav/raw/t/TestPage.txt", di.getHref() );
+    }
+
+    public void testDirURL()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+    
+        DavItem di = m_provider.getItem( new DavPath("") );
+    
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/dav/raw/", di.getHref() );
+    }
+
+    public void testDirURL2()
+        throws Exception
+    {
+        engine.saveText("TestPage", "foobar");
+
+        DavItem di = m_provider.getItem( new DavPath("t/") );
+
+        assertNotNull( "No di", di );
+        assertTrue( "DI is of wrong type", di instanceof DirectoryItem );
+        assertEquals("URL", "http://localhost/dav/raw/t/", di.getHref() );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( RawPagesDavProviderTest.class );
+    }
+
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,22 @@
+/*
+ * (C) Janne Jalkanen 2005
+ * 
+ */
+package com.ecyrd.jspwiki.diff;
+
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AllTests extends TestCase
+{
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("DIFF tests");
+
+        suite.addTest( ContextualDiffProviderTest.suite() );
+
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/diff/ContextualDiffProviderTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,196 @@
+package com.ecyrd.jspwiki.diff;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.log4j.PropertyConfigurator;
+
+import com.ecyrd.jspwiki.*;
+
+public class ContextualDiffProviderTest extends TestCase
+{
+    /**
+     * Sets up some shorthand notation for writing test cases.
+     * <p>
+     * The quick |^Brown Fox^-Blue Monster-| jumped over |^the^| moon.
+     * <p>
+     * Get it?
+     */
+    private void specializedNotation(ContextualDiffProvider diff)
+    {
+        diff.m_changeEndHtml = "|";
+        diff.m_changeStartHtml = "|";
+
+        diff.m_deletionEndHtml = "-";
+        diff.m_deletionStartHtml = "-";
+
+        diff.m_diffEnd = "";
+        diff.m_diffStart = "";
+
+        diff.m_elidedHeadIndicatorHtml = "...";
+        diff.m_elidedTailIndicatorHtml = "...";
+
+        diff.m_emitChangeNextPreviousHyperlinks = false;
+
+        diff.m_insertionEndHtml = "^";
+        diff.m_insertionStartHtml = "^";
+
+        diff.m_lineBreakHtml = "";
+        diff.m_alternatingSpaceHtml = "_";
+    }
+
+
+
+    public void testNoChanges() throws IOException, WikiException
+    {
+        diffTest(null, "", "", "");
+        diffTest(null, "A", "A", "A");
+        diffTest(null, "A B", "A B", "A B");
+
+        diffTest(null, "      ", "      ", " _ _ _");
+        diffTest(null, "A B  C", "A B  C", "A B _C");
+        diffTest(null, "A B   C", "A B   C", "A B _ C");
+    }
+
+
+
+    public void testSimpleInsertions() throws IOException, WikiException
+    {
+        // Ah, the white space trailing an insertion is tacked onto the insertion, this is fair, the
+        // alternative would be to greedily take the leading whitespace before the insertion as part
+        // of it instead, and that doesn't make any more or less sense. just remember this behaviour
+        // when writing tests.
+
+        // Simple inserts...
+        diffTest(null, "A C", "A B C", "A |^B ^|C");
+        diffTest(null, "A D", "A B C D", "A |^B C ^|D");
+
+        // Simple inserts with spaces...
+        diffTest(null, "A C", "A B  C", "A |^B _^|C");
+        diffTest(null, "A C", "A B   C", "A |^B _ ^|C");
+        diffTest(null, "A C", "A B    C", "A |^B _ _^|C");
+
+        // Just inserted spaces...
+        diffTest(null, "A B", "A  B", "A |^_^|B");
+        diffTest(null, "A B", "A   B", "A |^_ ^|B");
+        diffTest(null, "A B", "A    B", "A |^_ _^|B");
+        diffTest(null, "A B", "A     B", "A |^_ _ ^|B");
+    }
+
+
+
+    public void testSimpleDeletions() throws IOException, WikiException
+    {
+        // Simple deletes...
+        diffTest(null, "A B C", "A C", "A |-B -|C");
+        diffTest(null, "A B C D", "A D", "A |-B C -|D");
+
+        // Simple deletes with spaces...
+        diffTest(null, "A B  C", "A C", "A |-B _-|C");
+        diffTest(null, "A B   C", "A C", "A |-B _ -|C");
+
+        // Just deleted spaces...
+        diffTest(null, "A  B", "A B", "A |-_-|B");
+        diffTest(null, "A   B", "A B", "A |-_ -|B");
+        diffTest(null, "A    B", "A B", "A |-_ _-|B");
+    }
+
+
+
+    public void testContextLimits() throws IOException, WikiException
+    {
+        // No change
+        diffTest("1", "A B C D E F G H I", "A B C D E F G H I", "A...");
+        //TODO Hmm, should the diff provider instead return the string, "No Changes"?
+        
+        // Bad property value, should default to huge context limit and return entire string.
+        diffTest("foobar", "A B C D E F G H I", "A B C D F G H I", "A B C D |-E -|F G H I");
+
+        // One simple deletion, limit context to 2...
+        diffTest("2", "A B C D E F G H I", "A B C D F G H I", "...D |-E -|F ...");
+
+        // Deletion of first element, limit context to 2...
+        diffTest("2", "A B C D E", "B C D E", "|-A -|B ...");
+        
+        // Deletion of last element, limit context to 2...
+        diffTest("2", "A B C D E", "A B C D ", "...D |-E-|");
+        
+        // Two simple deletions, limit context to 2...
+        diffTest("2", "A B C D E F G H I J K L M N O P", "A B C E F G H I J K M N O P",
+            "...C |-D -|E ......K |-L -|M ...");
+                
+    }
+
+    public void testMultiples() throws IOException, WikiException
+    {
+        diffTest(null, "A F", "A B C D E F", "A |^B C D E ^|F");
+        diffTest(null, "A B C D E F", "A F", "A |-B C D E -|F");
+        
+    }
+
+    public void testSimpleChanges() throws IOException, WikiException
+    {
+        // *changes* are actually an insert and a delete in the output...
+
+        //single change
+        diffTest(null, "A B C", "A b C", "A |^b^-B-| C");
+
+        //non-consequtive changes...
+        diffTest(null, "A B C D E", "A b C d E", "A |^b^-B-| C |^d^-D-| E");
+
+    }
+
+    // FIXME: This test fails; must be enabled again asap.
+    /*
+    public void testKnownProblemCases() throws NoRequiredPropertyException, IOException
+    {
+        //These all fail...
+        
+        //make two consequtive changes
+        diffTest(null, "A B C D", "A b c D", "A |^b c^-B C-| D");
+        //acually returns ->                 "A |^b^-B-| |^c^-C-| D"
+
+        //collapse adjacent elements...
+        diffTest(null, "A B C D", "A BC D", "A |^BC^-B C-| D");
+        //acually returns ->                "A |^BC^-B-| |-C -|D"
+        
+        
+        //These failures are all due to how we process the diff results, we need to collapse 
+        //adjacent edits into one...
+        
+    }
+     */
+    
+    private void diffTest(String contextLimit, String oldText, String newText, String expectedDiff)
+        throws IOException, WikiException
+    {
+        ContextualDiffProvider diff = new ContextualDiffProvider();
+
+        specializedNotation(diff);
+
+        Properties props = new Properties();
+        if (null != contextLimit)
+            props.put(ContextualDiffProvider.PROP_UNCHANGED_CONTEXT_LIMIT, contextLimit);
+
+        diff.initialize(null, props);
+
+        props.load( TestEngine.findTestProperties() );
+        PropertyConfigurator.configure(props);
+        TestEngine engine = new TestEngine(props);
+        
+        WikiContext ctx = engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(engine,"Dummy") );
+        String actualDiff = diff.makeDiffHtml( ctx, oldText, newText);
+
+        assertEquals(expectedDiff, actualDiff);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( ContextualDiffProviderTest.class );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,21 @@
+
+package com.ecyrd.jspwiki.filters;
+
+import junit.framework.*;
+
+public class AllTests extends TestCase
+{
+    public AllTests( String s )
+    {
+        super( s );
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("PageFilter tests");
+
+        suite.addTest( FilterManagerTest.suite() );
+
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/FilterManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/FilterManagerTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/FilterManagerTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/FilterManagerTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,76 @@
+
+package com.ecyrd.jspwiki.filters;
+
+import junit.framework.*;
+import java.util.*;
+
+import org.apache.log4j.*;
+
+import com.ecyrd.jspwiki.*;
+
+public class FilterManagerTest extends TestCase
+{
+    Properties props = new Properties();
+
+    TestEngine engine;
+
+    public FilterManagerTest( 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 testInitFilters()
+        throws Exception
+    {
+        FilterManager m = new FilterManager( engine, props );
+
+        List l = m.getFilterList();
+
+        assertEquals("Wrong number of filters", 2, l.size());
+
+        Iterator i = l.iterator();
+        PageFilter f1 = (PageFilter)i.next();
+
+        assertTrue("Not a Profanityfilter", f1 instanceof ProfanityFilter);
+
+        PageFilter f2 = (PageFilter)i.next();
+
+        assertTrue("Not a Testfilter", f2 instanceof TestFilter);
+    }
+
+    public void testInitParams()
+        throws Exception
+    {
+        FilterManager m = new FilterManager( engine, props );
+
+        List l = m.getFilterList();
+
+        Iterator i = l.iterator();
+        i.next();
+        TestFilter f2 = (TestFilter)i.next();
+
+        Properties p = f2.m_properties;
+
+        assertEquals("no foobar", "Zippadippadai", p.getProperty("foobar"));
+
+        assertEquals("no blatblaa", "5", p.getProperty( "blatblaa" ) );
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( FilterManagerTest.class );
+    }
+
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/TestFilter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/TestFilter.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/TestFilter.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/filters/TestFilter.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,16 @@
+package com.ecyrd.jspwiki.filters;
+
+import java.util.Properties;
+
+import com.ecyrd.jspwiki.WikiEngine;
+
+public class TestFilter
+    extends BasicPageFilter
+{
+    public Properties m_properties;
+
+    public void initialize( WikiEngine engine, Properties props )
+    {
+        m_properties = props;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,20 @@
+package com.ecyrd.jspwiki.htmltowiki;
+
+import junit.framework.*;
+
+public class AllTests extends TestCase
+{
+    public AllTests( String s )
+    {
+        super( s );
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("HtmlStringToWikiTranslatorTest tests");
+
+        suite.addTest( HtmlStringToWikiTranslatorTest.suite() );
+
+        return suite;
+    }
+}



Mime
View raw message