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