]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
cf6a617606dc0f6d411adde46474ced649c33f78
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permRoles and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.authorization.client.test;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Hashtable;
28 import java.util.List;
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.jaxb.AbstractCommonList;
32 import org.collectionspace.services.authorization.perms.EffectType;
33 import org.collectionspace.services.authorization.perms.Permission;
34 import org.collectionspace.services.authorization.perms.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
40 import org.collectionspace.services.client.CollectionSpaceClient;
41 import org.collectionspace.services.client.PermissionClient;
42 import org.collectionspace.services.client.PermissionFactory;
43 import org.collectionspace.services.client.PermissionRoleClient;
44 import org.collectionspace.services.client.PermissionRoleFactory;
45 import org.collectionspace.services.client.RoleClient;
46 import org.collectionspace.services.client.RoleFactory;
47
48 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
49 import org.collectionspace.services.client.test.ServiceRequestType;
50
51 import org.jboss.resteasy.client.ClientResponse;
52
53 import org.testng.Assert;
54 import org.testng.annotations.Test;
55
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.testng.annotations.AfterClass;
59 import org.testng.annotations.BeforeClass;
60
61 /**
62  * PermissionServiceTest, carries out tests against a
63  * deployed and running Permission, Role and PermissionRole Services.
64  * 
65  * $LastChangedRevision: 917 $
66  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
67  */
68 public class PermissionRoleServiceTest extends AbstractServiceTestImpl {
69
70     /** The Constant logger. */
71     private final static String CLASS_NAME = PermissionRoleServiceTest.class.getName();
72     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
73     // Instance variables specific to this test.
74     /** The known resource id. */
75     private String knownResourceId = null;
76     /** The all resource ids created. */
77     private List<String> allResourceIdsCreated = new ArrayList<String>();
78     final private static String TEST_MARKER = "_PermissionRoleServiceTest";
79     final private static String TEST_SERVICE_NAME = "fakeservice";
80     final private static String NO_REL_SUFFIX = "-no-rel";
81     /** The perm values. */
82     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
83     /** The role values. */
84     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
85     /*
86      * This method is called only by the parent class, AbstractServiceTestImpl
87      */
88
89     /* (non-Javadoc)
90      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
91      */
92     @Override
93     protected String getServicePathComponent() {
94         return new PermissionRoleClient().getServicePathComponent();
95     }
96     
97         @Override
98         protected String getServiceName() {
99         return PermissionClient.SERVICE_NAME; //Since we're a sub-resource of permission service return its name?
100         }
101
102     /**
103      * Seed data.
104      */
105     @BeforeClass(alwaysRun = true)
106     public void seedData() {
107         String ra = TEST_SERVICE_NAME + TEST_MARKER;
108         String accPermId = createPermission(ra, EffectType.PERMIT);
109         PermissionValue pva = new PermissionValue();
110         pva.setResourceName(ra);
111         pva.setPermissionId(accPermId);
112         permValues.put(pva.getResourceName(), pva);
113
114         String rc = TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX;
115         String coPermId = createPermission(rc, EffectType.DENY);
116         PermissionValue pvc = new PermissionValue();
117         pvc.setResourceName(rc);
118         pvc.setPermissionId(coPermId);
119         permValues.put(pvc.getResourceName(), pvc);
120 //
121 //        String ri = "intakes";
122 //        String iPermId = createPermission(ri, EffectType.DENY);
123 //        PermissionValue pvi = new PermissionValue();
124 //        pvi.setResourceName(ri);
125 //        pvi.setPermissionId(iPermId);
126 //        permValues.put(pvi.getResourceName(), pvi);
127
128         String rn1 = "ROLE_CO1" + TEST_MARKER;
129         String r1RoleId = createRole(rn1);
130         RoleValue rv1 = new RoleValue();
131         rv1.setRoleId(r1RoleId);
132         rv1.setRoleName(rn1);
133         roleValues.put(rv1.getRoleName(), rv1);
134
135         String rn2 = "ROLE_CO2" + TEST_MARKER;
136         String r2RoleId = createRole(rn2);
137         RoleValue rv2 = new RoleValue();
138         rv2.setRoleId(r2RoleId);
139         rv2.setRoleName(rn2);
140         roleValues.put(rv2.getRoleName(), rv2);
141     }
142
143     /* (non-Javadoc)
144      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
145      */
146     @Override
147     protected CollectionSpaceClient getClientInstance() {
148         return new PermissionRoleClient();
149     }
150
151     /* (non-Javadoc)
152      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
153      */
154     @Override
155     protected AbstractCommonList getAbstractCommonList(
156             ClientResponse<AbstractCommonList> response) {
157         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
158         throw new UnsupportedOperationException();
159     }
160
161     /* (non-Javadoc)
162      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
163      */
164     @Test(dataProvider = "testName")
165     @Override
166     public void readPaginatedList(String testName) throws Exception {
167         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
168     }
169     // ---------------------------------------------------------------
170     // CRUD tests : CREATE tests
171     // ---------------------------------------------------------------
172     // Success outcomes
173     /* (non-Javadoc)
174      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
175      */
176
177     @Override
178     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
179     public void create(String testName) throws Exception {
180
181         if (logger.isDebugEnabled()) {
182             logger.debug(testBanner(testName, CLASS_NAME));
183         }
184
185         // Perform setup, such as initializing the type of service request
186         // (e.g. CREATE, DELETE), its valid and expected status codes, and
187         // its associated HTTP method name (e.g. POST, DELETE).
188         setupCreate();
189
190         // Submit the request to the service and store the response.
191         PermissionValue pv = permValues.get(TEST_SERVICE_NAME + TEST_MARKER);
192         PermissionRole permRole = createPermissionRoleInstance(pv,
193                 roleValues.values(), true, true);
194         PermissionRoleClient client = new PermissionRoleClient();
195         ClientResponse<Response> res = null;
196         try {
197             res = client.create(pv.getPermissionId(), permRole);
198             int statusCode = res.getStatus();
199
200             if (logger.isDebugEnabled()) {
201                 logger.debug(testName + ": status = " + statusCode);
202             }
203             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
204                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
205             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
206             res.releaseConnection();
207             // Store the ID returned from this create operation
208             // for additional tests below.
209             //this is is not important in case of this relationship
210             knownResourceId = extractId(res);
211             if (logger.isDebugEnabled()) {
212                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
213             }
214         } finally {
215             if (res != null) {
216                 res.releaseConnection();
217             }
218         }
219     }
220
221     //to not cause uniqueness violation for permRole, createList is removed
222     /* (non-Javadoc)
223      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
224      */
225     @Override
226     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
227     dependsOnMethods = {"create"})
228     public void createList(String testName) throws Exception {
229         //Should this really be empty?
230     }
231
232     // Failure outcomes
233     // Placeholders until the three tests below can be uncommented.
234     // See Issue CSPACE-401.
235     /* (non-Javadoc)
236      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
237      */
238     @Override
239     public void createWithEmptyEntityBody(String testName) throws Exception {
240         //Should this really be empty?
241     }
242
243     /* (non-Javadoc)
244      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
245      */
246     @Override
247     public void createWithMalformedXml(String testName) throws Exception {
248         //Should this really be empty?
249     }
250
251     /* (non-Javadoc)
252      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
253      */
254     @Override
255     public void createWithWrongXmlSchema(String testName) throws Exception {
256         //Should this really be empty?
257     }
258
259     // ---------------------------------------------------------------
260     // CRUD tests : READ tests
261     // ---------------------------------------------------------------
262     // Success outcomes
263     /* (non-Javadoc)
264      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
265      */
266     @Override
267     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268     dependsOnMethods = {"create"})
269     public void read(String testName) throws Exception {
270
271         if (logger.isDebugEnabled()) {
272             logger.debug(testBanner(testName, CLASS_NAME));
273         }
274         // Perform setup.
275         setupRead();
276
277         // Submit the request to the service and store the response.
278         PermissionRoleClient client = new PermissionRoleClient();
279         ClientResponse<PermissionRole> res = null;
280         try {
281             res = client.read(
282                     permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
283             assertStatusCode(res, testName);
284             PermissionRole output = (PermissionRole) res.getEntity();
285             Assert.assertNotNull(output);
286         } finally {
287             if (res != null) {
288                 res.releaseConnection();
289             }
290         }
291
292     }
293
294     // Failure outcomes
295     /* (non-Javadoc)
296      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
297      */
298     @Override
299     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
300     public void readNonExistent(String testName) throws Exception {
301
302         if (logger.isDebugEnabled()) {
303             logger.debug(testBanner(testName, CLASS_NAME));
304         }
305         // Perform setup.
306         setupReadNonExistent();
307
308         // Submit the request to the service and store the response.
309         PermissionRoleClient client = new PermissionRoleClient();
310         ClientResponse<PermissionRole> res = null;
311         try {
312             res = client.read(NON_EXISTENT_ID);
313             int statusCode = res.getStatus();
314
315             // Check the status code of the response: does it match
316             // the expected response(s)?
317             if (logger.isDebugEnabled()) {
318                 logger.debug(testName + ": status = " + statusCode);
319             }
320             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
321                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
322             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
323         } finally {
324             if (res != null) {
325                 res.releaseConnection();
326             }
327         }
328     }
329
330     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
331     dependsOnMethods = {"create"})
332     public void readNoRelationship(String testName) throws Exception {
333
334         if (logger.isDebugEnabled()) {
335             logger.debug(testBanner(testName, CLASS_NAME));
336         }
337         // Perform setup.
338         setupRead();
339
340         // Submit the request to the service and store the response.
341         PermissionRoleClient client = new PermissionRoleClient();
342         ClientResponse<PermissionRole> res = null;
343         try {
344             res = client.read(
345                     permValues.get(TEST_SERVICE_NAME + TEST_MARKER + NO_REL_SUFFIX).getPermissionId());
346             assertStatusCode(res, testName);
347             
348             PermissionRole output = (PermissionRole) res.getEntity();
349
350             String sOutput = objectAsXmlString(output, PermissionRole.class);
351             if (logger.isDebugEnabled()) {
352                 logger.debug(testName + " received " + sOutput);
353             }
354         } finally {
355             if (res != null) {
356                 res.releaseConnection();
357             }
358         }
359
360     }
361     // ---------------------------------------------------------------
362     // CRUD tests : READ_LIST tests
363     // ---------------------------------------------------------------
364     // Success outcomes
365     /* (non-Javadoc)
366      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
367      */
368
369     @Override
370     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
371     dependsOnMethods = {"createList", "read"})
372     public void readList(String testName) throws Exception {
373         //Should this really be empty?
374     }
375
376     // Failure outcomes
377     // None at present.
378     // ---------------------------------------------------------------
379     // CRUD tests : UPDATE tests
380     // ---------------------------------------------------------------
381     // Success outcomes
382     /* (non-Javadoc)
383      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
384      */
385     @Override
386     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
387     dependsOnMethods = {"read", "readList", "readNonExistent"})
388     public void update(String testName) throws Exception {
389         //Should this really be empty?
390     }
391
392     // Failure outcomes
393     // Placeholders until the three tests below can be uncommented.
394     // See Issue CSPACE-401.
395     /* (non-Javadoc)
396      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
397      */
398     @Override
399     public void updateWithEmptyEntityBody(String testName) throws Exception {
400         //Should this really be empty?
401     }
402
403     /* (non-Javadoc)
404      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
405      */
406     @Override
407     public void updateWithMalformedXml(String testName) throws Exception {
408         //Should this really be empty?
409     }
410
411     /* (non-Javadoc)
412      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
413      */
414     @Override
415     public void updateWithWrongXmlSchema(String testName) throws Exception {
416         //Should this really be empty?
417     }
418
419     /* (non-Javadoc)
420      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
421      */
422     @Override
423     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
424     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
425     public void updateNonExistent(String testName) throws Exception {
426         //Should this really be empty?
427     }
428
429     // ---------------------------------------------------------------
430     // CRUD tests : DELETE tests
431     // ---------------------------------------------------------------
432     // Success outcomes
433     /* (non-Javadoc)
434      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
435      */
436     @Override
437     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
438     dependsOnMethods = {"read"})
439     public void delete(String testName) throws Exception {
440
441         if (logger.isDebugEnabled()) {
442             logger.debug(testBanner(testName, CLASS_NAME));
443         }
444         // Perform setup.
445         setupDelete();
446
447         //
448         //
449         //
450         PermissionRoleClient client = new PermissionRoleClient();
451         ClientResponse<PermissionRole> readResponse = client.read(
452                         permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
453         PermissionRole toDelete = null;
454         try {
455                 toDelete = readResponse.getEntity();
456         } finally {
457                 readResponse.releaseConnection();
458         }        
459
460         ClientResponse<Response> res = client.delete(
461                         toDelete.getPermission().get(0).getPermissionId(), toDelete);
462         try {
463             int statusCode = res.getStatus();
464             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
465                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
466             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
467         } finally {
468             if (res != null) {
469                 res.releaseConnection();
470             }
471         }
472         
473         //
474         // recreate 'TEST_SERVICE_NAME + TEST_MARKER' account and roles
475         //
476         create(testName);
477         setupDelete();
478      
479         //
480         // Lookup a know permission, and delete all of its role relationships
481         //
482         readResponse = client.read(
483                         permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
484         toDelete = null;
485         try {
486                 toDelete = readResponse.getEntity();
487         } finally {
488                 readResponse.releaseConnection();
489         }
490
491         res = client.delete(toDelete.getPermission().get(0).getPermissionId());
492         try {
493             int statusCode = res.getStatus();
494             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
495                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
496             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
497         } finally {
498             res.releaseConnection();
499         }
500         
501     }
502
503     // Failure outcomes
504     /* (non-Javadoc)
505      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
506      */
507     @Override
508     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
509     public void deleteNonExistent(String testName) throws Exception {
510         //ignoring this test as the service side returns 200 now even if it does
511         //not find a record in the db
512     }
513     
514     // ---------------------------------------------------------------
515     // Search tests
516     // ---------------------------------------------------------------
517     
518     @Override
519     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
520     public void searchWorkflowDeleted(String testName) throws Exception {
521         // Fixme: null test for now, overriding test in base class
522     }
523
524     // ---------------------------------------------------------------
525     // Utility tests : tests of code used in tests above
526     // ---------------------------------------------------------------
527     /**
528      * Tests the code for manually submitting data that is used by several
529      * of the methods above.
530      * @throws Exception 
531      */
532     @Test(dependsOnMethods = {"create"})
533     public void testSubmitRequest() throws Exception { //FIXME: REM - This is testing /permissions not /permissions/permroles
534
535         // Expected status code: 200 OK
536         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
537
538         // Submit the request to the service and store the response.
539         String method = ServiceRequestType.READ.httpMethodName();
540         String url = getResourceURL(permValues.get(TEST_SERVICE_NAME + TEST_MARKER).getPermissionId());
541         int statusCode = submitRequest(method, url);
542
543         // Check the status code of the response: does it match
544         // the expected response(s)?
545         if (logger.isDebugEnabled()) {
546             logger.debug("testSubmitRequest: url=" + url
547                     + " status=" + statusCode);
548         }
549         Assert.assertEquals(statusCode, EXPECTED_STATUS);
550
551
552     }
553
554     // ---------------------------------------------------------------
555     // Utility methods used by tests above
556     // ---------------------------------------------------------------
557     /**
558      * create permRolerole instance
559      * @param pv permissionvalue
560      * @param rvs rolevalue array
561      * @param usePermId 
562      * @param useRoleId
563      * @return PermissionRole
564      */
565     public static PermissionRole createPermissionRoleInstance(PermissionValue pv,
566             Collection<RoleValue> rvs,
567             boolean usePermId,
568             boolean useRoleId) {
569
570         List<RoleValue> rvls = new ArrayList<RoleValue>();
571         rvls.addAll(rvs);
572         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
573                 pv, rvls, usePermId, useRoleId);
574         if (logger.isDebugEnabled()) {
575             logger.debug("to be created, permRole");
576             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
577         }
578         return permRole;
579     }
580
581     /**
582      * Clean up.
583      */
584     @AfterClass(alwaysRun = true)
585     @Override
586     public void cleanUp() {
587         setupDelete();
588         String noTest = System.getProperty("noTestCleanup");
589         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
590             if (logger.isDebugEnabled()) {
591                 logger.debug("Skipping Cleanup phase ...");
592             }
593             return;
594         }
595         if (logger.isDebugEnabled()) {
596             logger.debug("Cleaning up temporary resources created for testing ...");
597         }
598
599         for (PermissionValue pv : permValues.values()) {
600             deletePermission(pv.getPermissionId());
601         }
602         for (RoleValue rv : roleValues.values()) {
603             deleteRole(rv.getRoleId());
604         }
605     }
606
607     /**
608      * Creates the permission.
609      *
610      * @param resName the res name
611      * @param effect the effect
612      * @return the string
613      */
614     private String createPermission(String resName, EffectType effect) {
615         if (logger.isDebugEnabled()) {
616             logger.debug(testBanner("createPermission"));
617         }
618         setupCreate();
619         PermissionClient permClient = new PermissionClient();
620         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
621         Permission permission = PermissionFactory.createPermissionInstance(resName,
622                 "default permissions for " + resName,
623                 actions, effect, true, true, true);
624         String id = null;
625         ClientResponse<Response> res = null;
626         try {
627             res = permClient.create(permission);
628
629             int statusCode = res.getStatus();
630             if (logger.isDebugEnabled()) {
631                 logger.debug("createPermission: resName=" + resName
632                         + " status = " + statusCode);
633             }
634             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637             id = extractId(res);
638         } finally {
639             if (res != null) {
640                 res.releaseConnection();
641             }
642         }
643         return id;
644     }
645
646     /**
647      * Delete permission.
648      *
649      * @param permId the perm id
650      */
651     private void deletePermission(String permId) {
652         if (logger.isDebugEnabled()) {
653             logger.debug(testBanner("deletePermission"));
654         }
655         setupDelete();
656         PermissionClient permClient = new PermissionClient();
657         ClientResponse<Response> res = null;
658         try {
659             res = permClient.delete(permId);
660             int statusCode = res.getStatus();
661             if (logger.isDebugEnabled()) {
662                 logger.debug("deletePermission: delete permission id="
663                         + permId + " status=" + statusCode);
664             }
665             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
668         } finally {
669             res.releaseConnection();
670         }
671
672     }
673
674     /**
675      * Creates the role.
676      *
677      * @param roleName the role name
678      * @return the string
679      */
680     private String createRole(String roleName) {
681         if (logger.isDebugEnabled()) {
682             logger.debug(testBanner("createRole"));
683         }
684         setupCreate();
685         RoleClient roleClient = new RoleClient();
686
687         Role role = RoleFactory.createRoleInstance(roleName,
688                         roleName, //the display name
689                 "role for " + roleName, true);
690         ClientResponse<Response> res = null;
691         String id = null;
692         try {
693             res = roleClient.create(role);
694             int statusCode = res.getStatus();
695             if (logger.isDebugEnabled()) {
696                 logger.debug("createRole: name=" + roleName
697                         + " status = " + statusCode);
698             }
699             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702
703             id = extractId(res);
704         } finally {
705             res.releaseConnection();
706         }
707         return id;
708     }
709
710     /**
711      * Delete role.
712      *
713      * @param roleId the role id
714      */
715     private void deleteRole(String roleId) {
716         if (logger.isDebugEnabled()) {
717             logger.debug(testBanner("deleteRole"));
718         }
719         setupDelete();
720         RoleClient roleClient = new RoleClient();
721         ClientResponse<Response> res = null;
722         try {
723             res = roleClient.delete(roleId);
724             int statusCode = res.getStatus();
725             if (logger.isDebugEnabled()) {
726                 logger.debug("deleteRole: delete role id=" + roleId
727                         + " status=" + statusCode);
728             }
729             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
730                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
731             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
732         } finally {
733             res.releaseConnection();
734         }
735     }
736     
737 }