Author: ajaquith
Date: Thu May 22 21:10:08 2008
New Revision: 659410

URL: http://svn.apache.org/viewvc?rev=659410&view=rev
Log:
Checked in three new features for UserProfile and the UserDatabase classes. 
First, profiles can now store arbitrary Serializable objects via a new method 
in UserProfile, getAttributes, that returns a Map<Serializable,Serializable> 
that can be directly manipulated. Arbitrary attributes such as user preferences 
can be added to the profile and be guaranteed to be persisted on save. Second, 
the UserProfile now has two methods setLockExpiry(Date)/getLockExpiry that 
allow callers to disable user profiles. These are NOT enforced in 
AuthenticationManager yet. Third, user profile now have a 'uid' field that 
stores a long value for uniquely identifying users. Existing profiles without 
UIDs are automatically upgraded when they are loaded by a findBy___() method. 
The default XML/JDBC UserDatabase implementations have been enhanced to support 
all of these new features. If you have custom UserDatabase implementations, you 
should take a look at the new code.

Added:
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/SerializerTest.java
Modified:
    
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java
    
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
    
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java
    
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
    incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
 (original)
+++ 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/AuthorizationManagerTest.java
 Thu May 22 21:10:08 2008
@@ -505,7 +505,7 @@
     public void testResolveUsers() throws WikiException
     {
         // We should be able to resolve a user by login, user, or wiki name
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = 
m_engine.getUserManager().getUserDatabase().newProfile();
         profile.setEmail( "[EMAIL PROTECTED]" );
         profile.setFullname( "AuthorizationManagerTest User" );
         profile.setLoginName( "authmanagertest" );

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java 
(original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/UserManagerTest.java 
Thu May 22 21:10:08 2008
@@ -110,7 +110,7 @@
       String oldName      = "Test User " + now;
       String newLogin     = "RenamedLogin" + now;
       String newName      = "Renamed User " + now;
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setLoginName( oldLogin );
       profile.setFullname ( oldName );
@@ -152,7 +152,7 @@
       assertFalse  ( "Bob !view page", authManager.checkPermission( 
bobSession, PermissionFactory.getPagePermission( p, "view" ) ) );
       
       // Setup Step 4: change the user name in the profile and see what happens
-      profile = new DefaultUserProfile();
+      profile = m_db.newProfile();
       profile.setEmail    ( "[EMAIL PROTECTED]" );
       profile.setLoginName( oldLogin );
       profile.setFullname ( newName );
@@ -211,7 +211,7 @@
       assertFalse  ( "Bob !view page", authManager.checkPermission( 
bobSession, PermissionFactory.getPagePermission( p, "view" ) ) );
       
       // Setup Step 8: re-save the profile with the new login name
-      profile = new DefaultUserProfile();
+      profile = m_db.newProfile();
       profile.setEmail    ( "[EMAIL PROTECTED]" );
       profile.setLoginName( newLogin );
       profile.setFullname ( oldName );
@@ -268,7 +268,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -295,7 +295,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -349,7 +349,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -397,7 +397,7 @@
       // Create a new user with random name
       WikiSession session = m_engine.guestSession();
       String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
 (original)
+++ 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/JDBCUserDatabaseTest.java
 Thu May 22 21:10:08 2008
@@ -1,11 +1,13 @@
 package com.ecyrd.jspwiki.auth.user;
 
 import java.io.File;
+import java.io.Serializable;
 import java.security.Principal;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.Timestamp;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -26,25 +28,31 @@
 public class JDBCUserDatabaseTest extends TestCase
 {
     private JDBCUserDatabase m_db   = null;
+    
+    private static final String TEST_ATTRIBUTES = 
"rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAx3CAAAABAAAAACdAAKYXR0cmlidXRlMXQAEXNvbWUgcmFuZG9tIHZhbHVldAAKYXR0cmlidXRlMnQADWFub3RoZXIgdmFsdWV4";
 
     private static final String INSERT_JANNE = "INSERT INTO users (" +
+          JDBCUserDatabase.DEFAULT_DB_UID + "," +
           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 (" +
-          "'[EMAIL PROTECTED]'," + "'Janne Jalkanen'," + "'janne'," +
+          JDBCUserDatabase.DEFAULT_DB_CREATED + "," +
+          JDBCUserDatabase.DEFAULT_DB_ATTRIBUTES + ") VALUES (" +
+          "'-7739839977499061014'," + "'[EMAIL PROTECTED]'," + "'Janne 
Jalkanen'," + "'janne'," +
           "'{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee'," +
           "'JanneJalkanen'," +
-          "'" + new Timestamp( new Timestamp( System.currentTimeMillis() 
).getTime() ).toString() + "'" + ");";
+          "'" + new Timestamp( new Timestamp( System.currentTimeMillis() 
).getTime() ).toString() + "'," +
+          "'" + TEST_ATTRIBUTES +"'" + ");";
 
     private static final String INSERT_USER = "INSERT INTO users (" +
+        JDBCUserDatabase.DEFAULT_DB_UID + "," +
         JDBCUserDatabase.DEFAULT_DB_EMAIL + "," +
         JDBCUserDatabase.DEFAULT_DB_LOGIN_NAME + "," +
         JDBCUserDatabase.DEFAULT_DB_PASSWORD + "," +
         JDBCUserDatabase.DEFAULT_DB_CREATED + ") VALUES (" +
-        "'[EMAIL PROTECTED]'," + "'user'," +
+        "'-8629747547991531672'," + "'[EMAIL PROTECTED]'," + "'user'," +
         "'{SHA}5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'," +
         "'" + new Timestamp( new Timestamp( System.currentTimeMillis() 
).getTime() ).toString() + "'" + ");";
 
@@ -103,7 +111,7 @@
 
         // Create a new user with random name
         String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = m_db.newProfile();
         profile.setEmail("[EMAIL PROTECTED]");
         profile.setLoginName( loginName );
         profile.setFullname( "FullName"+loginName );
@@ -120,11 +128,45 @@
         assertEquals( oldUserCount, m_db.getWikiNames().length );
     }
 
+    public void testAttributes() throws Exception
+    {
+        UserProfile profile = m_db.findByEmail( "[EMAIL PROTECTED]" );
+        
+        Map<Serializable,Serializable> attributes = profile.getAttributes();
+        assertEquals( 2, attributes.size() );
+        assertTrue( attributes.containsKey( "attribute1" ) );
+        assertTrue( attributes.containsKey( "attribute2" ) );
+        assertEquals( "some random value", attributes.get( "attribute1" ) );
+        assertEquals( "another value", attributes.get( "attribute2" ) );
+        
+        // Change attribute 1, and add another one
+        attributes.put( "attribute1", "replacement value" );
+        attributes.put( "attribute the third", "some value" );
+        m_db.save( profile );
+        
+        // Retrieve the profile again and make sure our values got saved
+        profile = m_db.findByEmail( "[EMAIL PROTECTED]" );
+        attributes = profile.getAttributes();
+        assertEquals( 3, attributes.size() );
+        assertTrue( attributes.containsKey( "attribute1" ) );
+        assertTrue( attributes.containsKey( "attribute2" ) );
+        assertTrue( attributes.containsKey( "attribute the third" ) );
+        assertEquals( "replacement value", attributes.get( "attribute1" ) );
+        assertEquals( "another value", attributes.get( "attribute2" ) );
+        assertEquals( "some value", attributes.get( "attribute the third" ) );
+        
+        // Restore the original attributes and re-save
+        attributes.put( "attribute1", "some random value" );
+        attributes.remove( "attribute the third" );
+        m_db.save( profile );
+    }
+    
     public void testFindByEmail()
     {
         try
         {
             UserProfile profile = m_db.findByEmail( "[EMAIL PROTECTED]" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -154,6 +196,7 @@
         try
         {
             UserProfile profile = m_db.findByFullName( "Janne Jalkanen" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -178,11 +221,42 @@
         }
     }
 
+    public void testFindByUid()
+    {
+        try
+        {
+            UserProfile profile = m_db.findByUid( -7739839977499061014L );
+            assertEquals( -7739839977499061014L, profile.getUid() );
+            assertEquals( "janne", profile.getLoginName() );
+            assertEquals( "Janne Jalkanen", profile.getFullname() );
+            assertEquals( "JanneJalkanen", profile.getWikiName() );
+            assertEquals( "{SHA}457b08e825da547c3b77fbc1ff906a1d00a7daee", 
profile.getPassword() );
+            assertEquals( "[EMAIL PROTECTED]", profile.getEmail() );
+            assertNotNull( profile.getCreated() );
+            assertNull( profile.getLastModified() );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( false );
+        }
+        try
+        {
+            m_db.findByEmail( "[EMAIL PROTECTED]" );
+            // We should never get here
+            assertTrue( false );
+        }
+        catch( NoSuchPrincipalException e )
+        {
+            assertTrue( true );
+        }
+    }
+    
     public void testFindByWikiName()
     {
         try
         {
             UserProfile profile = m_db.findByWikiName( "JanneJalkanen" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -212,6 +286,7 @@
         try
         {
             UserProfile profile = m_db.findByLoginName( "janne" );
+            assertEquals( -7739839977499061014L, profile.getUid() );
             assertEquals( "janne", profile.getLoginName() );
             assertEquals( "Janne Jalkanen", profile.getFullname() );
             assertEquals( "JanneJalkanen", profile.getWikiName() );
@@ -256,7 +331,7 @@
         }
 
         // Create new user & verify it saved ok
-        UserProfile profile = new DefaultUserProfile();
+        UserProfile profile = m_db.newProfile();
         profile.setEmail( "[EMAIL PROTECTED]" );
         profile.setFullname( "Renamed User" );
         profile.setLoginName( "olduser" );
@@ -306,7 +381,7 @@
         try
         {
             // Overwrite existing user
-            UserProfile profile = new DefaultUserProfile();
+            UserProfile profile = m_db.newProfile();
             profile.setEmail( "[EMAIL PROTECTED]" );
             profile.setFullname( "Test User" );
             profile.setLoginName( "user" );
@@ -323,7 +398,7 @@
             assertNotSame( profile.getCreated(), profile.getLastModified() );
 
             // Create new user
-            profile = new DefaultUserProfile();
+            profile = m_db.newProfile();
             profile.setEmail( "[EMAIL PROTECTED]" );
             profile.setFullname( "Test User 2" );
             profile.setLoginName( "user2" );

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java 
(original)
+++ 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/UserProfileTest.java 
Thu May 22 21:10:08 2008
@@ -1,6 +1,6 @@
 package com.ecyrd.jspwiki.auth.user;
 
-import java.io.IOException;
+import java.util.Date;
 import java.util.Properties;
 
 import junit.framework.Test;
@@ -10,6 +10,7 @@
 import org.apache.log4j.PropertyConfigurator;
 
 import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiEngine;
 
 /**
  *  Tests the DefaultUserProfile class.
@@ -17,31 +18,79 @@
  */
 public class UserProfileTest extends TestCase
 {
-    public UserProfileTest( String s )
+    private UserDatabase m_db;
+    
+    public void setUp()
+        throws Exception
     {
-        super( s );
-        Properties props = new Properties();
-        try
-        {
+            Properties props = new Properties();
             props.load( TestEngine.findTestProperties() );
             PropertyConfigurator.configure(props);
-        }
-        catch( IOException e ) {}
+            WikiEngine engine  = new TestEngine(props);
+            m_db = engine.getUserManager().getUserDatabase();
     }
 
-    public void setUp()
-        throws Exception
+    public void tearDown()
     {
     }
-
-    public void tearDown()
+    
+    public void testSetAttribute()
     {
+        UserProfile p = m_db.newProfile();
+        assertEquals( 0, p.getAttributes().size() );
+        
+        p.getAttributes().put( "MyAttribute", "some arbitrary value." );
+        assertEquals( 1, p.getAttributes().size() );
+        
+        p.getAttributes().put( "YourAttribute", "another arbitrary value." );
+        assertEquals( 2, p.getAttributes().size() );
+        assertTrue( p.getAttributes().containsKey( "MyAttribute" ) );
+        assertTrue( p.getAttributes().containsKey( "YourAttribute" ) );
+        
+        p.getAttributes().remove( "MyAttribute" );
+        assertEquals( 1, p.getAttributes().size() );
+    }
+    
+    public void testSetLockExpiry()
+    {
+        UserProfile p = m_db.newProfile();
+        assertNull( p.getLockExpiry() );
+        assertFalse( p.isLocked() );
+        
+        // Set a lock expiry for 1 second in the past; should cause lock to 
report as null
+        p.setLockExpiry( new Date( System.currentTimeMillis() - 1000 ) );
+        assertNull( p.getLockExpiry() );
+        assertFalse( p.isLocked() );
+        
+        // Set a lock expiry for 1 second in the past; should say it's not 
locked
+        p.setLockExpiry( new Date( System.currentTimeMillis() - 1000 ) );
+        assertFalse( p.isLocked() );
+        assertNull( p.getLockExpiry() );
+        
+        // Now set a lock for 100 seconds in the future; lock should be 
reported correctly
+        Date future = new Date( System.currentTimeMillis() + 100000 );
+        p.setLockExpiry( future );
+        assertTrue( p.isLocked() );
+        assertEquals( future, p.getLockExpiry() );
+        
+        // Clear the lock
+        p.setLockExpiry( null );
+        assertFalse( p.isLocked() );
+        assertNull( p.getLockExpiry() );
+    }
+    
+    public void testSetUid()
+    {
+        UserProfile p = m_db.newProfile();
+        assertNotSame( 1234567890, p.getUid() );
+        p.setUid( 1234567890 );
+        assertEquals( 1234567890, p.getUid() );
     }
 
     public void testEquals()
     {
-        UserProfile p = new DefaultUserProfile();
-        UserProfile p2 = new DefaultUserProfile();
+        UserProfile p = m_db.newProfile();
+        UserProfile p2 = m_db.newProfile();
 
         p.setFullname("Alice");
         p2.setFullname("Bob");
@@ -51,8 +100,8 @@
 
     public void testEquals2()
     {
-        UserProfile p = new DefaultUserProfile();
-        UserProfile p2 = new DefaultUserProfile();
+        UserProfile p = m_db.newProfile();
+        UserProfile p2 = m_db.newProfile();
 
         p.setFullname("Alice");
         p2.setFullname("Alice");

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
 (original)
+++ 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/auth/user/XMLUserDatabaseTest.java
 Thu May 22 21:10:08 2008
@@ -1,5 +1,7 @@
 package com.ecyrd.jspwiki.auth.user;
+import java.io.Serializable;
 import java.security.Principal;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.commons.lang.ArrayUtils;
@@ -45,7 +47,7 @@
 
       // Create a new user with random name
       String loginName = "TestUser" + String.valueOf( 
System.currentTimeMillis() );
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail("[EMAIL PROTECTED]");
       profile.setLoginName( loginName );
       profile.setFullname( "FullName"+loginName );
@@ -62,11 +64,45 @@
       assertEquals( oldUserCount, m_db.getWikiNames().length );
   }
 
+  public void testAttributes() throws Exception
+  {
+      UserProfile profile = m_db.findByEmail( "[EMAIL PROTECTED]" );
+      
+      Map<Serializable,Serializable> attributes = profile.getAttributes();
+      assertEquals( 2, attributes.size() );
+      assertTrue( attributes.containsKey( "attribute1" ) );
+      assertTrue( attributes.containsKey( "attribute2" ) );
+      assertEquals( "some random value", attributes.get( "attribute1" ) );
+      assertEquals( "another value", attributes.get( "attribute2" ) );
+      
+      // Change attribute 1, and add another one
+      attributes.put( "attribute1", "replacement value" );
+      attributes.put( "attribute the third", "some value" );
+      m_db.save( profile );
+      
+      // Retrieve the profile again and make sure our values got saved
+      profile = m_db.findByEmail( "[EMAIL PROTECTED]" );
+      attributes = profile.getAttributes();
+      assertEquals( 3, attributes.size() );
+      assertTrue( attributes.containsKey( "attribute1" ) );
+      assertTrue( attributes.containsKey( "attribute2" ) );
+      assertTrue( attributes.containsKey( "attribute the third" ) );
+      assertEquals( "replacement value", attributes.get( "attribute1" ) );
+      assertEquals( "another value", attributes.get( "attribute2" ) );
+      assertEquals( "some value", attributes.get( "attribute the third" ) );
+      
+      // Restore the original attributes and re-save
+      attributes.put( "attribute1", "some random value" );
+      attributes.remove( "attribute the third" );
+      m_db.save( profile );
+  }
+
   public void testFindByEmail()
   {
     try
     {
         UserProfile profile = m_db.findByEmail("[EMAIL PROTECTED]");
+        assertEquals( -7739839977499061014L, profile.getUid() );
         assertEquals("janne",           profile.getLoginName());
         assertEquals("Janne Jalkanen",  profile.getFullname());
         assertEquals("JanneJalkanen",   profile.getWikiName());
@@ -89,11 +125,72 @@
     }
   }
 
+  public void testFindByFullName()
+  {
+      try
+      {
+          UserProfile profile = m_db.findByFullName( "Janne Jalkanen" );
+          assertEquals( -7739839977499061014L, profile.getUid() );
+          assertEquals( "janne", profile.getLoginName() );
+          assertEquals( "Janne Jalkanen", profile.getFullname() );
+          assertEquals( "JanneJalkanen", profile.getWikiName() );
+          assertEquals("{SSHA}1WFv9OV11pD5IySgVH3sFa2VlCyYjbLrcVT/qw==", 
profile.getPassword());
+          assertEquals( "[EMAIL PROTECTED]", profile.getEmail() );
+          assertNotNull( profile.getCreated() );
+          assertNotNull( profile.getLastModified() );
+      }
+      catch( NoSuchPrincipalException e )
+      {
+          assertTrue( false );
+      }
+      try
+      {
+          m_db.findByEmail( "[EMAIL PROTECTED]" );
+          // We should never get here
+          assertTrue( false );
+      }
+      catch( NoSuchPrincipalException e )
+      {
+          assertTrue( true );
+      }
+  }
+
+  public void testFindByUid()
+  {
+      try
+      {
+          UserProfile profile = m_db.findByUid( -7739839977499061014L );
+          assertEquals( -7739839977499061014L, profile.getUid() );
+          assertEquals( "janne", profile.getLoginName() );
+          assertEquals( "Janne Jalkanen", profile.getFullname() );
+          assertEquals( "JanneJalkanen", profile.getWikiName() );
+          assertEquals("{SSHA}1WFv9OV11pD5IySgVH3sFa2VlCyYjbLrcVT/qw==", 
profile.getPassword());
+          assertEquals( "[EMAIL PROTECTED]", profile.getEmail() );
+          assertNotNull( profile.getCreated() );
+          assertNotNull( profile.getLastModified() );
+      }
+      catch( NoSuchPrincipalException e )
+      {
+          assertTrue( false );
+      }
+      try
+      {
+          m_db.findByEmail( "[EMAIL PROTECTED]" );
+          // We should never get here
+          assertTrue( false );
+      }
+      catch( NoSuchPrincipalException e )
+      {
+          assertTrue( true );
+      }
+  }
+  
   public void testFindByWikiName()
   {
       try
       {
           UserProfile profile = m_db.findByWikiName("JanneJalkanen");
+          assertEquals( -7739839977499061014L, profile.getUid() );
           assertEquals("janne",           profile.getLoginName());
           assertEquals("Janne Jalkanen",  profile.getFullname());
           assertEquals("JanneJalkanen",   profile.getWikiName());
@@ -121,6 +218,7 @@
       try
       {
           UserProfile profile = m_db.findByLoginName("janne");
+          assertEquals( -7739839977499061014L, profile.getUid() );
           assertEquals("janne",           profile.getLoginName());
           assertEquals("Janne Jalkanen",  profile.getFullname());
           assertEquals("JanneJalkanen",   profile.getWikiName());
@@ -172,7 +270,7 @@
       }
 
       // Create new user & verify it saved ok
-      UserProfile profile = new DefaultUserProfile();
+      UserProfile profile = m_db.newProfile();
       profile.setEmail( "[EMAIL PROTECTED]" );
       profile.setFullname( "Renamed User" );
       profile.setLoginName( "olduser" );
@@ -221,7 +319,7 @@
   {
       try
       {
-          UserProfile profile = new DefaultUserProfile();
+          UserProfile profile = m_db.newProfile();
           profile.setEmail("[EMAIL PROTECTED]");
           profile.setLoginName("user");
           profile.setPassword("password");

Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java?rev=659410&r1=659409&r2=659410&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java 
(original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/AllTests.java Thu May 
22 21:10:08 2008
@@ -20,6 +20,7 @@
         suite.addTest( CryptoUtilTest.suite() );
         suite.addTest( MailUtilTest.suite() );
         suite.addTest( PriorityListTest.suite() );
+        suite.addTest( SerializerTest.suite() );
         suite.addTest( TextUtilTest.suite() );
         suite.addTest( TimedCounterListTest.suite() );
         

Added: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/SerializerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/SerializerTest.java?rev=659410&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/SerializerTest.java 
(added)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/SerializerTest.java 
Thu May 22 21:10:08 2008
@@ -0,0 +1,33 @@
+package com.ecyrd.jspwiki.util;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class SerializerTest extends TestCase
+{
+
+    public static Test suite()
+    {
+        return new TestSuite( SerializerTest.class );
+    }
+
+    public void testSerializeMap() throws Exception
+    {
+        Map<Serializable, Serializable> map = new HashMap<Serializable, 
Serializable>();
+        map.put( "attribute1", "some random value" );
+        map.put( "attribute2", "another value" );
+        String serializedForm = Serializer.serializeToBase64( map );
+
+        Map<? extends Serializable, ? extends Serializable> newMap = 
Serializer.deserializeFromBase64( serializedForm );
+        assertEquals( 2, newMap.size() );
+        assertTrue( newMap.containsKey( "attribute1" ) );
+        assertTrue( newMap.containsKey( "attribute2" ) );
+        assertEquals( "some random value", newMap.get( "attribute1" ) );
+        assertEquals( "another value", newMap.get( "attribute2" ) );
+    }
+}


Reply via email to