1 12 13 package com.openedit.users.filesystem; 14 15 import java.util.Collection ; 16 17 import com.openedit.hittracker.HitTracker; 18 import com.openedit.users.BaseUserTest; 19 import com.openedit.users.Group; 20 import com.openedit.users.User; 21 import com.openedit.users.UserManager; 22 23 24 30 public class UserManagerTest extends BaseUserTest 31 { 32 33 public UserManagerTest(String inName) 34 { 35 super(inName); 36 } 37 38 43 public void testAuthenticate() throws Exception 44 { 45 assertTrue( 46 "Should have authenticated user1", 47 fieldUserManager.authenticate(fieldUserManager.getUser("user1"), "user1pwd")); 48 } 49 50 55 public void testAuthenticate_Negative() throws Exception 56 { 57 assertTrue( 58 "Should not have authenticated user1", 59 !fieldUserManager.authenticate(fieldUserManager.getUser("user1"), "thisiswrong")); 60 } 61 62 public void testLoadPermissions() throws Exception 63 { 64 String v = "this is;: a test"; 67 String [] two = v.split(";"); 68 assertEquals( two.length , 2); 69 70 two = v.split(":"); 71 assertEquals( two.length , 2); 72 73 } 74 75 80 public void testCreateUser() throws Exception 81 { 82 User newUser = fieldUserManager.createUser("newuser", "mypassword"); 83 assertEquals("Username", "newuser", newUser.getUserName()); 84 assertEquals("Number of groups", 0, newUser.getGroups().size()); 85 assertEquals("Number of users", 4, fieldUserManager.getUsers().size()); 86 } 87 88 93 public void testDeleteGroup() throws Exception 94 { 95 Group group1 = fieldUserManager.getGroup("group1"); 96 fieldUserManager.deleteGroup(group1); 97 assertEquals("Number of groups", 2, fieldUserManager.getGroups().size()); 98 assertEquals( 99 "Number of groups of which user1 is a member", 1, 100 fieldUserManager.getUser("user1").getGroups().size()); 101 assertEquals( 102 "Number of groups of which user2 is a member", 1, 103 fieldUserManager.getUser("user2").getGroups().size()); 104 assertTrue( 105 "user1 should not be in group1", 106 !fieldUserManager.getUser("user1").getGroups().contains(group1)); 107 assertTrue( 108 "user2 should not be in group1", 109 !fieldUserManager.getUser("user2").getGroups().contains(group1)); 110 } 111 112 117 public void testDeleteUser() throws Exception 118 { 119 User user1 = fieldUserManager.getUser("user1"); 120 fieldUserManager.deleteUser(fieldUserManager.getUser("user1")); 121 assertEquals("Number of users", 2, fieldUserManager.getUsers().size()); 122 assertEquals( 123 "Number of users in group1", 0, fieldUserManager.getUsersInGroup("group1").size()); 124 assertEquals( 125 "Number of users in group2", 1, fieldUserManager.getUsersInGroup("group2").size()); 126 assertTrue( 127 "group1 should not still contain user1", 128 !fieldUserManager.getUsersInGroup("group1").contains(user1)); 129 assertTrue( 130 "group2 should not still contain user1", 131 !fieldUserManager.getUsersInGroup("group2").contains(user1)); 132 } 133 134 135 140 public void testGetGroup_Group1() throws Exception 141 { 142 Group group1 = fieldUserManager.getGroup("group1"); 143 assertEquals("Group name", "group1", group1.getName()); 144 assertEquals("Number of users", 1, fieldUserManager.getUsersInGroup(group1).size()); 145 assertTrue( 146 "group1 should contain user1", 147 fieldUserManager.getUsersInGroup("group1").contains(fieldUserManager.getUser("user1"))); 148 assertTrue( 149 "group1 should contain user2", 150 fieldUserManager.getUsersInGroup("group2").contains(fieldUserManager.getUser("user2"))); 151 } 152 153 158 public void testGetGroup_Group2() throws Exception 159 { 160 Group group2 = fieldUserManager.getGroup("group2"); 161 assertEquals("Group name", "group2", group2.getName()); 162 assertTrue( 163 "group2 should contain user1", 164 fieldUserManager.getUsersInGroup("group2").contains(fieldUserManager.getUser("user1"))); 165 } 166 167 172 public void testGetGroup_Group3() throws Exception 173 { 174 Group group3 = fieldUserManager.getGroup("group3"); 175 assertEquals("Group name", "group3", group3.getName()); 176 assertEquals("Number of users", 1, fieldUserManager.getUsersInGroup(group3).size()); 177 } 178 179 184 public void testGetGroups() throws Exception 185 { 186 assertEquals("Number of groups", 3, fieldUserManager.getGroups().size()); 187 188 for (int i = 1; i <= 3; i++) 189 { 190 assertTrue( 191 "group" + i + " exists", 192 fieldUserManager.getGroups().contains(fieldUserManager.getGroup("group" + i))); 193 } 194 } 195 196 201 public void testGetUser_User1() throws Exception 202 { 203 User user1 = fieldUserManager.getUser("user1"); 204 assertNotNull(user1); 205 assertEquals("Username", "user1", user1.getUserName()); 206 207 Collection groups = user1.getGroups(); 208 assertEquals("Number of groups", 2, groups.size()); 209 assertTrue( 210 "user1 should be in group1", groups.contains(fieldUserManager.getGroup("group1"))); 211 assertTrue( 212 "user1 should be in group2", groups.contains(fieldUserManager.getGroup("group2"))); 213 } 214 215 220 public void testGetUser_User2() throws Exception 221 { 222 User user2 = fieldUserManager.getUser("user2"); 223 assertNotNull(user2); 224 assertEquals("Username", "user2", user2.getUserName()); 225 226 Collection groups = user2.getGroups(); 227 assertEquals("Number of groups", 1, groups.size()); 228 assertTrue( 229 "user2 should be in group2", groups.contains(fieldUserManager.getGroup("group2"))); 230 } 231 232 237 public void testGetUser_User3() throws Exception 238 { 239 User user3 = fieldUserManager.getUser("user3"); 240 assertNotNull(user3); 241 assertEquals("Username", "user3", user3.getUserName()); 242 assertEquals("Number of groups", 1, user3.getGroups().size()); 243 } 244 245 250 public void testGetUsers() throws Exception 251 { 252 HitTracker users = fieldUserManager.getUsers(); 253 assertEquals("Number of users", 3, users.size()); 254 255 for (int i = 1; i <= 3; i++) 256 { 257 User found = fieldUserManager.getUser("user" + i); 258 assertTrue( 259 "user" + i + " exists", users.contains(found.getUserName())); 260 } 261 } 262 263 266 protected void setUp() throws Exception 267 { 268 fieldUserManager = createUserManager(); 269 270 Group group1 = fieldUserManager.createGroup("group1"); 280 Group group2 = fieldUserManager.createGroup("group2"); 281 Group group3 = fieldUserManager.createGroup("group3"); 282 User user1 = fieldUserManager.createUser("user1", "user1pwd"); 283 User user2 = fieldUserManager.createUser("user2", "user2pwd"); 284 User user3 = fieldUserManager.createUser("user3", "user3pwd"); 285 286 user1.addGroup(group1); 287 user1.addGroup(group2); 288 289 user2.addGroup(group2); 290 user3.addGroup(group3); 291 } 292 protected void tearDown() throws Exception 293 { 294 deleteUserManager(fieldUserManager); 295 } 296 } 297 | Popular Tags |