1 12 13 package com.openedit.users.filesystem; 14 15 import java.util.HashMap ; 16 import java.util.Map ; 17 18 import com.openedit.users.BaseUserTest; 19 import com.openedit.users.Group; 20 import com.openedit.users.User; 21 22 23 24 30 public abstract class UserTest extends BaseUserTest 31 { 32 protected User fieldUser; 33 34 public UserTest(String inName) 35 { 36 super(inName); 37 } 38 39 public void testHasPermission() throws Exception 40 { 41 assertTrue("User should have permission1", fieldUser.hasPermission("permission1")); 42 assertTrue("User should have permission3", fieldUser.hasPermission("permission3")); 43 } 44 45 public void testHasPermission_Negative() throws Exception 46 { 47 assertTrue( 48 "User should not have nosuchpermission", !fieldUser.hasPermission("nosuchpermission")); 49 } 50 51 public void testPut() throws Exception 52 { 53 fieldUser.put("foo", "bar"); 54 assertEquals("bar", fieldUser.get("foo")); 55 } 56 57 public void testPutAll() throws Exception 58 { 59 Map map = new HashMap (); 60 map.put( "foo", "bar" ); 61 map.put( "baz", "wibble" ); 62 fieldUser.putAll(map); 63 assertEquals("bar", fieldUser.get("foo")); 64 assertEquals("wibble", fieldUser.get("baz")); 65 } 66 67 public void testSetPassword() throws Exception 68 { 69 fieldUser.setPassword("newpwd"); 70 assertTrue( 71 "Should have authenticated with new password successfully", 72 fieldUserManager.authenticate(fieldUser, "newpwd")); 73 assertTrue( 74 "Should not have authenticated with old password", 75 !fieldUserManager.authenticate(fieldUser, "testpwd")); 76 } 77 78 public void testGetCreationDate() throws Exception 79 { 80 long currentTime = System.currentTimeMillis(); 81 assertTrue( "Dates are not within 2 seconds of each other", 85 currentTime - fieldUser.getCreationDate().getTime() <= 2000 ); 86 } 87 88 91 protected void setUp() throws Exception 92 { 93 fieldUserManager = createUserManager(); 94 fieldUser = fieldUserManager.createUser("testuser", "testpwd"); 95 96 Group group = fieldUserManager.createGroup("testgroup"); 97 group.addPermission("permission1"); 98 fieldUser.addGroup(group ); 99 fieldUserManager.saveGroup(group); 100 Group group2 = fieldUserManager.createGroup("testgroup2"); 101 group2.addPermission("permission2"); 102 group2.addPermission("permission3"); 103 fieldUser.addGroup(group2); 104 fieldUserManager.saveGroup(group2); 105 fieldUserManager.saveUser(fieldUser); 106 } 107 108 111 protected void tearDown() throws Exception 112 { 113 deleteUserManager(fieldUserManager); 114 } 115 } 116 | Popular Tags |