]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bb33ec820b464d635eedde4611eced412814bf89
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permRoles and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.authorization.client.test;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Date;
28 import java.util.Hashtable;
29 import java.util.List;
30 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.authorization.EffectType;
32
33 import org.collectionspace.services.authorization.Permission;
34 import org.collectionspace.services.authorization.PermissionAction;
35 import org.collectionspace.services.authorization.PermissionRole;
36 import org.collectionspace.services.authorization.PermissionValue;
37 import org.collectionspace.services.authorization.Role;
38 import org.collectionspace.services.authorization.RoleValue;
39 import org.collectionspace.services.client.CollectionSpaceClient;
40 import org.collectionspace.services.client.PermissionClient;
41 import org.collectionspace.services.client.PermissionFactory;
42 import org.collectionspace.services.client.RolePermissionClient;
43 import org.collectionspace.services.client.PermissionRoleFactory;
44 import org.collectionspace.services.client.RoleClient;
45 import org.collectionspace.services.client.RoleFactory;
46 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
47 import org.collectionspace.services.client.test.ServiceRequestType;
48 import org.collectionspace.services.jaxb.AbstractCommonList;
49 import org.jboss.resteasy.client.ClientResponse;
50
51 import org.testng.Assert;
52 import org.testng.annotations.Test;
53
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.BeforeClass;
58
59 /**
60  * PermissionServiceTest, carries out tests against a
61  * deployed and running Permission, Role and PermissionRole Services.
62  * 
63  * $LastChangedRevision: 917 $
64  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
65  */
66 public class RolePermissionServiceTest extends AbstractServiceTestImpl {
67
68     /** The Constant logger. */
69     private final static String CLASS_NAME = RolePermissionServiceTest.class.getName();
70     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
71     // Instance variables specific to this test.
72     /** The known resource id. */
73     private String knownResourceId = null;
74     /** The all resource ids created. */
75     private List<String> allResourceIdsCreated = new ArrayList<String>();
76     final private static String TEST_MARKER = "_RolePermissionServiceTest";
77     final private static String TEST_ROLE_NAME = "ROLE";
78     final private static String NO_REL_SUFFIX = "-no-rel";
79     /** The perm values. */
80     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
81     /** The role values. */
82     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
83     private Date now = new Date();
84     /*
85      * This method is called only by the parent class, AbstractServiceTestImpl
86      */
87
88     /* (non-Javadoc)
89      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
90      */
91     @Override
92     protected String getServicePathComponent() {
93         return new RolePermissionClient().getServicePathComponent();
94     }
95
96     private String getRoleName() {
97         return TEST_ROLE_NAME + TEST_MARKER + now.toString();
98     }
99
100     /**
101      * Seed data.
102      */
103     @BeforeClass(alwaysRun = true)
104     public void seedData() {
105
106         String rn1 = getRoleName();
107         String r1RoleId = createRole(rn1);
108         RoleValue rv1 = new RoleValue();
109         rv1.setRoleId(r1RoleId);
110         rv1.setRoleName(rn1);
111         roleValues.put(rv1.getRoleName(), rv1);
112
113         String rn2 = getRoleName() + NO_REL_SUFFIX;
114         String r2RoleId = createRole(rn2);
115         RoleValue rv2 = new RoleValue();
116         rv2.setRoleId(r2RoleId);
117         rv2.setRoleName(rn2);
118         roleValues.put(rv2.getRoleName(), rv2);
119
120         String ra1 = "fooService" + TEST_MARKER;
121         String permId1 = createPermission(ra1, EffectType.PERMIT);
122         PermissionValue pva1 = new PermissionValue();
123         pva1.setResourceName(ra1);
124         pva1.setPermissionId(permId1);
125         permValues.put(pva1.getResourceName(), pva1);
126
127         String ra2 = "barService" + TEST_MARKER;
128         String permId2 = createPermission(ra1, EffectType.PERMIT);
129         PermissionValue pva2 = new PermissionValue();
130         pva2.setResourceName(ra2);
131         pva2.setPermissionId(permId2);
132         permValues.put(pva2.getResourceName(), pva2);
133     }
134
135     /* (non-Javadoc)
136      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
137      */
138     @Override
139     protected CollectionSpaceClient getClientInstance() {
140         return new RolePermissionClient();
141     }
142
143     /* (non-Javadoc)
144      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
145      */
146     @Override
147     protected AbstractCommonList getAbstractCommonList(
148             ClientResponse<AbstractCommonList> response) {
149         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
150         throw new UnsupportedOperationException();
151     }
152
153     /* (non-Javadoc)
154      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
155      */
156     @Test(dataProvider = "testName")
157     @Override
158     public void readPaginatedList(String testName) throws Exception {
159         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
160     }
161     // ---------------------------------------------------------------
162     // CRUD tests : CREATE tests
163     // ---------------------------------------------------------------
164     // Success outcomes
165     /* (non-Javadoc)
166      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
167      */
168
169     @Override
170     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
171     public void create(String testName) throws Exception {
172
173         if (logger.isDebugEnabled()) {
174             logger.debug(testBanner(testName, CLASS_NAME));
175         }
176         ;
177         // Perform setup, such as initializing the type of service request
178         // (e.g. CREATE, DELETE), its valid and expected status codes, and
179         // its associated HTTP method name (e.g. POST, DELETE).
180         setupCreate();
181
182         // Submit the request to the service and store the response.
183         RoleValue rv = roleValues.get(getRoleName());
184         PermissionRole permRole = createPermissionRoleInstance(rv,
185                 permValues.values(), true, true);
186         RolePermissionClient client = new RolePermissionClient();
187         ClientResponse<Response> res = null;
188         try {
189             res = client.create(rv.getRoleId(), permRole);
190
191             int statusCode = res.getStatus();
192
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(
275                     roleValues.get(getRoleName()).getRoleId(), "123");
276             int statusCode = res.getStatus();
277
278             // Check the status code of the response: does it match
279             // the expected response(s)?
280             if (logger.isDebugEnabled()) {
281                 logger.debug(testName + ": status = " + statusCode);
282             }
283             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
284                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
285             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
286
287             PermissionRole output = (PermissionRole) res.getEntity();
288             Assert.assertNotNull(output);
289         } finally {
290             if (res != null) {
291                 res.releaseConnection();
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         ;
308         // Perform setup.
309         setupReadNonExistent();
310
311         // Submit the request to the service and store the response.
312         RolePermissionClient client = new RolePermissionClient();
313         ClientResponse<PermissionRole> res = null;
314         try {
315
316             res = client.read(NON_EXISTENT_ID, "123");
317             int statusCode = res.getStatus();
318
319             // Check the status code of the response: does it match
320             // the expected response(s)?
321             if (logger.isDebugEnabled()) {
322                 logger.debug(testName + ": status = " + statusCode);
323             }
324             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
325                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
326             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
327         } finally {
328             if (res != null) {
329                 res.releaseConnection();
330             }
331         }
332     }
333
334     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
335     public void readNoRelationship(String testName) throws Exception {
336
337         if (logger.isDebugEnabled()) {
338             logger.debug(testBanner(testName, CLASS_NAME));
339         }
340         ;
341         setupRead();
342         // Submit the request to the service and store the response.
343         RolePermissionClient client = new RolePermissionClient();
344         ClientResponse<PermissionRole> res = null;
345         try {
346
347             res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId(), "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             PermissionRole output = (PermissionRole) res.getEntity();
359
360             String sOutput = objectAsXmlString(output, PermissionRole.class);
361             if(logger.isDebugEnabled()) {
362                 logger.debug(testName + " received " + sOutput);
363             }
364         } finally {
365             if (res != null) {
366                 res.releaseConnection();
367             }
368         }
369     }
370
371     // ---------------------------------------------------------------
372     // CRUD tests : READ_LIST tests
373     // ---------------------------------------------------------------
374     // Success outcomes
375     /* (non-Javadoc)
376      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
377      */
378     @Override
379     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
380     dependsOnMethods = {"createList", "read"})
381     public void readList(String testName) throws Exception {
382         //Should this really be empty?
383     }
384
385     // Failure outcomes
386     // None at present.
387     // ---------------------------------------------------------------
388     // CRUD tests : UPDATE tests
389     // ---------------------------------------------------------------
390     // Success outcomes
391     /* (non-Javadoc)
392      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
393      */
394     @Override
395     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
396     dependsOnMethods = {"read", "readList", "readNonExistent"})
397     public void update(String testName) throws Exception {
398         //Should this really be empty?
399     }
400
401     // Failure outcomes
402     // Placeholders until the three tests below can be uncommented.
403     // See Issue CSPACE-401.
404     /* (non-Javadoc)
405      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
406      */
407     @Override
408     public void updateWithEmptyEntityBody(String testName) throws Exception {
409         //Should this really be empty?
410     }
411
412     /* (non-Javadoc)
413      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
414      */
415     @Override
416     public void updateWithMalformedXml(String testName) throws Exception {
417         //Should this really be empty?
418     }
419
420     /* (non-Javadoc)
421      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
422      */
423     @Override
424     public void updateWithWrongXmlSchema(String testName) throws Exception {
425         //Should this really be empty?
426     }
427
428     /* (non-Javadoc)
429      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
430      */
431     @Override
432     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
433     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
434     public void updateNonExistent(String testName) throws Exception {
435         //Should this really be empty?
436     }
437
438     // ---------------------------------------------------------------
439     // CRUD tests : DELETE tests
440     // ---------------------------------------------------------------
441     // Success outcomes
442     /* (non-Javadoc)
443      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
444      */
445     @Override
446     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
447     dependsOnMethods = {"read"})
448     public void delete(String testName) throws Exception {
449
450         if (logger.isDebugEnabled()) {
451             logger.debug(testBanner(testName, CLASS_NAME));
452         }
453         ;
454         // Perform setup.
455         setupDelete();
456
457         // Submit the request to the service and store the response.
458         RolePermissionClient client = new RolePermissionClient();
459         ClientResponse<Response> res = null;
460         try {
461             res = client.delete(
462                     roleValues.get(getRoleName()).getRoleId(), "123");
463             int statusCode = res.getStatus();
464
465             // Check the status code of the response: does it match
466             // the expected response(s)?
467             if (logger.isDebugEnabled()) {
468                 logger.debug(testName + ": status = " + statusCode);
469             }
470             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
471                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
472             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
473         } finally {
474             if (res != null) {
475                 res.releaseConnection();
476             }
477         }
478     }
479
480     // Failure outcomes
481     /* (non-Javadoc)
482      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
483      */
484     @Override
485     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
486     public void deleteNonExistent(String testName) throws Exception {
487         //ignoring this test as the service side returns 200 now even if it does
488         //not find a record in the db
489     }
490
491     // ---------------------------------------------------------------
492     // Utility tests : tests of code used in tests above
493     // ---------------------------------------------------------------
494     /**
495      * Tests the code for manually submitting data that is used by several
496      * of the methods above.
497      * @throws Exception 
498      */
499     @Test(dependsOnMethods = {"create"})
500     public void testSubmitRequest() throws Exception {
501
502         // Expected status code: 200 OK
503         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
504
505         // Submit the request to the service and store the response.
506         String method = ServiceRequestType.READ.httpMethodName();
507         String url = getResourceURL(roleValues.get(getRoleName()).getRoleId());
508         int statusCode = submitRequest(method, url);
509
510         // Check the status code of the response: does it match
511         // the expected response(s)?
512         if (logger.isDebugEnabled()) {
513             logger.debug("testSubmitRequest: url=" + url
514                     + " status=" + statusCode);
515         }
516         Assert.assertEquals(statusCode, EXPECTED_STATUS);
517
518
519     }
520
521     // ---------------------------------------------------------------
522     // Utility methods used by tests above
523     // ---------------------------------------------------------------
524     /**
525      * create PermissionRole instance
526      * @param rv rolevalue
527      * @param pvs permission value array
528      * @param usePermId 
529      * @param useRoleId
530      * @return PermissionRole
531      */
532     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
533             Collection<PermissionValue> pvs,
534             boolean usePermId,
535             boolean useRoleId) {
536         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
537         pvls.addAll(pvs);
538         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
539                 rv, pvls, usePermId, useRoleId);
540         if (logger.isDebugEnabled()) {
541             logger.debug("to be created, permRole");
542             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
543         }
544         return permRole;
545     }
546
547     /**
548      * Clean up.
549      */
550     @AfterClass(alwaysRun = true)
551     @Override
552     public void cleanUp() {
553         setupDelete();
554         String noTest = System.getProperty("noTestCleanup");
555         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
556             if (logger.isDebugEnabled()) {
557                 logger.debug("Skipping Cleanup phase ...");
558             }
559             return;
560         }
561         if (logger.isDebugEnabled()) {
562             logger.debug("Cleaning up temporary resources created for testing ...");
563         }
564
565         RolePermissionClient client = new RolePermissionClient();
566         for (String resourceId : allResourceIdsCreated) {
567
568             ClientResponse<Response> res = client.delete(resourceId, "123");
569             int statusCode = res.getStatus();
570             try {
571                 if (logger.isDebugEnabled()) {
572                     logger.debug("cleanup: delete relationships for permission id="
573                             + resourceId + " status=" + statusCode);
574                 }
575                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578             } finally {
579                 res.releaseConnection();
580             }
581         }
582
583         for (PermissionValue pv : permValues.values()) {
584             deletePermission(pv.getPermissionId());
585         }
586         for (RoleValue rv : roleValues.values()) {
587             deleteRole(rv.getRoleId());
588         }
589     }
590
591     /**
592      * Creates the permission.
593      *
594      * @param resName the res name
595      * @param effect the effect
596      * @return the string
597      */
598     private String createPermission(String resName, EffectType effect) {
599         setupCreate();
600         PermissionClient permClient = new PermissionClient();
601         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
602         Permission permission = PermissionFactory.createPermissionInstance(resName,
603                 "default permissions for " + resName,
604                 actions, effect, true, true, true);
605         ClientResponse<Response> res = null;
606         String id = null;
607         try {
608             res = permClient.create(permission);
609             int statusCode = res.getStatus();
610             if (logger.isDebugEnabled()) {
611                 logger.debug("createPermission: resName=" + resName
612                         + " status = " + statusCode);
613             }
614             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617             id = extractId(res);
618         } finally {
619             if (res != null) {
620                 res.releaseConnection();
621             }
622         }
623         return id;
624     }
625
626     /**
627      * Delete permission.
628      *
629      * @param permId the perm id
630      */
631     private void deletePermission(String permId) {
632         setupDelete();
633         PermissionClient permClient = new PermissionClient();
634
635         ClientResponse<Response> res = null;
636         try {
637             res = permClient.delete(permId);
638             int statusCode = res.getStatus();
639             if (logger.isDebugEnabled()) {
640                 logger.debug("deletePermission: delete permission id="
641                         + permId + " status=" + statusCode);
642             }
643             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
644                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
645             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
646
647         } finally {
648             if (res != null) {
649                 res.releaseConnection();
650             }
651         }
652     }
653
654     /**
655      * Creates the role.
656      *
657      * @param roleName the role name
658      * @return the string
659      */
660     private String createRole(String roleName) {
661         setupCreate();
662         RoleClient roleClient = new RoleClient();
663
664         Role role = RoleFactory.createRoleInstance(roleName,
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 }