1 23 24 package com.rift.coad.lib.security.user; 25 26 import java.util.HashSet ; 27 import junit.framework.*; 28 import com.rift.coad.lib.security.ThreadsPermissionContainer; 29 import com.rift.coad.lib.security.ThreadPermissionSession; 30 import com.rift.coad.lib.security.UserSession; 31 32 37 public class UserSessionManagerTest extends TestCase { 38 39 public UserSessionManagerTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws Exception { 44 } 45 46 protected void tearDown() throws Exception { 47 } 48 49 public static Test suite() { 50 TestSuite suite = new TestSuite(UserSessionManagerTest.class); 51 52 return suite; 53 } 54 55 58 public void testInitSessionForUser() throws Exception { 59 System.out.println("initSessionForUser"); 60 61 ThreadsPermissionContainer permissions = new ThreadsPermissionContainer(); 62 UserStoreManager userStoreManager = new UserStoreManager(); 63 UserSessionManager instance = new UserSessionManager(permissions, 64 userStoreManager); 65 instance.startCleanup(); 66 instance.initSessionForUser("test1"); 68 69 UserSession user = new UserSession("test2",new HashSet ()); 71 user.setExpiryTime(500); 72 instance.initSessionForUser(user); 73 UserSession user2 = new UserSession("test2",new HashSet ()); 74 user2.setExpiryTime(500); 75 instance.initSessionForUser(user2); 76 77 if (user != instance.getSessionById(user.getSessionId())) { 79 fail("The user session could not be found by id."); 80 } 81 if (user2 != instance.getSessionById(user2.getSessionId())) { 82 fail("The user 2 session could not be found by id."); 83 } 84 85 for (int count = 0; count < 4; count++) { 86 Thread.sleep(450); 87 user2.touch(); 88 } 89 90 try { 91 instance.getSessionById(user.getSessionId()); 92 fail("The user session could be found."); 93 } catch (UserException ex) { 94 } 96 if (user2 != instance.getSessionById(user2.getSessionId())) { 97 fail("The user 2 session could be found."); 98 } 99 100 instance.shutdown(); 101 } 102 103 } 104 | Popular Tags |