]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2df8503620b7bf2be271e16f2ecc69467c6a9ba8
[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.Date;
28 import java.util.Hashtable;
29 import java.util.List;
30 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.authorization.EffectType;
32
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 import org.collectionspace.services.client.CollectionSpaceClient;
40 import org.collectionspace.services.client.PermissionClient;
41 import org.collectionspace.services.client.PermissionFactory;
42 import org.collectionspace.services.client.RolePermissionClient;
43 import org.collectionspace.services.client.PermissionRoleFactory;
44 import org.collectionspace.services.client.RoleClient;
45 import org.collectionspace.services.client.RoleFactory;
46 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
47 import org.collectionspace.services.client.test.ServiceRequestType;
48 import org.collectionspace.services.jaxb.AbstractCommonList;
49 import org.jboss.resteasy.client.ClientResponse;
50
51 import org.testng.Assert;
52 import org.testng.annotations.Test;
53
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.BeforeClass;
58
59 /**
60  * PermissionServiceTest, carries out tests against a
61  * deployed and running Permission, Role and PermissionRole Services.
62  * 
63  * $LastChangedRevision: 917 $
64  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
65  */
66 public class RolePermissionServiceTest extends AbstractServiceTestImpl {
67
68     /** The Constant logger. */
69     private final static String CLASS_NAME = RolePermissionServiceTest.class.getName();
70     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
71     // Instance variables specific to this test.
72     /** The known resource id. */
73     private String knownResourceId = null;
74     /** The all resource ids created. */
75     private List<String> allResourceIdsCreated = new ArrayList<String>();
76     final private static String TEST_MARKER = "_RolePermissionServiceTest";
77     final private static String TEST_ROLE_NAME = "ROLE";
78     final private static String NO_REL_SUFFIX = "-no-rel";
79     /** The perm values. */
80     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
81     /** The role values. */
82     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
83     private Date now = new Date();
84     /*
85      * This method is called only by the parent class, AbstractServiceTestImpl
86      */
87
88     /* (non-Javadoc)
89      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
90      */
91     @Override
92     protected String getServicePathComponent() {
93         return new RolePermissionClient().getServicePathComponent();
94     }
95
96     private String getRoleName() {
97         return TEST_ROLE_NAME + TEST_MARKER + now.toString();
98     }
99
100     /**
101      * Seed data.
102      */
103     @BeforeClass(alwaysRun = true)
104     public void seedData() {
105
106         String rn1 = getRoleName();
107         String r1RoleId = createRole(rn1);
108         RoleValue rv1 = new RoleValue();
109         rv1.setRoleId(r1RoleId);
110         rv1.setRoleName(rn1);
111         roleValues.put(rv1.getRoleName(), rv1);
112
113         String rn2 = getRoleName() + NO_REL_SUFFIX;
114         String r2RoleId = createRole(rn2);
115         RoleValue rv2 = new RoleValue();
116         rv2.setRoleId(r2RoleId);
117         rv2.setRoleName(rn2);
118         roleValues.put(rv2.getRoleName(), rv2);
119
120         String ra1 = "fooService" + TEST_MARKER;
121         String permId1 = createPermission(ra1, EffectType.PERMIT);
122         PermissionValue pva1 = new PermissionValue();
123         pva1.setResourceName(ra1);
124         pva1.setPermissionId(permId1);
125         permValues.put(pva1.getResourceName(), pva1);
126
127         String ra2 = "barService" + TEST_MARKER;
128         String permId2 = createPermission(ra1, EffectType.PERMIT);
129         PermissionValue pva2 = new PermissionValue();
130         pva2.setResourceName(ra2);
131         pva2.setPermissionId(permId2);
132         permValues.put(pva2.getResourceName(), pva2);
133     }
134
135     /* (non-Javadoc)
136      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
137      */
138     @Override
139     protected CollectionSpaceClient getClientInstance() {
140         return new RolePermissionClient();
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         RoleValue rv = roleValues.get(getRoleName());
184         PermissionRole permRole = createPermissionRoleInstance(rv,
185                 permValues.values(), true, true);
186         RolePermissionClient client = new RolePermissionClient();
187         ClientResponse<Response> res = null;
188         try {
189             res = client.create(rv.getRoleId(), permRole);
190             int statusCode = res.getStatus();
191             if (logger.isDebugEnabled()) {
192                 logger.debug(testName + ": status = " + statusCode);
193             }
194             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
195                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
196             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
197             // Store the ID returned from this create operation
198             // for additional tests below.
199             //this is is not important in case of this relationship
200             knownResourceId = extractId(res);
201             if (logger.isDebugEnabled()) {
202                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
203             }
204         } finally {
205             if (res != null) {
206                 res.releaseConnection();
207             }
208         }
209     }
210
211     //to not cause uniqueness violation for permRole, createList is removed
212     /* (non-Javadoc)
213      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
214      */
215     @Override
216     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
217     dependsOnMethods = {"create"})
218     public void createList(String testName) throws Exception {
219         //Should this really be empty?
220     }
221
222     // Failure outcomes
223     // Placeholders until the three tests below can be uncommented.
224     // See Issue CSPACE-401.
225     /* (non-Javadoc)
226      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
227      */
228     @Override
229     public void createWithEmptyEntityBody(String testName) throws Exception {
230         //Should this really be empty?
231     }
232
233     /* (non-Javadoc)
234      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
235      */
236     @Override
237     public void createWithMalformedXml(String testName) throws Exception {
238         //Should this really be empty?
239     }
240
241     /* (non-Javadoc)
242      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
243      */
244     @Override
245     public void createWithWrongXmlSchema(String testName) throws Exception {
246         //Should this really be empty?
247     }
248
249     // ---------------------------------------------------------------
250     // CRUD tests : READ tests
251     // ---------------------------------------------------------------
252     // Success outcomes
253     /* (non-Javadoc)
254      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
255      */
256     @Override
257     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
258     dependsOnMethods = {"create"})
259     public void read(String testName) throws Exception {
260
261         if (logger.isDebugEnabled()) {
262             logger.debug(testBanner(testName, CLASS_NAME));
263         }
264         ;
265         // Perform setup.
266         setupRead();
267
268         // Submit the request to the service and store the response.
269         RolePermissionClient client = new RolePermissionClient();
270         ClientResponse<PermissionRole> res = null;
271         try {
272             res = client.read(
273                     roleValues.get(getRoleName()).getRoleId(), "123");
274             int statusCode = res.getStatus();
275
276             // Check the status code of the response: does it match
277             // the expected response(s)?
278             if (logger.isDebugEnabled()) {
279                 logger.debug(testName + ": status = " + statusCode);
280             }
281             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
282                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
283             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
284
285             PermissionRole output = (PermissionRole) res.getEntity();
286             Assert.assertNotNull(output);
287         } finally {
288             if (res != null) {
289                 res.releaseConnection();
290             }
291         }
292     }
293
294     // Failure outcomes
295     /* (non-Javadoc)
296      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
297      */
298     @Override
299     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
300     public void readNonExistent(String testName) throws Exception {
301
302         if (logger.isDebugEnabled()) {
303             logger.debug(testBanner(testName, CLASS_NAME));
304         }
305         ;
306         // Perform setup.
307         setupReadNonExistent();
308
309         // Submit the request to the service and store the response.
310         RolePermissionClient client = new RolePermissionClient();
311         ClientResponse<PermissionRole> res = null;
312         try {
313
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     public void readNoRelationship(String testName) throws Exception {
334
335         if (logger.isDebugEnabled()) {
336             logger.debug(testBanner(testName, CLASS_NAME));
337         }
338         ;
339         setupRead();
340         // Submit the request to the service and store the response.
341         RolePermissionClient client = new RolePermissionClient();
342         ClientResponse<PermissionRole> res = null;
343         try {
344
345             res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId(), "123");
346             int statusCode = res.getStatus();
347
348             // Check the status code of the response: does it match
349             // the expected response(s)?
350             if (logger.isDebugEnabled()) {
351                 logger.debug(testName + ": status = " + statusCode);
352             }
353             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
354                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
355             Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
356             PermissionRole output = (PermissionRole) res.getEntity();
357
358             String sOutput = objectAsXmlString(output, PermissionRole.class);
359             if (logger.isDebugEnabled()) {
360                 logger.debug(testName + " received " + sOutput);
361             }
362         } finally {
363             if (res != null) {
364                 res.releaseConnection();
365             }
366         }
367     }
368
369     // ---------------------------------------------------------------
370     // CRUD tests : READ_LIST tests
371     // ---------------------------------------------------------------
372     // Success outcomes
373     /* (non-Javadoc)
374      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
375      */
376     @Override
377     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
378     dependsOnMethods = {"createList", "read"})
379     public void readList(String testName) throws Exception {
380         //Should this really be empty?
381     }
382
383     // Failure outcomes
384     // None at present.
385     // ---------------------------------------------------------------
386     // CRUD tests : UPDATE tests
387     // ---------------------------------------------------------------
388     // Success outcomes
389     /* (non-Javadoc)
390      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
391      */
392     @Override
393     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
394     dependsOnMethods = {"read", "readList", "readNonExistent"})
395     public void update(String testName) throws Exception {
396         //Should this really be empty?
397     }
398
399     // Failure outcomes
400     // Placeholders until the three tests below can be uncommented.
401     // See Issue CSPACE-401.
402     /* (non-Javadoc)
403      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
404      */
405     @Override
406     public void updateWithEmptyEntityBody(String testName) throws Exception {
407         //Should this really be empty?
408     }
409
410     /* (non-Javadoc)
411      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
412      */
413     @Override
414     public void updateWithMalformedXml(String testName) throws Exception {
415         //Should this really be empty?
416     }
417
418     /* (non-Javadoc)
419      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
420      */
421     @Override
422     public void updateWithWrongXmlSchema(String testName) throws Exception {
423         //Should this really be empty?
424     }
425
426     /* (non-Javadoc)
427      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
428      */
429     @Override
430     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
431     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
432     public void updateNonExistent(String testName) throws Exception {
433         //Should this really be empty?
434     }
435
436     // ---------------------------------------------------------------
437     // CRUD tests : DELETE tests
438     // ---------------------------------------------------------------
439     // Success outcomes
440     /* (non-Javadoc)
441      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
442      */
443     @Override
444     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
445     dependsOnMethods = {"read"})
446     public void delete(String testName) throws Exception {
447
448         if (logger.isDebugEnabled()) {
449             logger.debug(testBanner(testName, CLASS_NAME));
450         }
451         ;
452         // Perform setup.
453         setupDelete();
454
455         // Submit the request to the service and store the response.
456         RolePermissionClient client = new RolePermissionClient();
457         ClientResponse<Response> res = null;
458         try {
459             RoleValue rv = roleValues.get(getRoleName());
460             PermissionRole permRole = createPermissionRoleInstance(rv,
461                     permValues.values(), true, true);
462             res = client.delete(
463                     roleValues.get(getRoleName()).getRoleId(), permRole);
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(roleValues.get(getRoleName()).getRoleId());
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 PermissionRole instance
527      * @param rv rolevalue
528      * @param pvs permission value array
529      * @param usePermId 
530      * @param useRoleId
531      * @return PermissionRole
532      */
533     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
534             Collection<PermissionValue> pvs,
535             boolean usePermId,
536             boolean useRoleId) {
537         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
538         pvls.addAll(pvs);
539         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
540                 rv, pvls, usePermId, useRoleId);
541         if (logger.isDebugEnabled()) {
542             logger.debug("" +
543                     "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         for (PermissionValue pv : permValues.values()) {
567             deletePermission(pv.getPermissionId());
568         }
569         for (RoleValue rv : roleValues.values()) {
570             deleteRole(rv.getRoleId());
571         }
572     }
573
574     /**
575      * Creates the permission.
576      *
577      * @param resName the res name
578      * @param effect the effect
579      * @return the string
580      */
581     private String createPermission(String resName, EffectType effect) {
582         setupCreate();
583         PermissionClient permClient = new PermissionClient();
584         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
585         Permission permission = PermissionFactory.createPermissionInstance(resName,
586                 "default permissions for " + resName,
587                 actions, effect, true, true, true);
588         ClientResponse<Response> res = null;
589         String id = null;
590         try {
591             res = permClient.create(permission);
592             int statusCode = res.getStatus();
593             if (logger.isDebugEnabled()) {
594                 logger.debug("createPermission: resName=" + resName
595                         + " status = " + statusCode);
596             }
597             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
598                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
599             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
600             id = extractId(res);
601         } finally {
602             if (res != null) {
603                 res.releaseConnection();
604             }
605         }
606         return id;
607     }
608
609     /**
610      * Delete permission.
611      *
612      * @param permId the perm id
613      */
614     private void deletePermission(String permId) {
615         setupDelete();
616         PermissionClient permClient = new PermissionClient();
617
618         ClientResponse<Response> res = null;
619         try {
620             res = permClient.delete(permId);
621             int statusCode = res.getStatus();
622             if (logger.isDebugEnabled()) {
623                 logger.debug("deletePermission: delete permission id="
624                         + permId + " status=" + statusCode);
625             }
626             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
627                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
628             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629
630         } finally {
631             if (res != null) {
632                 res.releaseConnection();
633             }
634         }
635     }
636
637     /**
638      * Creates the role.
639      *
640      * @param roleName the role name
641      * @return the string
642      */
643     private String createRole(String roleName) {
644         setupCreate();
645         RoleClient roleClient = new RoleClient();
646
647         Role role = RoleFactory.createRoleInstance(roleName,
648                 "role for " + roleName, true);
649         role.setRoleGroup("something");
650         ClientResponse<Response> res = null;
651         String id = null;
652         try {
653             res = roleClient.create(role);
654             int statusCode = res.getStatus();
655             if (logger.isDebugEnabled()) {
656                 logger.debug("createRole: name=" + roleName
657                         + " status = " + statusCode);
658             }
659             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
660                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
661             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
662             id = extractId(res);
663         } finally {
664             if (res != null) {
665                 res.releaseConnection();
666             }
667         }
668         return id;
669     }
670
671     /**
672      * Delete role.
673      *
674      * @param roleId the role id
675      */
676     private void deleteRole(String roleId) {
677         setupDelete();
678         RoleClient roleClient = new RoleClient();
679         ClientResponse<Response> res = null;
680         try {
681             res = roleClient.delete(roleId);
682             int statusCode = res.getStatus();
683             if (logger.isDebugEnabled()) {
684                 logger.debug("deleteRole: delete role id=" + roleId
685                         + " status=" + statusCode);
686             }
687             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
690         } finally {
691             res.releaseConnection();
692         }
693
694     }
695 }