]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
65f66e498df67526dd27d9fa1648a57fcebcfa1b
[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 2010 University of California at Berkeley
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
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 /*
25  * To change this template, choose Tools | Templates
26  * and open the template in the editor.
27  */
28 package org.collectionspace.services.security.client.test;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Date;
33 import java.util.Hashtable;
34 import java.util.List;
35
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import org.jboss.resteasy.client.ClientResponse;
39
40 import org.collectionspace.services.account.AccountsCommon;
41 import org.collectionspace.services.authorization.AccountRole;
42 import org.collectionspace.services.authorization.AccountValue;
43 import org.collectionspace.services.authorization.perms.ActionType;
44 import org.collectionspace.services.authorization.perms.EffectType;
45 import org.collectionspace.services.authorization.perms.Permission;
46 import org.collectionspace.services.authorization.perms.PermissionAction;
47 import org.collectionspace.services.authorization.PermissionRole;
48 import org.collectionspace.services.authorization.PermissionValue;
49 import org.collectionspace.services.authorization.Role;
50 import org.collectionspace.services.authorization.RoleValue;
51 import org.collectionspace.services.client.AccountClient;
52 import org.collectionspace.services.client.AccountFactory;
53 import org.collectionspace.services.client.AccountRoleClient;
54 import org.collectionspace.services.client.AccountRoleFactory;
55 import org.collectionspace.services.client.CollectionSpaceClient;
56 import org.collectionspace.services.client.DimensionClient;
57 import org.collectionspace.services.client.DimensionFactory;
58 import org.collectionspace.services.client.IntakeClient;
59 import org.collectionspace.services.client.PayloadOutputPart;
60 import org.collectionspace.services.client.PermissionClient;
61 import org.collectionspace.services.client.PermissionFactory;
62 import org.collectionspace.services.client.PermissionRoleClient;
63 import org.collectionspace.services.client.PermissionRoleFactory;
64 import org.collectionspace.services.client.PoxPayloadIn;
65 import org.collectionspace.services.client.PoxPayloadOut;
66 import org.collectionspace.services.client.RoleClient;
67 import org.collectionspace.services.client.RoleFactory;
68 import org.collectionspace.services.client.test.BaseServiceTest;
69 import org.collectionspace.services.dimension.DimensionsCommon;
70 import org.collectionspace.services.intake.IntakesCommon;
71 import org.collectionspace.services.jaxb.AbstractCommonList;
72
73 import org.testng.Assert;
74 import org.testng.annotations.Test;
75 import org.testng.annotations.AfterClass;
76 import org.testng.annotations.BeforeClass;
77
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
80
81 /**
82  * AuthorizationServiceTest, carries out tests against a
83  * deployed and running Permission, Role, AccountRole, PermissionRole and
84  * CollectionObject Services.
85  *
86  * Pre-requisite : authorization-mgt/client tests seed some permissions used
87  * by this test
88  *
89  * $LastChangedRevision: 917 $
90  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
91  */
92 public class AuthorizationServiceTest extends BaseServiceTest<AbstractCommonList> {
93
94     private final String CLASS_NAME = AuthorizationServiceTest.class.getName();
95     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
96     // Instance variables specific to this test.
97     private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
98     //key for permValues is id as there could be several perms for the same resource
99     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
100     //key for roleValues is roleName
101     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
102     private String bigbirdPermId;
103     private String elmoPermId;
104     private final static String TEST_SERVICE_NAME = "dimensions";
105     private boolean accountRolesFlipped = false;
106     /*
107      * This method is called only by the parent class, AbstractServiceTestImpl
108      */
109
110     @Override
111         protected String getServiceName() {
112         // no need to return anything but null since no auth resources are
113         // accessed
114         throw new UnsupportedOperationException();
115         }
116         
117     @Override
118     protected String getServicePathComponent() {
119         // no need to return anything but null since no auth resources are
120         // accessed
121         throw new UnsupportedOperationException();
122     }
123
124     @BeforeClass(alwaysRun = true)
125     public void seedData() {
126         seedPermissions();
127         seedRoles();
128         seedAccounts();
129         seedAccountRoles();
130         seedPermissionRoles();
131     }
132
133     private void seedPermissions() {
134         String res = TEST_SERVICE_NAME;
135
136         PermissionAction pac = new PermissionAction();
137         pac.setName(ActionType.CREATE);
138         PermissionAction par = new PermissionAction();
139         par.setName(ActionType.READ);
140         PermissionAction pau = new PermissionAction();
141         pau.setName(ActionType.UPDATE);
142
143
144         //bigbird can create, read and update but not delete
145         List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
146         bbactions.add(pac);
147         bbactions.add(par);
148         bbactions.add(pau);
149         bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
150         PermissionValue bbpv = new PermissionValue();
151         bbpv.setResourceName(res);
152         bbpv.setPermissionId(bigbirdPermId);
153         permValues.put(bbpv.getPermissionId(), bbpv);
154
155         //elmo can only read
156         List<PermissionAction> eactions = new ArrayList<PermissionAction>();
157         eactions.add(par);
158         elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
159         PermissionValue epv = new PermissionValue();
160         epv.setResourceName(res);
161         epv.setPermissionId(elmoPermId);
162         permValues.put(epv.getPermissionId(), epv);
163     }
164
165     private void seedRoles() {
166         String rn1 = "ROLE_TEST_CM";
167         String r1RoleId = createRole(rn1);
168         RoleValue rv1 = new RoleValue();
169         rv1.setRoleId(r1RoleId);
170         rv1.setRoleName(rn1);
171         roleValues.put(rv1.getRoleName(), rv1);
172
173         String rn2 = "ROLE_TEST_INTERN";
174         String r2RoleId = createRole(rn2);
175         RoleValue rv2 = new RoleValue();
176         rv2.setRoleId(r2RoleId);
177         rv2.setRoleName(rn2);
178         roleValues.put(rv2.getRoleName(), rv2);
179     }
180
181     private void seedAccounts() {
182         String userId1 = "bigbird2010";
183         String accId1 = createAccount(userId1, "bigbird@cspace.org");
184         AccountValue av1 = new AccountValue();
185         av1.setScreenName(userId1);
186         av1.setUserId(userId1);
187         av1.setAccountId(accId1);
188         accValues.put(av1.getUserId(), av1);
189
190         String userId2 = "elmo2010";
191         String accId2 = createAccount(userId2, "elmo@cspace.org");
192         AccountValue av2 = new AccountValue();
193         av2.setScreenName(userId2);
194         av2.setUserId(userId2);
195         av2.setAccountId(accId2);
196         accValues.put(av2.getUserId(), av2);
197
198         String userId3 = "lockedOut";
199         String accId3 = createAccount(userId3, "lockedOut@cspace.org");
200         AccountValue av3 = new AccountValue();
201         av3.setScreenName(userId3);
202         av3.setUserId(userId3);
203         av3.setAccountId(accId3);
204         accValues.put(av3.getUserId(), av3);
205     }
206
207     private void seedAccountRoles() {
208
209         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
210         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
211         createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
212
213         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
214         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
215         createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
216     }
217
218     private void seedPermissionRoles() {
219
220         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
221         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
222         createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
223
224         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
225         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
226         createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
227
228     }
229
230
231     /* (non-Javadoc)
232      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
233      */
234     @Override
235     protected CollectionSpaceClient getClientInstance() {
236         // This method is meaningless to this test.
237         return null;
238     }
239
240     // ---------------------------------------------------------------
241     // CRUD tests : CREATE tests
242     // ---------------------------------------------------------------
243     // Success outcomes
244
245     @Test(dataProvider = "testName")
246     public void create(String testName) throws Exception {
247         setupCreate();
248
249         // Submit the request to the service and store the response.
250         DimensionClient client = new DimensionClient();
251         //bigbird allowed to create
252         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
253         String identifier = createIdentifier();
254         DimensionsCommon dimension = new DimensionsCommon();
255         dimension.setDimension("dimensionType");
256         dimension.setMeasurementUnit("measurementUnit-" + identifier);
257         dimension.setValueDate(new Date().toString());
258         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
259                 dimension);
260         ClientResponse<Response> res = client.create(multipart);
261
262         int statusCode = res.getStatus();
263
264         if (logger.isDebugEnabled()) {
265             logger.debug(testName + ": status = " + statusCode);
266         }
267         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
268                 invalidStatusCodeMessage(testRequestType, statusCode));
269         Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
270         knownResourceId = extractId(res);
271         if (logger.isDebugEnabled()) {
272             logger.debug(testName + ": knownResourceId=" + knownResourceId);
273         }
274         
275         // Now verify that elmo cannot create
276         client = new DimensionClient();
277         client.setAuth(true, "elmo2010", true, "elmo2010", true);
278         res = client.create(multipart);
279
280         statusCode = res.getStatus();
281         if (logger.isDebugEnabled()) {
282             logger.debug(testName + " (verify not allowed): status = " + statusCode);
283         }
284         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
285                 invalidStatusCodeMessage(testRequestType, statusCode));
286         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
287         
288         //Finally, verify that elmo has no access to Intakes
289         // Submit the request to the service and store the response.
290         IntakeClient iclient = new IntakeClient();
291         iclient.setAuth(true, "elmo2010", true, "elmo2010", true);
292         multipart = createIntakeInstance(
293                 "entryNumber-" + identifier,
294                 "entryDate-" + identifier,
295                 "depositor-" + identifier);
296         res = iclient.create(multipart);
297         if (logger.isDebugEnabled()) {
298             logger.debug(testName + " (verify create intake not allowed): status = " + statusCode);
299         }
300         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
301                 invalidStatusCodeMessage(testRequestType, statusCode));
302         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
303         
304     }
305     
306     /**
307      * Creates the intake instance.
308      *
309      * @param entryNumber the entry number
310      * @param entryDate the entry date
311      * @param depositor the depositor
312      * @return the multipart output
313      */
314     private PoxPayloadOut createIntakeInstance(String entryNumber,
315                 String entryDate,
316                 String depositor) {
317         IntakesCommon intake = new IntakesCommon();
318         intake.setEntryNumber(entryNumber);
319         intake.setEntryDate(entryDate);
320         intake.setDepositor(depositor);
321
322         PoxPayloadOut multipart = new PoxPayloadOut(IntakeClient.SERVICE_PAYLOAD_NAME);
323         PayloadOutputPart commonPart =
324             multipart.addPart(intake, MediaType.APPLICATION_XML_TYPE);
325         commonPart.setLabel(new IntakeClient().getCommonPartName());
326
327         if(logger.isDebugEnabled()){
328             logger.debug("to be created, intake common");
329             logger.debug(objectAsXmlString(intake, IntakesCommon.class));
330         }
331
332         return multipart;
333     }
334     
335     @Test(dataProvider = "testName",
336             dependsOnMethods = {"delete"})
337     public void verifyCreateWithFlippedRoles(String testName) throws Exception {
338         setupCreate();
339
340         // Submit the request to the service and store the response.
341         DimensionClient client = new DimensionClient();
342         flipInitialAccountRoles();
343
344         // Now verify that elmo can create
345         client.setAuth(true, "elmo2010", true, "elmo2010", true);
346         client = new DimensionClient();
347         
348         String identifier = createIdentifier();
349         DimensionsCommon dimension = new DimensionsCommon();
350         dimension.setDimension("dimensionType");
351         dimension.setMeasurementUnit("measurementUnit-" + identifier);
352         dimension.setValueDate(new Date().toString());
353         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
354                 dimension);
355         ClientResponse<Response> res = client.create(multipart);
356
357         int statusCode = res.getStatus();
358
359         if (logger.isDebugEnabled()) {
360             logger.debug(testName + ": status = " + statusCode);
361         }
362         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
363                 invalidStatusCodeMessage(testRequestType, statusCode));
364         Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
365         knownResourceId = extractId(res);
366         if (logger.isDebugEnabled()) {
367             logger.debug(testName + ": knownResourceId=" + knownResourceId);
368         }
369         
370         //bigbird no longer allowed to create
371         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
372         res = client.create(multipart);
373
374         statusCode = res.getStatus();
375         if (logger.isDebugEnabled()) {
376             logger.debug(testName + " (verify not allowed): status = " + statusCode);
377         }
378         Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
379                 invalidStatusCodeMessage(testRequestType, statusCode));
380         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
381         restoreInitialAccountRoles();
382     }
383
384     // ---------------------------------------------------------------
385     // CRUD tests : READ tests
386     // ---------------------------------------------------------------
387     // Success outcomes
388     @Test(dataProvider = "testName",
389                 dependsOnMethods = {"create"})
390     public void read(String testName) throws Exception {
391         // Perform setup.
392         setupRead();
393
394         // Submit the request to the service and store the response.
395         DimensionClient client = new DimensionClient();
396         //elmo allowed to read
397         client.setAuth(true, "elmo2010", true, "elmo2010", true);
398         ClientResponse<String> res = client.read(knownResourceId);
399         try {
400                 assertStatusCode(res, testName);
401                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
402                 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
403                         client.getCommonPartName(), DimensionsCommon.class);
404                 Assert.assertNotNull(dimension);
405         } finally {
406                 if (res != null) {
407                 res.releaseConnection();
408             }
409         }
410     }
411
412     @Test(dataProvider = "testName",
413             dependsOnMethods = {"read"})
414     public void readLockedOut(String testName) throws Exception {
415         // Perform setup.
416         setupForbidden();
417
418         // Submit the request to the service and store the response.
419         DimensionClient client = new DimensionClient();
420         //lockedOut allowed to read
421         client.setAuth(true, "lockedOut", true, "lockedOut", true);
422         ClientResponse<String> res = client.read(knownResourceId);
423         try {
424                 assertStatusCode(res, testName);
425         } finally {
426                 if (res != null) {
427                 res.releaseConnection();
428             }
429         }
430     }
431
432     @Test(dataProvider = "testName",
433                 dependsOnMethods = {"read"})
434     public void updateNotAllowed(String testName) throws Exception {
435         setupForbidden();
436
437         // Create a new client and change its AuthN credentials
438         DimensionClient client = new DimensionClient();
439         //elmo not allowed to update
440         client.setAuth(true, "elmo2010", true, "elmo2010", true);
441         //
442         // Create a new dimension object
443         //
444         DimensionsCommon dimension = new DimensionsCommon();
445         dimension.setDimension("dimensionType");
446         // Update the content of this resource.
447         dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
448         dimension.setValueDate("updated-" + dimension.getValueDate());
449         //
450         // Create and submit the request to the service and store the response.
451         //
452         PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
453         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension);
454         ClientResponse<String> res = client.update(knownResourceId, output);
455         try {
456                 assertStatusCode(res, testName);
457         } finally {
458                 if (res != null) {
459                 res.releaseConnection();
460             }
461         }
462         //
463         // Create another new client with new credentials
464         //
465         client = new DimensionClient();
466         //lockedOut not allowed to update
467         client.setAuth(true, "lockedOut", true, "lockedOut", true);
468         //
469         // Try the update again.
470         //
471         res = client.update(knownResourceId, output);
472         try {
473                 assertStatusCode(res, testName);
474         } finally {
475                 if (res != null) {
476                 res.releaseConnection();
477             }
478         }
479         
480     }
481
482     // ---------------------------------------------------------------
483     // CRUD tests : DELETE tests
484     // ---------------------------------------------------------------
485     // Success outcomes
486     @Test(dataProvider = "testName",
487                 dependsOnMethods = {"updateNotAllowed"})
488     public void deleteNotAllowed(String testName) throws Exception {
489         // Perform setup.
490         setupForbidden();
491         //
492         // Create a new client and change the AuthN credentials
493         //
494         DimensionClient client = new DimensionClient();
495         //bigbird can not delete
496         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
497         //
498         // Try to make a DELETE request
499         //
500         ClientResponse<Response> res = client.delete(knownResourceId);
501         try {
502                 assertStatusCode(res, testName);
503         } finally {
504                 if (res != null) {
505                 res.releaseConnection();
506             }
507         }
508     }
509
510     @Test(dataProvider = "testName",
511         dependsOnMethods = {"deleteNotAllowed"})
512     public void delete(String testName) throws Exception {
513         // Perform setup.
514         setupDelete();
515
516         // Submit the request to the service and store the response.
517         DimensionClient client = new DimensionClient();
518
519         ClientResponse<Response> res = client.delete(knownResourceId);
520         try {
521                 assertStatusCode(res, testName);
522         } finally {
523                 if (res != null) {
524                 res.releaseConnection();
525             }
526         }
527     }
528
529     // ---------------------------------------------------------------
530     // Utility methods used by tests above
531     // ---------------------------------------------------------------
532     @AfterClass(alwaysRun = true)
533     public void cleanUp() {
534         setupDelete();
535         String noTest = System.getProperty("noTestCleanup");
536         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
537             if (logger.isDebugEnabled()) {
538                 logger.debug("Skipping Cleanup phase ...");
539             }
540             return;
541         }
542         if (logger.isDebugEnabled()) {
543             logger.debug("Cleaning up temporary resources created for testing ...");
544         }
545
546         deletePermissionRoles();
547         deleteAccountRoles();
548         //FIXME delete on permission deletes all associations with roles
549         //this would delete association with ROLE_ADMINISTRATOR too
550         //deletePermissions();
551         deleteRoles();
552         deleteAccounts();
553     }
554
555     private void deletePermissionRoles() {
556         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
557         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
558         deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
559
560         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
561         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
562         deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
563     }
564
565     private void deleteAccountRoles() {
566         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
567         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
568
569         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
570         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
571         if(!accountRolesFlipped) {
572                 deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
573                 deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues);
574         } else {
575                 deleteAccountRole(accValues.get("bigbird2010"), elmoRoleValues);
576                 deleteAccountRole(accValues.get("elmo2010"),bigbirdRoleValues );
577         }
578     }
579     
580     private void flipInitialAccountRoles() {
581         if(!accountRolesFlipped) {
582                 List<RoleValue> cmRoleValues = new ArrayList<RoleValue>();
583                 List<RoleValue> internRoleValues = new ArrayList<RoleValue>();
584                 cmRoleValues.add(roleValues.get("ROLE_TEST_CM"));
585                 internRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
586                 
587                 deleteAccountRole(accValues.get("bigbird2010"), cmRoleValues);
588                 deleteAccountRole(accValues.get("elmo2010"), internRoleValues);
589
590                 createAccountRole(accValues.get("bigbird2010"), internRoleValues);
591                 createAccountRole(accValues.get("elmo2010"), cmRoleValues);
592                 
593                 accountRolesFlipped = true;
594         }
595     }
596
597     private void restoreInitialAccountRoles() {
598         if(accountRolesFlipped) {
599                 List<RoleValue> cmRoleValues = new ArrayList<RoleValue>();
600                 List<RoleValue> internRoleValues = new ArrayList<RoleValue>();
601                 cmRoleValues.add(roleValues.get("ROLE_TEST_CM"));
602                 internRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
603                 
604                 deleteAccountRole(accValues.get("bigbird2010"), internRoleValues);
605                 deleteAccountRole(accValues.get("elmo2010"), cmRoleValues);
606
607                 createAccountRole(accValues.get("bigbird2010"), internRoleValues);
608                 createAccountRole(accValues.get("elmo2010"), cmRoleValues);
609                 accountRolesFlipped = false;
610         }
611     }
612
613     private void deletePermissions() {
614         //delete entities
615         for (PermissionValue pv : permValues.values()) {
616             deletePermission(pv.getPermissionId());
617         }
618     }
619
620     private void deleteRoles() {
621         for (RoleValue rv : roleValues.values()) {
622             deleteRole(rv.getRoleId());
623         }
624     }
625
626     private void deleteAccounts() {
627
628         for (AccountValue av1 : accValues.values()) {
629             deleteAccount(av1.getAccountId());
630         }
631     }
632
633     private String createPermission(String resName, EffectType effect) {
634         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
635         return createPermission(resName, actions, effect);
636     }
637
638     private String createPermission(String resName,
639             List<PermissionAction> actions, EffectType effect) {
640         String result = null;
641         
642         setupCreate();
643         PermissionClient permClient = new PermissionClient();
644         Permission permission = PermissionFactory.createPermissionInstance(resName,
645                 "default permissions for " + resName, actions, effect, true, true, true);
646         ClientResponse<Response> res = permClient.create(permission);
647         try {
648                 assertStatusCode(res, "CreatePermission");
649                 result = extractId(res);
650         } finally {
651                 if (res != null) {
652                 res.releaseConnection();
653             }
654         }
655
656         return result;
657     }
658
659     private void deletePermission(String permId) {
660         setupDelete();
661         PermissionClient permClient = new PermissionClient();
662         ClientResponse<Response> res = permClient.delete(permId);
663         try {
664                 assertStatusCode(res, "DeletePermission");
665         } finally {
666                 if (res != null) {
667                 res.releaseConnection();
668             }
669         }
670     }
671
672     private String createRole(String roleName) {
673         String result = null;
674         
675         setupCreate();
676         RoleClient roleClient = new RoleClient();
677         Role role = RoleFactory.createRoleInstance(roleName,
678                         roleName, //the display name
679                 "role for " + roleName, true);
680         ClientResponse<Response> res = roleClient.create(role);
681         try {
682                 assertStatusCode(res, "CreateRole");
683                 result = extractId(res);
684         } finally {
685                 if (res != null) {
686                 res.releaseConnection();
687             }
688         }
689         
690         return result;
691     }
692
693     private void deleteRole(String roleId) {
694         setupDelete();
695         RoleClient roleClient = new RoleClient();
696         ClientResponse<Response> res = roleClient.delete(roleId);
697         try {
698                 assertStatusCode(res, "DeleteRole");
699         } finally {
700                 if (res != null) {
701                 res.releaseConnection();
702             }
703         }
704     }
705
706     private String createAccount(String userName, String email) {
707         String result = null;
708         
709         setupCreate();
710         AccountClient accountClient = new AccountClient();
711         AccountsCommon account = AccountFactory.createAccountInstance(
712                 userName, userName, userName, email, accountClient.getTenantId(),
713                 true, false, true, true);
714         ClientResponse<Response> res = accountClient.create(account);
715         try {
716                 assertStatusCode(res, "CreateAccount");
717                 result = extractId(res);
718         } finally {
719                 if (res != null) {
720                 res.releaseConnection();
721             }
722         }
723         
724         return result;
725     }
726
727     private void deleteAccount(String accId) {
728         setupDelete();
729         AccountClient accClient = new AccountClient();
730         ClientResponse<Response> res = accClient.delete(accId);
731         try {
732                 assertStatusCode(res, "DeleteAccount");
733         } finally {
734                 if (res != null) {
735                 res.releaseConnection();
736             }
737         }
738     }
739
740     private String createAccountRole(AccountValue av,
741             Collection<RoleValue> rvs) {
742         String result = null;
743         
744         setupCreate();
745         // Submit the request to the service and store the response.
746         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
747                 av, rvs, true, true);
748         AccountRoleClient client = new AccountRoleClient();
749         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
750         try {
751                 assertStatusCode(res, "CreateAccountRole");
752                 result = extractId(res);
753         } finally {
754                 if (res != null) {
755                 res.releaseConnection();
756             }
757         }
758         
759         return result;
760     }
761
762     private void deleteAccountRole(AccountValue av,
763             Collection<RoleValue> rvs) {
764         // Perform setup.
765         setupDelete();
766
767         // Submit the request to the service and store the response.
768         AccountRoleClient client = new AccountRoleClient();
769         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
770                 av, rvs, true, true);
771         ClientResponse<Response> res = client.delete(av.getAccountId());
772         try {
773                 assertStatusCode(res, "DeleteAccountRole");
774         } finally {
775                 if (res != null) {
776                 res.releaseConnection();
777             }
778         }
779     }
780
781     private String createPermissionRole(PermissionValue pv, Collection<RoleValue> rvs) {
782         String result = null;
783         
784         setupCreate();
785         List<RoleValue> rvls = new ArrayList<RoleValue>();
786         rvls.addAll(rvs);
787         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
788                 pv, rvls, true, true);
789         PermissionRoleClient client = new PermissionRoleClient();
790         ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
791         try {
792                 assertStatusCode(res, "CreatePermissionRole");
793                 result = extractId(res);
794         } finally {
795                 if (res != null) {
796                 res.releaseConnection();
797             }
798         }
799         
800         return result;
801     }
802
803     private void deletePermissionRole(PermissionValue pv,
804             Collection<RoleValue> rvs) {
805         List<RoleValue> rvls = new ArrayList<RoleValue>();
806         rvls.addAll(rvs);
807
808         // Perform setup.
809         setupDelete();
810
811         // Submit the request to the service and store the response.
812         PermissionRoleClient client = new PermissionRoleClient();
813         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
814                 pv, rvls, true, true);
815         ClientResponse<Response> res = client.delete(pv.getPermissionId());
816         try {
817                 assertStatusCode(res, "DeletePermissionRole");
818         } finally {
819                 if (res != null) {
820                 res.releaseConnection();
821             }
822         }
823     }
824
825         @Override
826         protected Class<AbstractCommonList> getCommonListType() {
827                 throw new UnsupportedOperationException();
828         }
829 }