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
29
30
31
32
33
34
35
36
37
38
39
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
98 this.resourceManager = manager ;
99
100
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
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
134 ResourceData created = this.resourceManager.addResource() ;
135 assertNotNull(
136 "Null resource",
137 created
138 ) ;
139
140
141 String ident = created.getIdent() ;
142 assertNotNull(
143 "Null resource ident",
144 ident
145 ) ;
146
147
148 ResourceData found = this.resourceManager.getResource(ident) ;
149 assertNotNull(
150 "Null resource",
151 found
152 ) ;
153
154
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
174 ResourceData created = this.resourceManager.addResource() ;
175 assertNotNull(
176 "Null resource",
177 created
178 ) ;
179
180
181 String ident = created.getIdent() ;
182 assertNotNull(
183 "Null resource ident",
184 ident
185 ) ;
186
187
188 ResourceData found = this.resourceManager.getResource(ident) ;
189 assertNotNull(
190 "Null resource",
191 found
192 ) ;
193
194
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
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
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
264 ResourceData created = this.resourceManager.addResource() ;
265 assertNotNull(
266 "Null resource",
267 created
268 ) ;
269
270
271 String ident = created.getIdent() ;
272 assertNotNull(
273 "Null resource ident",
274 ident
275 ) ;
276
277
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
287 assertEquals("Descriptions don't match",
288 description,
289 modified.getDescription()
290 ) ;
291
292
293 ResourceData found = this.resourceManager.getResource(ident) ;
294 assertNotNull(
295 "Null resource",
296 found
297 ) ;
298
299
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
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
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
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
395 ResourceData created = this.resourceManager.addResource() ;
396 assertNotNull(
397 "Null resource",
398 created
399 ) ;
400
401
402 String ident = created.getIdent() ;
403 assertNotNull(
404 "Null resource ident",
405 ident
406 ) ;
407
408
409 ResourceData found = this.resourceManager.getResource(ident) ;
410 assertNotNull(
411 "Null resource",
412 found
413 ) ;
414
415
416 ResourceData deleted = this.resourceManager.delResource(ident) ;
417 assertNotNull(
418 "Null resource",
419 deleted
420 ) ;
421
422
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
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
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 }