]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
82be06e7d88a8cfd2de6ac2153412c7fc87a1314
[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             PermissionValue pv = permValues.get(TEST_SERVICE_NAME + TEST_MARKER);
463         PermissionRole permRole = createPermissionRoleInstance(pv,
464                 roleValues.values(), true, true);
465             res = client.delete(pv.getPermissionId(), permRole);
466             int statusCode = res.getStatus();
467
468             // Check the status code of the response: does it match
469             // the expected response(s)?
470             if (logger.isDebugEnabled()) {
471                 logger.debug(testName + ": status = " + statusCode);
472             }
473             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
474                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
475             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
476         } finally {
477             if (res != null) {
478                 res.releaseConnection();
479             }
480         }
481     }
482
483     // Failure outcomes
484     /* (non-Javadoc)
485      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
486      */
487     @Override
488     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
489     public void deleteNonExistent(String testName) throws Exception {
490         //ignoring this test as the service side returns 200 now even if it does
491         //not find a record in the db
492     }
493
494     // ---------------------------------------------------------------
495     // Utility tests : tests of code used in tests above
496     // ---------------------------------------------------------------
497     /**
498      * Tests the code for manually submitting data that is used by several
499      * of the methods above.
500      * @throws Exception 
501      */
502     @Test(dependsOnMethods = {"create"})
503     public void testSubmitRequest() throws Exception {
504
505         // Expected status code: 200 OK
506         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
507
508         // Submit the request to the service and store the response.
509         String method = ServiceRequestType.READ.httpMethodName();
510         String url = getResourceURL(permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
511         int statusCode = submitRequest(method, url);
512
513         // Check the status code of the response: does it match
514         // the expected response(s)?
515         if (logger.isDebugEnabled()) {
516             logger.debug("testSubmitRequest: url=" + url
517                     + " status=" + statusCode);
518         }
519         Assert.assertEquals(statusCode, EXPECTED_STATUS);
520
521
522     }
523
524     // ---------------------------------------------------------------
525     // Utility methods used by tests above
526     // ---------------------------------------------------------------
527     /**
528      * create permRolerole instance
529      * @param pv permissionvalue
530      * @param rvs rolevalue array
531      * @param usePermId 
532      * @param useRoleId
533      * @return PermissionRole
534      */
535     public static PermissionRole createPermissionRoleInstance(PermissionValue pv,
536             Collection<RoleValue> rvs,
537             boolean usePermId,
538             boolean useRoleId) {
539
540         List<RoleValue> rvls = new ArrayList<RoleValue>();
541         rvls.addAll(rvs);
542         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
543                 pv, rvls, usePermId, useRoleId);
544         if (logger.isDebugEnabled()) {
545             logger.debug("to be created, permRole");
546             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
547         }
548         return permRole;
549     }
550
551     /**
552      * Clean up.
553      */
554     @AfterClass(alwaysRun = true)
555     @Override
556     public void cleanUp() {
557         setupDelete();
558         String noTest = System.getProperty("noTestCleanup");
559         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
560             if (logger.isDebugEnabled()) {
561                 logger.debug("Skipping Cleanup phase ...");
562             }
563             return;
564         }
565         if (logger.isDebugEnabled()) {
566             logger.debug("Cleaning up temporary resources created for testing ...");
567         }
568
569         for (PermissionValue pv : permValues.values()) {
570             deletePermission(pv.getPermissionId());
571         }
572         for (RoleValue rv : roleValues.values()) {
573             deleteRole(rv.getRoleId());
574         }
575     }
576
577     /**
578      * Creates the permission.
579      *
580      * @param resName the res name
581      * @param effect the effect
582      * @return the string
583      */
584     private String createPermission(String resName, EffectType effect) {
585         if (logger.isDebugEnabled()) {
586             logger.debug(testBanner("createPermission"));
587         }
588         setupCreate();
589         PermissionClient permClient = new PermissionClient();
590         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
591         Permission permission = PermissionFactory.createPermissionInstance(resName,
592                 "default permissions for " + resName,
593                 actions, effect, true, true, true);
594         String id = null;
595         ClientResponse<Response> res = null;
596         try {
597             res = permClient.create(permission);
598
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         if (logger.isDebugEnabled()) {
623             logger.debug(testBanner("deletePermission"));
624         }
625         setupDelete();
626         PermissionClient permClient = new PermissionClient();
627         ClientResponse<Response> res = null;
628         try {
629             res = permClient.delete(permId);
630             int statusCode = res.getStatus();
631             if (logger.isDebugEnabled()) {
632                 logger.debug("deletePermission: delete permission id="
633                         + permId + " status=" + statusCode);
634             }
635             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
636                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
637             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
638         } finally {
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         if (logger.isDebugEnabled()) {
652             logger.debug(testBanner("createRole"));
653         }
654         setupCreate();
655         RoleClient roleClient = new RoleClient();
656
657         Role role = RoleFactory.createRoleInstance(roleName,
658                 "role for " + roleName, true);
659         ClientResponse<Response> res = null;
660         String id = null;
661         try {
662             res = roleClient.create(role);
663             int statusCode = res.getStatus();
664             if (logger.isDebugEnabled()) {
665                 logger.debug("createRole: name=" + roleName
666                         + " status = " + statusCode);
667             }
668             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
669                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
670             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
671
672             id = extractId(res);
673         } finally {
674             res.releaseConnection();
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         if (logger.isDebugEnabled()) {
686             logger.debug(testBanner("deleteRole"));
687         }
688         setupDelete();
689         RoleClient roleClient = new RoleClient();
690         ClientResponse<Response> res = null;
691         try {
692             res = roleClient.delete(roleId);
693             int statusCode = res.getStatus();
694             if (logger.isDebugEnabled()) {
695                 logger.debug("deleteRole: delete role id=" + roleId
696                         + " status=" + statusCode);
697             }
698             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701         } finally {
702             res.releaseConnection();
703         }
704     }
705 }