]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
06cafd955460d001fd45fec97ce755499c5f001f
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.authorization.client.test;
24
25 //import java.util.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.Response;
28 //import org.collectionspace.services.authorization.ActionType;
29 import org.collectionspace.services.authorization.EffectType;
30
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.PermissionClient;
33 import org.collectionspace.services.authorization.Permission;
34 import org.collectionspace.services.authorization.PermissionAction;
35 import org.collectionspace.services.authorization.PermissionsList;
36 import org.collectionspace.services.client.PermissionFactory;
37 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
38 import org.collectionspace.services.client.test.ServiceRequestType;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.jboss.resteasy.client.ClientResponse;
41
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * PermissionServiceTest, carries out tests against a
50  * deployed and running Permission Service.
51  * 
52  * $LastChangedRevision: 917 $
53  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
54  */
55 public class PermissionServiceTest extends AbstractServiceTestImpl {
56
57     /** The Constant logger. */
58     static private final Logger logger =
59             LoggerFactory.getLogger(PermissionServiceTest.class);
60     // Instance variables specific to this test.
61     /** The known resource id. */
62     private String knownResourceId = null;
63     
64     /** The add tenant. */
65     boolean addTenant = true;
66     /*
67      * This method is called only by the parent class, AbstractServiceTestImpl
68      */
69
70     /* (non-Javadoc)
71      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
72      */
73     @Override
74     protected String getServicePathComponent() {
75         return new PermissionClient().getServicePathComponent();
76     }
77
78     /* (non-Javadoc)
79      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
80      */
81     @Override
82     protected CollectionSpaceClient getClientInstance() {
83         return new PermissionClient();
84     }
85     
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
88      */
89     @Override
90         protected AbstractCommonList getAbstractCommonList(
91                         ClientResponse<AbstractCommonList> response) {
92         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
93         throw new UnsupportedOperationException();
94     }
95     
96         /* (non-Javadoc)
97          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
98          */
99         @Test(dataProvider = "testName")
100         @Override
101     public void readPaginatedList(String testName) throws Exception {
102                 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
103         }    
104
105         // ---------------------------------------------------------------
106     // CRUD tests : CREATE tests
107     // ---------------------------------------------------------------
108     // Success outcomes
109     /* (non-Javadoc)
110          * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
111          */
112         @Override
113     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
114     public void create(String testName) throws Exception {
115
116         // Perform setup, such as initializing the type of service request
117         // (e.g. CREATE, DELETE), its valid and expected status codes, and
118         // its associated HTTP method name (e.g. POST, DELETE).
119         setupCreate(testName);
120
121         // Submit the request to the service and store the response.
122         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
123         Permission permission = createPermissionInstance("accounts",
124                 "default permissions for account",
125                 actions,
126                 EffectType.PERMIT,
127                 true,
128                 true,
129                 true);
130         PermissionClient client = new PermissionClient();
131         ClientResponse<Response> res = client.create(permission);
132         int statusCode = res.getStatus();
133
134         // Check the status code of the response: does it match
135         // the expected response(s)?
136         //
137         // Specifically:
138         // Does it fall within the set of valid status codes?
139         // Does it exactly match the expected status code?
140         if (logger.isDebugEnabled()) {
141             logger.debug(testName + ": status = " + statusCode);
142         }
143         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
144                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
145         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
146
147         // Store the ID returned from this create operation
148         // for additional tests below.
149         knownResourceId = extractId(res);
150         if (logger.isDebugEnabled()) {
151             logger.debug(testName + ": knownResourceId=" + knownResourceId);
152         }
153     }
154
155     /**
156      * Creates the without resource name.
157      *
158      * @param testName the test name
159      * @throws Exception the exception
160      */
161     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
162     dependsOnMethods = {"create"})
163     public void createWithoutResourceName(String testName) throws Exception {
164
165         setupCreate(testName);
166
167         // Submit the request to the service and store the response.
168         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
169         Permission permission = createPermissionInstance(null,
170                 "default permissions for account",
171                 actions,
172                 EffectType.PERMIT,
173                 false,
174                 true,
175                 true);
176         PermissionClient client = new PermissionClient();
177         ClientResponse<Response> res = client.create(permission);
178         int statusCode = res.getStatus();
179         // Does it exactly match the expected status code?
180         if (logger.isDebugEnabled()) {
181             logger.debug(testName + ": status = " + statusCode);
182         }
183         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
184                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
185         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
186     }
187
188     //to not cause uniqueness violation for permission, createList is removed
189     /* (non-Javadoc)
190      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
191      */
192     @Override
193     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
194     dependsOnMethods = {"create"})
195     public void createList(String testName) throws Exception {
196
197         setupCreate(testName);
198         // Submit the request to the service and store the response.
199         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
200         Permission permission1 = createPermissionInstance("collectionobjects",
201                 "default permissions for collectionobjects",
202                 actions,
203                 EffectType.PERMIT,
204                 true,
205                 true,
206                 true);
207         PermissionClient client = new PermissionClient();
208         ClientResponse<Response> res = client.create(permission1);
209         int statusCode = res.getStatus();
210         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
211                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
212         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
213         allResourceIdsCreated.add(extractId(res));
214
215         Permission permission2 = createPermissionInstance("acquisitions",
216                 "default permissions for acquisitions",
217                 actions,
218                 EffectType.PERMIT,
219                 true,
220                 true,
221                 true);
222         res = client.create(permission2);
223         statusCode = res.getStatus();
224         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
225                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
226         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
227         allResourceIdsCreated.add(extractId(res));
228
229         Permission permission3 = createPermissionInstance("ids",
230                 "default permissions for id service",
231                 actions,
232                 EffectType.PERMIT,
233                 true,
234                 true,
235                 true);
236         res = client.create(permission3);
237         statusCode = res.getStatus();
238         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
239                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
240         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
241         allResourceIdsCreated.add(extractId(res));
242     }
243
244     // Failure outcomes
245     // Placeholders until the three tests below can be uncommented.
246     // See Issue CSPACE-401.
247     /* (non-Javadoc)
248      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
249      */
250     @Override
251     public void createWithEmptyEntityBody(String testName) throws Exception {
252         //FIXME: Should this test really be empty?  If so, please comment accordingly.
253     }
254
255     /* (non-Javadoc)
256      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
257      */
258     @Override
259     public void createWithMalformedXml(String testName) throws Exception {
260         //FIXME: Should this test really be empty?  If so, please comment accordingly.
261     }
262
263     /* (non-Javadoc)
264      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
265      */
266     @Override
267     public void createWithWrongXmlSchema(String testName) throws Exception {
268         //FIXME: Should this test really be empty?  If so, please comment accordingly.
269     }
270
271     // ---------------------------------------------------------------
272     // CRUD tests : READ tests
273     // ---------------------------------------------------------------
274     // Success outcomes
275     /* (non-Javadoc)
276      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
277      */
278     @Override
279     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
280     dependsOnMethods = {"create"})
281     public void read(String testName) throws Exception {
282
283         // Perform setup.
284         setupRead(testName);
285
286         // Submit the request to the service and store the response.
287         PermissionClient client = new PermissionClient();
288         ClientResponse<Permission> res = client.read(knownResourceId);
289         int statusCode = res.getStatus();
290
291         // Check the status code of the response: does it match
292         // the expected response(s)?
293         if (logger.isDebugEnabled()) {
294             logger.debug(testName + ": status = " + statusCode);
295         }
296         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
297                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
298         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
299
300         Permission output = (Permission) res.getEntity();
301         Assert.assertNotNull(output);
302     }
303
304     // Failure outcomes
305     /* (non-Javadoc)
306      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
307      */
308     @Override
309     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
310     dependsOnMethods = {"read"})
311     public void readNonExistent(String testName) throws Exception {
312
313         // Perform setup.
314         setupReadNonExistent(testName);
315
316         // Submit the request to the service and store the response.
317         PermissionClient client = new PermissionClient();
318         ClientResponse<Permission> res = client.read(NON_EXISTENT_ID);
319         int statusCode = res.getStatus();
320
321         // Check the status code of the response: does it match
322         // the expected response(s)?
323         if (logger.isDebugEnabled()) {
324             logger.debug(testName + ": status = " + statusCode);
325         }
326         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
327                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
328         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
329     }
330
331     // ---------------------------------------------------------------
332     // CRUD tests : READ_LIST tests
333     // ---------------------------------------------------------------
334     // Success outcomes
335     /* (non-Javadoc)
336      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
337      */
338     @Override
339     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
340     dependsOnMethods = {"createList", "read"})
341     public void readList(String testName) throws Exception {
342
343         // Perform setup.
344         setupReadList(testName);
345
346         // Submit the request to the service and store the response.
347         PermissionClient client = new PermissionClient();
348         ClientResponse<PermissionsList> res = client.readList();
349         PermissionsList list = res.getEntity();
350         int statusCode = res.getStatus();
351
352         // Check the status code of the response: does it match
353         // the expected response(s)?
354         if (logger.isDebugEnabled()) {
355             logger.debug(testName + ": status = " + statusCode);
356         }
357         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
358                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
359         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
360
361         // Optionally output additional data about list members for debugging.
362         boolean iterateThroughList = true;
363         if (iterateThroughList && logger.isDebugEnabled()) {
364             printList(testName, list);
365         }
366     }
367
368     /**
369      * Search resource name.
370      *
371      * @param testName the test name
372      * @throws Exception the exception
373      */
374     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
375     dependsOnMethods = {"createList", "read"})
376     public void searchResourceName(String testName) throws Exception {
377
378         // Perform setup.
379         setupReadList(testName);
380
381         // Submit the request to the service and store the response.
382         PermissionClient client = new PermissionClient();
383         ClientResponse<PermissionsList> res = client.readSearchList("acquisition");
384         PermissionsList list = res.getEntity();
385         int statusCode = res.getStatus();
386         // Check the status code of the response: does it match
387         // the expected response(s)?
388         if (logger.isDebugEnabled()) {
389             logger.debug(testName + ": status = " + statusCode);
390         }
391         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
392                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
393         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
394         int EXPECTED_ITEMS = 1;
395         if (logger.isDebugEnabled()) {
396             logger.debug(testName + ": received = " + list.getPermissions().size()
397                     + " expected=" + EXPECTED_ITEMS);
398         }
399         Assert.assertEquals(EXPECTED_ITEMS, list.getPermissions().size());
400         // Optionally output additional data about list members for debugging.
401         boolean iterateThroughList = true;
402         if (iterateThroughList && logger.isDebugEnabled()) {
403             printList(testName, list);
404         }
405     }
406
407     // Failure outcomes
408     // None at present.
409     // ---------------------------------------------------------------
410     // CRUD tests : UPDATE tests
411     // ---------------------------------------------------------------
412     // Success outcomes
413     /* (non-Javadoc)
414      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
415      */
416     @Override
417     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
418     dependsOnMethods = {"read", "readList", "readNonExistent"})
419     public void update(String testName) throws Exception {
420
421         // Perform setup.
422         setupUpdate(testName);
423
424         Permission permToUpdate = new Permission();
425         permToUpdate.setCsid(knownResourceId);
426         // Update the content of this resource.
427         permToUpdate.setResourceName("updated-resource");
428         if (logger.isDebugEnabled()) {
429             logger.debug("updated object");
430             logger.debug(objectAsXmlString(permToUpdate,
431                     Permission.class));
432         }
433         PermissionClient client = new PermissionClient();
434         // Submit the request to the service and store the response.
435         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
436         int statusCode = res.getStatus();
437         // Check the status code of the response: does it match the expected response(s)?
438         if (logger.isDebugEnabled()) {
439             logger.debug(testName + ": status = " + statusCode);
440         }
441         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
442                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
443         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
444
445
446         Permission permUpdated = (Permission) res.getEntity();
447         Assert.assertNotNull(permUpdated);
448
449         Assert.assertEquals(permUpdated.getResourceName(),
450                 permToUpdate.getResourceName(),
451                 "Data in updated object did not match submitted data.");
452     }
453
454     /**
455      * Update actions.
456      *
457      * @param testName the test name
458      * @throws Exception the exception
459      */
460     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
461     dependsOnMethods = {"update"})
462     public void updateActions(String testName) throws Exception {
463
464         // Perform setup.
465         setupUpdate(testName);
466
467         Permission permToUpdate = new Permission();
468         permToUpdate.setCsid(knownResourceId);
469         // Update the content of this resource.
470         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
471         int default_actions = actions.size();
472         actions.remove(0);
473         actions.remove(0);
474         int toUpdate_actions = actions.size();
475         if (logger.isDebugEnabled()) {
476             logger.debug(testName + " no. of actions default=" + default_actions
477                     + " to update =" + toUpdate_actions);
478         }
479         permToUpdate.setActions(actions);
480         if (logger.isDebugEnabled()) {
481             logger.debug(testName + " updated object\n"
482                     + objectAsXmlString(permToUpdate, Permission.class));
483         }
484         PermissionClient client = new PermissionClient();
485         // Submit the request to the service and store the response.
486         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
487         int statusCode = res.getStatus();
488         // Check the status code of the response: does it match the expected response(s)?
489         if (logger.isDebugEnabled()) {
490             logger.debug(testName + ": status = " + statusCode);
491         }
492         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
493                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
494         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
495
496         Permission permUpdated = (Permission) res.getEntity();
497         Assert.assertNotNull(permUpdated);
498         int updated_actions = permToUpdate.getActions().size();
499         if (logger.isDebugEnabled()) {
500             logger.debug(testName + " no. of actions to update=" + toUpdate_actions
501                     + " updated =" + updated_actions);
502         }
503         Assert.assertEquals(toUpdate_actions,
504                 updated_actions,
505                 "Data in updated object did not match submitted data.");
506     }
507     // Failure outcomes
508     // Placeholders until the three tests below can be uncommented.
509     // See Issue CSPACE-401.
510
511     /* (non-Javadoc)
512      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
513      */
514     @Override
515     public void updateWithEmptyEntityBody(String testName) throws Exception {
516         //FIXME: Should this test really be empty?  If so, please comment accordingly.
517     }
518
519     /* (non-Javadoc)
520      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
521      */
522     @Override
523     public void updateWithMalformedXml(String testName) throws Exception {
524         //FIXME: Should this test really be empty?  If so, please comment accordingly.
525     }
526
527     /* (non-Javadoc)
528      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
529      */
530     @Override
531     public void updateWithWrongXmlSchema(String testName) throws Exception {
532         //FIXME: Should this test really be empty?  If so, please comment accordingly.
533     }
534
535     /* (non-Javadoc)
536      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
537      */
538     @Override
539     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
540     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
541     public void updateNonExistent(String testName) throws Exception {
542
543         // Perform setup.
544         setupUpdateNonExistent(testName);
545
546         // Submit the request to the service and store the response.
547         //
548         // Note: The ID used in this 'create' call may be arbitrary.
549         // The only relevant ID may be the one used in updatePermission(), below.
550         PermissionClient client = new PermissionClient();
551         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
552         Permission permission = createPermissionInstance("acquisitions",
553                 "default permissions for acquisitions",
554                 actions,
555                 EffectType.PERMIT,
556                 true,
557                 true,
558                 true);
559         ClientResponse<Permission> res =
560                 client.update(NON_EXISTENT_ID, permission);
561         int statusCode = res.getStatus();
562
563         // Check the status code of the response: does it match
564         // the expected response(s)?
565         if (logger.isDebugEnabled()) {
566             logger.debug(testName + ": status = " + statusCode);
567         }
568         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
569                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
570         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
571     }
572
573     // ---------------------------------------------------------------
574     // CRUD tests : DELETE tests
575     // ---------------------------------------------------------------
576     // Success outcomes
577     /* (non-Javadoc)
578      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
579      */
580     @Override
581     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
582     dependsOnMethods = {"updateActions"})
583     public void delete(String testName) throws Exception {
584
585         // Perform setup.
586         setupDelete(testName);
587
588         // Submit the request to the service and store the response.
589         PermissionClient client = new PermissionClient();
590         ClientResponse<Response> res = client.delete(knownResourceId);
591         int statusCode = res.getStatus();
592
593         // Check the status code of the response: does it match
594         // the expected response(s)?
595         if (logger.isDebugEnabled()) {
596             logger.debug(testName + ": status = " + statusCode);
597         }
598         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
599                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
600         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601     }
602
603     // Failure outcomes
604     /* (non-Javadoc)
605      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
606      */
607     @Override
608     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
609     dependsOnMethods = {"delete"})
610     public void deleteNonExistent(String testName) throws Exception {
611
612         // Perform setup.
613         setupDeleteNonExistent(testName);
614
615         // Submit the request to the service and store the response.
616         PermissionClient client = new PermissionClient();
617         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
618         int statusCode = res.getStatus();
619
620         // Check the status code of the response: does it match
621         // the expected response(s)?
622         if (logger.isDebugEnabled()) {
623             logger.debug(testName + ": status = " + statusCode);
624         }
625         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
626                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
627         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628     }
629
630     // ---------------------------------------------------------------
631     // Utility tests : tests of code used in tests above
632     // ---------------------------------------------------------------
633     /**
634      * Tests the code for manually submitting data that is used by several
635      * of the methods above.
636      * @throws Exception 
637      */
638     @Test(dependsOnMethods = {"create", "read"})
639     public void testSubmitRequest() throws Exception {
640
641         // Expected status code: 200 OK
642         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
643
644         // Submit the request to the service and store the response.
645         String method = ServiceRequestType.READ.httpMethodName();
646         String url = getResourceURL(knownResourceId);
647         int statusCode = submitRequest(method, url);
648
649         // Check the status code of the response: does it match
650         // the expected response(s)?
651         if (logger.isDebugEnabled()) {
652             logger.debug("testSubmitRequest: url=" + url
653                     + " status=" + statusCode);
654         }
655         Assert.assertEquals(statusCode, EXPECTED_STATUS);
656
657     }
658
659     // ---------------------------------------------------------------
660     // Utility methods used by tests above
661     // ---------------------------------------------------------------
662     /**
663      * create permission instance
664      * @param resourceName
665      * @param description
666      * @param actionList list of actions for this permission
667      * @param effect effect of the permission
668      * @param useResourceName
669      * @param useAction
670      * @param useEffect
671      * @return permission
672      */
673     public static Permission createPermissionInstance(String resourceName,
674             String description,
675             List<PermissionAction> actionList,
676             EffectType effect,
677             boolean useResourceName,
678             boolean useAction,
679             boolean useEffect) {
680
681         Permission permission = PermissionFactory.createPermissionInstance(resourceName,
682                 description, actionList, effect,
683                 useResourceName, useAction, useEffect);
684
685         if (logger.isDebugEnabled()) {
686             logger.debug("to be created, permission");
687             logger.debug(objectAsXmlString(permission, Permission.class));
688         }
689         return permission;
690     }
691
692     /**
693      * Prints the list.
694      *
695      * @param testName the test name
696      * @param list the list
697      * @return the int
698      */
699     private int printList(String testName, PermissionsList list) {
700
701         int i = 0;
702
703         for (Permission permission : list.getPermissions()) {
704             logger.debug(testName + " permission csid=" + permission.getCsid()
705                     + " name=" + permission.getResourceName()
706                     + " desc=" + permission.getDescription());
707             i++;
708         }
709         return i;
710     }
711 }