]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2e28b189a526f9ef657109d4297ad668c2b02d6e
[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(Response response) {
271         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
272         throw new UnsupportedOperationException();
273     }
274
275     // ---------------------------------------------------------------
276     // CRUD tests : CREATE tests
277     // ---------------------------------------------------------------
278     // Success outcomes
279
280     @Test(dataProvider = "testName")
281     public void create(String testName) throws Exception {
282         TENANT_RESOURCE_1 = create(testName, TENANT_1_USER, TENANT_1);
283         if (logger.isDebugEnabled()) {
284             logger.debug(testName + ": tenantId= " + TENANT_1
285                     + " userId=" + TENANT_1_USER
286                     + " TENANT_RESOURCE_1 id=" + TENANT_RESOURCE_1);
287         }
288     }
289
290     @Test(dataProvider = "testName")
291     public void create2(String testName) throws Exception {
292         TENANT_RESOURCE_2 = create(testName, TENANT_2_USER, TENANT_2);
293         if (logger.isDebugEnabled()) {
294             logger.debug(testName + ": tenantId= " + TENANT_2
295                     + " userId=" + TENANT_2_USER
296                     + " TENANT_RESOURCE_2 id=" + TENANT_RESOURCE_2);
297         }
298     }
299
300     private String create(String testName, String userName, String tenatnId) {
301         String result = null;
302         
303         setupCreate();
304         //
305         // Create a new client and change the default AuthN credentials
306         //
307         DimensionClient client = new DimensionClient();
308         client.setAuth(true, userName, true, userName, true);
309         //
310         // Setup a dimension object to create
311         //
312         String identifier = createIdentifier();
313         DimensionsCommon dimension = new DimensionsCommon();
314         dimension.setDimension("dimensionType");
315         dimension.setMeasurementUnit("measurementUnit-" + identifier);
316         dimension.setValueDate(new Date().toString());
317         //
318         // Create a payload and send the POST request
319         //
320         PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
321                 dimension);
322         Response res = client.create(multipart);
323         try {
324                 assertStatusCode(res, testName);
325                 result = extractId(res);
326         } finally {
327                 if (res != null) {
328                 res.close();
329             }
330         }
331
332         return result;
333
334     }
335
336     // ---------------------------------------------------------------
337     // CRUD tests : READ tests
338     // ---------------------------------------------------------------
339     // Success outcomes
340     @Test(dataProvider = "testName",
341                 dependsOnMethods = {"create"})
342     public void read(String testName) throws Exception {
343         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER);
344         Assert.assertNotNull(dimension);
345         if (logger.isDebugEnabled()) {
346             logger.debug(testName + ": tenantId= " + TENANT_1
347                     + " userId=" + TENANT_1_USER
348                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
349         }
350     }
351
352     @Test(dataProvider = "testName",
353                 dependsOnMethods = {"create2"})
354     public void read2(String testName) throws Exception {
355         DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER);
356         Assert.assertNotNull(dimension);
357         if (logger.isDebugEnabled()) {
358             logger.debug(testName + ": tenantId= " + TENANT_2
359                     + " userId=" + TENANT_2_USER
360                     + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
361         }
362     }
363
364     private DimensionsCommon read(String testName, String id, String userName) throws Exception {
365         DimensionsCommon result = null;
366         
367         setupRead();
368         // Submit the request to the service and store the response.
369         DimensionClient client = new DimensionClient();
370         client.setAuth(true, userName, true, userName, true);
371         Response res = client.read(id);
372         try {
373                 assertStatusCode(res, testName);
374                 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
375                 result = (DimensionsCommon) extractPart(input,
376                         client.getCommonPartName(), DimensionsCommon.class);
377         } finally {
378                 if (res != null) {
379                 res.close();
380             }
381         }
382         
383         return result;
384     }
385
386     // ---------------------------------------------------------------
387     // CRUD tests : READ_LIST tests
388     // ---------------------------------------------------------------
389
390     @Test(dataProvider = "testName",
391                 dependsOnMethods = {"read2"})
392     public void updateNonExistent(String testName) throws Exception {
393         
394         setupUpdateNonExistent();
395         //
396         // Create a new client and change the default AuthN credentials
397         //
398         DimensionClient client = new DimensionClient();
399         //TENANT_1_USER is not allowed to update the resource of TENANT_2
400         client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true);
401         //
402         // Create a new dimension object to try to update
403         //
404         DimensionsCommon dimension = new DimensionsCommon();
405         dimension.setDimension("dimensionType");
406         // Update the content of this resource.
407         dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
408         dimension.setValueDate("updated-" + dimension.getValueDate());
409         //
410         // Create and send a dimension payload for the UPDATE request
411         //
412         PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
413         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), dimension);
414         Response res = client.update(TENANT_RESOURCE_2, output);
415         try {
416                 assertStatusCode(res, testName);
417         } finally {
418                 if (res != null) {
419                 res.close();
420             }
421         }
422     }
423
424     // ---------------------------------------------------------------
425     // CRUD tests : DELETE tests
426     // ---------------------------------------------------------------
427     // Success outcomes
428     @Test(dataProvider = "testName",
429                 dependsOnMethods = {"deleteNonExistent"})
430     public void delete(String testName) throws Exception {
431         int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER);
432     }
433
434     @Test(dataProvider = "testName",
435                 dependsOnMethods = {"updateNonExistent"})
436     public void delete2(String testName) throws Exception {
437         int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER);
438
439     }
440
441     private int delete(String testName, String id, String userName) throws Exception {
442         int result = -1;
443         
444         // Perform setup.
445         setupDelete();
446         // Submit the request to the service and store the response.
447         DimensionClient client = new DimensionClient();
448         client.setAuth(true, userName, true, userName, true);
449         Response res = client.delete(id);
450         try {
451                 result = assertStatusCode(res, testName);
452         } finally {
453                 if (res != null) {
454                 res.close();
455             }
456         }
457         
458         return result;
459     }
460
461     // Failure outcomes
462     @Test(dataProvider = "testName",
463                 dependsOnMethods = {"read"})
464     public void deleteNonExistent(String testName) throws Exception {
465         //ignoring this test as the service side returns 200 now even if it does
466         //not find a record in the db
467
468         // Perform setup.
469         setupDelete();
470
471         // Submit the request to the service and store the response.
472         DimensionClient client = new DimensionClient();
473         //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1
474         client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true);
475         Response res = client.delete(TENANT_RESOURCE_1);
476         try {
477                 int statusCode = res.getStatus();
478                 // Check the status code of the response: does it match
479                 // the expected response(s)?
480                 if (logger.isDebugEnabled()) {
481                     logger.debug(testName + ": status = " + statusCode);
482                 }
483                 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
484                         invalidStatusCodeMessage(testRequestType, statusCode));
485                 //going to incorrect Nuxeo domain would give DocumentNotFoundException
486                 //instead of giving FORBIDDEN
487                 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
488         } finally {
489                 if (res != null) {
490                 res.close();
491             }
492         }
493     }
494     
495     // ---------------------------------------------------------------
496     // Utility methods used by tests above
497     // ---------------------------------------------------------------
498     @AfterClass(alwaysRun = true)
499     public void cleanUp() {
500         setupDelete();
501         String noTest = System.getProperty("noTestCleanup");
502         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
503             if (logger.isDebugEnabled()) {
504                 logger.debug("Skipping Cleanup phase ...");
505             }
506             return;
507         }
508         if (logger.isDebugEnabled()) {
509             logger.debug("Cleaning up temporary resources created for testing ...");
510         }
511
512         //tenant admin users are used to create accounts, roles and permissions and relationships
513         //assumption : two tenant admin users exist before running this test
514
515         deletePermissionRoles();
516         deleteAccountRoles();
517         //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
518         //deletePermissions();
519         deleteRoles();
520         deleteAccounts();
521     }
522
523     private void deletePermissionRoles() {
524         for (String tenantId : tenantPermissions.keySet()) {
525             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
526             tenantRoleValues.add(tenantRoles.get(tenantId));
527             PermissionValue pv = tenantPermissions.get(tenantId);
528             deletePermissionRole(tenantId, pv, tenantRoleValues);
529         }
530     }
531
532     private void deleteAccountRoles() {
533         for (String tenantId : tenantAccounts.keySet()) {
534             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
535             tenantRoleValues.add(tenantRoles.get(tenantId));
536             AccountValue av = tenantAccounts.get(tenantId);
537             deleteAccountRole(tenantId, av, tenantRoleValues);
538         }
539     }
540
541     private void deletePermissions() {
542         for (String tenantId : tenantPermissions.keySet()) {
543             PermissionValue pv = tenantPermissions.get(tenantId);
544             deletePermission(tenantId, pv.getPermissionId());
545         }
546     }
547
548     private void deleteRoles() {
549         for (String tenantId : tenantRoles.keySet()) {
550             RoleValue rv = tenantRoles.get(tenantId);
551             deleteRole(tenantId, rv.getRoleId());
552         }
553     }
554
555     private void deleteAccounts() {
556         for (String tenantId : tenantAccounts.keySet()) {
557             AccountValue av = tenantAccounts.get(tenantId);
558             deleteAccount(tenantId, av.getAccountId());
559         }
560     }
561
562     private String createPermission(String tenantId, String resName,
563             List<PermissionAction> actions, EffectType effect) {
564         String result = null;
565         
566         setupCreate();
567         PermissionClient permClient = new PermissionClient();
568         UserInfo ui = tenantAdminUsers.get(tenantId);
569         permClient.setAuth(true, ui.userName, true, ui.password, true);
570         Permission permission = PermissionFactory.createPermissionInstance(resName,
571                 "default permissions for " + resName,
572                 actions, effect, true, true, true);
573         permission.setTenantId(tenantId);
574         ClientResponse<Response> res = permClient.create(permission);
575         try {
576                 assertStatusCode(res, "CreatePermission");
577                 result = extractId(res);
578         } finally {
579                 if (res != null) {
580                 res.close();
581             }
582         }
583         
584         return result;
585     }
586
587     private void deletePermission(String tenantId, String permId) {
588         setupDelete();
589         PermissionClient permClient = new PermissionClient();
590         UserInfo ui = tenantAdminUsers.get(tenantId);
591         permClient.setAuth(true, ui.userName, true, ui.password, true);
592         Response res = permClient.delete(permId);
593         try {
594                 assertStatusCode(res, "DeletePermission");
595         } finally {
596                 if (res != null) {
597                 res.close();
598             }
599         }
600     }
601
602     private String createRole(String tenantId, String roleName) {
603         String result = null;
604         
605         setupCreate();
606         RoleClient roleClient = new RoleClient();
607         UserInfo ui = tenantAdminUsers.get(tenantId);
608         roleClient.setAuth(true, ui.userName, true, ui.password, true);
609         Role role = RoleFactory.createRoleInstance(roleName,
610                         roleName, //the display name
611                 "role for " + roleName, true);
612         role.setTenantId(tenantId);
613         ClientResponse<Response> res = roleClient.create(role);
614         try {
615                 assertStatusCode(res, "CreateRole");
616                 result = extractId(res);
617         } finally {
618                 if (res != null) {
619                 res.close();
620             }
621         }
622         
623         return result;
624     }
625
626     private void deleteRole(String tenantId, String roleId) {
627         setupDelete();
628         RoleClient roleClient = new RoleClient();
629         UserInfo ui = tenantAdminUsers.get(tenantId);
630         roleClient.setAuth(true, ui.userName, true, ui.password, true);
631         Response res = roleClient.delete(roleId);
632         try {
633                 assertStatusCode(res, "DeleteRole");
634         } finally {
635                 if (res != null) {
636                 res.close();
637             }
638         }
639     }
640
641     private String createAccount(String tenantId, String userName, String email) {
642         String result = null;
643         
644         setupCreate();
645         AccountClient accountClient = new AccountClient();
646         UserInfo ui = tenantAdminUsers.get(tenantId);
647         accountClient.setAuth(true, ui.userName, true, ui.password, true);
648         AccountsCommon account = AccountFactory.createAccountInstance(
649                 userName, userName, userName, email, tenantId,
650                 true, false, true, true);
651         ClientResponse<Response> res = accountClient.create(account);
652         try {
653                 assertStatusCode(res, "CreateAccount");
654                 result = extractId(res);
655         } finally {
656                 if (res != null) {
657                 res.close();
658             }
659         }
660         
661         return result;
662     }
663
664     private void deleteAccount(String tenantId, String accId) {
665         setupDelete();
666         AccountClient accClient = new AccountClient();
667         UserInfo ui = tenantAdminUsers.get(tenantId);
668         accClient.setAuth(true, ui.userName, true, ui.password, true);
669         Response res = accClient.delete(accId);
670         try {
671                 assertStatusCode(res, "DeleteAccount");
672         } finally {
673                 if (res != null) {
674                 res.close();
675             }
676         }
677     }
678
679     private String createAccountRole(String tenantId, AccountValue av,
680             Collection<RoleValue> rvs) {
681         String result = null;
682         
683         setupCreate();
684         // Submit the request to the service and store the response.
685         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
686                 av, rvs, true, true);
687         AccountRoleClient client = new AccountRoleClient();
688         UserInfo ui = tenantAdminUsers.get(tenantId);
689         client.setAuth(true, ui.userName, true, ui.password, true);
690         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
691         try {
692                 assertStatusCode(res, "CreateAccountRole");
693                 result = extractId(res);
694         } finally {
695                 if (res != null) {
696                 res.close();
697             }
698         }
699
700         return result;
701     }
702
703     private void deleteAccountRole(String tenantId, AccountValue av,
704             List<RoleValue> rvs) {
705         // Perform setup.
706         setupDelete();
707
708         // Submit the request to the service and store the response.
709         AccountRoleClient client = new AccountRoleClient();
710         UserInfo ui = tenantAdminUsers.get(tenantId);
711         client.setAuth(true, ui.userName, true, ui.password, true);
712         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
713                 av, rvs, true, true);
714         Response res = client.delete(av.getAccountId());
715         try {
716                 assertStatusCode(res, "DeleteAccountRole");
717         } finally {
718                 if (res != null) {
719                 res.close();
720             }
721         }
722     }
723
724     private String createPermissionRole(String tenantId, PermissionValue pv,
725             Collection<RoleValue> rvs) {
726         String result = null;
727         
728         setupCreate();
729         List<RoleValue> rvls = new ArrayList<RoleValue>();
730         rvls.addAll(rvs);
731         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
732                 pv, rvls, true, true);
733         PermissionRoleClient client = new PermissionRoleClient();
734         UserInfo ui = tenantAdminUsers.get(tenantId);
735         client.setAuth(true, ui.userName, true, ui.password, true);
736         ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
737         try {
738                 assertStatusCode(res, "createPermissionRole");
739                 result = extractId(res);
740         }  finally {
741                 if (res != null) {
742                 res.close();
743             }
744         }
745         
746         return result;
747     }
748
749     private void deletePermissionRole(String tenantId, PermissionValue pv, List<RoleValue> rvls) {
750         // Perform setup.
751         setupDelete();
752
753         // Submit the request to the service and store the response.
754         PermissionRoleClient client = new PermissionRoleClient();
755         UserInfo ui = tenantAdminUsers.get(tenantId);
756         client.setAuth(true, ui.userName, true, ui.password, true);
757         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
758                 pv, rvls, true, true);
759         Response res = client.delete(pv.getPermissionId());
760         try {
761                 assertStatusCode(res, "DeletePermissionRole");
762         } finally {
763                 if (res != null) {
764                 res.close();
765             }
766         }
767     }
768
769         @Override
770         protected String getServiceName() {
771                 // TODO Auto-generated method stub
772         throw new UnsupportedOperationException();
773         }
774
775         @Override
776         protected Class<AbstractCommonList> getCommonListType() {
777                 // TODO Auto-generated method stub
778                 throw new UnsupportedOperationException();
779         }
780 }