]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b92fc8a3ec83655c660318cf2acc14553069fb46
[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
31 import javax.ws.rs.core.Response;
32
33 import org.collectionspace.services.authorization.perms.EffectType;
34 import org.collectionspace.services.authorization.perms.Permission;
35 import org.collectionspace.services.authorization.perms.PermissionAction;
36 import org.collectionspace.services.authorization.PermissionRole;
37 import org.collectionspace.services.authorization.PermissionValue;
38 import org.collectionspace.services.authorization.Role;
39 import org.collectionspace.services.authorization.RoleValue;
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.RolePermissionClient;
44 import org.collectionspace.services.client.PermissionRoleFactory;
45 import org.collectionspace.services.client.RoleClient;
46 import org.collectionspace.services.client.RoleFactory;
47 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
48 import org.collectionspace.services.client.test.ServiceRequestType;
49 import org.testng.Assert;
50 import org.testng.annotations.Test;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53 import org.testng.annotations.AfterClass;
54 import org.testng.annotations.BeforeClass;
55
56 /**
57  * PermissionServiceTest, carries out tests against a
58  * deployed and running Permission, Role and PermissionRole Services.
59  * 
60  * $LastChangedRevision: 917 $
61  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
62  */
63 public class RolePermissionServiceTest extends AbstractServiceTestImpl<PermissionRole, PermissionRole,
64                 PermissionRole, PermissionRole> {
65
66     /** The Constant logger. */
67     private final static String CLASS_NAME = RolePermissionServiceTest.class.getName();
68     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
69     // Instance variables specific to this test.
70     final private static String TEST_MARKER = "_RolePermissionServiceTest";
71     final private static String TEST_ROLE_NAME = "ROLE";
72     final private static String NO_REL_SUFFIX = "-no-rel";
73     /** The perm values. */
74     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
75     /** The role values. */
76     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
77     private Date now = new Date();
78
79     /* (non-Javadoc)
80      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
81      */
82     @Override
83     protected String getServicePathComponent() throws Exception {
84         return new RolePermissionClient().getServicePathComponent();
85     }
86     
87     @Override
88     public String getServiceName() { 
89         return RoleClient.SERVICE_NAME; // RolePermission is a sub-resource of 'roles' resource.
90     }
91     
92     private String getRoleName() {
93         return TEST_ROLE_NAME + TEST_MARKER + now.toString();
94     }
95
96     /**
97      * The entity type expected from the JAX-RS Response object
98      */
99     public Class<PermissionRole> getEntityResponseType() {
100         return PermissionRole.class;
101     }
102     
103     /**
104      * Seed data.
105      * @throws Exception 
106      */
107     @BeforeClass(alwaysRun = true)
108     public void seedData() throws Exception {
109         String rn1 = getRoleName();
110         String r1RoleId = createRole(rn1);
111         RoleValue rv1 = new RoleValue();
112         rv1.setRoleId(r1RoleId);
113         rv1.setRoleName(rn1);
114         roleValues.put(rv1.getRoleName(), rv1);
115
116         String rn2 = getRoleName() + NO_REL_SUFFIX;
117         String r2RoleId = createRole(rn2);
118         RoleValue rv2 = new RoleValue();
119         rv2.setRoleId(r2RoleId);
120         rv2.setRoleName(rn2);
121         roleValues.put(rv2.getRoleName(), rv2);
122
123         String permId1 = createPermission("fooService" + TEST_MARKER);
124         Permission persistedPerm = readPermission(permId1);
125         PermissionValue pva1 = new PermissionValue();
126         pva1.setResourceName(persistedPerm.getResourceName());
127         pva1.setActionGroup(persistedPerm.getActionGroup());
128         pva1.setTenantId(persistedPerm.getTenantId());
129         pva1.setPermissionId(permId1);
130         permValues.put(pva1.getResourceName(), pva1);
131
132         String permId2 = createPermission("barService" + TEST_MARKER);
133         persistedPerm = readPermission(permId2);
134         PermissionValue pva2 = new PermissionValue();
135         pva2.setResourceName(persistedPerm.getResourceName());
136         pva2.setActionGroup(persistedPerm.getActionGroup());
137         pva2.setTenantId(persistedPerm.getTenantId());
138         pva2.setPermissionId(permId2);
139         permValues.put(pva2.getResourceName(), pva2);
140     }
141
142     /* (non-Javadoc)
143      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
144      */
145     @Override
146     protected CollectionSpaceClient getClientInstance() throws Exception {
147         return new RolePermissionClient();
148     }
149
150         @Override
151         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
152         return new RolePermissionClient(clientPropertiesFilename);
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     // ---------------------------------------------------------------
165     // CRUD tests : CREATE tests
166     // ---------------------------------------------------------------
167     // Success outcomes
168     /* (non-Javadoc)
169      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
170      */
171
172     @Override
173 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
174     public void create(String testName) throws Exception {
175         // Perform setup, such as initializing the type of service request
176         // (e.g. CREATE, DELETE), its valid and expected status codes, and
177         // its associated HTTP method name (e.g. POST, DELETE).
178         setupCreate();
179
180         // Submit the request to the service and store the response.
181         RoleValue rv = roleValues.get(getRoleName());
182         PermissionRole permRole = createPermissionRoleInstance(rv,
183                 permValues.values(), true, true);
184         RolePermissionClient client = new RolePermissionClient();
185         Response res = client.create(rv.getRoleId(), permRole);
186         try {
187             int statusCode = res.getStatus();
188             if (logger.isDebugEnabled()) {
189                 logger.debug(testName + ": status = " + statusCode);
190             }
191             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
192                     invalidStatusCodeMessage(testRequestType, statusCode));
193             Assert.assertEquals(statusCode, testExpectedStatusCode);
194
195             knownResourceId = extractId(res); //This is meaningless in this test, see getKnowResourceId() method for details
196             if (logger.isDebugEnabled()) {
197                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
198             }
199         } finally {
200             if (res != null) {
201                 res.close();
202             }
203         }
204     }
205
206     //to not cause uniqueness violation for permRole, createList is removed
207     /* (non-Javadoc)
208      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
209      */
210     @Override
211 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
212 //      dependsOnMethods = {"create"})
213     public void createList(String testName) throws Exception {
214         //Should this really be empty?
215     }
216
217     // Failure outcomes
218     // Placeholders until the three tests below can be uncommented.
219     // See Issue CSPACE-401.
220     /* (non-Javadoc)
221      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
222      */
223     @Override
224     public void createWithEmptyEntityBody(String testName) throws Exception {
225         //Should this really be empty?
226     }
227
228     /* (non-Javadoc)
229      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
230      */
231     @Override
232     public void createWithMalformedXml(String testName) throws Exception {
233         //Should this really be empty?
234     }
235
236     /* (non-Javadoc)
237      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
238      */
239     @Override
240     public void createWithWrongXmlSchema(String testName) throws Exception {
241         //Should this really be empty?
242     }
243
244     // ---------------------------------------------------------------
245     // CRUD tests : READ tests
246     // ---------------------------------------------------------------
247     // Success outcomes
248     /* (non-Javadoc)
249      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
250      */
251     @Override
252 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
253 //      dependsOnMethods = {"create"})
254     public void read(String testName) throws Exception {
255         // Perform setup.
256         setupRead();
257
258         // Submit the request to the service and store the response.
259         RolePermissionClient client = new RolePermissionClient();
260         Response res = client.read(roleValues.get(getRoleName()).getRoleId());
261         try {
262             int statusCode = res.getStatus();
263
264             // Check the status code of the response: does it match
265             // the expected response(s)?
266             if (logger.isDebugEnabled()) {
267                 logger.debug(testName + ": status = " + statusCode);
268             }
269             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
270                     invalidStatusCodeMessage(testRequestType, statusCode));
271             Assert.assertEquals(statusCode, testExpectedStatusCode);
272
273             PermissionRole output = res.readEntity(PermissionRole.class);
274             Assert.assertNotNull(output);
275         } finally {
276             if (res != null) {
277                 res.close();
278             }
279         }
280     }
281
282     // Failure outcomes
283     /* (non-Javadoc)
284      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
285      */
286     @Override
287 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
288     public void readNonExistent(String testName) throws Exception {
289         // Perform setup.
290         setupReadNonExistent();
291
292         // Submit the request to the service and store the response.
293         RolePermissionClient client = new RolePermissionClient();
294         Response res = client.read(NON_EXISTENT_ID);
295         try {
296             int statusCode = res.getStatus();
297
298             // Check the status code of the response: does it match
299             // the expected response(s)?
300             if (logger.isDebugEnabled()) {
301                 logger.debug(testName + ": status = " + statusCode);
302             }
303             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
304                     invalidStatusCodeMessage(testRequestType, statusCode));
305             Assert.assertEquals(statusCode, testExpectedStatusCode);
306         } finally {
307             if (res != null) {
308                 res.close();
309             }
310         }
311     }
312
313     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
314     public void readNoRelationship(String testName) throws Exception {
315         setupRead();
316         // Submit the request to the service and store the response.
317         RolePermissionClient client = new RolePermissionClient();
318         Response res = client.read(roleValues.get(getRoleName() + NO_REL_SUFFIX).getRoleId());
319         try {
320             int statusCode = res.getStatus();
321
322             // Check the status code of the response: does it match
323             // the expected response(s)?
324             if (logger.isDebugEnabled()) {
325                 logger.debug(testName + ": status = " + statusCode);
326             }
327             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
328                     invalidStatusCodeMessage(testRequestType, statusCode));
329             Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
330             PermissionRole output = res.readEntity(PermissionRole.class);
331
332             String sOutput = objectAsXmlString(output, PermissionRole.class);
333             if (logger.isDebugEnabled()) {
334                 logger.debug(testName + " received " + sOutput);
335             }
336         } finally {
337             if (res != null) {
338                 res.close();
339             }
340         }
341     }
342
343     // ---------------------------------------------------------------
344     // CRUD tests : READ_LIST tests
345     // ---------------------------------------------------------------
346     // Success outcomes
347     /* (non-Javadoc)
348      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
349      */
350     @Override
351 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 //      dependsOnMethods = {"createList", "read"})
353     public void readList(String testName) throws Exception {
354         //Should this really be empty?
355     }
356
357     // Failure outcomes
358     // None at present.
359     // ---------------------------------------------------------------
360     // CRUD tests : UPDATE tests
361     // ---------------------------------------------------------------
362     // Success outcomes
363     /* (non-Javadoc)
364      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
365      */
366     @Override
367 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
368 //      dependsOnMethods = {"read", "readList", "readNonExistent"})
369     public void update(String testName) throws Exception {
370         //Should this really be empty?
371     }
372
373     // Failure outcomes
374     // Placeholders until the three tests below can be uncommented.
375     // See Issue CSPACE-401.
376     /* (non-Javadoc)
377      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
378      */
379     @Override
380     public void updateWithEmptyEntityBody(String testName) throws Exception {
381         //Should this really be empty?
382     }
383
384     /* (non-Javadoc)
385      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
386      */
387     @Override
388     public void updateWithMalformedXml(String testName) throws Exception {
389         //Should this really be empty?
390     }
391
392     /* (non-Javadoc)
393      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
394      */
395     @Override
396     public void updateWithWrongXmlSchema(String testName) throws Exception {
397         //Should this really be empty?
398     }
399
400     /* (non-Javadoc)
401      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
402      */
403     @Override
404 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
405 //    dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
406     public void updateNonExistent(String testName) throws Exception {
407         //Should this really be empty?
408     }
409
410     // ---------------------------------------------------------------
411     // CRUD tests : DELETE tests
412     // ---------------------------------------------------------------
413     // Success outcomes
414     /* (non-Javadoc)
415      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
416      */
417     @Override
418 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
419 //    dependsOnMethods = {"read"})
420     public void delete(String testName) throws Exception {
421         // Perform setup.
422         setupDelete();
423                 
424         // Submit the request to the service and store the response.
425         RolePermissionClient client = new RolePermissionClient();
426         RoleValue rv = roleValues.get(getRoleName());
427         Response delRes = client.delete(rv.getRoleId());
428         try {
429             int statusCode = delRes.getStatus();
430             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
431                     invalidStatusCodeMessage(testRequestType, statusCode));
432             Assert.assertEquals(statusCode, testExpectedStatusCode);
433         } finally {
434             if (delRes != null) {
435                 delRes.close();
436             }
437         }
438
439         // reset for next delete
440         create(testName);
441         setupDelete();
442         
443         rv = roleValues.get(getRoleName());
444         Response readResponse = client.read(rv.getRoleId());
445         PermissionRole toDelete = null;
446         try {
447                 toDelete = readResponse.readEntity(PermissionRole.class);
448         } finally {
449                 readResponse.close();
450         }
451         
452         rv = toDelete.getRole().get(0);
453         Response res = client.delete(rv.getRoleId(), toDelete);
454         try {
455             int statusCode = res.getStatus();
456             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
457                     invalidStatusCodeMessage(testRequestType, statusCode));
458             Assert.assertEquals(statusCode, testExpectedStatusCode);
459         } finally {
460             if (res != null) {
461                 res.close();
462             }
463         }
464     }
465
466     // Failure outcomes
467     /* (non-Javadoc)
468      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
469      */
470     @Override
471 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
472     public void deleteNonExistent(String testName) throws Exception {
473         //ignoring this test as the service side returns 200 now even if it does
474         //not find a record in the db
475     }
476     
477     // ---------------------------------------------------------------
478     // Search tests
479     // ---------------------------------------------------------------
480     
481     @Override
482 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
483     public void searchWorkflowDeleted(String testName) throws Exception {
484         // Fixme: null test for now, overriding test in base class
485     }
486
487     // ---------------------------------------------------------------
488     // Utility tests : tests of code used in tests above
489     // ---------------------------------------------------------------
490     /**
491      * Tests the code for manually submitting data that is used by several
492      * of the methods above.
493      */
494     @Override
495 //    @Test(dependsOnMethods = {"create"}) //FIXME: REM - This is not a test of a submit to the permroles service, but to just authorization/roles
496     public void testSubmitRequest() {
497
498         // Expected status code: 200 OK
499         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
500
501         // Submit the request to the service and store the response.
502         String method = ServiceRequestType.READ.httpMethodName();
503         String url = getResourceURL(roleValues.get(getRoleName()).getRoleId());
504         int statusCode = submitRequest(method, url);
505
506         // Check the status code of the response: does it match
507         // the expected response(s)?
508         if (logger.isDebugEnabled()) {
509             logger.debug("testSubmitRequest: url=" + url
510                     + " status=" + statusCode);
511         }
512         Assert.assertEquals(statusCode, EXPECTED_STATUS);
513     }
514
515     // ---------------------------------------------------------------
516     // Utility methods used by tests above
517     // ---------------------------------------------------------------
518     /**
519      * create PermissionRole instance
520      * @param rv rolevalue
521      * @param pvs permission value array
522      * @param usePermId 
523      * @param useRoleId
524      * @return PermissionRole
525      */
526     public static PermissionRole createPermissionRoleInstance(RoleValue rv,
527             Collection<PermissionValue> pvs,
528             boolean usePermId,
529             boolean useRoleId) {
530         List<PermissionValue> pvls = new ArrayList<PermissionValue>();
531         pvls.addAll(pvs);
532         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
533                 rv, pvls, usePermId, useRoleId);
534         if (logger.isDebugEnabled()) {
535             logger.debug("" +
536                     "permRole");
537             logger.debug(objectAsXmlString(permRole, PermissionRole.class));
538         }
539         return permRole;
540     }
541
542     /**
543      * Clean up.
544      * @throws Exception 
545      */
546     @AfterClass(alwaysRun = true)
547     @Override
548     public void cleanUp() throws Exception {
549         setupDelete();
550         String noTest = System.getProperty("noTestCleanup");
551         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
552             if (logger.isDebugEnabled()) {
553                 logger.debug("Skipping Cleanup phase ...");
554             }
555             return;
556         }
557         if (logger.isDebugEnabled()) {
558             logger.debug("Cleaning up temporary resources created for testing ...");
559         }
560         for (PermissionValue pv : permValues.values()) {
561             deletePermission(pv.getPermissionId());
562         }
563         for (RoleValue rv : roleValues.values()) {
564             deleteRole(rv.getRoleId());
565         }
566     }
567
568     /**
569      * Creates the permission.
570      *
571      * @param resName the res name
572      * @param effect the effect
573      * @return the string
574      * @throws Exception 
575      */
576     private String createPermission(String resName) throws Exception {
577         setupCreate();
578         PermissionClient permClient = new PermissionClient();
579         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
580         Permission permission = PermissionFactory.createPermissionInstance(resName,
581                 "default permissions for " + resName,
582                 actions, EffectType.PERMIT, true, true, true);
583         Response res = null;
584         String id = null;
585         try {
586             res = permClient.create(permission);
587             int statusCode = res.getStatus();
588             if (logger.isDebugEnabled()) {
589                 logger.debug("createPermission: resName=" + resName
590                         + " status = " + statusCode);
591             }
592             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
593                     invalidStatusCodeMessage(testRequestType, statusCode));
594             Assert.assertEquals(statusCode, testExpectedStatusCode);
595             id = extractId(res);
596         } finally {
597             if (res != null) {
598                 res.close();
599             }
600         }
601         return id;
602     }
603     
604     private Permission readPermission(String csid) throws Exception {
605         Permission result = null;
606         
607         setupRead();
608         PermissionClient permClient = new PermissionClient();
609         Response res = null;
610
611         try {
612             res = permClient.read(csid);
613             int statusCode = res.getStatus();
614             if (logger.isDebugEnabled()) {
615                 logger.debug("readPermission: csid=" + csid
616                         + " status = " + statusCode);
617             }
618             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
619                     invalidStatusCodeMessage(testRequestType, statusCode));
620             Assert.assertEquals(statusCode, testExpectedStatusCode);
621             result = (Permission) res.readEntity(Permission.class);
622         } finally {
623             if (res != null) {
624                 res.close();
625             }
626         }
627         return result;
628     }
629
630     /**
631      * Delete permission.
632      *
633      * @param permId the perm id
634      * @throws Exception 
635      */
636     private void deletePermission(String permId) throws Exception {
637         setupDelete();
638         PermissionClient permClient = new PermissionClient();
639
640         Response res = permClient.delete(permId);
641         try {
642             int statusCode = res.getStatus();
643             if (logger.isDebugEnabled()) {
644                 logger.debug("deletePermission: delete permission id="
645                         + permId + " status=" + statusCode);
646             }
647             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
648                     invalidStatusCodeMessage(testRequestType, statusCode));
649             Assert.assertEquals(statusCode, testExpectedStatusCode);
650
651         } finally {
652             if (res != null) {
653                 res.close();
654             }
655         }
656     }
657
658     /**
659      * Creates the role.
660      *
661      * @param roleName the role name
662      * @return the string
663      * @throws Exception 
664      */
665     private String createRole(String roleName) throws Exception {
666         setupCreate();
667         RoleClient roleClient = new RoleClient();
668
669         Role role = RoleFactory.createRoleInstance(roleName,
670                         roleName, //the display name
671                 "role for " + roleName, true, RoleFactory.EMPTY_PERMVALUE_LIST);
672         role.setRoleGroup("something");
673         Response res = null;
674         String id = null;
675         try {
676             res = roleClient.create(role);
677             int statusCode = res.getStatus();
678             if (logger.isDebugEnabled()) {
679                 logger.debug("createRole: name=" + roleName
680                         + " status = " + statusCode);
681             }
682             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
683                     invalidStatusCodeMessage(testRequestType, statusCode));
684             Assert.assertEquals(statusCode, testExpectedStatusCode);
685             id = extractId(res);
686         } finally {
687             if (res != null) {
688                 res.close();
689             }
690         }
691         return id;
692     }
693
694     /**
695      * Delete role.
696      *
697      * @param roleId the role id
698      * @throws Exception 
699      */
700     private void deleteRole(String roleId) throws Exception {
701         setupDelete();
702         RoleClient roleClient = new RoleClient();
703         Response res = null;
704         try {
705             res = roleClient.delete(roleId);
706             int statusCode = res.getStatus();
707             if (logger.isDebugEnabled()) {
708                 logger.debug("deleteRole: delete role id=" + roleId
709                         + " status=" + statusCode);
710             }
711             Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
712                     invalidStatusCodeMessage(testRequestType, statusCode));
713             Assert.assertEquals(statusCode, testExpectedStatusCode);
714         } finally {
715             res.close();
716         }
717
718     }
719
720         @Override
721         protected PermissionRole createInstance(String commonPartName,
722                         String identifier) {
723                 // TODO Auto-generated method stub
724                 return null;
725         }
726
727         @Override
728         protected PermissionRole updateInstance(PermissionRole commonPartObject) {
729                 // TODO Auto-generated method stub
730                 return null;
731         }
732
733         @Override
734         protected void compareUpdatedInstances(PermissionRole original,
735                         PermissionRole updated) throws Exception {
736                 // TODO Auto-generated method stub
737                 
738         }
739
740         @Override
741         protected Class<PermissionRole> getCommonListType() {
742                 // TODO Auto-generated method stub
743                 return null;
744         }
745
746     @Override
747     protected String getKnowResourceId() {
748         return roleValues.get(getRoleName()).getRoleId();
749     }
750         
751         @Override
752         protected long getSizeOfList(PermissionRole permRole) {
753                 // TODO Auto-generated method stub
754                 throw new UnsupportedOperationException("Method getSizeOfList() is not implemented because this service does not support lists.");
755         }
756     
757     /*
758      * For convenience and terseness, this test method is the base of the test execution dependency chain.  Other test methods may
759      * refer to this method in their @Test annotation declarations.
760      */
761     @Override
762     @Test(dataProvider = "testName",
763                 dependsOnMethods = {
764                         "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})    
765     public void CRUDTests(String testName) {
766         // Do nothing.  Simply here to for a TestNG execution order for our tests
767     }
768 }