Removed DOCUMENT ME comments that were generated and applied source code
[utils] / security / src / test / java / org / wamblee / usermgt / UserAdministrationImplTest.java
index 5dde8b9b246df2df7d725867e7ebc182e9f978ac..d3990a2e762ff92873b938688065ccf1f10ddd8d 100644 (file)
@@ -25,80 +25,45 @@ import org.wamblee.usermgt.UserMgtException.Reason;
 
 import java.util.Set;
 
-
 /**
  * Test of user administration implementation.
- *
+ * 
  * @author Erik Brakkee
  */
 public class UserAdministrationImplTest extends TestCase {
-    /**
-     * DOCUMENT ME!
-     */
-    private static final Logger LOGGER = Logger.getLogger(UserAdministrationImplTest.class);
+    private static final Logger LOGGER = Logger
+        .getLogger(UserAdministrationImplTest.class);
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String USER1 = "piet";
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String PASS1 = "passpiet";
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String USER2 = "kees";
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String PASS2 = "passkees";
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String GROUP1 = "cyclists";
 
-    /**
-     * DOCUMENT ME!
-     */
     private static final String GROUP2 = "runners";
 
-    /**
-     * DOCUMENT ME!
-     */
     private UserAdministration admin;
 
     /*
      * (non-Javadoc)
-     *
+     * 
      * @see junit.framework.TestCase#setUp()
      */
-    /**
-     * DOCUMENT ME!
-     *
-     * @throws Exception DOCUMENT ME!
-     */
     @Override
     protected void setUp() throws Exception {
         super.setUp();
         admin = createAdmin();
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     */
     protected UserAdministration createAdmin() {
-        UserSet  users  = new InMemoryUserSet(new RegexpNameValidator(
-                    RegexpNameValidator.PASSWORD_PATTERN,
-                    Reason.INVALID_PASSWORD,
-                    "Password must contain at least 6 characters"),
-                new Md5HexMessageDigester());
+        UserSet users = new InMemoryUserSet(new RegexpNameValidator(
+            RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD,
+            "Password must contain at least 6 characters"),
+            new Md5HexMessageDigester());
         GroupSet groups = new InMemoryGroupSet();
 
         return new UserAdministrationImpl(users, groups,
@@ -108,17 +73,6 @@ public class UserAdministrationImplTest extends TestCase {
                 Reason.INVALID_GROUPNAME, "Invalid group"));
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param aName DOCUMENT ME!
-     * @param aPassword DOCUMENT ME!
-     * @param aGroup DOCUMENT ME!
-     *
-     * @return DOCUMENT ME!
-     *
-     * @throws UserMgtException DOCUMENT ME!
-     */
     protected User createUser(String aName, String aPassword, Group aGroup)
         throws UserMgtException {
         return UsermgtTestUtils.createUser(aName, aPassword, aGroup);
@@ -135,10 +89,9 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Creates a new group. Verifies the group is created correctly and
-     * that the user is added.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Creates a new group. Verifies the group is created correctly and that the
+     * user is added.
+     * 
      */
     public void testCreateGroup() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
@@ -151,26 +104,21 @@ public class UserAdministrationImplTest extends TestCase {
         assertTrue(groups.contains(group));
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param aUsername DOCUMENT ME!
-     */
     private void createInvalidGroup(String aUsername) {
         try {
             admin.createGroup(aUsername);
             fail();
         } catch (UserMgtException e) {
-            assertEquals(UserMgtException.Reason.INVALID_GROUPNAME,
-                e.getReason());
+            assertEquals(UserMgtException.Reason.INVALID_GROUPNAME, e
+                .getReason());
             assertEquals(0, admin.getGroupCount());
         }
     }
 
     /**
-     * Creates a new group with an invalid name. Verifies that the
-     * appropriate exception is thrown.
-     *
+     * Creates a new group with an invalid name. Verifies that the appropriate
+     * exception is thrown.
+     * 
      * @throws UserMgtException
      */
     public void testCreateInvalidGroupName() throws UserMgtException {
@@ -182,11 +130,9 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Creates a new group which conflicts with an existing one.
-     * Verifies that the UserMgtException is thrown and that no group is
-     * added.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Creates a new group which conflicts with an existing one. Verifies that
+     * the UserMgtException is thrown and that no group is added.
+     * 
      */
     public void testCreateDuplicateGroup() throws UserMgtException {
         admin.createGroup(GROUP1);
@@ -204,14 +150,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Creates a new user. Verifies the user is created correctly and
-     * that the user is added.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Creates a new user. Verifies the user is created correctly and that the
+     * user is added.
+     * 
      */
     public void testCreateUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = admin.createUser(USER1, PASS1, group);
+        User user = admin.createUser(USER1, PASS1, group);
         assertNotNull(user);
         assertEquals(USER1, user.getName());
         user.checkPassword(PASS1);
@@ -222,27 +167,21 @@ public class UserAdministrationImplTest extends TestCase {
         assertTrue(users.contains(user));
     }
 
-    /**
-     * DOCUMENT ME!
-     *
-     * @param aUsername DOCUMENT ME!
-     * @param aGroup DOCUMENT ME!
-     */
     private void createInvalidUser(String aUsername, Group aGroup) {
         try {
             admin.createUser(aUsername, "pass", aGroup);
             fail();
         } catch (UserMgtException e) {
-            assertEquals(UserMgtException.Reason.INVALID_USERNAME, e.getReason());
+            assertEquals(UserMgtException.Reason.INVALID_USERNAME, e
+                .getReason());
             assertEquals(0, admin.getUserCount());
         }
     }
 
     /**
-     * Constructs users with invalid names. Verifies that the
-     * appropriate exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Constructs users with invalid names. Verifies that the appropriate
+     * exception is thrown.
+     * 
      */
     public void testCreateInvalidUserName() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
@@ -254,10 +193,9 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Creates a new user which conflicts with an existing one.
-     * Verifies that the UserMgtException is thrown and that no user is added.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Creates a new user which conflicts with an existing one. Verifies that
+     * the UserMgtException is thrown and that no user is added.
+     * 
      */
     public void testCreateDuplicateUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
@@ -273,43 +211,39 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Gets a known user by name. Verifies the correct user is
-     * obtained. Verifies that null is returned when trying to obtain an
-     * unknown user.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Gets a known user by name. Verifies the correct user is obtained.
+     * Verifies that null is returned when trying to obtain an unknown user.
+     * 
      */
     public void testGetUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = admin.createUser(USER1, PASS1, group);
-        User  user2 = admin.getUser(USER1);
+        User user = admin.createUser(USER1, PASS1, group);
+        User user2 = admin.getUser(USER1);
         assertTrue(user.equals(user2));
         assertNull(admin.getUser(USER2));
     }
 
     /**
-     * Gets a known group by name. Verifies the correct group is
-     * obtained. Verifies that null is returned when the group is not known.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Gets a known group by name. Verifies the correct group is obtained.
+     * Verifies that null is returned when the group is not known.
+     * 
      */
     public void testGetGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
+        Group group = admin.createGroup(GROUP1);
         Group group2 = admin.getGroup(GROUP1);
         assertTrue(group.equals(group2));
         assertNull(admin.getGroup(GROUP2));
     }
 
     /**
-     * Adds a user to a group. Verifies that the user is added using
-     * several API calls. Verifies that an exception occurs if the user is not
-     * already part of the group.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Adds a user to a group. Verifies that the user is added using several API
+     * calls. Verifies that an exception occurs if the user is not already part
+     * of the group.
+     * 
      */
     public void testAddUserToGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
-        User  user   = admin.createUser(USER1, PASS1, group);
+        Group group = admin.createGroup(GROUP1);
+        User user = admin.createUser(USER1, PASS1, group);
         Group group2 = admin.createGroup(GROUP2);
         assertTrue(user.isInGroup(group));
         assertFalse(user.isInGroup(group2));
@@ -325,8 +259,8 @@ public class UserAdministrationImplTest extends TestCase {
         try {
             admin.addUserToGroup(user, group);
         } catch (UserMgtException e) {
-            assertEquals(UserMgtException.Reason.USER_ALREADY_IN_GROUP,
-                e.getReason());
+            assertEquals(UserMgtException.Reason.USER_ALREADY_IN_GROUP, e
+                .getReason());
 
             return;
         }
@@ -335,14 +269,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Adds a user to a group where the user does not exist. Verifies
-     * that an exception occurs.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Adds a user to a group where the user does not exist. Verifies that an
+     * exception occurs.
+     * 
      */
     public void testAddUserToGroupUnknownUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = createUser(USER1, PASS1, group);
+        User user = createUser(USER1, PASS1, group);
 
         try {
             admin.addUserToGroup(user, group);
@@ -356,14 +289,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Adds a user to a group where the user does not exist. Verifies
-     * that an exception occurs.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Adds a user to a group where the user does not exist. Verifies that an
+     * exception occurs.
+     * 
      */
     public void testAddUserToGroupUnknownGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
-        User  user   = admin.createUser(USER1, PASS1, group);
+        Group group = admin.createGroup(GROUP1);
+        User user = admin.createUser(USER1, PASS1, group);
         Group group2 = new Group(GROUP2);
 
         try {
@@ -378,17 +310,15 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a user from a group. Verifies that the user is removed
-     * from the group using several API calls. Verifies that an exception
-     * occurs if the user not part of the group or if the user is only part of
-     * one group.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a user from a group. Verifies that the user is removed from the
+     * group using several API calls. Verifies that an exception occurs if the
+     * user not part of the group or if the user is only part of one group.
+     * 
      */
     public void testRemoveUserFromGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
+        Group group = admin.createGroup(GROUP1);
 
-        User  user   = admin.createUser(USER1, PASS1, group);
+        User user = admin.createUser(USER1, PASS1, group);
         Group group2 = admin.createGroup(GROUP2);
         admin.addUserToGroup(user, group2);
 
@@ -405,14 +335,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a user from a group where the user is not known.
-     * Verifies that an exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a user from a group where the user is not known. Verifies that an
+     * exception is thrown.
+     * 
      */
     public void testRemoveUserFromGroupUnknownUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = createUser(USER1, GROUP1, group);
+        User user = createUser(USER1, GROUP1, group);
 
         try {
             admin.removeUserFromGroup(user, group);
@@ -422,14 +351,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a user from a group where the group is not known.
-     * Verifies that an exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a user from a group where the group is not known. Verifies that
+     * an exception is thrown.
+     * 
      */
     public void testRemoveUserFromGroupUnknownGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
-        User  user   = admin.createUser(USER1, PASS1, group);
+        Group group = admin.createGroup(GROUP1);
+        User user = admin.createUser(USER1, PASS1, group);
         Group group2 = new Group(GROUP2);
 
         try {
@@ -440,38 +368,36 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a user from a group where the user is only part of one
-     * group. Verifies that an exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a user from a group where the user is only part of one group.
+     * Verifies that an exception is thrown.
+     * 
      */
     public void testRemoveUserFromGroupOnlyGroup() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = admin.createUser(USER1, PASS1, group);
+        User user = admin.createUser(USER1, PASS1, group);
 
         try {
             admin.removeUserFromGroup(user, group);
         } catch (UserMgtException e) {
-            assertEquals(UserMgtException.Reason.USER_MUST_BE_IN_A_GROUP,
-                e.getReason());
+            assertEquals(UserMgtException.Reason.USER_MUST_BE_IN_A_GROUP, e
+                .getReason());
         }
     }
 
     /**
-     * Gets the list of users and groups. Verifies that the correct
-     * suers and groups are returned. Verifies also that the relations from
-     * user to group are correct.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Gets the list of users and groups. Verifies that the correct suers and
+     * groups are returned. Verifies also that the relations from user to group
+     * are correct.
+     * 
      */
     public void testGetUsersAndGroups() throws UserMgtException {
         Group group1 = admin.createGroup(GROUP1);
         Group group2 = admin.createGroup(GROUP2);
 
-        User  user1  = admin.createUser(USER1, PASS1, group1);
+        User user1 = admin.createUser(USER1, PASS1, group1);
         admin.addUserToGroup(user1, group2);
 
-        User      user2 = admin.createUser(USER2, PASS2, group2);
+        User user2 = admin.createUser(USER2, PASS2, group2);
 
         Set<User> users = admin.getUsers();
         assertEquals(2, users.size());
@@ -499,12 +425,11 @@ public class UserAdministrationImplTest extends TestCase {
      * Renames a user. Verifies that the user is renamed. Verifies that
      * exceptions are thrown when an attempt is made to rename the user to
      * itself or to another existing user, or when the group does not exist.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * 
      */
     public void testRenameUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user1 = admin.createUser(USER1, PASS1, group);
+        User user1 = admin.createUser(USER1, PASS1, group);
         admin.renameUser(user1, USER2);
         assertEquals(USER2, user1.getName());
         assertEquals(user1, admin.getUser(USER2));
@@ -520,8 +445,8 @@ public class UserAdministrationImplTest extends TestCase {
             try {
                 admin.renameUser(user1, user1.getName());
             } catch (UserMgtException e2) {
-                assertEquals(UserMgtException.Reason.TRIVIAL_RENAME,
-                    e2.getReason());
+                assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, e2
+                    .getReason());
 
                 return;
             }
@@ -533,14 +458,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Renames a user to a user with an invalid username. Verifies that
-     * the appropriate exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Renames a user to a user with an invalid username. Verifies that the
+     * appropriate exception is thrown.
+     * 
      */
     public void testRenameUserInvalidUsername() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user1 = admin.createUser(USER1, PASS1, group);
+        User user1 = admin.createUser(USER1, PASS1, group);
 
         try {
             admin.renameUser(user1, USER2);
@@ -550,12 +474,10 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Renames a group. Verifies that the group is renamed. Verifies
-     * that exceptions are thrown when an attempt is made to rename the group
-     * to itself or to another existing group or when the group does not
-     * exist.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Renames a group. Verifies that the group is renamed. Verifies that
+     * exceptions are thrown when an attempt is made to rename the group to
+     * itself or to another existing group or when the group does not exist.
+     * 
      */
     public void testRenameGroup() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
@@ -574,8 +496,8 @@ public class UserAdministrationImplTest extends TestCase {
             try {
                 admin.renameGroup(group, group.getName());
             } catch (UserMgtException e2) {
-                assertEquals(UserMgtException.Reason.TRIVIAL_RENAME,
-                    e2.getReason());
+                assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, e2
+                    .getReason());
 
                 return;
             }
@@ -589,10 +511,9 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Renames a group to a group with an invalid name. Verifies that
-     * the appropriate exception is thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Renames a group to a group with an invalid name. Verifies that the
+     * appropriate exception is thrown.
+     * 
      */
     public void testRenameGroupInvalidGroupname() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
@@ -605,14 +526,13 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a user. Verifies that the user is removed. Verifies that
-     * the an exception is thrown when the user does not exist.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a user. Verifies that the user is removed. Verifies that the an
+     * exception is thrown when the user does not exist.
+     * 
      */
     public void testRemoveUser() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = admin.createUser(USER1, PASS1, group);
+        User user = admin.createUser(USER1, PASS1, group);
 
         assertEquals(1, admin.getUserCount());
         admin.removeUser(user);
@@ -631,11 +551,10 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Removes a group. Verifies that the group is removed. Verifies
-     * that the an exception is thrown when the group does not exist or if
-     * there are still users in the group.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Removes a group. Verifies that the group is removed. Verifies that the an
+     * exception is thrown when the group does not exist or if there are still
+     * users in the group.
+     * 
      */
     public void testRemoveGroup() throws UserMgtException {
         Group group1 = admin.createGroup(GROUP1);
@@ -649,8 +568,8 @@ public class UserAdministrationImplTest extends TestCase {
         try {
             admin.removeGroup(group1);
         } catch (UserMgtException e) {
-            assertEquals(UserMgtException.Reason.GROUP_STILL_OCCUPIED,
-                e.getReason());
+            assertEquals(UserMgtException.Reason.GROUP_STILL_OCCUPIED, e
+                .getReason());
 
             return;
         }
@@ -659,13 +578,11 @@ public class UserAdministrationImplTest extends TestCase {
     }
 
     /**
-     * Tries to remove an unknown group. Verifies that an exception is
-     * thrown.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * Tries to remove an unknown group. Verifies that an exception is thrown.
+     * 
      */
     public void testRemoveGroupUnknownGroup() throws UserMgtException {
-        Group group  = admin.createGroup(GROUP1);
+        Group group = admin.createGroup(GROUP1);
         Group group2 = new Group(GROUP2);
 
         try {
@@ -677,12 +594,12 @@ public class UserAdministrationImplTest extends TestCase {
 
     /**
      * Changes the password, verifies that this succeeds.
-     *
+     * 
      * @throws UserMgtException
      */
     public void testChangePassword() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
-        User  user  = admin.createUser(USER1, PASS1, group);
+        User user = admin.createUser(USER1, PASS1, group);
         user.changePassword(PASS1, PASS2);
 
         // retrieve the user and verifies the password hasn't changed.
@@ -704,21 +621,20 @@ public class UserAdministrationImplTest extends TestCase {
 
     /**
      * Performance test. Finds a user by name.
-     *
-     * @throws UserMgtException DOCUMENT ME!
+     * 
      */
     public void testPerformanceFindUserByName() throws UserMgtException {
         Group group = admin.createGroup(GROUP1);
         admin.createUser(USER1, PASS1, group);
 
-        int  n    = 1000;
+        int n = 1000;
         long time = System.currentTimeMillis();
 
         for (int i = 0; i < n; i++) {
             admin.getUser(USER1);
         }
 
-        LOGGER.info("Looked up a user " + n + " times in "
-            ((float) (System.currentTimeMillis() - time) / 1000.0));
+        LOGGER.info("Looked up a user " + n + " times in " +
+            ((float) (System.currentTimeMillis() - time) / 1000.0));
     }
 }