1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
84 this.communityManager = manager ;
85
86
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
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
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
142 assertNotNull("Null community",
143 communityManager.addCommunity("test-community")
144 ) ;
145
146
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
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
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
219 CommunityData created = communityManager.addCommunity("test-community") ;
220 assertNotNull("Null community", created) ;
221
222
223 CommunityData found = communityManager.getCommunity("test-community") ;
224 assertNotNull("Null community", found) ;
225
226
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
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
288 CommunityData community = communityManager.addCommunity("test-community") ;
289 assertNotNull("Null community", community) ;
290
291
292 community.setDescription("Test Description") ;
293
294
295 community = communityManager.setCommunity(community) ;
296 assertNotNull("Null community", community) ;
297
298
299 assertEquals("Different details", "Test Description", community.getDescription()) ;
300
301
302 community = communityManager.getCommunity("test-community") ;
303 assertNotNull("Null community", community) ;
304
305
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
363 CommunityData created = communityManager.addCommunity("test-community") ;
364 assertNotNull("Null community", created) ;
365
366
367 CommunityData deleted = communityManager.delCommunity("test-community") ;
368 assertNotNull("Null community", deleted) ;
369
370
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
386 CommunityData created = communityManager.addCommunity("test-community") ;
387 assertNotNull("Null community", created) ;
388
389
390 CommunityData deleted = communityManager.delCommunity("test-community") ;
391 assertNotNull("Null community", deleted) ;
392
393
394 assertEquals("Different identifiers", created, deleted) ;
395
396
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 }