1 23 24 package com.rift.coad.lib.security; 25 26 import junit.framework.*; 27 28 import java.util.Set ; 30 import java.util.HashSet ; 31 32 36 public class ValidatorTest extends TestCase { 37 38 public ValidatorTest(String testName) { 39 super(testName); 40 } 41 42 protected void setUp() throws Exception { 43 } 44 45 protected void tearDown() throws Exception { 46 } 47 48 public static Test suite() { 49 TestSuite suite = new TestSuite(ValidatorTest.class); 50 51 return suite; 52 } 53 54 57 public void testValidate() throws Exception { 58 System.out.println("validate"); 59 60 Class ref = null; 61 String roleName = ""; 62 63 ThreadsPermissionContainer permissionContainer = 65 new ThreadsPermissionContainer(); 66 SessionManager.init(permissionContainer); 67 SessionManager.getInstance().initSession(); 68 69 RoleManager.getInstance(); 71 72 try { 73 Validator.validate(getClass(), "test"); 74 fail("The test case is a prototype."); 75 } catch (Exception ex) { 76 System.out.println("Access failed success : " + ex.getMessage()); 77 } 78 79 Set set = new HashSet (); 81 set.add("test"); 82 UserSession user = new UserSession("testuser", set); 83 permissionContainer.putSession(new Long (Thread.currentThread().getId()), 84 new ThreadPermissionSession( 85 new Long (Thread.currentThread().getId()),user)); 86 87 try { 88 Validator.validate(getClass(), "test"); 89 } catch (Exception ex) { 90 fail("The test case is a prototype : " + ex.getMessage()); 91 } 92 93 permissionContainer.pushRole("middle"); 94 permissionContainer.pushRole("master"); 95 96 try { 97 Validator.validate(getClass(), "master"); 98 } catch (Exception ex) { 99 fail("The test case is a prototype : " + ex.getMessage()); 100 } 101 102 permissionContainer.popRole("master"); 103 permissionContainer.popRole("middle"); 104 105 try { 106 Validator.validate(getClass(), "master"); 107 fail("Invalid role should not have role master"); 108 } catch (Exception ex) { 109 } 111 112 try { 113 Validator.validate(getClass(), "test"); 114 } catch (Exception ex) { 115 fail("The test case is a prototype : " + ex.getMessage()); 116 } 117 118 } 119 120 } 121 | Popular Tags |