1 12 13 package com.openedit.modules.edit; 14 15 import junit.framework.TestCase; 16 17 import com.openedit.users.BaseUserTest; 18 import com.openedit.users.User; 19 import com.openedit.users.UserManager; 20 21 22 27 public class EditLockRegistryTest extends BaseUserTest 28 { 29 protected static final String LOCKED_PATH = "/foo/locked.html"; 30 protected static final String UNLOCKED_PATH = "/foo/unlocked.html"; 31 protected EditLockRegistry fieldRegistry; 32 protected User fieldUser1; 33 protected User fieldUser2; 34 protected UserManager fieldUserManager; 35 36 public EditLockRegistryTest(String inName) 37 { 38 super(inName); 39 } 40 41 44 public void testCanLock_LockedByDifferentUser() 45 { 46 assertTrue( 47 "Should not be able to lock path", !fieldRegistry.canLock(LOCKED_PATH, fieldUser2)); 48 } 49 50 53 public void testCanLock_LockedBySameUser() 54 { 55 assertTrue("Should be able to lock path", fieldRegistry.canLock(LOCKED_PATH, fieldUser1)); 56 } 57 58 61 public void testCanLock_NullPath() 62 { 63 assertTrue( 64 "Should not be able to lock a null path", !fieldRegistry.canLock(null, fieldUser1)); 65 } 66 67 70 public void testCanLock_NullUser() 71 { 72 assertTrue( 73 "Should not be able to lock a path with a null user", 74 !fieldRegistry.canLock(UNLOCKED_PATH, null)); 75 } 76 77 80 public void testCanLock_Unlocked() 81 { 82 assertTrue("Should be able to lock path", fieldRegistry.canLock(UNLOCKED_PATH, fieldUser1)); 83 } 84 85 88 public void testForciblyLockPath_LockedByDifferentUser() 89 { 90 fieldRegistry.forciblyLockPath(LOCKED_PATH, fieldUser2); 91 assertEquals("New lock owner", fieldUser2, fieldRegistry.getLockOwner(LOCKED_PATH)); 92 } 93 94 97 public void testForciblyLockPath_LockedBySameUser() 98 { 99 fieldRegistry.forciblyLockPath(LOCKED_PATH, fieldUser1); 100 assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH)); 101 } 102 103 106 public void testForciblyLockPath_Unlocked() 107 { 108 fieldRegistry.forciblyLockPath(UNLOCKED_PATH, fieldUser1); 109 assertEquals("New lock owner", fieldUser1, fieldRegistry.getLockOwner(UNLOCKED_PATH)); 110 } 111 112 115 public void testGetLockOwner_Locked() 116 { 117 assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH)); 118 } 119 120 123 public void testGetLockOwner_Unlocked() 124 { 125 assertNull("Lock owner should be null", fieldRegistry.getLockOwner(UNLOCKED_PATH)); 126 } 127 128 131 public void testIsLocked_Locked() 132 { 133 assertTrue(LOCKED_PATH + " should be locked", fieldRegistry.isLocked(LOCKED_PATH)); 134 } 135 136 139 public void testIsLocked_Unlocked() 140 { 141 assertTrue(UNLOCKED_PATH + " should not be locked", !fieldRegistry.isLocked(UNLOCKED_PATH)); 142 } 143 144 149 public void testLockPath_LockedByDifferentUser() throws Exception 150 { 151 boolean caughtException = false; 152 153 try 154 { 155 fieldRegistry.lockPath(LOCKED_PATH, fieldUser2); 156 } 157 catch (AlreadyLockedException ale) 158 { 159 caughtException = true; 160 } 161 162 assertTrue("Should have caught exception", caughtException); 163 } 164 165 170 public void testLockPath_LockedBySameUser() throws Exception 171 { 172 fieldRegistry.lockPath(LOCKED_PATH, fieldUser1); 173 assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH)); 174 } 175 176 181 public void testLockPath_NewLock() throws Exception 182 { 183 fieldRegistry.lockPath(UNLOCKED_PATH, fieldUser1); 184 assertEquals("New lock owner", fieldUser1, fieldRegistry.getLockOwner(UNLOCKED_PATH)); 185 } 186 187 190 public void testUnlockPath_AlreadyUnlocked() 191 { 192 fieldRegistry.unlockPath(UNLOCKED_PATH, fieldUser1); 193 assertNull("Lock owner should still be null", fieldRegistry.getLockOwner(UNLOCKED_PATH)); 194 } 195 196 199 public void testUnlockPath_LockedByDifferentUser() 200 { 201 fieldRegistry.unlockPath(LOCKED_PATH, fieldUser2); 202 assertEquals( 203 "Lock owner should not have changed", fieldUser1, 204 fieldRegistry.getLockOwner(LOCKED_PATH)); 205 } 206 207 210 public void testUnlockPath_LockedBySameUser() 211 { 212 fieldRegistry.unlockPath(LOCKED_PATH, fieldUser1); 213 assertNull("Lock owner should now be null", fieldRegistry.getLockOwner(LOCKED_PATH)); 214 } 215 216 219 protected void setUp() throws Exception 220 { 221 fieldUserManager = createUserManager(); 222 fieldUser1 = fieldUserManager.createUser("user1", "user1"); 223 fieldUser2 = fieldUserManager.createUser("user2", "user2"); 224 225 fieldRegistry = new EditLockRegistry(); 226 fieldRegistry.lockPath(LOCKED_PATH, fieldUser1); 227 } 228 229 protected void tearDown() throws Exception 230 { 231 deleteUserManager(fieldUserManager); 232 } 233 } 234 | Popular Tags |