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