View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/manager/GroupManagerTest.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2004/11/22 13:03:04 $</cvs:date>
5    * <cvs:version>$Revision: 1.6 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: GroupManagerTest.java,v $
9    *   Revision 1.6  2004/11/22 13:03:04  jdt
10   *   Merges from Comm_KMB_585
11   *
12   *   Revision 1.5.22.1  2004/11/05 08:55:49  KevinBenson
13   *   Moved the GroupMember out of PolicyManager in the commons and client section.
14   *   Added more unit tests for GroupMember and PermissionManager for testing.
15   *   Still have some errors that needs some fixing.
16   *
17   *   Revision 1.5  2004/09/16 23:18:08  dave
18   *   Replaced debug logging in Community.
19   *   Added stream close() to FileStore.
20   *
21   *   Revision 1.4.82.1  2004/09/16 09:58:48  dave
22   *   Replaced debug with commons logging ....
23   *
24   *   Revision 1.4  2004/06/18 13:45:20  dave
25   *   Merged development branch, dave-dev-200406081614, into HEAD
26   *
27   *   Revision 1.3.32.2  2004/06/17 14:50:03  dave
28   *   Removed unused imports (PMD report).
29   *
30   *   Revision 1.3.32.1  2004/06/17 13:38:59  dave
31   *   Tidied up old CVS log entries
32   *
33   * </cvs:log>
34   *
35   */
36  package org.astrogrid.community.common.policy.manager ;
37  
38  import org.apache.commons.logging.Log ;
39  import org.apache.commons.logging.LogFactory ;
40  
41  import org.astrogrid.community.common.policy.data.GroupData ;
42  
43  import org.astrogrid.community.common.exception.CommunityPolicyException ;
44  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
45  
46  import org.astrogrid.community.common.service.CommunityServiceTest ;
47  
48  public class GroupManagerTest
49      extends CommunityServiceTest
50      {
51      /***
52       * Our debug logger.
53       *
54       */
55  	private static Log log = LogFactory.getLog(GroupManagerTest.class);
56  
57      /***
58       * Public constructor.
59       *
60       */
61      public GroupManagerTest()
62          {
63          }
64  
65      /***
66       * Our target GroupManager.
67       *
68       */
69      private GroupManager groupManager ;
70  
71      /***
72       * Get our target GroupManager.
73       *
74       */
75      public GroupManager getGroupManager()
76          {
77          return this.groupManager ;
78          }
79  
80      /***
81       * Set our target GroupManager.
82       *
83       */
84      public void setGroupManager(GroupManager manager)
85          {
86          log.debug("") ;
87          log.debug("----\"----") ;
88          log.debug("GroupManagerTest.setGroupManager()") ;
89          log.debug("  Manager : " + manager.getClass()) ;
90          //
91          // Set our GroupManager reference.
92          this.groupManager = manager ;
93          //
94          // Set our CommunityService reference.
95          this.setCommunityService(manager) ;
96          }
97  
98      /***
99       * Try creating a null Group.
100      *
101      */
102     public void testCreateNull()
103         throws Exception
104         {
105         log.debug("") ;
106         log.debug("----\"----") ;
107         log.debug("GroupManagerTest:testCreateNull()") ;
108         //
109         // Try creating the Group.
110         try {
111             groupManager.addGroup((String)null) ;
112             fail("Expected CommunityIdentifierException") ;
113             }
114         catch (CommunityIdentifierException ouch)
115             {
116             log.debug("Caught expected Exception") ;
117             log.debug("Exception : " + ouch) ;
118             }
119         //
120         // Try creating the Group.
121         try {
122             groupManager.addGroup((GroupData)null) ;
123             fail("Expected CommunityIdentifierException") ;
124             }
125         catch (CommunityIdentifierException ouch)
126             {
127             log.debug("Caught expected Exception") ;
128             log.debug("Exception : " + ouch) ;
129             }
130         }
131 
132     /***
133      * Check we can create a valid Group.
134      *
135      */
136     public void testCreateValid()
137         throws Exception
138         {
139         log.debug("") ;
140         log.debug("----\"----") ;
141         log.debug("GroupManagerTest:testCreateValid()") ;
142         //
143         // Try creating the Group.
144         assertNotNull("Null group",
145             groupManager.addGroup(
146                 createLocal("test-group").toString()
147                 )
148             ) ;
149         }
150 
151     /***
152      * Check we can create a valid Group.
153      *
154      */
155     public void testCreateData()
156         throws Exception
157         {
158         log.debug("") ;
159         log.debug("----\"----") ;
160         log.debug("GroupManagerTest:testCreateData()") ;
161         //
162         // Try creating the Group.
163         assertNotNull("Null group",
164             groupManager.addGroup(
165                 new GroupData(
166                     createLocal("test-group").toString()
167                     )
168                 )
169             ) ;
170         }
171 
172     /***
173      * Try to create a duplicate Group.
174      *
175      */
176     public void testCreateDuplicate()
177         throws Exception
178         {
179         log.debug("") ;
180         log.debug("----\"----") ;
181         log.debug("GroupManagerTest:testCreateDuplicate()") ;
182         //
183         // Try creating the Group.
184         assertNotNull("Null group",
185             groupManager.addGroup(
186                 createLocal("test-group").toString()
187                 )
188             ) ;
189         //
190         // Try creating the same Group.
191         try {
192             groupManager.addGroup(
193                 createLocal("test-group").toString()
194                 ) ;
195             fail("Expected CommunityPolicyException") ;
196             }
197         catch (CommunityPolicyException ouch)
198             {
199             log.debug("Caught expected Exception") ;
200             log.debug("Exception : " + ouch) ;
201             }
202         }
203 
204     /***
205      * Try getting a null Group.
206      *
207      */
208     public void testGetNull()
209         throws Exception
210         {
211         log.debug("") ;
212         log.debug("----\"----") ;
213         log.debug("GroupManagerTest:testGetNull()") ;
214         //
215         // Try getting the details.
216         try {
217             groupManager.getGroup(null) ;
218             fail("Expected CommunityIdentifierException") ;
219             }
220         catch (CommunityIdentifierException ouch)
221             {
222             log.debug("Caught expected Exception") ;
223             log.debug("Exception : " + ouch) ;
224             }
225         }
226 
227     /***
228      * Try getting an unknown Group.
229      *
230      */
231     public void testGetUnknown()
232         throws Exception
233         {
234         log.debug("") ;
235         log.debug("----\"----") ;
236         log.debug("GroupManagerTest:testGetUnknown()") ;
237         //
238         // Try getting the details.
239         try {
240             groupManager.getGroup(
241                 createLocal("unknown-group").toString()
242                 ) ;
243             fail("Expected CommunityPolicyException") ;
244             }
245         catch (CommunityPolicyException ouch)
246             {
247             log.debug("Caught expected Exception") ;
248             log.debug("Exception : " + ouch) ;
249             }
250         }
251 
252     /***
253      * Try getting a valid Group.
254      *
255      */
256     public void testGetValid()
257         throws Exception
258         {
259         log.debug("") ;
260         log.debug("----\"----") ;
261         log.debug("GroupManagerTest:testGetValid()") ;
262         //
263         // Try creating the Group.
264         GroupData created = groupManager.addGroup(
265             createLocal("test-group").toString()
266             ) ;
267         assertNotNull("Null group", created) ;
268         //
269         // Try getting the details.
270         GroupData found = groupManager.getGroup(
271             createLocal("test-group").toString()
272             ) ;
273         assertNotNull("Null group", found) ;
274         //
275         // Check that they refer to the same group.
276         assertEquals("Different identifiers", created, found) ;
277         }
278     
279     /***
280      * Try getting a valid Group.
281      *
282      */
283     public GroupData testGetValidGroupData()
284         throws Exception
285         {
286         log.debug("") ;
287         log.debug("----\"----") ;
288         log.debug("GroupManagerTest:testGetValid()") ;
289         //
290         // Try creating the Group.
291         GroupData created = groupManager.addGroup(
292             createLocal("test-group").toString()
293             ) ;
294         assertNotNull("Null group", created) ;
295         //
296         // Try getting the details.
297         GroupData found = groupManager.getGroup(
298             createLocal("test-group").toString()
299             ) ;
300         assertNotNull("Null group", found) ;
301         //
302         // Check that they refer to the same group.
303         assertEquals("Different identifiers", created, found) ;
304         return found;
305     }
306     
307 
308     /***
309      * Try setting a null Group.
310      *
311      */
312     public void testSetNull()
313         throws Exception
314         {
315         log.debug("") ;
316         log.debug("----\"----") ;
317         log.debug("GroupManagerTest:testSetNull()") ;
318         try {
319             groupManager.setGroup(null) ;
320             fail("Expected CommunityIdentifierException") ;
321             }
322         catch (CommunityIdentifierException ouch)
323             {
324             log.debug("Caught expected Exception") ;
325             log.debug("Exception : " + ouch) ;
326             }
327         }
328 
329     /***
330      * Try setting an unknown Group.
331      *
332      */
333     public void testSetUnknown()
334         throws Exception
335         {
336         log.debug("") ;
337         log.debug("----\"----") ;
338         log.debug("GroupManagerTest:testSetUnknown()") ;
339         //
340         // Try setting an unknown group.
341         try {
342             groupManager.setGroup(
343                 new GroupData(
344                     createLocal("unknown-group").toString()
345                     )
346                 ) ;
347             fail("Expected CommunityPolicyException") ;
348             }
349         catch (CommunityPolicyException ouch)
350             {
351             log.debug("Caught expected Exception") ;
352             log.debug("Exception : " + ouch) ;
353             }
354         }
355 
356     /***
357      * Try setting a valid Group.
358      *
359      */
360     public void testSetValid()
361         throws Exception
362         {
363         log.debug("") ;
364         log.debug("----\"----") ;
365         log.debug("GroupManagerTest:testSetValid()") ;
366         //
367         // Try creating the Group.
368         GroupData group = groupManager.addGroup(
369             createLocal("test-group").toString()
370             ) ;
371         assertNotNull("Null group", group) ;
372         //
373         // Change the details.
374         group.setDisplayName("Test DisplayName") ;
375         group.setDescription("Test Description") ;
376         //
377         // Try setting the details.
378         group = groupManager.setGroup(group) ;
379         assertNotNull("Null group", group) ;
380         //
381         // Check the details have been changed.
382         assertEquals("Different details", "Test DisplayName",  group.getDisplayName())  ;
383         assertEquals("Different details", "Test Description",  group.getDescription())  ;
384         //
385         // Try getting the details.
386         group = groupManager.getGroup(
387             createLocal("test-group").toString()
388             ) ;
389         assertNotNull("Null group", group) ;
390         //
391         // Check the details have been changed.
392         assertEquals("Different details", "Test DisplayName",  group.getDisplayName())  ;
393         assertEquals("Different details", "Test Description",  group.getDescription())  ;
394         }
395 
396     /***
397      * Try deleting a null Group.
398      *
399      */
400     public void testDeleteNull()
401         throws Exception
402         {
403         log.debug("") ;
404         log.debug("----\"----") ;
405         log.debug("GroupManagerTest:testDeleteNull()") ;
406         try {
407             groupManager.delGroup(null) ;
408             fail("Expected CommunityIdentifierException") ;
409             }
410         catch (CommunityIdentifierException ouch)
411             {
412             log.debug("Caught expected Exception") ;
413             log.debug("Exception : " + ouch) ;
414             }
415         }
416 
417     /***
418      * Try deleting an unknown Group.
419      *
420      */
421     public void testDeleteUnknown()
422         throws Exception
423         {
424         log.debug("") ;
425         log.debug("----\"----") ;
426         log.debug("GroupManagerTest:testDeleteUnknown()") ;
427         try {
428             groupManager.delGroup(
429                 createLocal("unknown-group").toString()
430                 ) ;
431             fail("Expected CommunityPolicyException") ;
432             }
433         catch (CommunityPolicyException ouch)
434             {
435             log.debug("Caught expected Exception") ;
436             log.debug("Exception : " + ouch) ;
437             }
438         }
439 
440     /***
441      * Try deleting a valid Group.
442      *
443      */
444     public void testDeleteValid()
445         throws Exception
446         {
447         log.debug("") ;
448         log.debug("----\"----") ;
449         log.debug("GroupManagerTest:testDeleteValid()") ;
450         //
451         // Try creating the Group.
452         GroupData created = groupManager.addGroup(
453             createLocal("test-group").toString()
454             ) ;
455         assertNotNull("Null group", created) ;
456         //
457         // Try deleting the Group.
458         GroupData deleted = groupManager.delGroup(
459             createLocal("test-group").toString()
460             ) ;
461         assertNotNull("Null group", deleted) ;
462         //
463         // Check that the two objects represent the same Group.
464         assertEquals("Different identifiers", created, deleted) ;
465         }
466 
467     /***
468      * Try deleting the same Group.
469      *
470      */
471     public void testDeleteTwice()
472         throws Exception
473         {
474         log.debug("") ;
475         log.debug("----\"----") ;
476         log.debug("GroupManagerTest:testDeleteTwice()") ;
477         //
478         // Try creating the Group.
479         GroupData created = groupManager.addGroup(
480             createLocal("test-group").toString()
481             ) ;
482         assertNotNull("Null group", created) ;
483         //
484         // Try deleting the Group.
485         GroupData deleted = groupManager.delGroup(
486             createLocal("test-group").toString()
487             ) ;
488         assertNotNull("Null group", deleted) ;
489         //
490         // Check that the two objects represent the same Group.
491         assertEquals("Different identifiers", created, deleted) ;
492         //
493         // Try deleting the Group again.
494         try {
495             groupManager.delGroup(
496                 createLocal("test-group").toString()
497                 ) ;
498             fail("Expected CommunityPolicyException") ;
499             }
500         catch (CommunityPolicyException ouch)
501             {
502             log.debug("Caught expected Exception") ;
503             log.debug("Exception : " + ouch) ;
504             }
505         }
506     }