james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r1241453 - /james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
Date Tue, 07 Feb 2012 13:06:54 GMT
Author: eric
Date: Tue Feb  7 13:06:53 2012
New Revision: 1241453

URL: http://svn.apache.org/viewvc?rev=1241453&view=rev
Log:
Add test for lower/upper cases + re-enable tests via public visibility (JAMES-1369)

Modified:
    james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java

Modified: james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java?rev=1241453&r1=1241452&r2=1241453&view=diff
==============================================================================
--- james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
(original)
+++ james/server/trunk/data-library/src/test/java/org/apache/james/user/lib/AbstractUsersRepositoryTest.java
Tue Feb  7 13:06:53 2012
@@ -22,6 +22,7 @@ package org.apache.james.user.lib;
 import java.util.ArrayList;
 import java.util.Iterator;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.james.lifecycle.api.LifecycleUtil;
@@ -47,6 +48,22 @@ public abstract class AbstractUsersRepos
      */
     protected abstract UsersRepository getUsersRepository() throws Exception;
 
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.usersRepository = getUsersRepository();
+    }
+
+    /**
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        disposeUsersRepository();
+        super.tearDown();
+    }
+
     public void testUsersRepositoryEmpty() throws UsersRepositoryException {
         assertEquals("users repository not empty", 0, usersRepository.countUsers());
         assertFalse("users repository not empty", usersRepository.list().hasNext());
@@ -57,9 +74,8 @@ public abstract class AbstractUsersRepos
         try {
             usersRepository.addUser("username", "password2");
             fail("User added twice!");
-
         } catch (UsersRepositoryException e) {
-
+            // UsersRepositoryException must be thrown by implementation.
         }
         try {
             usersRepository.addUser("username2", "password2");
@@ -69,7 +85,6 @@ public abstract class AbstractUsersRepos
         } catch (UnsupportedOperationException e) {
 
         }
-
     }
 
     public void testUserAddedIsFound() throws UsersRepositoryException {
@@ -114,6 +129,17 @@ public abstract class AbstractUsersRepos
         assertEquals("Some user has not be found", 0, check.size());
     }
 
+    public void testUpperCaseSameUser() throws UsersRepositoryException {
+        usersRepository.addUser("myUsername", "password");
+        try {
+            usersRepository.addUser("MyUsername", "password");
+            Assert.fail("We should not be able to insert same users, even with different
cases");
+        }
+        catch (UsersRepositoryException e) {
+            Assert.assertTrue("The exception message must contain the username value", e.getMessage().contains("myusername"));
+        }
+    }
+
     public void testUserPassword() throws UsersRepositoryException {
         usersRepository.addUser("username", "password");
         assertEquals("didn't accept the correct password ", usersRepository.test("username",
"password"), getPasswordsEnabled());
@@ -124,18 +150,14 @@ public abstract class AbstractUsersRepos
         assertFalse("accepted the wrong password #5", usersRepository.test("userName", "password"));
     }
 
-    protected boolean getPasswordsEnabled() {
-        return true;
-    }
-
     public void testUserAddRemoveCycle() throws UsersRepositoryException {
         assertFalse("accepted login when no user existed", usersRepository.test("username",
"password"));
         try {
             usersRepository.removeUser("username");
             // UsersFileRepository accept this call for every argument
             // fail("removing an unknown user didn't fail!");
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (UsersRepositoryException e) {
+            // Do nothing, we should come here if test works.
         }
         usersRepository.addUser("username", "password");
         assertEquals("didn't accept the correct password", usersRepository.test("username",
"password"), getPasswordsEnabled());
@@ -167,41 +189,18 @@ public abstract class AbstractUsersRepos
     }
 
     /**
-     * @return
-     */
-    protected boolean getCheckCase() {
-        return true;
-    }
-
-    protected boolean getAllowMultipleUsersWithDifferentCases() {
-        return getCheckCase();
-    }
-
-    /**
-     * @see junit.framework.TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-        this.usersRepository = getUsersRepository();
-    }
-
-    /**
-     * @see junit.framework.TestCase#tearDown()
-     */
-    protected void tearDown() throws Exception {
-        disposeUsersRepository();
-        super.tearDown();
-    }
-
-    /**
      * Dispose the repository
      * 
      * @throws UsersRepositoryException
      */
-    protected void disposeUsersRepository() throws UsersRepositoryException {
+    private void disposeUsersRepository() throws UsersRepositoryException {
         if (usersRepository != null) {
             LifecycleUtil.dispose(this.usersRepository);
         }
     }
 
+    private boolean getPasswordsEnabled() {
+        return true;
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message