]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b162c81fec20243c35cdeb0c0caf13f5d440922f
[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.perms.EffectType;
32
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 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     /* (non-Javadoc)
86      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
87      */
88     @Override
89     protected String getServicePathComponent() {
90         return new RolePermissionClient().getServicePathComponent();
91     }
92     
93     @Override
94     public String getServiceName() { 
95         return RoleClient.SERVICE_NAME; // RolePermission is a sub-resource of 'roles' resource.
96     }
97     
98     private String getRoleName() {
99         return TEST_ROLE_NAME + TEST_MARKER + now.toString();
100     }
101
102     /**
103      * Seed data.
104      */
105     @BeforeClass(alwaysRun = true)
106     public void seedData() {
107
108         String rn1 = getRoleName();
109         String r1RoleId = createRole(rn1);
110         RoleValue rv1 = new RoleValue();
111         rv1.setRoleId(r1RoleId);
112         rv1.setRoleName(rn1);
113         roleValues.put(rv1.getRoleName(), rv1);
114
115         String rn2 = getRoleName() + NO_REL_SUFFIX;
116         String r2RoleId = createRole(rn2);
117         RoleValue rv2 = new RoleValue();
118         rv2.setRoleId(r2RoleId);
119         rv2.setRoleName(rn2);
120         roleValues.put(rv2.getRoleName(), rv2);
121
122         String ra1 = "fooService" + TEST_MARKER;
123         String permId1 = createPermission(ra1, EffectType.PERMIT);
124         PermissionValue pva1 = new PermissionValue();
125         pva1.setResourceName(ra1);
126         pva1.setPermissionId(permId1);
127         permValues.put(pva1.getResourceName(), pva1);
128
129         String ra2 = "barService" + TEST_MARKER;
130         String permId2 = createPermission(ra1, EffectType.PERMIT);
131         PermissionValue pva2 = new PermissionValue();
132         pva2.setResourceName(ra2);
133         pva2.setPermissionId(permId2);
134         permValues.put(pva2.getResourceName(), pva2);
135     }
136
137     /* (non-Javadoc)
138      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
139      */
140     @Override
141     protected CollectionSpaceClient getClientInstance() {
142         return new RolePermissionClient();
143     }
144
145     /* (non-Javadoc)
146      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
147      */
148     @Override
149     protected AbstractCommonList getAbstractCommonList(
150             ClientResponse<AbstractCommonList> response) {
151         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
152         throw new UnsupportedOperationException();
153     }
154
155     /* (non-Javadoc)
156      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
157      */
158     @Test(dataProvider = "testName")
159     @Override
160     public void readPaginatedList(String testName) throws Exception {
161         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
162     }
163     // ---------------------------------------------------------------
164     // CRUD tests : CREATE tests
165     // ---------------------------------------------------------------
166     // Success outcomes
167     /* (non-Javadoc)
168      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
169      */
170
171     @Override
172     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
173     public void create(String testName) throws Exception {
174
175         if (logger.isDebugEnabled()) {
176             logger.debug(testBanner(testName, CLASS_NAME));
177         }
178         ;
179         // Perform setup, such as initializing the type of service request
180         // (e.g. CREATE, DELETE), its valid and expected status codes, and
181         // its associated HTTP method name (e.g. POST, DELETE).
182         setupCreate();
183
184         // Submit the request to the service and store the response.
185         RoleValue rv = roleValues.get(getRoleName());
186         PermissionRole permRole = createPermissionRoleInstance(rv,
187                 permValues.values(), true, true);
188         RolePermissionClient client = new RolePermissionClient();
189         ClientResponse<Response> res = null;
190         try {
191             res = client.create(rv.getRoleId(), permRole);
192             int statusCode = res.getStatus();
193             if (logger.isDebugEnabled()) {
194                 logger.debug(testName + ": status = " + statusCode);
195             }
196             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
197                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
198             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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         ;
267         // Perform setup.
268         setupRead();
269
270         // Submit the request to the service and store the response.
271         RolePermissionClient client = new RolePermissionClient();
272         ClientResponse<PermissionRole> res = null;
273         try {
274             res = client.read(roleValues.get(getRoleName()).getRoleId());
275             assertStatusCode(res, testName);
276             PermissionRole output = (PermissionRole) res.getEntity();
277             Assert.assertNotNull(output);
278         } finally {
279             if (res != null) {
280                 res.releaseConnection();
281             }
282         }
283     }
284
285     // Failure outcomes
286     /* (non-Javadoc)
287      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
288      */
289     @Override
290     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
291     public void readNonExistent(String testName) throws Exception {
292
293         if (logger.isDebugEnabled()) {
294             logger.debug(testBanner(testName, CLASS_NAME));
295         }
296         ;
297         // Perform setup.
298         setupReadNonExistent();
299
300         // Submit the request to the service and store the response.
301         RolePermissionClient client = new RolePermissionClient();
302         ClientResponse<PermissionRole> res = null;
303         try {
304
305             res = client.read(NON_EXISTENT_ID);
306             int statusCode = res.getStatus();
307
308             // Check the status code of the response: does it match
309             // the expected response(s)?
310             if (logger.isDebugEnabled()) {
311                 logger.debug(testName + ": status = " + statusCode);
312             }
313             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
314                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
315             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
316         } finally {
317             if (res != null) {
318                 res.releaseConnection();
319             }
320         }
321     }
322
323     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
324     public void readNoRelationship(String testName) throws Exception {
325
326         if (logger.isDebugEnabled()) {
327             logger.debug(testBanner(testName, CLASS_NAME));
328         }
329         ;
330         setupRead();
331         // Submit the request to the service and store the response.
332         RolePermissionClient client = new RolePermissionClient();
333         ClientResponse<PermissionRole> res = null;
334         try {
335
336             res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId());
337             assertStatusCode(res, testName);
338             PermissionRole output = (PermissionRole) res.getEntity();
339
340             String sOutput = objectAsXmlString(output, PermissionRole.class);
341             if (logger.isDebugEnabled()) {
342                 logger.debug(testName + " received " + sOutput);
343             }
344         } finally {
345             if (res != null) {
346                 res.releaseConnection();
347             }
348         }
349     }
350
351     // ---------------------------------------------------------------
352     // CRUD tests : READ_LIST tests
353     // ---------------------------------------------------------------
354     // Success outcomes
355     /* (non-Javadoc)
356      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
357      */
358     @Override
359     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
360     dependsOnMethods = {"createList", "read"})
361     public void readList(String testName) throws Exception {
362         //Should this really be empty?
363     }
364
365     // Failure outcomes
366     // None at present.
367     // ---------------------------------------------------------------
368     // CRUD tests : UPDATE tests
369     // ---------------------------------------------------------------
370     // Success outcomes
371     /* (non-Javadoc)
372      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
373      */
374     @Override
375     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
376     dependsOnMethods = {"read", "readList", "readNonExistent"})
377     public void update(String testName) throws Exception {
378         //Should this really be empty?
379     }
380
381     // Failure outcomes
382     // Placeholders until the three tests below can be uncommented.
383     // See Issue CSPACE-401.
384     /* (non-Javadoc)
385      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
386      */
387     @Override
388     public void updateWithEmptyEntityBody(String testName) throws Exception {
389         //Should this really be empty?
390     }
391
392     /* (non-Javadoc)
393      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
394      */
395     @Override
396     public void updateWithMalformedXml(String testName) throws Exception {
397         //Should this really be empty?
398     }
399
400     /* (non-Javadoc)
401      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
402      */
403     @Override
404     public void updateWithWrongXmlSchema(String testName) throws Exception {
405         //Should this really be empty?
406     }
407
408     /* (non-Javadoc)
409      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
410      */
411     @Override
412     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
413     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
414     public void updateNonExistent(String testName) throws Exception {
415         //Should this really be empty?
416     }
417
418     // ---------------------------------------------------------------
419     // CRUD tests : DELETE tests
420     // ---------------------------------------------------------------
421     // Success outcomes
422     /* (non-Javadoc)
423      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
424      */
425     @Override
426     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
427     dependsOnMethods = {"read"})
428     public void delete(String testName) throws Exception {
429
430         if (logger.isDebugEnabled()) {
431             logger.debug(testBanner(testName, CLASS_NAME));
432         }
433         
434         // Perform setup.
435         setupDelete();
436                 
437         // Submit the request to the service and store the response.
438         RolePermissionClient client = new RolePermissionClient();
439         RoleValue rv = roleValues.get(getRoleName());
440         ClientResponse<Response> delRes = null;
441         try {
442                 delRes = client.delete(rv.getRoleId());
443             int statusCode = delRes.getStatus();
444             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
445                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
446             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447         } finally {
448             if (delRes != null) {
449                 delRes.releaseConnection();
450             }
451         }
452
453         // reset for next delete
454         create(testName);
455         setupDelete();
456         
457         rv = roleValues.get(getRoleName());
458         ClientResponse<PermissionRole> readResponse = client.read(rv.getRoleId());
459         PermissionRole toDelete = readResponse.getEntity();
460         readResponse.releaseConnection();        
461         
462         rv = toDelete.getRole().get(0);
463         ClientResponse<Response> res = null;
464         try {
465             res = client.delete(
466                     rv.getRoleId(), toDelete);
467             int statusCode = res.getStatus();
468             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
471         } finally {
472             if (res != null) {
473                 res.releaseConnection();
474             }
475         }
476     }
477
478     // Failure outcomes
479     /* (non-Javadoc)
480      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
481      */
482     @Override
483     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
484     public void deleteNonExistent(String testName) throws Exception {
485         //ignoring this test as the service side returns 200 now even if it does
486         //not find a record in the db
487     }
488     
489     // ---------------------------------------------------------------
490     // Search tests
491     // ---------------------------------------------------------------
492     
493     @Override
494     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
495     public void searchWorkflowDeleted(String testName) throws Exception {
496         // Fixme: null test for now, overriding test in base class
497     }
498
499     // ---------------------------------------------------------------
500     // Utility tests : tests of code used in tests above
501     // ---------------------------------------------------------------
502     /**
503      * Tests the code for manually submitting data that is used by several
504      * of the methods above.
505      * @throws Exception 
506      */
507     @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles
508     public void testSubmitRequest() throws Exception {
509
510         // Expected status code: 200 OK
511         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
512
513         // Submit the request to the service and store the response.
514         String method = ServiceRequestType.READ.httpMethodName();
515         String url = getResourceURL(roleValues.get(getRoleName()).getRoleId());
516         int statusCode = submitRequest(method, url);
517
518         // Check the status code of the response: does it match
519         // the expected response(s)?
520         if (logger.isDebugEnabled()) {
521             logger.debug("testSubmitRequest: url=" + url
522                     + " status=" + statusCode);
523         }
524         Assert.assertEquals(statusCode, EXPECTED_STATUS);
525
526
527     }
528
529     // ---------------------------------------------------------------
530     // Utility methods used by tests above
531     // ---------------------------------------------------------------
532     /**
533      * create PermissionRole instance
534      * @param rv rolevalue
535      * @param pvs permission value array
536      * @param usePermId 
537      * @param useRoleId
538      * @return PermissionRole
539      */
540     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
541             Collection<PermissionValue> pvs,
542             boolean usePermId,
543             boolean useRoleId) {
544         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
545         pvls.addAll(pvs);
546         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
547                 rv, pvls, usePermId, useRoleId);
548         if (logger.isDebugEnabled()) {
549             logger.debug("" +
550                     "permRole");
551             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
552         }
553         return permRole;
554     }
555
556     /**
557      * Clean up.
558      */
559     @AfterClass(alwaysRun = true)
560     @Override
561     public void cleanUp() {
562         setupDelete();
563         String noTest = System.getProperty("noTestCleanup");
564         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
565             if (logger.isDebugEnabled()) {
566                 logger.debug("Skipping Cleanup phase ...");
567             }
568             return;
569         }
570         if (logger.isDebugEnabled()) {
571             logger.debug("Cleaning up temporary resources created for testing ...");
572         }
573         for (PermissionValue pv : permValues.values()) {
574             deletePermission(pv.getPermissionId());
575         }
576         for (RoleValue rv : roleValues.values()) {
577             deleteRole(rv.getRoleId());
578         }
579     }
580
581     /**
582      * Creates the permission.
583      *
584      * @param resName the res name
585      * @param effect the effect
586      * @return the string
587      */
588     private String createPermission(String resName, EffectType effect) {
589         setupCreate();
590         PermissionClient permClient = new PermissionClient();
591         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
592         Permission permission = PermissionFactory.createPermissionInstance(resName,
593                 "default permissions for " + resName,
594                 actions, effect, true, true, true);
595         ClientResponse<Response> res = null;
596         String id = null;
597         try {
598             res = permClient.create(permission);
599             int statusCode = res.getStatus();
600             if (logger.isDebugEnabled()) {
601                 logger.debug("createPermission: resName=" + resName
602                         + " status = " + statusCode);
603             }
604             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607             id = extractId(res);
608         } finally {
609             if (res != null) {
610                 res.releaseConnection();
611             }
612         }
613         return id;
614     }
615
616     /**
617      * Delete permission.
618      *
619      * @param permId the perm id
620      */
621     private void deletePermission(String permId) {
622         setupDelete();
623         PermissionClient permClient = new PermissionClient();
624
625         ClientResponse<Response> res = null;
626         try {
627             res = permClient.delete(permId);
628             int statusCode = res.getStatus();
629             if (logger.isDebugEnabled()) {
630                 logger.debug("deletePermission: delete permission id="
631                         + permId + " status=" + statusCode);
632             }
633             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
634                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
635             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
636
637         } finally {
638             if (res != null) {
639                 res.releaseConnection();
640             }
641         }
642     }
643
644     /**
645      * Creates the role.
646      *
647      * @param roleName the role name
648      * @return the string
649      */
650     private String createRole(String roleName) {
651         setupCreate();
652         RoleClient roleClient = new RoleClient();
653
654         Role role = RoleFactory.createRoleInstance(roleName,
655                         roleName, //the display name
656                 "role for " + roleName, true);
657         role.setRoleGroup("something");
658         ClientResponse<Response> res = null;
659         String id = null;
660         try {
661             res = roleClient.create(role);
662             int statusCode = res.getStatus();
663             if (logger.isDebugEnabled()) {
664                 logger.debug("createRole: name=" + roleName
665                         + " status = " + statusCode);
666             }
667             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
668                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
669             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
670             id = extractId(res);
671         } finally {
672             if (res != null) {
673                 res.releaseConnection();
674             }
675         }
676         return id;
677     }
678
679     /**
680      * Delete role.
681      *
682      * @param roleId the role id
683      */
684     private void deleteRole(String roleId) {
685         setupDelete();
686         RoleClient roleClient = new RoleClient();
687         ClientResponse<Response> res = null;
688         try {
689             res = roleClient.delete(roleId);
690             int statusCode = res.getStatus();
691             if (logger.isDebugEnabled()) {
692                 logger.debug("deleteRole: delete role id=" + roleId
693                         + " status=" + statusCode);
694             }
695             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
698         } finally {
699             res.releaseConnection();
700         }
701
702     }
703 }