]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
5142e0eb32274c699feaaeec0a92b396ceb198f5
[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     // Search tests
510     // ---------------------------------------------------------------
511     
512     @Override
513     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
514     public void searchWorkflowDeleted(String testName) throws Exception {
515         // Fixme: null test for now, overriding test in base class
516     }
517
518     // ---------------------------------------------------------------
519     // Utility tests : tests of code used in tests above
520     // ---------------------------------------------------------------
521     /**
522      * Tests the code for manually submitting data that is used by several
523      * of the methods above.
524      * @throws Exception 
525      */
526     @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles
527     public void testSubmitRequest() throws Exception {
528
529         // Expected status code: 200 OK
530         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
531
532         // Submit the request to the service and store the response.
533         String method = ServiceRequestType.READ.httpMethodName();
534         String url = getResourceURL(roleValues.get(getRoleName()).getRoleId());
535         int statusCode = submitRequest(method, url);
536
537         // Check the status code of the response: does it match
538         // the expected response(s)?
539         if (logger.isDebugEnabled()) {
540             logger.debug("testSubmitRequest: url=" + url
541                     + " status=" + statusCode);
542         }
543         Assert.assertEquals(statusCode, EXPECTED_STATUS);
544
545
546     }
547
548     // ---------------------------------------------------------------
549     // Utility methods used by tests above
550     // ---------------------------------------------------------------
551     /**
552      * create PermissionRole instance
553      * @param rv rolevalue
554      * @param pvs permission value array
555      * @param usePermId 
556      * @param useRoleId
557      * @return PermissionRole
558      */
559     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
560             Collection<PermissionValue> pvs,
561             boolean usePermId,
562             boolean useRoleId) {
563         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
564         pvls.addAll(pvs);
565         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
566                 rv, pvls, usePermId, useRoleId);
567         if (logger.isDebugEnabled()) {
568             logger.debug("" +
569                     "permRole");
570             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
571         }
572         return permRole;
573     }
574
575     /**
576      * Clean up.
577      */
578     @AfterClass(alwaysRun = true)
579     @Override
580     public void cleanUp() {
581         setupDelete();
582         String noTest = System.getProperty("noTestCleanup");
583         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
584             if (logger.isDebugEnabled()) {
585                 logger.debug("Skipping Cleanup phase ...");
586             }
587             return;
588         }
589         if (logger.isDebugEnabled()) {
590             logger.debug("Cleaning up temporary resources created for testing ...");
591         }
592         for (PermissionValue pv : permValues.values()) {
593             deletePermission(pv.getPermissionId());
594         }
595         for (RoleValue rv : roleValues.values()) {
596             deleteRole(rv.getRoleId());
597         }
598     }
599
600     /**
601      * Creates the permission.
602      *
603      * @param resName the res name
604      * @param effect the effect
605      * @return the string
606      */
607     private String createPermission(String resName, EffectType effect) {
608         setupCreate();
609         PermissionClient permClient = new PermissionClient();
610         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
611         Permission permission = PermissionFactory.createPermissionInstance(resName,
612                 "default permissions for " + resName,
613                 actions, effect, true, true, true);
614         ClientResponse<Response> res = null;
615         String id = null;
616         try {
617             res = permClient.create(permission);
618             int statusCode = res.getStatus();
619             if (logger.isDebugEnabled()) {
620                 logger.debug("createPermission: resName=" + resName
621                         + " status = " + statusCode);
622             }
623             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
624                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
625             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
626             id = extractId(res);
627         } finally {
628             if (res != null) {
629                 res.releaseConnection();
630             }
631         }
632         return id;
633     }
634
635     /**
636      * Delete permission.
637      *
638      * @param permId the perm id
639      */
640     private void deletePermission(String permId) {
641         setupDelete();
642         PermissionClient permClient = new PermissionClient();
643
644         ClientResponse<Response> res = null;
645         try {
646             res = permClient.delete(permId);
647             int statusCode = res.getStatus();
648             if (logger.isDebugEnabled()) {
649                 logger.debug("deletePermission: delete permission id="
650                         + permId + " status=" + statusCode);
651             }
652             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
653                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
654             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
655
656         } finally {
657             if (res != null) {
658                 res.releaseConnection();
659             }
660         }
661     }
662
663     /**
664      * Creates the role.
665      *
666      * @param roleName the role name
667      * @return the string
668      */
669     private String createRole(String roleName) {
670         setupCreate();
671         RoleClient roleClient = new RoleClient();
672
673         Role role = RoleFactory.createRoleInstance(roleName,
674                         roleName, //the display name
675                 "role for " + roleName, true);
676         role.setRoleGroup("something");
677         ClientResponse<Response> res = null;
678         String id = null;
679         try {
680             res = roleClient.create(role);
681             int statusCode = res.getStatus();
682             if (logger.isDebugEnabled()) {
683                 logger.debug("createRole: name=" + roleName
684                         + " status = " + statusCode);
685             }
686             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
687                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
688             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
689             id = extractId(res);
690         } finally {
691             if (res != null) {
692                 res.releaseConnection();
693             }
694         }
695         return id;
696     }
697
698     /**
699      * Delete role.
700      *
701      * @param roleId the role id
702      */
703     private void deleteRole(String roleId) {
704         setupDelete();
705         RoleClient roleClient = new RoleClient();
706         ClientResponse<Response> res = null;
707         try {
708             res = roleClient.delete(roleId);
709             int statusCode = res.getStatus();
710             if (logger.isDebugEnabled()) {
711                 logger.debug("deleteRole: delete role id=" + roleId
712                         + " status=" + statusCode);
713             }
714             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
715                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
716             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
717         } finally {
718             res.releaseConnection();
719         }
720
721     }
722 }