KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > openedit > modules > edit > EditLockRegistryTest


1 /*
2 Copyright (c) 2003 eInnovation Inc. All rights reserved
3
4 This library is free software; you can redistribute it and/or modify it under the terms
5 of the GNU Lesser General Public License as published by the Free Software Foundation;
6 either version 2.1 of the License, or (at your option) any later version.
7
8 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the GNU Lesser General Public License for more details.
11 */

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 /**
23  * Test case for {@link EditLockRegistry}
24  *
25  * @author Eric Galluzzo
26  */

27 public class EditLockRegistryTest extends BaseUserTest
28 {
29     protected static final String JavaDoc LOCKED_PATH = "/foo/locked.html";
30     protected static final String JavaDoc 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 JavaDoc inName)
37     {
38         super(inName);
39     }
40
41     /**
42          *
43          */

44     public void testCanLock_LockedByDifferentUser()
45     {
46         assertTrue(
47             "Should not be able to lock path", !fieldRegistry.canLock(LOCKED_PATH, fieldUser2));
48     }
49
50     /**
51          *
52          */

53     public void testCanLock_LockedBySameUser()
54     {
55         assertTrue("Should be able to lock path", fieldRegistry.canLock(LOCKED_PATH, fieldUser1));
56     }
57
58     /**
59          *
60          */

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     /**
68          *
69          */

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     /**
78          *
79          */

80     public void testCanLock_Unlocked()
81     {
82         assertTrue("Should be able to lock path", fieldRegistry.canLock(UNLOCKED_PATH, fieldUser1));
83     }
84
85     /**
86          *
87          */

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     /**
95          *
96          */

97     public void testForciblyLockPath_LockedBySameUser()
98     {
99         fieldRegistry.forciblyLockPath(LOCKED_PATH, fieldUser1);
100         assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH));
101     }
102
103     /**
104          *
105          */

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     /**
113          *
114          */

115     public void testGetLockOwner_Locked()
116     {
117         assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH));
118     }
119
120     /**
121          *
122          */

123     public void testGetLockOwner_Unlocked()
124     {
125         assertNull("Lock owner should be null", fieldRegistry.getLockOwner(UNLOCKED_PATH));
126     }
127
128     /**
129          *
130          */

131     public void testIsLocked_Locked()
132     {
133         assertTrue(LOCKED_PATH + " should be locked", fieldRegistry.isLocked(LOCKED_PATH));
134     }
135
136     /**
137          *
138          */

139     public void testIsLocked_Unlocked()
140     {
141         assertTrue(UNLOCKED_PATH + " should not be locked", !fieldRegistry.isLocked(UNLOCKED_PATH));
142     }
143
144     /**
145      * DOCUMENT ME!
146      *
147      * @throws Exception
148      */

149     public void testLockPath_LockedByDifferentUser() throws Exception JavaDoc
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     /**
166      * DOCUMENT ME!
167      *
168      * @throws Exception
169      */

170     public void testLockPath_LockedBySameUser() throws Exception JavaDoc
171     {
172         fieldRegistry.lockPath(LOCKED_PATH, fieldUser1);
173         assertEquals("Lock owner", fieldUser1, fieldRegistry.getLockOwner(LOCKED_PATH));
174     }
175
176     /**
177      * DOCUMENT ME!
178      *
179      * @throws Exception
180      */

181     public void testLockPath_NewLock() throws Exception JavaDoc
182     {
183         fieldRegistry.lockPath(UNLOCKED_PATH, fieldUser1);
184         assertEquals("New lock owner", fieldUser1, fieldRegistry.getLockOwner(UNLOCKED_PATH));
185     }
186
187     /**
188          *
189          */

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     /**
197          *
198          */

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     /**
208          *
209          */

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     /**
217      * @see TestCase#setUp()
218      */

219     protected void setUp() throws Exception JavaDoc
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 JavaDoc
230     {
231         deleteUserManager(fieldUserManager);
232     }
233 }
234
Popular Tags