]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
73fe14f62aaaccc8014df8ee135718c3497b08d1
[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     /* (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             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     // Failure outcomes
296     /* (non-Javadoc)
297      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
298      */
299     @Override
300     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
301     public void readNonExistent(String testName) throws Exception {
302
303         if (logger.isDebugEnabled()) {
304             logger.debug(testBanner(testName, CLASS_NAME));
305         }
306         ;
307         // Perform setup.
308         setupReadNonExistent();
309
310         // Submit the request to the service and store the response.
311         RolePermissionClient client = new RolePermissionClient();
312         ClientResponse<PermissionRole> res = null;
313         try {
314
315             res = client.read(NON_EXISTENT_ID);
316             int statusCode = res.getStatus();
317
318             // Check the status code of the response: does it match
319             // the expected response(s)?
320             if (logger.isDebugEnabled()) {
321                 logger.debug(testName + ": status = " + statusCode);
322             }
323             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
324                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
325             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
326         } finally {
327             if (res != null) {
328                 res.releaseConnection();
329             }
330         }
331     }
332
333     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
334     public void readNoRelationship(String testName) throws Exception {
335
336         if (logger.isDebugEnabled()) {
337             logger.debug(testBanner(testName, CLASS_NAME));
338         }
339         ;
340         setupRead();
341         // Submit the request to the service and store the response.
342         RolePermissionClient client = new RolePermissionClient();
343         ClientResponse<PermissionRole> res = null;
344         try {
345
346             res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId());
347             int statusCode = res.getStatus();
348
349             // Check the status code of the response: does it match
350             // the expected response(s)?
351             if (logger.isDebugEnabled()) {
352                 logger.debug(testName + ": status = " + statusCode);
353             }
354             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
355                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
356             Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
357             PermissionRole output = (PermissionRole) res.getEntity();
358
359             String sOutput = objectAsXmlString(output, PermissionRole.class);
360             if (logger.isDebugEnabled()) {
361                 logger.debug(testName + " received " + sOutput);
362             }
363         } finally {
364             if (res != null) {
365                 res.releaseConnection();
366             }
367         }
368     }
369
370     // ---------------------------------------------------------------
371     // CRUD tests : READ_LIST tests
372     // ---------------------------------------------------------------
373     // Success outcomes
374     /* (non-Javadoc)
375      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
376      */
377     @Override
378     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
379     dependsOnMethods = {"createList", "read"})
380     public void readList(String testName) throws Exception {
381         //Should this really be empty?
382     }
383
384     // Failure outcomes
385     // None at present.
386     // ---------------------------------------------------------------
387     // CRUD tests : UPDATE tests
388     // ---------------------------------------------------------------
389     // Success outcomes
390     /* (non-Javadoc)
391      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
392      */
393     @Override
394     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
395     dependsOnMethods = {"read", "readList", "readNonExistent"})
396     public void update(String testName) throws Exception {
397         //Should this really be empty?
398     }
399
400     // Failure outcomes
401     // Placeholders until the three tests below can be uncommented.
402     // See Issue CSPACE-401.
403     /* (non-Javadoc)
404      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
405      */
406     @Override
407     public void updateWithEmptyEntityBody(String testName) throws Exception {
408         //Should this really be empty?
409     }
410
411     /* (non-Javadoc)
412      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
413      */
414     @Override
415     public void updateWithMalformedXml(String testName) throws Exception {
416         //Should this really be empty?
417     }
418
419     /* (non-Javadoc)
420      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
421      */
422     @Override
423     public void updateWithWrongXmlSchema(String testName) throws Exception {
424         //Should this really be empty?
425     }
426
427     /* (non-Javadoc)
428      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
429      */
430     @Override
431     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
432     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
433     public void updateNonExistent(String testName) throws Exception {
434         //Should this really be empty?
435     }
436
437     // ---------------------------------------------------------------
438     // CRUD tests : DELETE tests
439     // ---------------------------------------------------------------
440     // Success outcomes
441     /* (non-Javadoc)
442      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
443      */
444     @Override
445     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
446     dependsOnMethods = {"read"})
447     public void delete(String testName) throws Exception {
448
449         if (logger.isDebugEnabled()) {
450             logger.debug(testBanner(testName, CLASS_NAME));
451         }
452         
453         // Perform setup.
454         setupDelete();
455                 
456         // Submit the request to the service and store the response.
457         RolePermissionClient client = new RolePermissionClient();
458         RoleValue rv = roleValues.get(getRoleName());
459         ClientResponse<Response> delRes = null;
460         try {
461                 delRes = client.delete(rv.getRoleId());
462             int statusCode = delRes.getStatus();
463             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
464                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
465             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466         } finally {
467             if (delRes != null) {
468                 delRes.releaseConnection();
469             }
470         }
471
472         // reset for next delete
473         create(testName);
474         setupDelete();
475         
476         rv = roleValues.get(getRoleName());
477         ClientResponse<PermissionRole> readResponse = client.read(rv.getRoleId());
478         PermissionRole toDelete = readResponse.getEntity();
479         readResponse.releaseConnection();        
480         
481         rv = toDelete.getRoles().get(0);
482         ClientResponse<Response> res = null;
483         try {
484             res = client.delete(
485                     rv.getRoleId(), toDelete);
486             int statusCode = res.getStatus();
487             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
488                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
489             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
490         } finally {
491             if (res != null) {
492                 res.releaseConnection();
493             }
494         }
495     }
496
497     // Failure outcomes
498     /* (non-Javadoc)
499      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
500      */
501     @Override
502     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
503     public void deleteNonExistent(String testName) throws Exception {
504         //ignoring this test as the service side returns 200 now even if it does
505         //not find a record in the db
506     }
507
508     // ---------------------------------------------------------------
509     // Utility tests : tests of code used in tests above
510     // ---------------------------------------------------------------
511     /**
512      * Tests the code for manually submitting data that is used by several
513      * of the methods above.
514      * @throws Exception 
515      */
516     @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles
517     public void testSubmitRequest() throws Exception {
518
519         // Expected status code: 200 OK
520         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
521
522         // Submit the request to the service and store the response.
523         String method = ServiceRequestType.READ.httpMethodName();
524         String url = getResourceURL(roleValues.get(getRoleName()).getRoleId());
525         int statusCode = submitRequest(method, url);
526
527         // Check the status code of the response: does it match
528         // the expected response(s)?
529         if (logger.isDebugEnabled()) {
530             logger.debug("testSubmitRequest: url=" + url
531                     + " status=" + statusCode);
532         }
533         Assert.assertEquals(statusCode, EXPECTED_STATUS);
534
535
536     }
537
538     // ---------------------------------------------------------------
539     // Utility methods used by tests above
540     // ---------------------------------------------------------------
541     /**
542      * create PermissionRole instance
543      * @param rv rolevalue
544      * @param pvs permission value array
545      * @param usePermId 
546      * @param useRoleId
547      * @return PermissionRole
548      */
549     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
550             Collection<PermissionValue> pvs,
551             boolean usePermId,
552             boolean useRoleId) {
553         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
554         pvls.addAll(pvs);
555         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
556                 rv, pvls, usePermId, useRoleId);
557         if (logger.isDebugEnabled()) {
558             logger.debug("" +
559                     "permRole");
560             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
561         }
562         return permRole;
563     }
564
565     /**
566      * Clean up.
567      */
568     @AfterClass(alwaysRun = true)
569     @Override
570     public void cleanUp() {
571         setupDelete();
572         String noTest = System.getProperty("noTestCleanup");
573         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
574             if (logger.isDebugEnabled()) {
575                 logger.debug("Skipping Cleanup phase ...");
576             }
577             return;
578         }
579         if (logger.isDebugEnabled()) {
580             logger.debug("Cleaning up temporary resources created for testing ...");
581         }
582         for (PermissionValue pv : permValues.values()) {
583             deletePermission(pv.getPermissionId());
584         }
585         for (RoleValue rv : roleValues.values()) {
586             deleteRole(rv.getRoleId());
587         }
588     }
589
590     /**
591      * Creates the permission.
592      *
593      * @param resName the res name
594      * @param effect the effect
595      * @return the string
596      */
597     private String createPermission(String resName, EffectType effect) {
598         setupCreate();
599         PermissionClient permClient = new PermissionClient();
600         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
601         Permission permission = PermissionFactory.createPermissionInstance(resName,
602                 "default permissions for " + resName,
603                 actions, effect, true, true, true);
604         ClientResponse<Response> res = null;
605         String id = null;
606         try {
607             res = permClient.create(permission);
608             int statusCode = res.getStatus();
609             if (logger.isDebugEnabled()) {
610                 logger.debug("createPermission: resName=" + resName
611                         + " status = " + statusCode);
612             }
613             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
616             id = extractId(res);
617         } finally {
618             if (res != null) {
619                 res.releaseConnection();
620             }
621         }
622         return id;
623     }
624
625     /**
626      * Delete permission.
627      *
628      * @param permId the perm id
629      */
630     private void deletePermission(String permId) {
631         setupDelete();
632         PermissionClient permClient = new PermissionClient();
633
634         ClientResponse<Response> res = null;
635         try {
636             res = permClient.delete(permId);
637             int statusCode = res.getStatus();
638             if (logger.isDebugEnabled()) {
639                 logger.debug("deletePermission: delete permission id="
640                         + permId + " status=" + statusCode);
641             }
642             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
645
646         } finally {
647             if (res != null) {
648                 res.releaseConnection();
649             }
650         }
651     }
652
653     /**
654      * Creates the role.
655      *
656      * @param roleName the role name
657      * @return the string
658      */
659     private String createRole(String roleName) {
660         setupCreate();
661         RoleClient roleClient = new RoleClient();
662
663         Role role = RoleFactory.createRoleInstance(roleName,
664                         roleName, //the display name
665                 "role for " + roleName, true);
666         role.setRoleGroup("something");
667         ClientResponse<Response> res = null;
668         String id = null;
669         try {
670             res = roleClient.create(role);
671             int statusCode = res.getStatus();
672             if (logger.isDebugEnabled()) {
673                 logger.debug("createRole: name=" + roleName
674                         + " status = " + statusCode);
675             }
676             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
677                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
678             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679             id = extractId(res);
680         } finally {
681             if (res != null) {
682                 res.releaseConnection();
683             }
684         }
685         return id;
686     }
687
688     /**
689      * Delete role.
690      *
691      * @param roleId the role id
692      */
693     private void deleteRole(String roleId) {
694         setupDelete();
695         RoleClient roleClient = new RoleClient();
696         ClientResponse<Response> res = null;
697         try {
698             res = roleClient.delete(roleId);
699             int statusCode = res.getStatus();
700             if (logger.isDebugEnabled()) {
701                 logger.debug("deleteRole: delete role id=" + roleId
702                         + " status=" + statusCode);
703             }
704             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
707         } finally {
708             res.releaseConnection();
709         }
710
711     }
712 }