View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/community/common/src/java/org/astrogrid/community/common/policy/manager/CommunityManagerTest.java,v $</cvs:source>
3    * <cvs:author>$Author: dave $</cvs:author>
4    * <cvs:date>$Date: 2004/09/16 23:18:08 $</cvs:date>
5    * <cvs:version>$Revision: 1.4 $</cvs:version>
6    *
7    * <cvs:log>
8    *   $Log: CommunityManagerTest.java,v $
9    *   Revision 1.4  2004/09/16 23:18:08  dave
10   *   Replaced debug logging in Community.
11   *   Added stream close() to FileStore.
12   *
13   *   Revision 1.3.82.1  2004/09/16 09:58:48  dave
14   *   Replaced debug with commons logging ....
15   *
16   *   Revision 1.3  2004/06/18 13:45:20  dave
17   *   Merged development branch, dave-dev-200406081614, into HEAD
18   *
19   *   Revision 1.2.38.2  2004/06/17 14:50:03  dave
20   *   Removed unused imports (PMD report).
21   *
22   *   Revision 1.2.38.1  2004/06/17 13:38:59  dave
23   *   Tidied up old CVS log entries
24   *
25   * </cvs:log>
26   *
27   */
28  package org.astrogrid.community.common.policy.manager ;
29  
30  import org.apache.commons.logging.Log ;
31  import org.apache.commons.logging.LogFactory ;
32  
33  import org.astrogrid.community.common.policy.data.CommunityData ;
34  
35  import org.astrogrid.community.common.exception.CommunityPolicyException ;
36  import org.astrogrid.community.common.exception.CommunityIdentifierException ;
37  
38  import org.astrogrid.community.common.service.CommunityServiceTest ;
39  
40  public class CommunityManagerTest
41      extends CommunityServiceTest
42      {
43      /***
44       * Our debug logger.
45       *
46       */
47      private static Log log = LogFactory.getLog(CommunityManagerTest.class);
48  
49      /***
50       * Public constructor.
51       *
52       */
53      public CommunityManagerTest()
54          {
55          }
56  
57      /***
58       * Our target CommunityManager.
59       *
60       */
61      private CommunityManager communityManager ;
62  
63      /***
64       * Get our target CommunityManager.
65       *
66       */
67      public CommunityManager getCommunityManager()
68          {
69          return this.communityManager ;
70          }
71  
72      /***
73       * Set our target CommunityManager.
74       *
75       */
76      public void setCommunityManager(CommunityManager manager)
77          {
78          log.debug("") ;
79          log.debug("----\"----") ;
80          log.debug("CommunityManagerTest.setCommunityManager()") ;
81          log.debug("  Manager : " + manager.getClass()) ;
82          //
83          // Set our CommunityManager reference.
84          this.communityManager = manager ;
85          //
86          // Set our CommunityService reference.
87          this.setCommunityService(manager) ;
88          }
89  
90      /***
91       * Try creating a null Community.
92       *
93       */
94      public void testCreateNull()
95          throws Exception
96          {
97          log.debug("") ;
98          log.debug("----\"----") ;
99          log.debug("CommunityManagerTest:testCreateNull()") ;
100         //
101         // Try creating a Community.
102         try {
103             communityManager.addCommunity(null) ;
104             fail("Expected CommunityIdentifierException") ;
105             }
106         catch (CommunityIdentifierException ouch)
107             {
108             log.debug("Caught expected Exception") ;
109             log.debug("Exception : " + ouch) ;
110             }
111         }
112 
113     /***
114      * Check we can create a valid Community.
115      *
116      */
117     public void testCreateValid()
118         throws Exception
119         {
120         log.debug("") ;
121         log.debug("----\"----") ;
122         log.debug("CommunityManagerTest:testCreateValid()") ;
123         //
124         // Try creating an Community.
125         assertNotNull("Null community",
126             communityManager.addCommunity("test-community")
127             ) ;
128         }
129 
130     /***
131      * Try to create a duplicate Community.
132      *
133      */
134     public void testCreateDuplicate()
135         throws Exception
136         {
137         log.debug("") ;
138         log.debug("----\"----") ;
139         log.debug("CommunityManagerTest:testCreateDuplicate()") ;
140         //
141         // Try creating an Community.
142         assertNotNull("Null community",
143             communityManager.addCommunity("test-community")
144             ) ;
145         //
146         // Try creating the same Community.
147         try {
148             communityManager.addCommunity("test-community") ;
149             fail("Expected CommunityPolicyException") ;
150             }
151         catch (CommunityPolicyException ouch)
152             {
153             log.debug("Caught expected Exception") ;
154             log.debug("Exception : " + ouch) ;
155             }
156         }
157 
158     /***
159      * Try getting a null Community.
160      *
161      */
162     public void testGetNull()
163         throws Exception
164         {
165         log.debug("") ;
166         log.debug("----\"----") ;
167         log.debug("CommunityManagerTest:testGetNull()") ;
168         //
169         // Try getting the details.
170         try {
171             communityManager.getCommunity(null) ;
172             fail("Expected CommunityIdentifierException") ;
173             }
174         catch (CommunityIdentifierException ouch)
175             {
176             log.debug("Caught expected Exception") ;
177             log.debug("Exception : " + ouch) ;
178             }
179         }
180 
181     /***
182      * Try getting an unknown Community.
183      *
184      */
185     public void testGetUnknown()
186         throws Exception
187         {
188         log.debug("") ;
189         log.debug("----\"----") ;
190         log.debug("CommunityManagerTest:testGetUnknown()") ;
191         //
192         // Try getting the details.
193         try {
194             communityManager.getCommunity("unknown-community") ;
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 valid Community.
206      *
207      */
208     public void testGetValid()
209         throws Exception
210         {
211         log.debug("") ;
212         log.debug("----\"----") ;
213         log.debug("CommunityManagerTest:testGetValid()") ;
214         log.debug("") ;
215         log.debug("----\"----") ;
216         log.debug("CommunityManagerTest:testCreateValid()") ;
217         //
218         // Try creating a Community.
219         CommunityData created = communityManager.addCommunity("test-community") ;
220         assertNotNull("Null community", created) ;
221         //
222         // Try getting the details.
223         CommunityData found = communityManager.getCommunity("test-community") ;
224         assertNotNull("Null community", found) ;
225         //
226         // Check that they refer to the same community.
227         assertEquals("Different identifiers", created, found) ;
228         }
229 
230     /***
231      * Try setting a null Community.
232      *
233      */
234     public void testSetNull()
235         throws Exception
236         {
237         log.debug("") ;
238         log.debug("----\"----") ;
239         log.debug("CommunityManagerTest:testSetNull()") ;
240         try {
241             communityManager.setCommunity(null) ;
242             fail("Expected CommunityIdentifierException") ;
243             }
244         catch (CommunityIdentifierException ouch)
245             {
246             log.debug("Caught expected Exception") ;
247             log.debug("Exception : " + ouch) ;
248             }
249         }
250 
251     /***
252      * Try setting an unknown Community.
253      *
254      */
255     public void testSetUnknown()
256         throws Exception
257         {
258         log.debug("") ;
259         log.debug("----\"----") ;
260         log.debug("CommunityManagerTest:testSetUnknown()") ;
261         //
262         // Try setting an unknown community.
263         try {
264             communityManager.setCommunity(
265                 new CommunityData("unknown-community")
266                 ) ;
267             fail("Expected CommunityPolicyException") ;
268             }
269         catch (CommunityPolicyException ouch)
270             {
271             log.debug("Caught expected Exception") ;
272             log.debug("Exception : " + ouch) ;
273             }
274         }
275 
276     /***
277      * Try setting a valid Community.
278      *
279      */
280     public void testSetValid()
281         throws Exception
282         {
283         log.debug("") ;
284         log.debug("----\"----") ;
285         log.debug("CommunityManagerTest:testSetValid()") ;
286         //
287         // Try creating an Community.
288         CommunityData community = communityManager.addCommunity("test-community") ;
289         assertNotNull("Null community", community) ;
290         //
291         // Change the details.
292         community.setDescription("Test Description") ;
293         //
294         // Try setting the details.
295         community = communityManager.setCommunity(community) ;
296         assertNotNull("Null community", community) ;
297         //
298         // Check the details have been changed.
299         assertEquals("Different details", "Test Description",  community.getDescription())  ;
300         //
301         // Try getting the details.
302         community = communityManager.getCommunity("test-community") ;
303         assertNotNull("Null community", community) ;
304         //
305         // Check the details have been changed.
306         assertEquals("Different details", community.getDescription(),  "Test Description")  ;
307         }
308 
309     /***
310      * Try deleting a null Community.
311      *
312      */
313     public void testDeleteNull()
314         throws Exception
315         {
316         log.debug("") ;
317         log.debug("----\"----") ;
318         log.debug("CommunityManagerTest:testDeleteNull()") ;
319         try {
320             communityManager.delCommunity(null) ;
321             fail("Expected CommunityIdentifierException") ;
322             }
323         catch (CommunityIdentifierException ouch)
324             {
325             log.debug("Caught expected Exception") ;
326             log.debug("Exception : " + ouch) ;
327             }
328         }
329 
330     /***
331      * Try deleting an unknown Community.
332      *
333      */
334     public void testDeleteUnknown()
335         throws Exception
336         {
337         log.debug("") ;
338         log.debug("----\"----") ;
339         log.debug("CommunityManagerTest:testDeleteUnknown()") ;
340         try {
341             communityManager.delCommunity("unknown-community") ;
342             fail("Expected CommunityPolicyException") ;
343             }
344         catch (CommunityPolicyException ouch)
345             {
346             log.debug("Caught expected Exception") ;
347             log.debug("Exception : " + ouch) ;
348             }
349         }
350 
351     /***
352      * Try deleting a valid Community.
353      *
354      */
355     public void testDeleteValid()
356         throws Exception
357         {
358         log.debug("") ;
359         log.debug("----\"----") ;
360         log.debug("CommunityManagerTest:testDeleteValid()") ;
361         //
362         // Try creating the Community.
363         CommunityData created = communityManager.addCommunity("test-community") ;
364         assertNotNull("Null community", created) ;
365         //
366         // Try deleting the Community.
367         CommunityData deleted = communityManager.delCommunity("test-community") ;
368         assertNotNull("Null community", deleted) ;
369         //
370         // Check that the two objects represent the same Community.
371         assertEquals("Different identifiers", created, deleted) ;
372         }
373 
374     /***
375      * Try deleting the same Community.
376      *
377      */
378     public void testDeleteTwice()
379         throws Exception
380         {
381         log.debug("") ;
382         log.debug("----\"----") ;
383         log.debug("CommunityManagerTest:testDeleteTwice()") ;
384         //
385         // Try creating the Community.
386         CommunityData created = communityManager.addCommunity("test-community") ;
387         assertNotNull("Null community", created) ;
388         //
389         // Try deleting the Community.
390         CommunityData deleted = communityManager.delCommunity("test-community") ;
391         assertNotNull("Null community", deleted) ;
392         //
393         // Check that the two objects represent the same Community.
394         assertEquals("Different identifiers", created, deleted) ;
395         //
396         // Try deleting the Community again.
397         try {
398             communityManager.delCommunity("test-community") ;
399             fail("Expected CommunityPolicyException") ;
400             }
401         catch (CommunityPolicyException ouch)
402             {
403             log.debug("Caught expected Exception") ;
404             log.debug("Exception : " + ouch) ;
405             }
406         }
407     }