X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=security%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fusermgt%2FInMemoryUserSetTest.java;h=55ca2099bd175ac1aca35cbbfcf0f52abd184668;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=4b035819b7617dc1c0645559e544046cc159d695;hpb=89c06d4d52b46c154128c97d6e758fa1f4fc7a6e;p=utils diff --git a/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java b/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java index 4b035819..55ca2099 100644 --- a/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java +++ b/security/src/test/java/org/wamblee/usermgt/InMemoryUserSetTest.java @@ -25,137 +25,77 @@ import java.sql.SQLException; import java.util.Set; - /** * Tests the inmemory user set. Intended to be subclassed for other * implementations of user set. */ public class InMemoryUserSetTest extends TestCase { - /** - * DOCUMENT ME! - */ protected static final String PASSWORD = "abc123"; - /** - * DOCUMENT ME! - */ private UserSet users; - /** - * DOCUMENT ME! - */ private GroupSet groups; - /** - * DOCUMENT ME! - */ private Group group; /** * This method must be overriden in subclasses. - * + * * @return New user set object. */ protected UserSet createUserSet() { return new InMemoryUserSet(new RegexpNameValidator( - RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD, - "Password must contain at least 6 characters"), + RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD, + "Password must contain at least 6 characters"), new Md5HexMessageDigester()); } /** * This method must be overriden in subclasses. - * + * * @return New group set object. */ protected GroupSet createGroupSet() { return new InMemoryGroupSet(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.wamblee.test.SpringTestCase#setUp() */ - /** - * DOCUMENT ME! - * - * @throws Exception DOCUMENT ME! - */ @Override protected void setUp() throws Exception { super.setUp(); - users = createUserSet(); - groups = createGroupSet(); - group = new Group("group0"); + users = createUserSet(); + groups = createGroupSet(); + group = new Group("group0"); groups.add(group); checkUserCount(0); } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ protected UserSet getUsers() { return users; } - /** - * DOCUMENT ME! - * - * @return DOCUMENT ME! - */ protected GroupSet getGroups() { return groups; } - /** - * DOCUMENT ME! - * - * @param aName DOCUMENT ME! - * - * @return DOCUMENT ME! - */ protected Group createGroup(String aName) { return new Group(aName); } - /** - * 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); } - /** - * DOCUMENT ME! - * - * @param aUser DOCUMENT ME! - * @param aGroup DOCUMENT ME! - * - * @throws UserMgtException DOCUMENT ME! - */ protected void addUserToGroup(User aUser, Group aGroup) throws UserMgtException { aUser.addGroup(aGroup); } - /** - * DOCUMENT ME! - * - * @param aUser DOCUMENT ME! - * @param aGroup DOCUMENT ME! - * - * @throws UserMgtException DOCUMENT ME! - */ protected void removeUserFromGroup(User aUser, Group aGroup) throws UserMgtException { aUser.removeGroup(aGroup); @@ -163,10 +103,10 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aUser User to check for existence. - * - * @throws SQLException DOCUMENT ME! + * + * @param aUser + * User to check for existence. + * */ protected void checkUserExists(String aUser) throws SQLException { // Empty @@ -174,10 +114,10 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aUser User to check for non-existence. - * - * @throws SQLException DOCUMENT ME! + * + * @param aUser + * User to check for non-existence. + * */ protected void checkUserNotExists(String aUser) throws SQLException { // Empty @@ -185,10 +125,10 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aSize Expected number of users. - * - * @throws SQLException DOCUMENT ME! + * + * @param aSize + * Expected number of users. + * */ protected void checkUserCount(int aSize) throws SQLException { assertEquals(aSize, users.size()); @@ -196,10 +136,10 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aUser User to check for existence. - * - * @throws SQLException DOCUMENT ME! + * + * @param aUser + * User to check for existence. + * */ protected void checkGroupExists(String aUser) throws SQLException { // Empty @@ -207,10 +147,10 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aUser User to check for non-existence. - * - * @throws SQLException DOCUMENT ME! + * + * @param aUser + * User to check for non-existence. + * */ protected void checkGroupNotExists(String aUser) throws SQLException { // Empty @@ -218,21 +158,19 @@ public class InMemoryUserSetTest extends TestCase { /** * Additional check to be implemented by a subclass. - * - * @param aSize Expected number of users. - * - * @throws SQLException DOCUMENT ME! + * + * @param aSize + * Expected number of users. + * */ protected void checkGroupCount(int aSize) throws SQLException { // Empty } /** - * Adds a user and verifies that the user is added using find(), - * list(), and contains(). - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Adds a user and verifies that the user is added using find(), list(), and + * contains(). + * */ public void testAdd() throws SQLException, UserMgtException { User user = createUser("user1", PASSWORD, group); @@ -250,11 +188,8 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Tries to find a non-existing user. Verifies that null is - * returned. - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Tries to find a non-existing user. Verifies that null is returned. + * */ public void testFindUnknownUser() throws SQLException, UserMgtException { User user1 = createUser("user1", PASSWORD, group); @@ -269,11 +204,8 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Adds duplicate user. Verifies that the existing user is left - * untouched. - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Adds duplicate user. Verifies that the existing user is left untouched. + * */ public void testAddDuplicateUser() throws SQLException, UserMgtException { User user1 = createUser("user1", PASSWORD, group); @@ -290,11 +222,9 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Removes a user. Verifies that the user is removed and the - * return value is true. - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Removes a user. Verifies that the user is removed and the return value is + * true. + * */ public void testRemoveUser() throws SQLException, UserMgtException { User user1 = createUser("user1", PASSWORD, group); @@ -310,14 +240,12 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Removes a non-existing user. Verifies that no users are removed - * an that the return value is true. - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Removes a non-existing user. Verifies that no users are removed an that + * the return value is true. + * */ - public void testRemoveNonExistingUser() - throws SQLException, UserMgtException { + public void testRemoveNonExistingUser() throws SQLException, + UserMgtException { User user1 = createUser("user1", PASSWORD, group); users.add(user1); checkUserCount(1); @@ -332,11 +260,9 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Adds a number of users to the set and verifies that list() - * returns them all. - * - * @throws SQLException DOCUMENT ME! - * @throws UserMgtException DOCUMENT ME! + * Adds a number of users to the set and verifies that list() returns them + * all. + * */ public void testList() throws SQLException, UserMgtException { User user1 = createUser("user1", PASSWORD, group); @@ -359,11 +285,10 @@ public class InMemoryUserSetTest extends TestCase { } /** - * Adds several users to different groups and verifies that the - * correct users are returned when looking for users in different groups. - * + * Adds several users to different groups and verifies that the correct + * users are returned when looking for users in different groups. + * * @throws SQLException - * @throws UserMgtException DOCUMENT ME! */ public void testListByGroup() throws SQLException, UserMgtException { Group group1 = new Group("group1"); @@ -373,10 +298,10 @@ public class InMemoryUserSetTest extends TestCase { groups.add(group2); groups.add(group3); - // user1 user2 user3 - // group1 y - // group2 y y - // group3 y y y + // user1 user2 user3 + // group1 y + // group2 y y + // group3 y y y User user1 = createUser("user1", PASSWORD, group1); user1.addGroup(group2); user1.addGroup(group3); @@ -398,7 +323,8 @@ public class InMemoryUserSetTest extends TestCase { checkGroupExists(group3.getName()); checkUserCount(3); - checkGroupCount(3 + 1); // also count the group that was created in the setUp(). + checkGroupCount(3 + 1); // also count the group that was created in the + // setUp(). Set list = users.list(group1); assertTrue(list.contains(user1));