View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/manager/AccountManagerTest.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.11 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: AccountManagerTest.java,v $
9    *   Revision 1.11  2004/11/22 13:03:04  jdt
10   *   Merges from Comm_KMB_585
11   *
12   *   Revision 1.10.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.10  2004/09/16 23:18:08  dave
18   *   Replaced debug logging in Community.
19   *   Added stream close() to FileStore.
20   *
21   *   Revision 1.9.82.1  2004/09/16 09:58:48  dave
22   *   Replaced debug with commons logging ....
23   *
24   *   Revision 1.9  2004/06/18 13:45:20  dave
25   *   Merged development branch, dave-dev-200406081614, into HEAD
26   *
27   *   Revision 1.8.32.3  2004/06/17 15:00:21  dave
28   *   Fixed debug flag
29   *
30   *   Revision 1.8.32.2  2004/06/17 14:50:01  dave
31   *   Removed unused imports (PMD report).
32   *
33   *   Revision 1.8.32.1  2004/06/17 13:38:59  dave
34   *   Tidied up old CVS log entries
35   *
36   * </cvs:log>
37   *
38   */
39  package org.astrogrid.community.common.policy.manager ;
40  
41  import org.apache.commons.logging.Log ;
42  import org.apache.commons.logging.LogFactory ;
43  
44  import java.rmi.RemoteException ;
45  
46  import org.astrogrid.community.common.policy.data.AccountData ;
47  
48  import org.astrogrid.community.common.exception.CommunityPolicyException ;
49  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
50  
51  import org.astrogrid.community.common.service.CommunityServiceTest ;
52  
53  /***
54   * Generic test case for AccountManager.
55   * @todo Change unknown to use the same ident - once reset is fixed.
56   * @todo Chech the Exception type wrapped in the RemoteException.
57   *
58   */
59  public class AccountManagerTest
60      extends CommunityServiceTest
61      {
62      /***
63       * Our debug logger.
64       *
65       */
66      private static Log log = LogFactory.getLog(AccountManagerTest.class);
67  
68      /***
69       * Public constructor.
70       *
71       */
72      public AccountManagerTest()
73          {
74          }
75  
76      /***
77       * Our target AccountManager.
78       *
79       */
80      private AccountManager accountManager ;
81  
82      /***
83       * Get our target AccountManager.
84       *
85       */
86      public AccountManager getAccountManager()
87          {
88          return this.accountManager ;
89          }
90  
91      /***
92       * Set our target AccountManager.
93       *
94       */
95      public void setAccountManager(AccountManager manager)
96          {
97          log.debug("") ;
98          log.debug("----\"----") ;
99          log.debug("AccountManagerTest.setAccountManager()") ;
100         log.debug("  Manager : " + manager.getClass()) ;
101         //
102         // Set our AccountManager reference.
103         this.accountManager = manager ;
104         //
105         // Set our CommunityService reference.
106         this.setCommunityService(manager) ;
107         }
108 
109     /***
110      * Try creating a null Account.
111      *
112      */
113     public void testCreateNull()
114         throws Exception
115         {
116         log.debug("") ;
117         log.debug("----\"----") ;
118         log.debug("AccountManagerTest:testCreateNull()") ;
119         //
120         // Try creating an Account.
121         try {
122             accountManager.addAccount((String)null) ;
123             fail("Expected CommunityIdentifierException") ;
124             }
125         catch (CommunityIdentifierException ouch)
126             {
127             log.debug("Caught expected Exception") ;
128             log.debug("Exception : " + ouch) ;
129             log.debug("Class     : " + ouch.getClass()) ;
130             }
131         catch (RemoteException ouch)
132             {
133             log.debug("Caught expected Exception") ;
134             log.debug("Exception : " + ouch) ;
135             log.debug("Class     : " + ouch.getClass()) ;
136             }
137         //
138         // Try creating an Account.
139         try {
140             accountManager.addAccount((AccountData)null) ;
141             fail("Expected CommunityIdentifierException") ;
142             }
143         catch (CommunityIdentifierException ouch)
144             {
145             log.debug("Caught expected Exception") ;
146             log.debug("Exception : " + ouch) ;
147             log.debug("Class     : " + ouch.getClass()) ;
148             }
149         catch (RemoteException ouch)
150             {
151             log.debug("Caught expected Exception") ;
152             log.debug("Exception : " + ouch) ;
153             log.debug("Class     : " + ouch.getClass()) ;
154             }
155         }
156 
157     /***
158      * Check we can create a valid Account.
159      *
160      */
161     public void testCreateValid()
162         throws Exception
163         {
164         log.debug("") ;
165         log.debug("----\"----") ;
166         log.debug("AccountManagerTest:testCreateValid()") ;
167         //
168         // Try creating an Account.
169         assertNotNull("Null account",
170             accountManager.addAccount(
171                 createLocal("test-account").toString()
172                 )
173             ) ;
174         }
175 
176     /***
177      * Check we can create a valid Account.
178      *
179      */
180     public void testCreateData()
181         throws Exception
182         {
183         log.debug("") ;
184         log.debug("----\"----") ;
185         log.debug("AccountManagerTest:testCreateData()") ;
186         //
187         // Try creating an Account.
188         assertNotNull("Null account",
189             accountManager.addAccount(
190                 new AccountData(
191                     createLocal("test-account").toString()
192                     )
193                 )
194             ) ;
195         }
196 
197     /***
198      * Try to create a duplicate Account.
199      *
200      */
201     public void testCreateDuplicate()
202         throws Exception
203         {
204         log.debug("") ;
205         log.debug("----\"----") ;
206         log.debug("AccountManagerTest:testCreateDuplicate()") ;
207         //
208         // Try creating an Account.
209         assertNotNull("Null account",
210             accountManager.addAccount(
211                 createLocal("test-account").toString()
212                 )
213             ) ;
214         //
215         // Try creating the same Account.
216         try {
217             accountManager.addAccount(
218                 createLocal("test-account").toString()
219                 ) ;
220             fail("Expected CommunityPolicyException") ;
221             }
222         catch (CommunityPolicyException ouch)
223             {
224             log.debug("Caught expected Exception") ;
225             log.debug("Exception : " + ouch) ;
226             log.debug("Class     : " + ouch.getClass()) ;
227             }
228         catch (RemoteException ouch)
229             {
230             log.debug("Caught expected Exception") ;
231             log.debug("Exception : " + ouch) ;
232             log.debug("Class     : " + ouch.getClass()) ;
233             }
234         }
235 
236     /***
237      * Try getting a null Account.
238      *
239      */
240     public void testGetNull()
241         throws Exception
242         {
243         log.debug("") ;
244         log.debug("----\"----") ;
245         log.debug("AccountManagerTest:testGetNull()") ;
246         //
247         // Try getting the details.
248         try {
249             accountManager.getAccount(null) ;
250             fail("Expected CommunityIdentifierException") ;
251             }
252         catch (CommunityIdentifierException ouch)
253             {
254             log.debug("Caught expected Exception") ;
255             log.debug("Exception : " + ouch) ;
256             log.debug("Class     : " + ouch.getClass()) ;
257             }
258         catch (RemoteException ouch)
259             {
260             log.debug("Caught expected Exception") ;
261             log.debug("Exception : " + ouch) ;
262             log.debug("Class     : " + ouch.getClass()) ;
263             }
264         }
265 
266     /***
267      * Try getting an unknown Account.
268      *
269      */
270     public void testGetUnknown()
271         throws Exception
272         {
273         log.debug("") ;
274         log.debug("----\"----") ;
275         log.debug("AccountManagerTest:testGetUnknown()") ;
276         //
277         // Try getting the details.
278         try {
279             accountManager.getAccount(
280                 createLocal("unknown-account").toString()
281                 ) ;
282             fail("Expected CommunityPolicyException") ;
283             }
284         catch (CommunityPolicyException ouch)
285             {
286             log.debug("Caught expected Exception") ;
287             log.debug("Exception : " + ouch) ;
288             log.debug("Class     : " + ouch.getClass()) ;
289             }
290         catch (RemoteException ouch)
291             {
292             log.debug("Caught expected Exception") ;
293             log.debug("Exception : " + ouch) ;
294             log.debug("Class     : " + ouch.getClass()) ;
295             }
296         }
297 
298     /***
299      * Try getting a valid Account.
300      *
301      */
302     public void testGetValid()
303         throws Exception
304         {
305         log.debug("") ;
306         log.debug("----\"----") ;
307         log.debug("AccountManagerTest:testGetValid()") ;
308         //
309         // Try creating an Account.
310         AccountData created = accountManager.addAccount(
311             createLocal("test-account").toString()
312             ) ;
313         assertNotNull("Null account", created) ;
314         //
315         // Try getting the details.
316         AccountData found = accountManager.getAccount(
317             createLocal("test-account").toString()
318             ) ;
319         assertNotNull("Null account", found) ;
320         //
321         // Check that they refer to the same account.
322         assertEquals("Different identifiers", created, found) ;
323         }
324     
325     /***
326      * Try getting a valid Account.
327      *
328      */
329     public AccountData testGetValidAccountData()
330         throws Exception
331         {
332         log.debug("") ;
333         log.debug("----\"----") ;
334         log.debug("AccountManagerTest:testGetValid()") ;
335         //
336         // Try creating an Account.
337         AccountData created = accountManager.addAccount(
338             createLocal("test-account").toString()
339             ) ;
340         assertNotNull("Null account", created) ;
341         //
342         // Try getting the details.
343         AccountData found = accountManager.getAccount(
344             createLocal("test-account").toString()
345             ) ;
346         assertNotNull("Null account", found) ;
347         //
348         // Check that they refer to the same account.
349         assertEquals("Different identifiers", created, found) ;
350         return found;
351     }
352     
353 
354     /***
355      * Try setting a null Account.
356      *
357      */
358     public void testSetNull()
359         throws Exception
360         {
361         log.debug("") ;
362         log.debug("----\"----") ;
363         log.debug("AccountManagerTest:testSetNull()") ;
364         try {
365             accountManager.setAccount(null) ;
366             fail("Expected CommunityIdentifierException") ;
367             }
368         catch (CommunityIdentifierException ouch)
369             {
370             log.debug("Caught expected Exception") ;
371             log.debug("Exception : " + ouch) ;
372             log.debug("Class     : " + ouch.getClass()) ;
373             }
374         catch (RemoteException ouch)
375             {
376             log.debug("Caught expected Exception") ;
377             log.debug("Exception : " + ouch) ;
378             log.debug("Class     : " + ouch.getClass()) ;
379             }
380         }
381 
382     /***
383      * Try setting an unknown Account.
384      *
385      */
386     public void testSetUnknown()
387         throws Exception
388         {
389         log.debug("") ;
390         log.debug("----\"----") ;
391         log.debug("AccountManagerTest:testSetUnknown()") ;
392         //
393         // Try setting an unknown account.
394         try {
395             accountManager.setAccount(
396                 new AccountData(
397                     createLocal("unknown-account").toString()
398                     )
399                 ) ;
400             fail("Expected CommunityPolicyException") ;
401             }
402         catch (CommunityPolicyException ouch)
403             {
404             log.debug("Caught expected Exception") ;
405             log.debug("Exception : " + ouch) ;
406             log.debug("Class     : " + ouch.getClass()) ;
407             }
408         catch (RemoteException ouch)
409             {
410             log.debug("Caught expected Exception") ;
411             log.debug("Exception : " + ouch) ;
412             log.debug("Class     : " + ouch.getClass()) ;
413             }
414         }
415 
416     /***
417      * Try setting a valid Account.
418      *
419      */
420     public void testSetValid()
421         throws Exception
422         {
423         log.debug("") ;
424         log.debug("----\"----") ;
425         log.debug("AccountManagerTest:testSetValid()") ;
426         //
427         // Try creating an Account.
428         AccountData account = accountManager.addAccount(
429             createLocal("test-account").toString()
430             ) ;
431         assertNotNull("Null account", account) ;
432         //
433         // Change the details.
434         account.setDisplayName("Test DisplayName") ;
435         account.setDescription("Test Description") ;
436         account.setEmailAddress("Test EmailAddress") ;
437         account.setHomeSpace("Test HomeSpace") ;
438         //
439         // Try setting the details.
440         account = accountManager.setAccount(account) ;
441         assertNotNull("Null account", account) ;
442         //
443         // Check the details have been changed.
444         assertEquals("Different details", "Test DisplayName",  account.getDisplayName())  ;
445         assertEquals("Different details", "Test Description",  account.getDescription())  ;
446         assertEquals("Different details", "Test EmailAddress", account.getEmailAddress()) ;
447         assertEquals("Different details", "Test HomeSpace",    account.getHomeSpace())    ;
448         //
449         // Try getting the details.
450         account = accountManager.getAccount(
451             createLocal("test-account").toString()
452             ) ;
453         assertNotNull("Null account", account) ;
454         //
455         // Check the details have been changed.
456         assertEquals("Different details", account.getDisplayName(),  "Test DisplayName")  ;
457         assertEquals("Different details", account.getDescription(),  "Test Description")  ;
458         assertEquals("Different details", account.getEmailAddress(), "Test EmailAddress") ;
459         assertEquals("Different details", account.getHomeSpace(),    "Test HomeSpace")    ;
460         }
461 
462     /***
463      * Try deleting a null Account.
464      *
465      */
466     public void testDeleteNull()
467         throws Exception
468         {
469         log.debug("") ;
470         log.debug("----\"----") ;
471         log.debug("AccountManagerTest:testDeleteNull()") ;
472         try {
473             accountManager.delAccount(null) ;
474             fail("Expected CommunityIdentifierException") ;
475             }
476         catch (CommunityIdentifierException ouch)
477             {
478             log.debug("Caught expected Exception") ;
479             log.debug("Exception : " + ouch) ;
480             log.debug("Class     : " + ouch.getClass()) ;
481             }
482         catch (RemoteException ouch)
483             {
484             log.debug("Caught expected Exception") ;
485             log.debug("Exception : " + ouch) ;
486             log.debug("Class     : " + ouch.getClass()) ;
487             }
488         }
489 
490     /***
491      * Try deleting an unknown Account.
492      *
493      */
494     public void testDeleteUnknown()
495         throws Exception
496         {
497         log.debug("") ;
498         log.debug("----\"----") ;
499         log.debug("AccountManagerTest:testDeleteUnknown()") ;
500         try {
501             accountManager.delAccount(
502                 createLocal("unknown-account").toString()
503                 ) ;
504             fail("Expected CommunityPolicyException") ;
505             }
506         catch (CommunityPolicyException ouch)
507             {
508             log.debug("Caught expected Exception") ;
509             log.debug("Exception : " + ouch) ;
510             log.debug("Class     : " + ouch.getClass()) ;
511             }
512         catch (RemoteException ouch)
513             {
514             log.debug("Caught expected Exception") ;
515             log.debug("Exception : " + ouch) ;
516             log.debug("Class     : " + ouch.getClass()) ;
517             }
518         }
519 
520     /***
521      * Try deleting a valid Account.
522      *
523      */
524     public void testDeleteValid()
525         throws Exception
526         {
527         log.debug("") ;
528         log.debug("----\"----") ;
529         log.debug("AccountManagerTest:testDeleteValid()") ;
530         //
531         // Try creating the Account.
532         AccountData created = accountManager.addAccount(
533             createLocal("test-account").toString()
534             ) ;
535         assertNotNull("Null account", created) ;
536         //
537         // Try deleting the Account.
538         AccountData deleted = accountManager.delAccount(
539             createLocal("test-account").toString()
540             ) ;
541         assertNotNull("Null account", deleted) ;
542         //
543         // Check that the two objects represent the same Account.
544         assertEquals("Different identifiers", created, deleted) ;
545         }
546 
547     /***
548      * Try deleting the same Account twice.
549      *
550      */
551     public void testDeleteTwice()
552         throws Exception
553         {
554         log.debug("") ;
555         log.debug("----\"----") ;
556         log.debug("AccountManagerTest:testDeleteTwice()") ;
557         //
558         // Try creating the Account.
559         AccountData created = accountManager.addAccount(
560             createLocal("test-account").toString()
561             ) ;
562         assertNotNull("Null account", created) ;
563         //
564         // Try deleting the Account.
565         AccountData deleted = accountManager.delAccount(
566             createLocal("test-account").toString()
567             ) ;
568         assertNotNull("Null account", deleted) ;
569         //
570         // Check that the two objects represent the same Account.
571         assertEquals("Different identifiers", created, deleted) ;
572         //
573         // Try deleting the Account again.
574         try {
575             accountManager.delAccount(
576                 createLocal("test-account").toString()
577                 ) ;
578             fail("Expected CommunityPolicyException") ;
579             }
580         catch (CommunityPolicyException ouch)
581             {
582             log.debug("Caught expected Exception") ;
583             log.debug("Exception : " + ouch) ;
584             log.debug("Class     : " + ouch.getClass()) ;
585             }
586         catch (RemoteException ouch)
587             {
588             log.debug("Caught expected Exception") ;
589             log.debug("Exception : " + ouch) ;
590             log.debug("Class     : " + ouch.getClass()) ;
591             }
592         }
593     }