]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0f498b46d42a02717672edecfb0c5feabd6f5c02
[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 permRoles 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.Collection;
27 import java.util.Hashtable;
28 import java.util.List;
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.jaxb.AbstractCommonList;
32 import org.collectionspace.services.authorization.EffectType;
33 import org.collectionspace.services.authorization.Permission;
34 import org.collectionspace.services.authorization.PermissionAction;
35 import org.collectionspace.services.authorization.PermissionRole;
36 import org.collectionspace.services.authorization.PermissionValue;
37 import org.collectionspace.services.authorization.Role;
38 import org.collectionspace.services.authorization.RoleValue;
39
40 import org.collectionspace.services.client.CollectionSpaceClient;
41 import org.collectionspace.services.client.PermissionClient;
42 import org.collectionspace.services.client.PermissionFactory;
43 import org.collectionspace.services.client.PermissionRoleClient;
44 import org.collectionspace.services.client.PermissionRoleFactory;
45 import org.collectionspace.services.client.RoleClient;
46 import org.collectionspace.services.client.RoleFactory;
47
48 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
49 import org.collectionspace.services.client.test.ServiceRequestType;
50
51 import org.jboss.resteasy.client.ClientResponse;
52
53 import org.testng.Assert;
54 import org.testng.annotations.Test;
55
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.testng.annotations.AfterClass;
59 import org.testng.annotations.BeforeClass;
60
61 /**
62  * PermissionServiceTest, carries out tests against a
63  * deployed and running Permission, Role and PermissionRole Services.
64  * 
65  * $LastChangedRevision: 917 $
66  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
67  */
68 public class PermissionRoleServiceTest extends AbstractServiceTestImpl {
69
70     /** The Constant logger. */
71     private final static String CLASS_NAME = PermissionRoleServiceTest.class.getName();
72     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
73     // Instance variables specific to this test.
74     /** The known resource id. */
75     private String knownResourceId = null;
76     /** The all resource ids created. */
77     private List<String> allResourceIdsCreated = new ArrayList<String>();
78     final private static String TEST_MARKER = "_PermissionRoleServiceTest";
79     final private static String TEST_SERVICE_NAME = "fakeservice";
80     final private static String NO_REL_SUFFIX = "-no-rel";
81     /** The perm values. */
82     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
83     /** The role values. */
84     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
85     /*
86      * This method is called only by the parent class, AbstractServiceTestImpl
87      */
88
89     /* (non-Javadoc)
90      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
91      */
92     @Override
93     protected String getServicePathComponent() {
94         return new PermissionRoleClient().getServicePathComponent();
95     }
96
97     /**
98      * Seed data.
99      */
100     @BeforeClass(alwaysRun = true)
101     public void seedData() {
102         String ra = TEST_SERVICE_NAME + TEST_MARKER;
103         String accPermId = createPermission(ra, EffectType.PERMIT);
104         PermissionValue pva = new PermissionValue();
105         pva.setResourceName(ra);
106         pva.setPermissionId(accPermId);
107         permValues.put(pva.getResourceName(), pva);
108
109         String rc = TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX;
110         String coPermId = createPermission(rc, EffectType.DENY);
111         PermissionValue pvc = new PermissionValue();
112         pvc.setResourceName(rc);
113         pvc.setPermissionId(coPermId);
114         permValues.put(pvc.getResourceName(), pvc);
115 //
116 //        String ri = "intakes";
117 //        String iPermId = createPermission(ri, EffectType.DENY);
118 //        PermissionValue pvi = new PermissionValue();
119 //        pvi.setResourceName(ri);
120 //        pvi.setPermissionId(iPermId);
121 //        permValues.put(pvi.getResourceName(), pvi);
122
123         String rn1 = "ROLE_CO1" + TEST_MARKER;
124         String r1RoleId = createRole(rn1);
125         RoleValue rv1 = new RoleValue();
126         rv1.setRoleId(r1RoleId);
127         rv1.setRoleName(rn1);
128         roleValues.put(rv1.getRoleName(), rv1);
129
130         String rn2 = "ROLE_CO2" + TEST_MARKER;
131         String r2RoleId = createRole(rn2);
132         RoleValue rv2 = new RoleValue();
133         rv2.setRoleId(r2RoleId);
134         rv2.setRoleName(rn2);
135         roleValues.put(rv2.getRoleName(), rv2);
136     }
137
138     /* (non-Javadoc)
139      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
140      */
141     @Override
142     protected CollectionSpaceClient getClientInstance() {
143         return new PermissionRoleClient();
144     }
145
146     /* (non-Javadoc)
147      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
148      */
149     @Override
150     protected AbstractCommonList getAbstractCommonList(
151             ClientResponse<AbstractCommonList> response) {
152         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
153         throw new UnsupportedOperationException();
154     }
155
156     /* (non-Javadoc)
157      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
158      */
159     @Test(dataProvider = "testName")
160     @Override
161     public void readPaginatedList(String testName) throws Exception {
162         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
163     }
164     // ---------------------------------------------------------------
165     // CRUD tests : CREATE tests
166     // ---------------------------------------------------------------
167     // Success outcomes
168     /* (non-Javadoc)
169      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
170      */
171
172     @Override
173     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
174     public void create(String testName) throws Exception {
175
176         if (logger.isDebugEnabled()) {
177             logger.debug(testBanner(testName, CLASS_NAME));
178         }
179
180         // Perform setup, such as initializing the type of service request
181         // (e.g. CREATE, DELETE), its valid and expected status codes, and
182         // its associated HTTP method name (e.g. POST, DELETE).
183         setupCreate();
184
185         // Submit the request to the service and store the response.
186         PermissionValue pv = permValues.get(TEST_SERVICE_NAME + TEST_MARKER);
187         PermissionRole permRole = createPermissionRoleInstance(pv,
188                 roleValues.values(), true, true);
189         PermissionRoleClient client = new PermissionRoleClient();
190         ClientResponse<Response> res = null;
191         try {
192             res = client.create(pv.getPermissionId(), permRole);
193             int statusCode = res.getStatus();
194
195             if (logger.isDebugEnabled()) {
196                 logger.debug(testName + ": status = " + statusCode);
197             }
198             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
199                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
200             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
201             res.releaseConnection();
202             // Store the ID returned from this create operation
203             // for additional tests below.
204             //this is is not important in case of this relationship
205             knownResourceId = extractId(res);
206             if (logger.isDebugEnabled()) {
207                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
208             }
209         } finally {
210             if (res != null) {
211                 res.releaseConnection();
212             }
213         }
214     }
215
216     //to not cause uniqueness violation for permRole, createList is removed
217     /* (non-Javadoc)
218      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
219      */
220     @Override
221     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
222     dependsOnMethods = {"create"})
223     public void createList(String testName) throws Exception {
224         //Should this really be empty?
225     }
226
227     // Failure outcomes
228     // Placeholders until the three tests below can be uncommented.
229     // See Issue CSPACE-401.
230     /* (non-Javadoc)
231      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
232      */
233     @Override
234     public void createWithEmptyEntityBody(String testName) throws Exception {
235         //Should this really be empty?
236     }
237
238     /* (non-Javadoc)
239      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
240      */
241     @Override
242     public void createWithMalformedXml(String testName) throws Exception {
243         //Should this really be empty?
244     }
245
246     /* (non-Javadoc)
247      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
248      */
249     @Override
250     public void createWithWrongXmlSchema(String testName) throws Exception {
251         //Should this really be empty?
252     }
253
254     // ---------------------------------------------------------------
255     // CRUD tests : READ tests
256     // ---------------------------------------------------------------
257     // Success outcomes
258     /* (non-Javadoc)
259      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
260      */
261     @Override
262     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
263     dependsOnMethods = {"create"})
264     public void read(String testName) throws Exception {
265
266         if (logger.isDebugEnabled()) {
267             logger.debug(testBanner(testName, CLASS_NAME));
268         }
269         // Perform setup.
270         setupRead();
271
272         // Submit the request to the service and store the response.
273         PermissionRoleClient client = new PermissionRoleClient();
274         ClientResponse<PermissionRole> res = null;
275         try {
276             res = client.read(
277                     permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
278             int statusCode = res.getStatus();
279
280             // Check the status code of the response: does it match
281             // the expected response(s)?
282             if (logger.isDebugEnabled()) {
283                 logger.debug(testName + ": status = " + statusCode);
284             }
285             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
286                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
287             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
288
289             PermissionRole output = (PermissionRole) res.getEntity();
290             Assert.assertNotNull(output);
291         } finally {
292             if (res != null) {
293                 res.releaseConnection();
294             }
295         }
296
297     }
298
299     // Failure outcomes
300     /* (non-Javadoc)
301      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
302      */
303     @Override
304     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
305     public void readNonExistent(String testName) throws Exception {
306
307         if (logger.isDebugEnabled()) {
308             logger.debug(testBanner(testName, CLASS_NAME));
309         }
310         // Perform setup.
311         setupReadNonExistent();
312
313         // Submit the request to the service and store the response.
314         PermissionRoleClient client = new PermissionRoleClient();
315         ClientResponse<PermissionRole> res = null;
316         try {
317             res = client.read(NON_EXISTENT_ID);
318             int statusCode = res.getStatus();
319
320             // Check the status code of the response: does it match
321             // the expected response(s)?
322             if (logger.isDebugEnabled()) {
323                 logger.debug(testName + ": status = " + statusCode);
324             }
325             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328         } finally {
329             if (res != null) {
330                 res.releaseConnection();
331             }
332         }
333     }
334
335     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
336     dependsOnMethods = {"create"})
337     public void readNoRelationship(String testName) throws Exception {
338
339         if (logger.isDebugEnabled()) {
340             logger.debug(testBanner(testName, CLASS_NAME));
341         }
342         // Perform setup.
343         setupRead();
344
345         // Submit the request to the service and store the response.
346         PermissionRoleClient client = new PermissionRoleClient();
347         ClientResponse<PermissionRole> res = null;
348         try {
349             res = client.read(
350                     permValues.get(TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX).getPermissionId());
351             int statusCode = res.getStatus();
352
353             // Check the status code of the response: does it match
354             // the expected response(s)?
355             if (logger.isDebugEnabled()) {
356                 logger.debug(testName + ": status = " + statusCode);
357             }
358             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
359                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
360             Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
361
362             PermissionRole output = (PermissionRole) res.getEntity();
363
364             String sOutput = objectAsXmlString(output, PermissionRole.class);
365             if (logger.isDebugEnabled()) {
366                 logger.debug(testName + " received " + sOutput);
367             }
368         } finally {
369             if (res != null) {
370                 res.releaseConnection();
371             }
372         }
373
374     }
375     // ---------------------------------------------------------------
376     // CRUD tests : READ_LIST tests
377     // ---------------------------------------------------------------
378     // Success outcomes
379     /* (non-Javadoc)
380      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
381      */
382
383     @Override
384     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385     dependsOnMethods = {"createList", "read"})
386     public void readList(String testName) throws Exception {
387         //Should this really be empty?
388     }
389
390     // Failure outcomes
391     // None at present.
392     // ---------------------------------------------------------------
393     // CRUD tests : UPDATE tests
394     // ---------------------------------------------------------------
395     // Success outcomes
396     /* (non-Javadoc)
397      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
398      */
399     @Override
400     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
401     dependsOnMethods = {"read", "readList", "readNonExistent"})
402     public void update(String testName) throws Exception {
403         //Should this really be empty?
404     }
405
406     // Failure outcomes
407     // Placeholders until the three tests below can be uncommented.
408     // See Issue CSPACE-401.
409     /* (non-Javadoc)
410      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
411      */
412     @Override
413     public void updateWithEmptyEntityBody(String testName) throws Exception {
414         //Should this really be empty?
415     }
416
417     /* (non-Javadoc)
418      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
419      */
420     @Override
421     public void updateWithMalformedXml(String testName) throws Exception {
422         //Should this really be empty?
423     }
424
425     /* (non-Javadoc)
426      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
427      */
428     @Override
429     public void updateWithWrongXmlSchema(String testName) throws Exception {
430         //Should this really be empty?
431     }
432
433     /* (non-Javadoc)
434      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
435      */
436     @Override
437     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
438     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
439     public void updateNonExistent(String testName) throws Exception {
440         //Should this really be empty?
441     }
442
443     // ---------------------------------------------------------------
444     // CRUD tests : DELETE tests
445     // ---------------------------------------------------------------
446     // Success outcomes
447     /* (non-Javadoc)
448      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
449      */
450     @Override
451     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
452     dependsOnMethods = {"read"})
453     public void delete(String testName) throws Exception {
454
455         if (logger.isDebugEnabled()) {
456             logger.debug(testBanner(testName, CLASS_NAME));
457         }
458         // Perform setup.
459         setupDelete();
460
461         //
462         //
463         //
464         PermissionRoleClient client = new PermissionRoleClient();
465         ClientResponse<PermissionRole> readResponse = client.read(
466                         permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
467         PermissionRole toDelete = null;
468         try {
469                 toDelete = readResponse.getEntity();
470         } finally {
471                 readResponse.releaseConnection();
472         }        
473
474         ClientResponse<Response> res = client.delete(
475                         toDelete.getPermissions().get(0).getPermissionId(), toDelete);
476         try {
477             int statusCode = res.getStatus();
478             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
479                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
480             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
481         } finally {
482             if (res != null) {
483                 res.releaseConnection();
484             }
485         }
486         
487         //
488         // recreate 'TEST_SERVICE_NAME + TEST_MARKER' account and roles
489         //
490         create(testName);
491         setupDelete();
492      
493         //
494         // Lookup a know permission, and delete all of its role relationships
495         //
496         readResponse = client.read(
497                         permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
498         toDelete = null;
499         try {
500                 toDelete = readResponse.getEntity();
501         } finally {
502                 readResponse.releaseConnection();
503         }
504
505         res = client.delete(toDelete.getPermissions().get(0).getPermissionId());
506         try {
507             int statusCode = res.getStatus();
508             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
509                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
510             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
511         } finally {
512             res.releaseConnection();
513         }
514         
515     }
516
517     // Failure outcomes
518     /* (non-Javadoc)
519      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
520      */
521     @Override
522     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
523     public void deleteNonExistent(String testName) throws Exception {
524         //ignoring this test as the service side returns 200 now even if it does
525         //not find a record in the db
526     }
527
528     // ---------------------------------------------------------------
529     // Utility tests : tests of code used in tests above
530     // ---------------------------------------------------------------
531     /**
532      * Tests the code for manually submitting data that is used by several
533      * of the methods above.
534      * @throws Exception 
535      */
536     @Test(dependsOnMethods = {"create"})
537     public void testSubmitRequest() throws Exception {
538
539         // Expected status code: 200 OK
540         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
541
542         // Submit the request to the service and store the response.
543         String method = ServiceRequestType.READ.httpMethodName();
544         String url = getResourceURL(permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
545         int statusCode = submitRequest(method, url);
546
547         // Check the status code of the response: does it match
548         // the expected response(s)?
549         if (logger.isDebugEnabled()) {
550             logger.debug("testSubmitRequest: url=" + url
551                     + " status=" + statusCode);
552         }
553         Assert.assertEquals(statusCode, EXPECTED_STATUS);
554
555
556     }
557
558     // ---------------------------------------------------------------
559     // Utility methods used by tests above
560     // ---------------------------------------------------------------
561     /**
562      * create permRolerole instance
563      * @param pv permissionvalue
564      * @param rvs rolevalue array
565      * @param usePermId 
566      * @param useRoleId
567      * @return PermissionRole
568      */
569     public static PermissionRole createPermissionRoleInstance(PermissionValue pv,
570             Collection<RoleValue> rvs,
571             boolean usePermId,
572             boolean useRoleId) {
573
574         List<RoleValue> rvls = new ArrayList<RoleValue>();
575         rvls.addAll(rvs);
576         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
577                 pv, rvls, usePermId, useRoleId);
578         if (logger.isDebugEnabled()) {
579             logger.debug("to be created, permRole");
580             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
581         }
582         return permRole;
583     }
584
585     /**
586      * Clean up.
587      */
588     @AfterClass(alwaysRun = true)
589     @Override
590     public void cleanUp() {
591         setupDelete();
592         String noTest = System.getProperty("noTestCleanup");
593         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
594             if (logger.isDebugEnabled()) {
595                 logger.debug("Skipping Cleanup phase ...");
596             }
597             return;
598         }
599         if (logger.isDebugEnabled()) {
600             logger.debug("Cleaning up temporary resources created for testing ...");
601         }
602
603         for (PermissionValue pv : permValues.values()) {
604             deletePermission(pv.getPermissionId());
605         }
606         for (RoleValue rv : roleValues.values()) {
607             deleteRole(rv.getRoleId());
608         }
609     }
610
611     /**
612      * Creates the permission.
613      *
614      * @param resName the res name
615      * @param effect the effect
616      * @return the string
617      */
618     private String createPermission(String resName, EffectType effect) {
619         if (logger.isDebugEnabled()) {
620             logger.debug(testBanner("createPermission"));
621         }
622         setupCreate();
623         PermissionClient permClient = new PermissionClient();
624         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
625         Permission permission = PermissionFactory.createPermissionInstance(resName,
626                 "default permissions for " + resName,
627                 actions, effect, true, true, true);
628         String id = null;
629         ClientResponse<Response> res = null;
630         try {
631             res = permClient.create(permission);
632
633             int statusCode = res.getStatus();
634             if (logger.isDebugEnabled()) {
635                 logger.debug("createPermission: resName=" + resName
636                         + " status = " + statusCode);
637             }
638             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
641             id = extractId(res);
642         } finally {
643             if (res != null) {
644                 res.releaseConnection();
645             }
646         }
647         return id;
648     }
649
650     /**
651      * Delete permission.
652      *
653      * @param permId the perm id
654      */
655     private void deletePermission(String permId) {
656         if (logger.isDebugEnabled()) {
657             logger.debug(testBanner("deletePermission"));
658         }
659         setupDelete();
660         PermissionClient permClient = new PermissionClient();
661         ClientResponse<Response> res = null;
662         try {
663             res = permClient.delete(permId);
664             int statusCode = res.getStatus();
665             if (logger.isDebugEnabled()) {
666                 logger.debug("deletePermission: delete permission id="
667                         + permId + " status=" + statusCode);
668             }
669             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
672         } finally {
673             res.releaseConnection();
674         }
675
676     }
677
678     /**
679      * Creates the role.
680      *
681      * @param roleName the role name
682      * @return the string
683      */
684     private String createRole(String roleName) {
685         if (logger.isDebugEnabled()) {
686             logger.debug(testBanner("createRole"));
687         }
688         setupCreate();
689         RoleClient roleClient = new RoleClient();
690
691         Role role = RoleFactory.createRoleInstance(roleName,
692                 "role for " + roleName, true);
693         ClientResponse<Response> res = null;
694         String id = null;
695         try {
696             res = roleClient.create(role);
697             int statusCode = res.getStatus();
698             if (logger.isDebugEnabled()) {
699                 logger.debug("createRole: name=" + roleName
700                         + " status = " + statusCode);
701             }
702             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
703                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
704             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
705
706             id = extractId(res);
707         } finally {
708             res.releaseConnection();
709         }
710         return id;
711     }
712
713     /**
714      * Delete role.
715      *
716      * @param roleId the role id
717      */
718     private void deleteRole(String roleId) {
719         if (logger.isDebugEnabled()) {
720             logger.debug(testBanner("deleteRole"));
721         }
722         setupDelete();
723         RoleClient roleClient = new RoleClient();
724         ClientResponse<Response> res = null;
725         try {
726             res = roleClient.delete(roleId);
727             int statusCode = res.getStatus();
728             if (logger.isDebugEnabled()) {
729                 logger.debug("deleteRole: delete role id=" + roleId
730                         + " status=" + statusCode);
731             }
732             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
733                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
734             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
735         } finally {
736             res.releaseConnection();
737         }
738     }
739 }