View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/manager/ResourceManagerTest.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.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: ResourceManagerTest.java,v $
9    *   Revision 1.4  2004/11/22 13:03:04  jdt
10   *   Merges from Comm_KMB_585
11   *
12   *   Revision 1.3.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.3  2004/09/16 23:18:08  dave
18   *   Replaced debug logging in Community.
19   *   Added stream close() to FileStore.
20   *
21   *   Revision 1.2.82.1  2004/09/16 09:58:48  dave
22   *   Replaced debug with commons logging ....
23   *
24   *   Revision 1.2  2004/06/18 13:45:20  dave
25   *   Merged development branch, dave-dev-200406081614, into HEAD
26   *
27   *   Revision 1.1.2.6  2004/06/17 15:53:22  dave
28   *   Removed unused imports (PMD report).
29   *
30   *   Revision 1.1.2.5  2004/06/17 15:00:21  dave
31   *   Fixed debug flag
32   *
33   *   Revision 1.1.2.4  2004/06/17 14:50:03  dave
34   *   Removed unused imports (PMD report).
35   *
36   *   Revision 1.1.2.3  2004/06/17 13:38:59  dave
37   *   Tidied up old CVS log entries
38   *
39   * </cvs:log>
40   *
41   */
42  package org.astrogrid.community.common.policy.manager ;
43  
44  import org.apache.commons.logging.Log ;
45  import org.apache.commons.logging.LogFactory ;
46  
47  import org.astrogrid.community.common.policy.data.ResourceData ;
48  
49  import org.astrogrid.community.common.exception.CommunityResourceException   ;
50  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
51  
52  import org.astrogrid.community.common.service.CommunityServiceTest ;
53  
54  public class ResourceManagerTest
55      extends CommunityServiceTest
56      {
57      /***
58       * Our debug logger.
59       *
60       */
61      private static Log log = LogFactory.getLog(ResourceManagerTest.class);
62  
63      /***
64       * Public constructor.
65       *
66       */
67      public ResourceManagerTest()
68          {
69          }
70  
71      /***
72       * Our target ResourceManager.
73       *
74       */
75      private ResourceManager resourceManager ;
76  
77      /***
78       * Get our target GroupManager.
79       *
80       */
81      public ResourceManager getResourceManager()
82          {
83          return this.resourceManager ;
84          }
85  
86      /***
87       * Set our target ResourceManager.
88       *
89       */
90      public void setResourceManager(ResourceManager manager)
91          {
92          log.debug("") ;
93          log.debug("----\"----") ;
94          log.debug("ResourceManagerTest.setResourceManager()") ;
95          log.debug("  Manager : " + manager.getClass()) ;
96          //
97          // Set our ResourceManager reference.
98          this.resourceManager = manager ;
99          //
100         // Set our CommunityService reference.
101         this.setCommunityService(manager) ;
102         }
103 
104     /***
105      * Check we can create a Resource.
106      *
107      */
108     public void testRegisterValid()
109         throws Exception
110         {
111         log.debug("") ;
112         log.debug("----\"----") ;
113         log.debug("ResourceManagerTest:testRegisterValid()") ;
114         //
115         // Try creating the Resource.
116         assertNotNull(
117             "Null resource",
118             this.resourceManager.addResource()
119             ) ;
120         }
121 
122     /***
123      * Check we can find a known Resource.
124      *
125      */
126     public void testGetValid()
127         throws Exception
128         {
129         log.debug("") ;
130         log.debug("----\"----") ;
131         log.debug("ResourceManagerTest:testGetValid()") ;
132         //
133         // Try creating the Resource.
134         ResourceData created = this.resourceManager.addResource() ;
135         assertNotNull(
136             "Null resource",
137             created
138             ) ;
139         //
140         // Get the resource ident.
141         String ident = created.getIdent() ;
142         assertNotNull(
143             "Null resource ident",
144             ident
145             ) ;
146         //
147         // Try getting the resource details.
148         ResourceData found = this.resourceManager.getResource(ident) ;
149         assertNotNull(
150             "Null resource",
151             found
152             ) ;
153         //
154         // Check that the identifiers are the same.
155         assertEquals(
156             "Identifiers don't match",
157             created.getIdent(),
158             found.getIdent()
159             ) ;
160         }
161     
162     /***
163      * Check we can find a known Resource.
164      *
165      */
166     public ResourceData testGetValidResourceData()
167         throws Exception
168         {
169         log.debug("") ;
170         log.debug("----\"----") ;
171         log.debug("ResourceManagerTest:testGetValid()") ;
172         //
173         // Try creating the Resource.
174         ResourceData created = this.resourceManager.addResource() ;
175         assertNotNull(
176             "Null resource",
177             created
178             ) ;
179         //
180         // Get the resource ident.
181         String ident = created.getIdent() ;
182         assertNotNull(
183             "Null resource ident",
184             ident
185             ) ;
186         //
187         // Try getting the resource details.
188         ResourceData found = this.resourceManager.getResource(ident) ;
189         assertNotNull(
190             "Null resource",
191             found
192             ) ;
193         //
194         // Check that the identifiers are the same.
195         assertEquals(
196             "Identifiers don't match",
197             created.getIdent(),
198             found.getIdent()
199             ) ;
200             return found;
201         }
202     
203 
204     /***
205      * Check the service won't find an unknown Resource.
206      *
207      */
208     public void testGetUnknown()
209         throws Exception
210         {
211         log.debug("") ;
212         log.debug("----\"----") ;
213         log.debug("ResourceManagerTest:testGetUnknown()") ;
214         //
215         // Try finding an unknown resource.
216         try {
217             this.resourceManager.getResource("unknown") ;
218             fail("Expected CommunityResourceException") ;
219             }
220         catch (CommunityResourceException ouch)
221             {
222             log.debug("Caught expected Exception") ;
223             log.debug("Exception : " + ouch) ;
224             log.debug("Class     : " + ouch.getClass()) ;
225             }
226         }
227 
228     /***
229      * Check the service won't find a null Resource.
230      *
231      */
232     public void testGetNullIdent()
233         throws Exception
234         {
235         log.debug("") ;
236         log.debug("----\"----") ;
237         log.debug("ResourceManagerTest:testGetNullIdent()") ;
238         //
239         // Try finding a resource with a null ident.
240         try {
241             this.resourceManager.getResource(null) ;
242             fail("Expected CommunityIdentifierException") ;
243             }
244         catch (CommunityIdentifierException ouch)
245             {
246             log.debug("Caught expected Exception") ;
247             log.debug("Exception : " + ouch) ;
248             log.debug("Class     : " + ouch.getClass()) ;
249             }
250         }
251 
252     /***
253      * Check we can update a known Resource.
254      *
255      */
256     public void testSetValid()
257         throws Exception
258         {
259         log.debug("") ;
260         log.debug("----\"----") ;
261         log.debug("ResourceManagerTest:testSetValid()") ;
262         //
263         // Try creating the Resource.
264         ResourceData created = this.resourceManager.addResource() ;
265         assertNotNull(
266             "Null resource",
267             created
268             ) ;
269         //
270         // Get the resource ident.
271         String ident = created.getIdent() ;
272         assertNotNull(
273             "Null resource ident",
274             ident
275             ) ;
276         //
277         // Try changing the resource details.
278         String description = "Test description" ;
279         created.setDescription(description) ;
280         ResourceData modified = this.resourceManager.setResource(created) ;
281         assertNotNull(
282             "Null resource",
283             modified
284             ) ;
285         //
286         // Check the resource was updated.
287         assertEquals("Descriptions don't match",
288             description,
289             modified.getDescription()
290             ) ;
291         //
292         // Try getting the resource details.
293         ResourceData found = this.resourceManager.getResource(ident) ;
294         assertNotNull(
295             "Null resource",
296             found
297             ) ;
298         //
299         // Check the resource was updated.
300         assertEquals(
301             "Descriptions don't match",
302             description,
303             found.getDescription()
304             ) ;
305         }
306 
307     /***
308      * Check we can't update a null Resource.
309      *
310      */
311     public void testSetNull()
312         throws Exception
313         {
314         log.debug("") ;
315         log.debug("----\"----") ;
316         log.debug("ResourceManagerTest:testSetNull()") ;
317         //
318         // Try changing a null resource.
319         try {
320             this.resourceManager.setResource(null) ;
321             fail("Expected CommunityResourceException") ;
322             }
323         catch (CommunityResourceException ouch)
324             {
325             log.debug("Caught expected Exception") ;
326             log.debug("Exception : " + ouch) ;
327             log.debug("Class     : " + ouch.getClass()) ;
328             }
329         }
330 
331     /***
332      * Check we can't update a Resource with a null ident.
333      *
334      */
335     public void testSetNullIdent()
336         throws Exception
337         {
338         log.debug("") ;
339         log.debug("----\"----") ;
340         log.debug("ResourceManagerTest:testSetNullIdent()") ;
341         //
342         // Try changing a null resource.
343         try {
344             this.resourceManager.setResource(
345                 new ResourceData()
346                 ) ;
347             fail("Expected CommunityIdentifierException") ;
348             }
349         catch (CommunityIdentifierException ouch)
350             {
351             log.debug("Caught expected Exception") ;
352             log.debug("Exception : " + ouch) ;
353             log.debug("Class     : " + ouch.getClass()) ;
354             }
355         }
356 
357     /***
358      * Check we can't update a Resource with an invalid ident.
359      *
360      */
361     public void testSetUnknownIdent()
362         throws Exception
363         {
364         log.debug("") ;
365         log.debug("----\"----") ;
366         log.debug("ResourceManagerTest:testSetUnknownIdent()") ;
367         //
368         // Try changing an unknwon resource.
369         try {
370             this.resourceManager.setResource(
371                 new ResourceData("unknown")
372                 ) ;
373             fail("Expected CommunityResourceException") ;
374             }
375         catch (CommunityResourceException ouch)
376             {
377             log.debug("Caught expected Exception") ;
378             log.debug("Exception : " + ouch) ;
379             log.debug("Class     : " + ouch.getClass()) ;
380             }
381         }
382 
383     /***
384      * Check we can delete a known Resource.
385      *
386      */
387     public void testDelValid()
388         throws Exception
389         {
390         log.debug("") ;
391         log.debug("----\"----") ;
392         log.debug("ResourceManagerTest:testDelValid()") ;
393         //
394         // Try creating the Resource.
395         ResourceData created = this.resourceManager.addResource() ;
396         assertNotNull(
397             "Null resource",
398             created
399             ) ;
400         //
401         // Get the resource ident.
402         String ident = created.getIdent() ;
403         assertNotNull(
404             "Null resource ident",
405             ident
406             ) ;
407         //
408         // Try finding the resource details.
409         ResourceData found = this.resourceManager.getResource(ident) ;
410         assertNotNull(
411             "Null resource",
412             found
413             ) ;
414         //
415         // Try deleting the resource.
416         ResourceData deleted = this.resourceManager.delResource(ident) ;
417         assertNotNull(
418             "Null resource",
419             deleted
420             ) ;
421         //
422         // Try finding the resource details.
423         try {
424             this.resourceManager.getResource(ident) ;
425             fail("Expected CommunityResourceException") ;
426             }
427         catch (CommunityResourceException ouch)
428             {
429             log.debug("Caught expected Exception") ;
430             log.debug("Exception : " + ouch) ;
431             log.debug("Class     : " + ouch.getClass()) ;
432             }
433         }
434 
435     /***
436      * Check the service won't delete an unknown Resource.
437      *
438      */
439     public void testDelUnknown()
440         throws Exception
441         {
442         log.debug("") ;
443         log.debug("----\"----") ;
444         log.debug("ResourceManagerTest:testDelUnknown()") ;
445         //
446         // Try deleting an unknown resource.
447         try {
448             this.resourceManager.delResource("unknown") ;
449             fail("Expected CommunityResourceException") ;
450             }
451         catch (CommunityResourceException ouch)
452             {
453             log.debug("Caught expected Exception") ;
454             log.debug("Exception : " + ouch) ;
455             log.debug("Class     : " + ouch.getClass()) ;
456             }
457         }
458 
459     /***
460      * Check the service won't delete a null Resource.
461      *
462      */
463     public void testDelNullIdent()
464         throws Exception
465         {
466         log.debug("") ;
467         log.debug("----\"----") ;
468         log.debug("ResourceManagerTest:testDelNullIdent()") ;
469         //
470         // Try deleting a resource with a null ident.
471         try {
472             this.resourceManager.delResource(null) ;
473             fail("Expected CommunityIdentifierException") ;
474             }
475         catch (CommunityIdentifierException ouch)
476             {
477             log.debug("Caught expected Exception") ;
478             log.debug("Exception : " + ouch) ;
479             log.debug("Class     : " + ouch.getClass()) ;
480             }
481         }
482     }