X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fusermgt%2FUserAdministrationImplTest.java;h=5dde8b9b246df2df7d725867e7ebc182e9f978ac;hb=ddd261f331280640c5b53c7128230b629ebcd268;hp=c64f5718d132faaef8e872e5ca188ba47294145e;hpb=6baa1546bf990db7c66e9837bbb23f1070bf81e0;p=utils diff --git a/security/src/test/java/org/wamblee/usermgt/UserAdministrationImplTest.java b/security/src/test/java/org/wamblee/usermgt/UserAdministrationImplTest.java index c64f5718..5dde8b9b 100644 --- a/security/src/test/java/org/wamblee/usermgt/UserAdministrationImplTest.java +++ b/security/src/test/java/org/wamblee/usermgt/UserAdministrationImplTest.java @@ -1,87 +1,126 @@ /* * Copyright 2005 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ - package org.wamblee.usermgt; -import java.util.Set; +import junit.framework.TestCase; import org.apache.log4j.Logger; -import org.wamblee.persistence.hibernate.HibernateMappingFiles; + import org.wamblee.security.encryption.Md5HexMessageDigester; -import org.wamblee.test.spring.SpringConfigFiles; -import org.wamblee.test.spring.SpringTestCase; + import org.wamblee.usermgt.UserMgtException.Reason; +import java.util.Set; + + /** * Test of user administration implementation. * * @author Erik Brakkee */ -public class UserAdministrationImplTest extends SpringTestCase { - - private static final Logger LOGGER = Logger - .getLogger(UserAdministrationImplTest.class); +public class UserAdministrationImplTest extends TestCase { + /** + * DOCUMENT ME! + */ + 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"; - private UserAdministration _admin; - - public UserAdministrationImplTest() { - super(SpringConfigFiles.class, HibernateMappingFiles.class); - } - - public UserAdministrationImplTest( - Class aSprings, - Class aMappings) { - super(aSprings, aMappings); - } + /** + * 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(); + 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"), + 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, - new RegexpNameValidator(RegexpNameValidator.ID_PATTERN, - Reason.INVALID_USERNAME, "Invalid user"), - new RegexpNameValidator(RegexpNameValidator.ID_PATTERN, - Reason.INVALID_GROUPNAME, "Invalid group")); + new RegexpNameValidator(RegexpNameValidator.ID_PATTERN, + Reason.INVALID_USERNAME, "Invalid user"), + new RegexpNameValidator(RegexpNameValidator.ID_PATTERN, + Reason.INVALID_GROUPNAME, "Invalid group")); } - - protected User createUser(String aName, String aPassword, Group aGroup) throws UserMgtException { + + /** + * 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); } @@ -89,43 +128,49 @@ public class UserAdministrationImplTest extends SpringTestCase { * Constructs the admin, verify it contains no users and no groups. */ public void testConstruct() { - assertEquals(0, _admin.getUsers().size()); - assertEquals(0, _admin.getGroups().size()); - assertEquals(0, _admin.getUserCount()); - assertEquals(0, _admin.getGroupCount()); + assertEquals(0, admin.getUsers().size()); + assertEquals(0, admin.getGroups().size()); + assertEquals(0, admin.getUserCount()); + assertEquals(0, admin.getGroupCount()); } /** - * Creates a new group. Verifies the group is created correctly and that the - * user is added. - * + * Creates a new group. Verifies the group is created correctly and + * that the user is added. + * + * @throws UserMgtException DOCUMENT ME! */ public void testCreateGroup() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); + Group group = admin.createGroup(GROUP1); assertNotNull(group); assertEquals(GROUP1, group.getName()); - Set groups = _admin.getGroups(); + Set groups = admin.getGroups(); assertEquals(1, groups.size()); - assertEquals(1, _admin.getGroupCount()); + assertEquals(1, admin.getGroupCount()); assertTrue(groups.contains(group)); } + /** + * DOCUMENT ME! + * + * @param aUsername DOCUMENT ME! + */ private void createInvalidGroup(String aUsername) { try { - _admin.createGroup(aUsername); + admin.createGroup(aUsername); fail(); } catch (UserMgtException e) { - assertEquals(UserMgtException.Reason.INVALID_GROUPNAME, e - .getReason()); - assertEquals(0, _admin.getGroupCount()); + 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 { @@ -137,58 +182,70 @@ public class UserAdministrationImplTest extends SpringTestCase { } /** - * Creates a new group which conflicts with an existing one. Verifies that - * the UserMgtException is thrown and that no group is added. - * + * 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! */ public void testCreateDuplicateGroup() throws UserMgtException { - _admin.createGroup(GROUP1); + admin.createGroup(GROUP1); + try { - _admin.createGroup(GROUP1); + admin.createGroup(GROUP1); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.DUPLICATE_GROUP, e.getReason()); - assertEquals(1, _admin.getGroupCount()); + assertEquals(1, admin.getGroupCount()); + return; } + fail(); } /** - * Creates a new user. Verifies the user is created correctly and that the - * user is added. - * + * Creates a new user. Verifies the user is created correctly and + * that the user is added. + * + * @throws UserMgtException DOCUMENT ME! */ public void testCreateUser() 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); assertNotNull(user); assertEquals(USER1, user.getName()); user.checkPassword(PASS1); - Set users = _admin.getUsers(); + Set users = admin.getUsers(); assertEquals(1, users.size()); - assertEquals(1, _admin.getUserCount()); + assertEquals(1, admin.getUserCount()); 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); + admin.createUser(aUsername, "pass", aGroup); fail(); } catch (UserMgtException e) { - assertEquals(UserMgtException.Reason.INVALID_USERNAME, e - .getReason()); - assertEquals(0, _admin.getUserCount()); + assertEquals(UserMgtException.Reason.INVALID_USERNAME, e.getReason()); + assertEquals(0, admin.getUserCount()); } } /** - * Constructs users with invalid names. Verifies that the appropriate - * exception is thrown. - * + * Constructs users with invalid names. Verifies that the + * appropriate exception is thrown. + * + * @throws UserMgtException DOCUMENT ME! */ public void testCreateInvalidUserName() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); + Group group = admin.createGroup(GROUP1); createInvalidUser("", group); createInvalidUser("0abc", group); // should not start with digits createInvalidUser("a b", group); // should not contain spaces @@ -197,130 +254,150 @@ public class UserAdministrationImplTest extends SpringTestCase { } /** - * Creates a new user which conflicts with an existing one. Verifies that - * the UserMgtException is thrown and that no user is added. - * + * 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! */ public void testCreateDuplicateUser() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - _admin.createUser(USER1, PASS1, group); + Group group = admin.createGroup(GROUP1); + admin.createUser(USER1, PASS1, group); + try { - _admin.createUser(USER1, PASS2, group); + admin.createUser(USER1, PASS2, group); fail(); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.DUPLICATE_USER, e.getReason()); - assertEquals(1, _admin.getUserCount()); + assertEquals(1, admin.getUserCount()); } } /** - * Gets a known user by name. Verifies the correct user is obtained. - * Verifies that null is returned when trying to obtain an unknown user. - * + * 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! */ public void testGetUser() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - User user = _admin.createUser(USER1, PASS1, group); - User user2 = _admin.getUser(USER1); + Group group = admin.createGroup(GROUP1); + User user = admin.createUser(USER1, PASS1, group); + User user2 = admin.getUser(USER1); assertTrue(user.equals(user2)); - assertNull(_admin.getUser(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. - * + * 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! */ public void testGetGroup() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - Group group2 = _admin.getGroup(GROUP1); + Group group = admin.createGroup(GROUP1); + Group group2 = admin.getGroup(GROUP1); assertTrue(group.equals(group2)); - assertNull(_admin.getGroup(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. - * + * 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! */ public void testAddUserToGroup() throws UserMgtException { - - Group group = _admin.createGroup(GROUP1); - User user = _admin.createUser(USER1, PASS1, group); - Group group2 = _admin.createGroup(GROUP2); + 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)); - _admin.addUserToGroup(user, group2); + admin.addUserToGroup(user, group2); assertTrue(user.isInGroup(group)); assertTrue(user.isInGroup(group2)); - Set users = _admin.getUsers(group2); + + Set users = admin.getUsers(group2); assertNotNull(users); assertEquals(1, users.size()); assertTrue(users.contains(user)); try { - _admin.addUserToGroup(user, group); + 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; } + fail(); } /** - * Adds a user to a group where the user does not exist. Verifies that an - * exception occurs. - * + * Adds a user to a group where the user does not exist. Verifies + * that an exception occurs. + * + * @throws UserMgtException DOCUMENT ME! */ public void testAddUserToGroupUnknownUser() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - User user = createUser(USER1, PASS1, group); + Group group = admin.createGroup(GROUP1); + User user = createUser(USER1, PASS1, group); + try { - _admin.addUserToGroup(user, group); + admin.addUserToGroup(user, group); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_USER, e.getReason()); + return; } + fail(); } /** - * Adds a user to a group where the user does not exist. Verifies that an - * exception occurs. - * + * Adds a user to a group where the user does not exist. Verifies + * that an exception occurs. + * + * @throws UserMgtException DOCUMENT ME! */ 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 { - _admin.addUserToGroup(user, group2); + admin.addUserToGroup(user, group2); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_GROUP, e.getReason()); + return; } + fail(); } /** - * 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. + * 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! */ public void testRemoveUserFromGroup() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); + Group group = admin.createGroup(GROUP1); + + User user = admin.createUser(USER1, PASS1, group); + Group group2 = admin.createGroup(GROUP2); + admin.addUserToGroup(user, group2); - User user = _admin.createUser(USER1, PASS1, group); - Group group2 = _admin.createGroup(GROUP2); - _admin.addUserToGroup(user, group2); Set groups = user.getGroups(); assertEquals(2, groups.size()); assertTrue(groups.contains(group)); assertTrue(groups.contains(group2)); - _admin.removeUserFromGroup(user, group); + admin.removeUserFromGroup(user, group); groups = user.getGroups(); assertEquals(1, groups.size()); assertTrue(groups.contains(group2)); @@ -328,71 +405,80 @@ public class UserAdministrationImplTest extends SpringTestCase { } /** - * Removes a user from a group where the user is not known. Verifies that an - * exception is thrown. - * + * Removes a user from a group where the user is not known. + * Verifies that an exception is thrown. + * + * @throws UserMgtException DOCUMENT ME! */ public void testRemoveUserFromGroupUnknownUser() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - User user = createUser(USER1, GROUP1, group); + Group group = admin.createGroup(GROUP1); + User user = createUser(USER1, GROUP1, group); + try { - _admin.removeUserFromGroup(user, group); + admin.removeUserFromGroup(user, group); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_USER, e.getReason()); } } /** - * Removes a user from a group where the group is not known. Verifies that - * an exception is thrown. - * + * Removes a user from a group where the group is not known. + * Verifies that an exception is thrown. + * + * @throws UserMgtException DOCUMENT ME! */ 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 { - _admin.removeUserFromGroup(user, group2); + admin.removeUserFromGroup(user, group2); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_GROUP, e.getReason()); } } /** - * Removes a user from a group where the user is only part of one group. - * Verifies that an exception is thrown. + * 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! */ public void testRemoveUserFromGroupOnlyGroup() 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); + try { - _admin.removeUserFromGroup(user, group); + 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. - * + * 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! */ public void testGetUsersAndGroups() throws UserMgtException { - Group group1 = _admin.createGroup(GROUP1); - Group group2 = _admin.createGroup(GROUP2); + Group group1 = admin.createGroup(GROUP1); + Group group2 = admin.createGroup(GROUP2); - User user1 = _admin.createUser(USER1, PASS1, group1); - _admin.addUserToGroup(user1, group2); - User user2 = _admin.createUser(USER2, PASS2, group2); + User user1 = admin.createUser(USER1, PASS1, group1); + admin.addUserToGroup(user1, group2); - Set users = _admin.getUsers(); + User user2 = admin.createUser(USER2, PASS2, group2); + + Set users = admin.getUsers(); assertEquals(2, users.size()); assertTrue(users.contains(user1)); assertTrue(users.contains(user2)); - Set groups = _admin.getGroups(); + Set groups = admin.getGroups(); assertEquals(2, groups.size()); assertTrue(groups.contains(group1)); assertTrue(groups.contains(group2)); @@ -413,154 +499,177 @@ public class UserAdministrationImplTest extends SpringTestCase { * 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); - _admin.renameUser(user1, USER2); + Group group = admin.createGroup(GROUP1); + User user1 = admin.createUser(USER1, PASS1, group); + admin.renameUser(user1, USER2); assertEquals(USER2, user1.getName()); - assertEquals(user1, _admin.getUser(USER2)); + assertEquals(user1, admin.getUser(USER2)); - _admin.createUser(USER1, PASS1, group); + admin.createUser(USER1, PASS1, group); try { - _admin.renameUser(user1, USER1); + admin.renameUser(user1, USER1); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.DUPLICATE_USER, e.getReason()); // do a trivial reanem try { - _admin.renameUser(user1, user1.getName()); + admin.renameUser(user1, user1.getName()); } catch (UserMgtException e2) { - assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, e2 - .getReason()); + assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, + e2.getReason()); + return; } + fail(); } + fail(); } /** - * Renames a user to a user with an invalid username. Verifies that the - * appropriate exception is thrown. - * + * Renames a user to a user with an invalid username. Verifies that + * the appropriate exception is thrown. + * + * @throws UserMgtException DOCUMENT ME! */ public void testRenameUserInvalidUsername() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - User user1 = _admin.createUser(USER1, PASS1, group); + Group group = admin.createGroup(GROUP1); + User user1 = admin.createUser(USER1, PASS1, group); + try { - _admin.renameUser(user1, USER2); + admin.renameUser(user1, USER2); } catch (UserMgtException e) { assertEquals(e.getReason(), Reason.INVALID_USERNAME); } } /** - * 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. - * + * 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! */ public void testRenameGroup() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); - _admin.renameGroup(group, GROUP2); + Group group = admin.createGroup(GROUP1); + admin.renameGroup(group, GROUP2); assertEquals(GROUP2, group.getName()); - assertEquals(group, _admin.getGroup(GROUP2)); + assertEquals(group, admin.getGroup(GROUP2)); + + admin.createGroup(GROUP1); - _admin.createGroup(GROUP1); try { - _admin.renameGroup(group, GROUP1); + admin.renameGroup(group, GROUP1); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.DUPLICATE_GROUP, e.getReason()); // do a trivial reanem try { - _admin.renameGroup(group, group.getName()); + admin.renameGroup(group, group.getName()); } catch (UserMgtException e2) { - assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, e2 - .getReason()); + assertEquals(UserMgtException.Reason.TRIVIAL_RENAME, + e2.getReason()); + return; } + fail(); + return; } + fail(); } /** - * Renames a group to a group with an invalid name. Verifies that the - * appropriate exception is thrown. - * + * Renames a group to a group with an invalid name. Verifies that + * the appropriate exception is thrown. + * + * @throws UserMgtException DOCUMENT ME! */ public void testRenameGroupInvalidGroupname() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); + Group group = admin.createGroup(GROUP1); + try { - _admin.renameGroup(group, "a b"); + admin.renameGroup(group, "a b"); } catch (UserMgtException e) { assertEquals(e.getReason(), Reason.INVALID_GROUPNAME); } } /** - * Removes a user. Verifies that the user is removed. Verifies that the an - * exception is thrown when the user does not exist. - * + * 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! */ public void testRemoveUser() 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); - assertEquals(1, _admin.getUserCount()); - _admin.removeUser(user); - assertEquals(0, _admin.getUserCount()); + assertEquals(1, admin.getUserCount()); + admin.removeUser(user); + assertEquals(0, admin.getUserCount()); - _admin.createUser(USER1, PASS1, group); - assertEquals(1, _admin.getUserCount()); + admin.createUser(USER1, PASS1, group); + assertEquals(1, admin.getUserCount()); User user2 = createUser(USER2, PASS2, group); try { - _admin.removeUser(user2); + admin.removeUser(user2); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_USER, e.getReason()); } } /** - * 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. - * + * 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! */ public void testRemoveGroup() throws UserMgtException { - Group group1 = _admin.createGroup(GROUP1); - assertEquals(1, _admin.getGroupCount()); - _admin.removeGroup(group1); - assertEquals(0, _admin.getGroupCount()); - group1 = _admin.createGroup(GROUP1); + Group group1 = admin.createGroup(GROUP1); + assertEquals(1, admin.getGroupCount()); + admin.removeGroup(group1); + assertEquals(0, admin.getGroupCount()); + group1 = admin.createGroup(GROUP1); + + admin.createUser(USER1, PASS1, group1); - _admin.createUser(USER1, PASS1, group1); try { - _admin.removeGroup(group1); + admin.removeGroup(group1); } catch (UserMgtException e) { - assertEquals(UserMgtException.Reason.GROUP_STILL_OCCUPIED, e - .getReason()); + assertEquals(UserMgtException.Reason.GROUP_STILL_OCCUPIED, + e.getReason()); + return; } + fail(); } /** - * Tries to remove an unknown group. Verifies that an exception is thrown. - * + * Tries to remove an unknown group. Verifies that an exception is + * thrown. + * + * @throws UserMgtException DOCUMENT ME! */ public void testRemoveGroupUnknownGroup() throws UserMgtException { - Group group = _admin.createGroup(GROUP1); + Group group = admin.createGroup(GROUP1); Group group2 = new Group(GROUP2); + try { - _admin.removeGroup(group2); + admin.removeGroup(group2); } catch (UserMgtException e) { assertEquals(UserMgtException.Reason.UNKNOWN_GROUP, e.getReason()); } @@ -568,16 +677,17 @@ public class UserAdministrationImplTest extends SpringTestCase { /** * 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); + Group group = admin.createGroup(GROUP1); + User user = admin.createUser(USER1, PASS1, group); user.changePassword(PASS1, PASS2); // retrieve the user and verifies the password hasn't changed. - User user2 = _admin.getUser(USER1); + User user2 = admin.getUser(USER1); + try { user2.checkPassword(PASS2); fail(); // password should not have changed already. @@ -586,28 +696,29 @@ public class UserAdministrationImplTest extends SpringTestCase { } // now notify the admin of the change in the user - _admin.userModified(user); + admin.userModified(user); - user2 = _admin.getUser(USER1); + user2 = admin.getUser(USER1); user2.checkPassword(PASS2); // this time it should succeed. - } /** * 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); + 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); + admin.getUser(USER1); } + LOGGER.info("Looked up a user " + n + " times in " - + (float) (System.currentTimeMillis() - time) / 1000.0); + + ((float) (System.currentTimeMillis() - time) / 1000.0)); } - }