]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
56a4cd762a0cd05cc98fd82064b709de0c24d5f1
[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 import javax.ws.rs.core.Response;
36 import org.collectionspace.services.account.AccountsCommon;
37 import org.collectionspace.services.authorization.AccountRole;
38 import org.collectionspace.services.authorization.AccountValue;
39 import org.collectionspace.services.authorization.perms.ActionType;
40 import org.collectionspace.services.authorization.perms.EffectType;
41
42 import org.collectionspace.services.authorization.perms.Permission;
43 import org.collectionspace.services.authorization.perms.PermissionAction;
44 import org.collectionspace.services.authorization.PermissionRole;
45 import org.collectionspace.services.authorization.PermissionValue;
46 import org.collectionspace.services.authorization.Role;
47 import org.collectionspace.services.authorization.RoleValue;
48 import org.collectionspace.services.client.AccountClient;
49 import org.collectionspace.services.client.AccountFactory;
50 import org.collectionspace.services.client.AccountRoleClient;
51 import org.collectionspace.services.client.AccountRoleFactory;
52 import org.collectionspace.services.client.CollectionSpaceClient;
53 import org.collectionspace.services.client.DimensionClient;
54 import org.collectionspace.services.client.DimensionFactory;
55 import org.collectionspace.services.client.PayloadOutputPart;
56 import org.collectionspace.services.client.PermissionClient;
57 import org.collectionspace.services.client.PermissionFactory;
58 import org.collectionspace.services.client.PermissionRoleClient;
59 import org.collectionspace.services.client.PermissionRoleFactory;
60 import org.collectionspace.services.client.PoxPayloadIn;
61 import org.collectionspace.services.client.PoxPayloadOut;
62 import org.collectionspace.services.client.RoleClient;
63 import org.collectionspace.services.client.RoleFactory;
64 import org.collectionspace.services.client.test.BaseServiceTest;
65 import org.collectionspace.services.dimension.DimensionsCommon;
66 import org.collectionspace.services.jaxb.AbstractCommonList;
67 import org.jboss.resteasy.client.ClientResponse;
68
69 import org.testng.Assert;
70 import org.testng.annotations.Test;
71
72 import org.slf4j.Logger;
73 import org.slf4j.LoggerFactory;
74 import org.testng.annotations.AfterClass;
75 import org.testng.annotations.BeforeClass;
76
77 /**
78  * AuthorizationServiceTest, carries out tests against a
79  * deployed and running Permission, Role, AccountRole, PermissionRole and
80  * CollectionObject Services.
81  *
82  * Pre-requisite : authorization-mgt/client tests seed some permissions used
83  * by this test
84  *
85  * $LastChangedRevision: 917 $
86  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
87  */
88 public class MultiTenancyTest extends BaseServiceTest<AbstractCommonList> {
89
90     private static class UserInfo {
91         String userName;
92         String password;
93
94         UserInfo(String u, String p) {
95             userName = u;
96             password = p;
97         }
98     }
99     
100     private final String CLASS_NAME = MultiTenancyTest.class.getName();
101     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
102     private final static String TENANT_1_ADMIN_USER = "admin@core.collectionspace.org";
103     private final static String TENANT_2_ADMIN_USER = "admin@lifesci.collectionspace.org";
104     private final static String TENANT_ADMIN_PASS = "Administrator";
105     private final static String TENANT_1_USER = "user1@museum1.org";
106     private final static String TENANT_2_USER = "user2@museum2.org";
107     private final static String TENANT_1 = "1";
108     private final static String TENANT_2 = "2";
109     private final static String TEST_ROLE_NAME = "ROLE_TEST_REGISTRAR";
110     private final static String TEST_SERVICE_A = "dimensions";
111
112     // Instance variables specific to this test.
113     private String TENANT_RESOURCE_1 = null;
114     private String TENANT_RESOURCE_2 = null;
115     //key for userAccounts is userId
116     private Hashtable<String, AccountValue> userAccounts = new Hashtable<String, AccountValue>();
117     //key for permValues is id as there could be several perms for the same resource
118     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
119     //key for all tenantXXX tables is tenant id, expecting only one entity per tenant for this test
120     private Hashtable<String, UserInfo> tenantAdminUsers = new Hashtable<String, UserInfo>();
121     private Hashtable<String, AccountValue> tenantAccounts = new Hashtable<String, AccountValue>();
122     private Hashtable<String, RoleValue> tenantRoles = new Hashtable<String, RoleValue>();
123     private Hashtable<String, Role> tenantAdminRoles = new Hashtable<String, Role>();
124     private Hashtable<String, PermissionValue> tenantPermissions = new Hashtable<String, PermissionValue>();
125
126     /*
127      * This method is called only by the parent class, AbstractServiceTestImpl
128      */
129     @Override
130     protected String getServicePathComponent() {
131         return null;
132     }
133
134     @BeforeClass(alwaysRun = true)
135     public void seedData() {
136         //tenant admin users are used to create accounts, roles and permissions and relationships
137         //assumption : two tenant admin users exist before running this test
138         tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS));
139         tenantAdminUsers.put(TENANT_2, new UserInfo(TENANT_2_ADMIN_USER, TENANT_ADMIN_PASS));
140
141         seedAccounts();
142         seedPermissions();
143         seedRoles();
144         seedAccountRoles();
145         seedPermissionRoles();
146     }
147
148     private void seedAccounts() {
149         seedAccount(TENANT_1, TENANT_1_USER);
150         seedAccount(TENANT_2, TENANT_2_USER);
151     }
152
153     private void seedAccount(String tenantId, String userId) {
154         //create account using default user in admin role but assign tenant id
155         //create username, email and password same for simplicity
156         String accId = createAccount(tenantId, userId, userId);
157         AccountValue ava = new AccountValue();
158         ava.setScreenName(userId);
159         ava.setUserId(userId);
160         ava.setAccountId(accId);
161         userAccounts.put(ava.getUserId(), ava);
162         tenantAccounts.put(tenantId, ava);
163         if (logger.isDebugEnabled()) {
164             logger.debug("seedAccount tenantId=" + tenantId + " userId=" + userId);
165         }
166     }
167
168     private void seedPermissions() {
169         String resource = TEST_SERVICE_A;
170
171         PermissionAction pac = new PermissionAction();
172         pac.setName(ActionType.CREATE);
173         PermissionAction par = new PermissionAction();
174         par.setName(ActionType.READ);
175         PermissionAction pau = new PermissionAction();
176         pau.setName(ActionType.UPDATE);
177         PermissionAction pad = new PermissionAction();
178         pad.setName(ActionType.DELETE);
179
180         //both users can create, read and update and delete
181         List<PermissionAction> testActions = new ArrayList<PermissionAction>();
182         testActions.add(pac);
183         testActions.add(par);
184         testActions.add(pau);
185         testActions.add(pad);
186
187         seedPermission(TENANT_1, resource, testActions, EffectType.PERMIT);
188         seedPermission(TENANT_2, resource, testActions, EffectType.PERMIT);
189     }
190
191     private void seedPermission(String tenantId,
192             String resource, List<PermissionAction> testActions, EffectType effect) {
193         //create permission using default user in admin role but assign tenant id
194         String id = createPermission(tenantId, resource, testActions, effect);
195         PermissionValue pv = new PermissionValue();
196         pv.setResourceName(resource);
197         pv.setPermissionId(id);
198         permValues.put(pv.getPermissionId(), pv);
199         tenantPermissions.put(tenantId, pv);
200         if (logger.isDebugEnabled()) {
201             logger.debug("seedPermission tenantId=" + tenantId
202                     + " permId=" + id + " resource=" + resource);
203         }
204     }
205
206     private void seedRoles() {
207         //create role using default user in admin role but assign tenant id
208         //use the same role name to check constraints
209         seedRole(TENANT_1, TEST_ROLE_NAME);
210         seedRole(TENANT_2, TEST_ROLE_NAME);
211     }
212
213     private void seedRole(String tenantId, String roleName) {
214         String rid = createRole(tenantId, roleName);
215         RoleValue rv = new RoleValue();
216         rv.setRoleId(rid);
217         rv.setRoleName(roleName);
218         tenantRoles.put(tenantId, rv);
219         if (logger.isDebugEnabled()) {
220             logger.debug("seedRole tenantId=" + tenantId + " roleName=" + roleName);
221         }
222     }
223
224     private void seedAccountRoles() {
225         for (String tenantId : tenantAccounts.keySet()) {
226             AccountValue av = (AccountValue) tenantAccounts.get(tenantId);
227             seedAccountRole(tenantId, av.getUserId());
228         }
229     }
230
231     private void seedAccountRole(String tenantId, String userId) {
232         List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
233         tenantRoleValues.add(tenantRoles.get(tenantId));
234         createAccountRole(tenantId, userAccounts.get(userId), tenantRoleValues);
235         if (logger.isDebugEnabled()) {
236             logger.debug("seedAccountRole tenantId=" + tenantId + " userId=" + userId);
237         }
238     }
239
240     private void seedPermissionRoles() {
241         for (String tenantId : tenantPermissions.keySet()) {
242             PermissionValue pv = tenantPermissions.get(tenantId);
243             seedPermissionRole(tenantId, pv.getPermissionId());
244         }
245     }
246
247     private void seedPermissionRole(String tenantId, String permId) {
248         List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
249         tenantRoleValues.add(tenantRoles.get(tenantId));
250         PermissionValue pv = permValues.get(permId);
251         createPermissionRole(tenantId, permValues.get(permId), tenantRoleValues);
252         if (logger.isDebugEnabled()) {
253             logger.debug("seedPermissionRole tenantId=" + tenantId
254                     + " permId=" + permId + " resource=" + pv.getResourceName());
255         }
256     }
257
258     /* (non-Javadoc)
259      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
260      */
261     @Override
262     protected CollectionSpaceClient getClientInstance() {
263         return null;
264     }
265
266     /* (non-Javadoc)
267      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
268      */
269     @Override
270     protected AbstractCommonList getCommonList(
271             ClientResponse<AbstractCommonList> response) {
272         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
273         throw new UnsupportedOperationException();
274     }
275
276     // ---------------------------------------------------------------
277     // CRUD tests : CREATE tests
278     // ---------------------------------------------------------------
279     // Success outcomes
280
281     @Test(dataProvider = "testName")
282     public void create(String testName) throws Exception {
283         TENANT_RESOURCE_1 = create(testName, TENANT_1_USER, TENANT_1);
284         if (logger.isDebugEnabled()) {
285             logger.debug(testName + ": tenantId= " + TENANT_1
286                     + " userId=" + TENANT_1_USER
287                     + " TENANT_RESOURCE_1 id=" + TENANT_RESOURCE_1);
288         }
289     }
290
291     @Test(dataProvider = "testName")
292     public void create2(String testName) throws Exception {
293         TENANT_RESOURCE_2 = create(testName, TENANT_2_USER, TENANT_2);
294         if (logger.isDebugEnabled()) {
295             logger.debug(testName + ": tenantId= " + TENANT_2
296                     + " userId=" + TENANT_2_USER
297                     + " TENANT_RESOURCE_2 id=" + TENANT_RESOURCE_2);
298         }
299     }
300
301     private String create(String testName, String userName, String tenatnId) {
302         String result = null;
303         
304         setupCreate();
305         //
306         // Create a new client and change the default AuthN credentials
307         //
308         DimensionClient client = new DimensionClient();
309         client.setAuth(true, userName, true, userName, true);
310         //
311         // Setup a dimension object to create
312         //
313         String identifier = createIdentifier();
314         DimensionsCommon dimension = new DimensionsCommon();
315         dimension.setDimension("dimensionType");
316         dimension.setMeasurementUnit("measurementUnit-" + identifier);
317         dimension.setValueDate(new Date().toString());
318         //
319         // Create a payload and send the POST request
320         //
321         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
322                 dimension);
323         Response res = client.create(multipart);
324         try {
325                 assertStatusCode(res, testName);
326                 result = extractId(res);
327         } finally {
328                 if (res != null) {
329                 res.close();
330             }
331         }
332
333         return result;
334
335     }
336
337     // ---------------------------------------------------------------
338     // CRUD tests : READ tests
339     // ---------------------------------------------------------------
340     // Success outcomes
341     @Test(dataProvider = "testName",
342                 dependsOnMethods = {"create"})
343     public void read(String testName) throws Exception {
344         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER);
345         Assert.assertNotNull(dimension);
346         if (logger.isDebugEnabled()) {
347             logger.debug(testName + ": tenantId= " + TENANT_1
348                     + " userId=" + TENANT_1_USER
349                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
350         }
351     }
352
353     @Test(dataProvider = "testName",
354                 dependsOnMethods = {"create2"})
355     public void read2(String testName) throws Exception {
356         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER);
357         Assert.assertNotNull(dimension);
358         if (logger.isDebugEnabled()) {
359             logger.debug(testName + ": tenantId= " + TENANT_2
360                     + " userId=" + TENANT_2_USER
361                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
362         }
363     }
364
365     private DimensionsCommon read(String testName, String id, String userName) throws Exception {
366         DimensionsCommon result = null;
367         
368         setupRead();
369         // Submit the request to the service and store the response.
370         DimensionClient client = new DimensionClient();
371         client.setAuth(true, userName, true, userName, true);
372         ClientResponse<String> res = client.read(id);
373         try {
374                 assertStatusCode(res, testName);
375                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
376                 result = (DimensionsCommon) extractPart(input,
377                         client.getCommonPartName(), DimensionsCommon.class);
378         } finally {
379                 if (res != null) {
380                 res.releaseConnection();
381             }
382         }
383         
384         return result;
385     }
386
387     // ---------------------------------------------------------------
388     // CRUD tests : READ_LIST tests
389     // ---------------------------------------------------------------
390
391     @Test(dataProvider = "testName",
392                 dependsOnMethods = {"read2"})
393     public void updateNonExistent(String testName) throws Exception {
394         
395         setupUpdateNonExistent();
396         //
397         // Create a new client and change the default AuthN credentials
398         //
399         DimensionClient client = new DimensionClient();
400         //TENANT_1_USER is not allowed to update the resource of TENANT_2
401         client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true);
402         //
403         // Create a new dimension object to try to update
404         //
405         DimensionsCommon dimension = new DimensionsCommon();
406         dimension.setDimension("dimensionType");
407         // Update the content of this resource.
408         dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
409         dimension.setValueDate("updated-" + dimension.getValueDate());
410         //
411         // Create and send a dimension payload for the UPDATE request
412         //
413         PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
414         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension);
415         ClientResponse<String> res = client.update(TENANT_RESOURCE_2, output);
416         try {
417                 assertStatusCode(res, testName);
418         } finally {
419                 if (res != null) {
420                 res.releaseConnection();
421             }
422         }
423     }
424
425     // ---------------------------------------------------------------
426     // CRUD tests : DELETE tests
427     // ---------------------------------------------------------------
428     // Success outcomes
429     @Test(dataProvider = "testName",
430                 dependsOnMethods = {"deleteNonExistent"})
431     public void delete(String testName) throws Exception {
432         int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER);
433     }
434
435     @Test(dataProvider = "testName",
436                 dependsOnMethods = {"updateNonExistent"})
437     public void delete2(String testName) throws Exception {
438         int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER);
439
440     }
441
442     private int delete(String testName, String id, String userName) throws Exception {
443         int result = -1;
444         
445         // Perform setup.
446         setupDelete();
447         // Submit the request to the service and store the response.
448         DimensionClient client = new DimensionClient();
449         client.setAuth(true, userName, true, userName, true);
450         ClientResponse<Response> res = client.delete(id);
451         try {
452                 result = assertStatusCode(res, testName);
453         } finally {
454                 if (res != null) {
455                 res.releaseConnection();
456             }
457         }
458         
459         return result;
460     }
461
462     // Failure outcomes
463     @Test(dataProvider = "testName",
464                 dependsOnMethods = {"read"})
465     public void deleteNonExistent(String testName) throws Exception {
466         //ignoring this test as the service side returns 200 now even if it does
467         //not find a record in the db
468
469         // Perform setup.
470         setupDelete();
471
472         // Submit the request to the service and store the response.
473         DimensionClient client = new DimensionClient();
474         //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1
475         client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true);
476         ClientResponse<Response> res = client.delete(TENANT_RESOURCE_1);
477         try {
478                 int statusCode = res.getStatus();
479                 // Check the status code of the response: does it match
480                 // the expected response(s)?
481                 if (logger.isDebugEnabled()) {
482                     logger.debug(testName + ": status = " + statusCode);
483                 }
484                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
485                         invalidStatusCodeMessage(testRequestType, statusCode));
486                 //going to incorrect Nuxeo domain would give DocumentNotFoundException
487                 //instead of giving FORBIDDEN
488                 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
489         } finally {
490                 if (res != null) {
491                 res.releaseConnection();
492             }
493         }
494     }
495     
496     // ---------------------------------------------------------------
497     // Utility methods used by tests above
498     // ---------------------------------------------------------------
499     @AfterClass(alwaysRun = true)
500     public void cleanUp() {
501         setupDelete();
502         String noTest = System.getProperty("noTestCleanup");
503         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
504             if (logger.isDebugEnabled()) {
505                 logger.debug("Skipping Cleanup phase ...");
506             }
507             return;
508         }
509         if (logger.isDebugEnabled()) {
510             logger.debug("Cleaning up temporary resources created for testing ...");
511         }
512
513         //tenant admin users are used to create accounts, roles and permissions and relationships
514         //assumption : two tenant admin users exist before running this test
515
516         deletePermissionRoles();
517         deleteAccountRoles();
518         //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
519         //deletePermissions();
520         deleteRoles();
521         deleteAccounts();
522     }
523
524     private void deletePermissionRoles() {
525         for (String tenantId : tenantPermissions.keySet()) {
526             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
527             tenantRoleValues.add(tenantRoles.get(tenantId));
528             PermissionValue pv = tenantPermissions.get(tenantId);
529             deletePermissionRole(tenantId, pv, tenantRoleValues);
530         }
531     }
532
533     private void deleteAccountRoles() {
534         for (String tenantId : tenantAccounts.keySet()) {
535             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
536             tenantRoleValues.add(tenantRoles.get(tenantId));
537             AccountValue av = tenantAccounts.get(tenantId);
538             deleteAccountRole(tenantId, av, tenantRoleValues);
539         }
540     }
541
542     private void deletePermissions() {
543         for (String tenantId : tenantPermissions.keySet()) {
544             PermissionValue pv = tenantPermissions.get(tenantId);
545             deletePermission(tenantId, pv.getPermissionId());
546         }
547     }
548
549     private void deleteRoles() {
550         for (String tenantId : tenantRoles.keySet()) {
551             RoleValue rv = tenantRoles.get(tenantId);
552             deleteRole(tenantId, rv.getRoleId());
553         }
554     }
555
556     private void deleteAccounts() {
557         for (String tenantId : tenantAccounts.keySet()) {
558             AccountValue av = tenantAccounts.get(tenantId);
559             deleteAccount(tenantId, av.getAccountId());
560         }
561     }
562
563     private String createPermission(String tenantId, String resName,
564             List<PermissionAction> actions, EffectType effect) {
565         String result = null;
566         
567         setupCreate();
568         PermissionClient permClient = new PermissionClient();
569         UserInfo ui = tenantAdminUsers.get(tenantId);
570         permClient.setAuth(true, ui.userName, true, ui.password, true);
571         Permission permission = PermissionFactory.createPermissionInstance(resName,
572                 "default permissions for " + resName,
573                 actions, effect, true, true, true);
574         permission.setTenantId(tenantId);
575         ClientResponse<Response> res = permClient.create(permission);
576         try {
577                 assertStatusCode(res, "CreatePermission");
578                 result = extractId(res);
579         } finally {
580                 if (res != null) {
581                 res.releaseConnection();
582             }
583         }
584         
585         return result;
586     }
587
588     private void deletePermission(String tenantId, String permId) {
589         setupDelete();
590         PermissionClient permClient = new PermissionClient();
591         UserInfo ui = tenantAdminUsers.get(tenantId);
592         permClient.setAuth(true, ui.userName, true, ui.password, true);
593         ClientResponse<Response> res = permClient.delete(permId);
594         try {
595                 assertStatusCode(res, "DeletePermission");
596         } finally {
597                 if (res != null) {
598                 res.releaseConnection();
599             }
600         }
601     }
602
603     private String createRole(String tenantId, String roleName) {
604         String result = null;
605         
606         setupCreate();
607         RoleClient roleClient = new RoleClient();
608         UserInfo ui = tenantAdminUsers.get(tenantId);
609         roleClient.setAuth(true, ui.userName, true, ui.password, true);
610         Role role = RoleFactory.createRoleInstance(roleName,
611                         roleName, //the display name
612                 "role for " + roleName, true);
613         role.setTenantId(tenantId);
614         ClientResponse<Response> res = roleClient.create(role);
615         try {
616                 assertStatusCode(res, "CreateRole");
617                 result = extractId(res);
618         } finally {
619                 if (res != null) {
620                 res.releaseConnection();
621             }
622         }
623         
624         return result;
625     }
626
627     private void deleteRole(String tenantId, String roleId) {
628         setupDelete();
629         RoleClient roleClient = new RoleClient();
630         UserInfo ui = tenantAdminUsers.get(tenantId);
631         roleClient.setAuth(true, ui.userName, true, ui.password, true);
632         ClientResponse<Response> res = roleClient.delete(roleId);
633         try {
634                 assertStatusCode(res, "DeleteRole");
635         } finally {
636                 if (res != null) {
637                 res.releaseConnection();
638             }
639         }
640     }
641
642     private String createAccount(String tenantId, String userName, String email) {
643         String result = null;
644         
645         setupCreate();
646         AccountClient accountClient = new AccountClient();
647         UserInfo ui = tenantAdminUsers.get(tenantId);
648         accountClient.setAuth(true, ui.userName, true, ui.password, true);
649         AccountsCommon account = AccountFactory.createAccountInstance(
650                 userName, userName, userName, email, tenantId,
651                 true, false, true, true);
652         ClientResponse<Response> res = accountClient.create(account);
653         try {
654                 assertStatusCode(res, "CreateAccount");
655                 result = extractId(res);
656         } finally {
657                 if (res != null) {
658                 res.releaseConnection();
659             }
660         }
661         
662         return result;
663     }
664
665     private void deleteAccount(String tenantId, String accId) {
666         setupDelete();
667         AccountClient accClient = new AccountClient();
668         UserInfo ui = tenantAdminUsers.get(tenantId);
669         accClient.setAuth(true, ui.userName, true, ui.password, true);
670         ClientResponse<Response> res = accClient.delete(accId);
671         try {
672                 assertStatusCode(res, "DeleteAccount");
673         } finally {
674                 if (res != null) {
675                 res.releaseConnection();
676             }
677         }
678     }
679
680     private String createAccountRole(String tenantId, AccountValue av,
681             Collection<RoleValue> rvs) {
682         String result = null;
683         
684         setupCreate();
685         // Submit the request to the service and store the response.
686         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
687                 av, rvs, true, true);
688         AccountRoleClient client = new AccountRoleClient();
689         UserInfo ui = tenantAdminUsers.get(tenantId);
690         client.setAuth(true, ui.userName, true, ui.password, true);
691         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
692         try {
693                 assertStatusCode(res, "CreateAccountRole");
694                 result = extractId(res);
695         } finally {
696                 if (res != null) {
697                 res.releaseConnection();
698             }
699         }
700
701         return result;
702     }
703
704     private void deleteAccountRole(String tenantId, AccountValue av,
705             List<RoleValue> rvs) {
706         // Perform setup.
707         setupDelete();
708
709         // Submit the request to the service and store the response.
710         AccountRoleClient client = new AccountRoleClient();
711         UserInfo ui = tenantAdminUsers.get(tenantId);
712         client.setAuth(true, ui.userName, true, ui.password, true);
713         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
714                 av, rvs, true, true);
715         ClientResponse<Response> res = client.delete(av.getAccountId());
716         try {
717                 assertStatusCode(res, "DeleteAccountRole");
718         } finally {
719                 if (res != null) {
720                 res.releaseConnection();
721             }
722         }
723     }
724
725     private String createPermissionRole(String tenantId, PermissionValue pv,
726             Collection<RoleValue> rvs) {
727         String result = null;
728         
729         setupCreate();
730         List<RoleValue> rvls = new ArrayList<RoleValue>();
731         rvls.addAll(rvs);
732         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
733                 pv, rvls, true, true);
734         PermissionRoleClient client = new PermissionRoleClient();
735         UserInfo ui = tenantAdminUsers.get(tenantId);
736         client.setAuth(true, ui.userName, true, ui.password, true);
737         ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
738         try {
739                 assertStatusCode(res, "createPermissionRole");
740                 result = extractId(res);
741         }  finally {
742                 if (res != null) {
743                 res.releaseConnection();
744             }
745         }
746         
747         return result;
748     }
749
750     private void deletePermissionRole(String tenantId, PermissionValue pv, List<RoleValue> rvls) {
751         // Perform setup.
752         setupDelete();
753
754         // Submit the request to the service and store the response.
755         PermissionRoleClient client = new PermissionRoleClient();
756         UserInfo ui = tenantAdminUsers.get(tenantId);
757         client.setAuth(true, ui.userName, true, ui.password, true);
758         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
759                 pv, rvls, true, true);
760         ClientResponse<Response> res = client.delete(pv.getPermissionId());
761         try {
762                 assertStatusCode(res, "DeletePermissionRole");
763         } finally {
764                 if (res != null) {
765                 res.releaseConnection();
766             }
767         }
768     }
769
770         @Override
771         protected String getServiceName() {
772                 // TODO Auto-generated method stub
773         throw new UnsupportedOperationException();
774         }
775
776         @Override
777         protected Class<AbstractCommonList> getCommonListType() {
778                 // TODO Auto-generated method stub
779                 throw new UnsupportedOperationException();
780         }
781 }