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