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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2010 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
25 * To change this template, choose Tools | Templates
26 * and open the template in the editor.
28 package org.collectionspace.services.security.client.test;
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.MediaType;
36 import javax.ws.rs.core.Response;
37 import org.collectionspace.services.account.AccountsCommon;
38 import org.collectionspace.services.authorization.AccountRole;
39 import org.collectionspace.services.authorization.AccountValue;
40 import org.collectionspace.services.authorization.ActionType;
41 import org.collectionspace.services.authorization.EffectType;
43 import org.collectionspace.services.authorization.Permission;
44 import org.collectionspace.services.authorization.PermissionAction;
45 import org.collectionspace.services.authorization.PermissionRole;
46 import org.collectionspace.services.authorization.PermissionValue;
47 import org.collectionspace.services.authorization.Role;
48 import org.collectionspace.services.authorization.RoleValue;
49 import org.collectionspace.services.client.AccountClient;
50 import org.collectionspace.services.client.AccountFactory;
51 import org.collectionspace.services.client.AccountRoleClient;
52 import org.collectionspace.services.client.AccountRoleFactory;
53 import org.collectionspace.services.client.CollectionSpaceClient;
54 import org.collectionspace.services.client.DimensionClient;
55 import org.collectionspace.services.client.DimensionFactory;
56 import org.collectionspace.services.client.PayloadOutputPart;
57 import org.collectionspace.services.client.PermissionClient;
58 import org.collectionspace.services.client.PermissionFactory;
59 import org.collectionspace.services.client.PermissionRoleClient;
60 import org.collectionspace.services.client.PermissionRoleFactory;
61 import org.collectionspace.services.client.PoxPayloadIn;
62 import org.collectionspace.services.client.PoxPayloadOut;
63 import org.collectionspace.services.client.RoleClient;
64 import org.collectionspace.services.client.RoleFactory;
65 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
66 import org.collectionspace.services.dimension.DimensionsCommon;
67 import org.collectionspace.services.jaxb.AbstractCommonList;
68 import org.jboss.resteasy.client.ClientResponse;
69 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
70 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
71 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
73 import org.testng.Assert;
74 import org.testng.annotations.Test;
76 import org.slf4j.Logger;
77 import org.slf4j.LoggerFactory;
78 import org.testng.annotations.AfterClass;
79 import org.testng.annotations.BeforeClass;
82 * AuthorizationServiceTest, carries out tests against a
83 * deployed and running Permission, Role, AccountRole, PermissionRole and
84 * CollectionObject Services.
86 * Pre-requisite : authorization-mgt/client tests seed some permissions used
89 * $LastChangedRevision: 917 $
90 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
92 public class MultiTenancyTest extends AbstractServiceTestImpl {
94 private final String CLASS_NAME = MultiTenancyTest.class.getName();
95 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
96 private final static String TENANT_1_ADMIN_USER = "admin@core.collectionspace.org";
97 private final static String TENANT_2_ADMIN_USER = "admin@lifesci.collectionspace.org";
98 private final static String TENANT_ADMIN_PASS = "Administrator";
99 private final static String TENANT_1_USER = "user1@museum1.org";
100 private final static String TENANT_2_USER = "user2@museum2.org";
101 private final static String TENANT_1 = "1";
102 private final static String TENANT_2 = "2";
103 private final static String TEST_ROLE_NAME = "ROLE_TEST_REGISTRAR";
104 private final static String TEST_SERVICE_A = "dimensions";
106 private static class UserInfo {
111 UserInfo(String u, String p) {
116 // Instance variables specific to this test.
117 private String TENANT_RESOURCE_1 = null;
118 private String TENANT_RESOURCE_2 = null;
119 private List<String> allResourceIdsCreated = new ArrayList();
120 //key for userAccounts is userId
121 private Hashtable<String, AccountValue> userAccounts = new Hashtable<String, AccountValue>();
122 //key for permValues is id as there could be several perms for the same resource
123 private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
124 //key for all tenantXXX tables is tenant id, expecting only one entity per tenant for this test
125 private Hashtable<String, UserInfo> tenantAdminUsers = new Hashtable<String, UserInfo>();
126 private Hashtable<String, AccountValue> tenantAccounts = new Hashtable<String, AccountValue>();
127 private Hashtable<String, RoleValue> tenantRoles = new Hashtable<String, RoleValue>();
128 private Hashtable<String, Role> tenantAdminRoles = new Hashtable<String, Role>();
129 private Hashtable<String, PermissionValue> tenantPermissions = new Hashtable<String, PermissionValue>();
131 // private String permId1;
132 // private String permId2;
135 * This method is called only by the parent class, AbstractServiceTestImpl
138 protected String getServicePathComponent() {
142 @BeforeClass(alwaysRun = true)
143 public void seedData() {
144 if (logger.isDebugEnabled()) {
145 testBanner("seedData", CLASS_NAME);
148 //tenant admin users are used to create accounts, roles and permissions and relationships
149 //assumption : two tenant admin users exist before running this test
150 tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS));
151 tenantAdminUsers.put(TENANT_2, new UserInfo(TENANT_2_ADMIN_USER, TENANT_ADMIN_PASS));
157 seedPermissionRoles();
160 private void seedAccounts() {
161 seedAccount(TENANT_1, TENANT_1_USER);
162 seedAccount(TENANT_2, TENANT_2_USER);
165 private void seedAccount(String tenantId, String userId) {
166 //create account using default user in admin role but assign tenant id
167 //create username, email and password same for simplicity
168 String accId = createAccount(tenantId, userId, userId);
169 AccountValue ava = new AccountValue();
170 ava.setScreenName(userId);
171 ava.setUserId(userId);
172 ava.setAccountId(accId);
173 userAccounts.put(ava.getUserId(), ava);
174 tenantAccounts.put(tenantId, ava);
175 if (logger.isDebugEnabled()) {
176 logger.debug("seedAccount tenantId=" + tenantId + " userId=" + userId);
180 private void seedPermissions() {
181 String resource = TEST_SERVICE_A;
183 PermissionAction pac = new PermissionAction();
184 pac.setName(ActionType.CREATE);
185 PermissionAction par = new PermissionAction();
186 par.setName(ActionType.READ);
187 PermissionAction pau = new PermissionAction();
188 pau.setName(ActionType.UPDATE);
189 PermissionAction pad = new PermissionAction();
190 pad.setName(ActionType.DELETE);
192 //both users can create, read and update and delete
193 List<PermissionAction> testActions = new ArrayList<PermissionAction>();
194 testActions.add(pac);
195 testActions.add(par);
196 testActions.add(pau);
197 testActions.add(pad);
199 seedPermission(TENANT_1, resource, testActions, EffectType.PERMIT);
200 seedPermission(TENANT_2, resource, testActions, EffectType.PERMIT);
203 private void seedPermission(String tenantId,
204 String resource, List<PermissionAction> testActions, EffectType effect) {
205 //create permission using default user in admin role but assign tenant id
206 String id = createPermission(tenantId, resource, testActions, effect);
207 PermissionValue pv = new PermissionValue();
208 pv.setResourceName(resource);
209 pv.setPermissionId(id);
210 permValues.put(pv.getPermissionId(), pv);
211 tenantPermissions.put(tenantId, pv);
212 if (logger.isDebugEnabled()) {
213 logger.debug("seedPermission tenantId=" + tenantId
214 + " permId=" + id + " resource=" + resource);
218 private void seedRoles() {
219 //create role using default user in admin role but assign tenant id
220 //use the same role name to check constraints
221 seedRole(TENANT_1, TEST_ROLE_NAME);
222 seedRole(TENANT_2, TEST_ROLE_NAME);
225 private void seedRole(String tenantId, String roleName) {
226 String rid = createRole(tenantId, roleName);
227 RoleValue rv = new RoleValue();
229 rv.setRoleName(roleName);
230 tenantRoles.put(tenantId, rv);
231 if (logger.isDebugEnabled()) {
232 logger.debug("seedRole tenantId=" + tenantId + " roleName=" + roleName);
236 private void seedAccountRoles() {
238 for (String tenantId : tenantAccounts.keySet()) {
239 AccountValue av = (AccountValue) tenantAccounts.get(tenantId);
240 seedAccountRole(tenantId, av.getUserId());
244 private void seedAccountRole(String tenantId, String userId) {
245 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
246 tenantRoleValues.add(tenantRoles.get(tenantId));
247 createAccountRole(tenantId, userAccounts.get(userId), tenantRoleValues);
248 if (logger.isDebugEnabled()) {
249 logger.debug("seedAccountRole tenantId=" + tenantId + " userId=" + userId);
253 private void seedPermissionRoles() {
255 for (String tenantId : tenantPermissions.keySet()) {
256 PermissionValue pv = tenantPermissions.get(tenantId);
257 seedPermissionRole(tenantId, pv.getPermissionId());
261 private void seedPermissionRole(String tenantId, String permId) {
262 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
263 tenantRoleValues.add(tenantRoles.get(tenantId));
264 PermissionValue pv = permValues.get(permId);
265 createPermissionRole(tenantId, permValues.get(permId), tenantRoleValues);
266 if (logger.isDebugEnabled()) {
267 logger.debug("seedPermissionRole tenantId=" + tenantId
268 + " permId=" + permId + " resource=" + pv.getResourceName());
274 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
277 protected CollectionSpaceClient getClientInstance() {
282 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
285 protected AbstractCommonList getAbstractCommonList(
286 ClientResponse<AbstractCommonList> response) {
287 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
288 throw new UnsupportedOperationException();
291 @Test(dataProvider = "testName")
293 public void readPaginatedList(String testName) throws Exception {
294 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
296 // ---------------------------------------------------------------
297 // CRUD tests : CREATE tests
298 // ---------------------------------------------------------------
302 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
303 public void create(String testName) throws Exception {
304 if (logger.isDebugEnabled()) {
305 logger.debug(testBanner(testName, CLASS_NAME));
308 ClientResponse<Response> res = create(testName, TENANT_1_USER, TENANT_1);
310 TENANT_RESOURCE_1 = extractId(res);
312 if (logger.isDebugEnabled()) {
313 logger.debug(testName + ": tenantId= " + TENANT_1
314 + " userId=" + TENANT_1_USER
315 + " TENANT_RESOURCE_1 id=" + TENANT_RESOURCE_1);
319 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
320 public void create2(String testName) throws Exception {
321 if (logger.isDebugEnabled()) {
322 logger.debug(testBanner(testName, CLASS_NAME));
325 ClientResponse<Response> res = create(testName, TENANT_2_USER, TENANT_2);
327 TENANT_RESOURCE_2 = extractId(res);
328 if (logger.isDebugEnabled()) {
329 logger.debug(testName + ": tenantId= " + TENANT_2
330 + " userId=" + TENANT_2_USER
331 + " TENANT_RESOURCE_2 id=" + TENANT_RESOURCE_2);
335 private ClientResponse<Response> create(String testName, String userName, String tenatnId) {
337 // Submit the request to the service and store the response.
338 DimensionClient client = new DimensionClient();
339 client.setAuth(true, userName, true, userName, true);
340 String identifier = createIdentifier();
341 DimensionsCommon dimension = new DimensionsCommon();
342 dimension.setDimension("dimensionType");
343 dimension.setMeasurementUnit("measurementUnit-" + identifier);
344 dimension.setValueDate(new Date().toString());
345 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
347 ClientResponse<Response> res = client.create(multipart);
348 int statusCode = res.getStatus();
350 if (logger.isDebugEnabled()) {
351 logger.debug(testName + ": status = " + statusCode);
353 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
354 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
355 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
360 //to not cause uniqueness violation for permRole, createList is removed
362 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
363 dependsOnMethods = {"create"})
364 public void createList(String testName) throws Exception {
368 // Placeholders until the three tests below can be uncommented.
369 // See Issue CSPACE-401.
371 public void createWithEmptyEntityBody(String testName) throws Exception {
375 public void createWithMalformedXml(String testName) throws Exception {
379 public void createWithWrongXmlSchema(String testName) throws Exception {
382 // ---------------------------------------------------------------
383 // CRUD tests : READ tests
384 // ---------------------------------------------------------------
387 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
388 dependsOnMethods = {"create"})
389 public void read(String testName) throws Exception {
391 if (logger.isDebugEnabled()) {
392 logger.debug(testBanner(testName, CLASS_NAME));
394 DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER);
395 Assert.assertNotNull(dimension);
396 if (logger.isDebugEnabled()) {
397 logger.debug(testName + ": tenantId= " + TENANT_1
398 + " userId=" + TENANT_1_USER
399 + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
403 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
404 dependsOnMethods = {"create2"})
405 public void read2(String testName) throws Exception {
407 if (logger.isDebugEnabled()) {
408 logger.debug(testBanner(testName, CLASS_NAME));
410 DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER);
411 Assert.assertNotNull(dimension);
412 if (logger.isDebugEnabled()) {
413 logger.debug(testName + ": tenantId= " + TENANT_2
414 + " userId=" + TENANT_2_USER
415 + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
419 private DimensionsCommon read(String testName, String id, String userName) throws Exception {
421 // Submit the request to the service and store the response.
422 DimensionClient client = new DimensionClient();
423 client.setAuth(true, userName, true, userName, true);
424 ClientResponse<String> res = client.read(id);
425 int statusCode = res.getStatus();
427 // Check the status code of the response: does it match
428 // the expected response(s)?
429 if (logger.isDebugEnabled()) {
430 logger.debug(testName + ": status = " + statusCode);
432 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
433 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
434 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
436 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
437 return (DimensionsCommon) extractPart(input,
438 client.getCommonPartName(), DimensionsCommon.class);
443 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
444 public void readNonExistent(String testName) throws Exception {
447 setupReadNonExistent();
450 // ---------------------------------------------------------------
451 // CRUD tests : READ_LIST tests
452 // ---------------------------------------------------------------
455 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456 dependsOnMethods = {"createList", "read"})
457 public void readList(String testName) throws Exception {
463 // ---------------------------------------------------------------
464 // CRUD tests : UPDATE tests
465 // ---------------------------------------------------------------
468 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
469 dependsOnMethods = {"read", "readList", "readNonExistent"})
470 public void update(String testName) throws Exception {
476 // Placeholders until the three tests below can be uncommented.
477 // See Issue CSPACE-401.
479 public void updateWithEmptyEntityBody(String testName) throws Exception {
483 public void updateWithMalformedXml(String testName) throws Exception {
487 public void updateWithWrongXmlSchema(String testName) throws Exception {
491 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
492 dependsOnMethods = {"read2", "readNonExistent", "testSubmitRequest"})
493 public void updateNonExistent(String testName) throws Exception {
495 DimensionClient client = new DimensionClient();
496 //TENANT_1_USER is not allowed to update the resource of TENANT_2
497 client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true);
499 DimensionsCommon dimension = new DimensionsCommon();
500 dimension.setDimension("dimensionType");
501 // Update the content of this resource.
502 dimension.setMeasurementUnit("updated-" + dimension.getMeasurementUnit());
503 dimension.setValueDate("updated-" + dimension.getValueDate());
504 // Submit the request to the service and store the response.
505 PoxPayloadOut output = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
506 PayloadOutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
507 commonPart.setLabel(client.getCommonPartName());
509 ClientResponse<String> res = client.update(TENANT_RESOURCE_2, output);
510 int statusCode = res.getStatus();
511 // Check the status code of the response: does it match the expected response(s)?
512 if (logger.isDebugEnabled()) {
513 logger.debug(testName + " resource = " + TENANT_RESOURCE_2
514 + " status = " + statusCode);
516 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
517 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
518 //going to incorrect Nuxeo domain would give DocumentNotFoundException
519 //instead of giving FORBIDDEN
520 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
523 // ---------------------------------------------------------------
524 // CRUD tests : DELETE tests
525 // ---------------------------------------------------------------
528 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
529 dependsOnMethods = {"deleteNonExistent"})
530 public void delete(String testName) throws Exception {
532 if (logger.isDebugEnabled()) {
533 logger.debug(testBanner(testName, CLASS_NAME));
536 int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER);
539 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
540 dependsOnMethods = {"updateNonExistent"})
541 public void delete2(String testName) throws Exception {
543 if (logger.isDebugEnabled()) {
544 logger.debug(testBanner(testName, CLASS_NAME));
546 int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER);
550 private int delete(String testName, String id, String userName) throws Exception {
553 // Submit the request to the service and store the response.
554 DimensionClient client = new DimensionClient();
555 client.setAuth(true, userName, true, userName, true);
556 ClientResponse<Response> res = client.delete(id);
557 int statusCode = res.getStatus();
559 // Check the status code of the response: does it match
560 // the expected response(s)?
561 if (logger.isDebugEnabled()) {
562 logger.debug(testName + ": status = " + statusCode);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
572 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
573 dependsOnMethods = {"read"})
574 public void deleteNonExistent(String testName) throws Exception {
575 //ignoring this test as the service side returns 200 now even if it does
576 //not find a record in the db
578 if (logger.isDebugEnabled()) {
579 logger.debug(testBanner(testName, CLASS_NAME));
584 // Submit the request to the service and store the response.
585 DimensionClient client = new DimensionClient();
586 //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1
587 client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true);
588 ClientResponse<Response> res = client.delete(TENANT_RESOURCE_1);
589 int statusCode = res.getStatus();
591 // Check the status code of the response: does it match
592 // the expected response(s)?
593 if (logger.isDebugEnabled()) {
594 logger.debug(testName + ": status = " + statusCode);
596 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
597 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
598 //going to incorrect Nuxeo domain would give DocumentNotFoundException
599 //instead of giving FORBIDDEN
600 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
603 // ---------------------------------------------------------------
605 // ---------------------------------------------------------------
608 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
609 public void searchWorkflowDeleted(String testName) throws Exception {
610 // Fixme: null test for now, overriding test in base class
613 // ---------------------------------------------------------------
614 // Utility tests : tests of code used in tests above
615 // ---------------------------------------------------------------
617 * Tests the code for manually submitting data that is used by several
618 * of the methods above.
620 @Test(dependsOnMethods = {"create"})
621 public void testSubmitRequest() throws Exception {
624 // ---------------------------------------------------------------
625 // Utility methods used by tests above
626 // ---------------------------------------------------------------
627 @AfterClass(alwaysRun = true)
628 public void cleanUp() {
629 if (logger.isDebugEnabled()) {
630 testBanner("cleanUp", CLASS_NAME);
633 String noTest = System.getProperty("noTestCleanup");
634 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
635 if (logger.isDebugEnabled()) {
636 logger.debug("Skipping Cleanup phase ...");
640 if (logger.isDebugEnabled()) {
641 logger.debug("Cleaning up temporary resources created for testing ...");
644 //tenant admin users are used to create accounts, roles and permissions and relationships
645 //assumption : two tenant admin users exist before running this test
647 deletePermissionRoles();
648 deleteAccountRoles();
649 //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
650 //deletePermissions();
655 private void deletePermissionRoles() {
657 for (String tenantId : tenantPermissions.keySet()) {
658 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
659 tenantRoleValues.add(tenantRoles.get(tenantId));
660 PermissionValue pv = tenantPermissions.get(tenantId);
661 deletePermissionRole(tenantId, pv, tenantRoleValues);
665 private void deleteAccountRoles() {
666 for (String tenantId : tenantAccounts.keySet()) {
667 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
668 tenantRoleValues.add(tenantRoles.get(tenantId));
669 AccountValue av = tenantAccounts.get(tenantId);
670 deleteAccountRole(tenantId, av, tenantRoleValues);
674 private void deletePermissions() {
675 for (String tenantId : tenantPermissions.keySet()) {
676 PermissionValue pv = tenantPermissions.get(tenantId);
677 deletePermission(tenantId, pv.getPermissionId());
681 private void deleteRoles() {
682 for (String tenantId : tenantRoles.keySet()) {
683 RoleValue rv = tenantRoles.get(tenantId);
684 deleteRole(tenantId, rv.getRoleId());
688 private void deleteAccounts() {
690 for (String tenantId : tenantAccounts.keySet()) {
691 AccountValue av = tenantAccounts.get(tenantId);
692 deleteAccount(tenantId, av.getAccountId());
696 private String createPermission(String tenantId, String resName,
697 List<PermissionAction> actions, EffectType effect) {
699 PermissionClient permClient = new PermissionClient();
700 UserInfo ui = tenantAdminUsers.get(tenantId);
701 permClient.setAuth(true, ui.userName, true, ui.password, true);
702 Permission permission = PermissionFactory.createPermissionInstance(resName,
703 "default permissions for " + resName,
704 actions, effect, true, true, true);
705 permission.setTenantId(tenantId);
706 ClientResponse<Response> res = permClient.create(permission);
707 int statusCode = res.getStatus();
708 if (logger.isDebugEnabled()) {
709 logger.debug("createPermission: resName=" + resName
710 + " status = " + statusCode);
712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
715 res.releaseConnection();
716 return extractId(res);
719 private void deletePermission(String tenantId, String permId) {
721 PermissionClient permClient = new PermissionClient();
722 UserInfo ui = tenantAdminUsers.get(tenantId);
723 permClient.setAuth(true, ui.userName, true, ui.password, true);
724 ClientResponse<Response> res = permClient.delete(permId);
725 int statusCode = res.getStatus();
726 if (logger.isDebugEnabled()) {
727 logger.debug("deletePermission: delete permission id="
728 + permId + " status=" + statusCode);
730 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
733 res.releaseConnection();
736 private String createRole(String tenantId, String roleName) {
738 RoleClient roleClient = new RoleClient();
739 UserInfo ui = tenantAdminUsers.get(tenantId);
740 roleClient.setAuth(true, ui.userName, true, ui.password, true);
741 Role role = RoleFactory.createRoleInstance(roleName,
742 roleName, //the display name
743 "role for " + roleName, true);
744 role.setTenantId(tenantId);
745 ClientResponse<Response> res = roleClient.create(role);
746 int statusCode = res.getStatus();
747 if (logger.isDebugEnabled()) {
748 logger.debug("createRole: name=" + roleName
749 + " status = " + statusCode);
751 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
752 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
753 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 res.releaseConnection();
755 return extractId(res);
758 private void deleteRole(String tenantId, String roleId) {
760 RoleClient roleClient = new RoleClient();
761 UserInfo ui = tenantAdminUsers.get(tenantId);
762 roleClient.setAuth(true, ui.userName, true, ui.password, true);
763 ClientResponse<Response> res = roleClient.delete(roleId);
764 int statusCode = res.getStatus();
765 if (logger.isDebugEnabled()) {
766 logger.debug("deleteRole: delete role id=" + roleId
767 + " status=" + statusCode);
769 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
770 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
771 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
772 res.releaseConnection();
775 private String createAccount(String tenantId, String userName, String email) {
777 AccountClient accountClient = new AccountClient();
778 UserInfo ui = tenantAdminUsers.get(tenantId);
779 accountClient.setAuth(true, ui.userName, true, ui.password, true);
780 AccountsCommon account = AccountFactory.createAccountInstance(
781 userName, userName, userName, email, tenantId,
782 true, false, true, true);
783 ClientResponse<Response> res = accountClient.create(account);
784 int statusCode = res.getStatus();
785 if (logger.isDebugEnabled()) {
786 logger.debug("createAccount: tenantId=" + tenantId + " userName=" + userName
787 + " status = " + statusCode);
789 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
792 res.releaseConnection();
793 return extractId(res);
796 private void deleteAccount(String tenantId, String accId) {
798 AccountClient accClient = new AccountClient();
799 UserInfo ui = tenantAdminUsers.get(tenantId);
800 accClient.setAuth(true, ui.userName, true, ui.password, true);
801 ClientResponse<Response> res = accClient.delete(accId);
802 int statusCode = res.getStatus();
803 if (logger.isDebugEnabled()) {
804 logger.debug("deleteAccount: delete account id="
805 + accId + " status=" + statusCode);
807 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
808 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
809 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
810 res.releaseConnection();
813 private String createAccountRole(String tenantId, AccountValue av,
814 Collection<RoleValue> rvs) {
817 // Submit the request to the service and store the response.
818 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
819 av, rvs, true, true);
820 AccountRoleClient client = new AccountRoleClient();
821 UserInfo ui = tenantAdminUsers.get(tenantId);
822 client.setAuth(true, ui.userName, true, ui.password, true);
823 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
824 int statusCode = res.getStatus();
826 if (logger.isDebugEnabled()) {
827 logger.debug("createAccountRole: status = " + statusCode);
829 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
830 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
831 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
832 res.releaseConnection();
833 return extractId(res);
836 private void deleteAccountRole(String tenantId, AccountValue av,
837 List<RoleValue> rvs) {
841 // Submit the request to the service and store the response.
842 AccountRoleClient client = new AccountRoleClient();
843 UserInfo ui = tenantAdminUsers.get(tenantId);
844 client.setAuth(true, ui.userName, true, ui.password, true);
845 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
846 av, rvs, true, true);
847 ClientResponse<Response> res = client.delete(
849 int statusCode = res.getStatus();
851 // Check the status code of the response: does it match
852 // the expected response(s)?
853 if (logger.isDebugEnabled()) {
854 logger.debug("deleteAccountRole: status = " + statusCode);
856 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
857 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
858 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
859 res.releaseConnection();
862 private String createPermissionRole(String tenantId, PermissionValue pv,
863 Collection<RoleValue> rvs) {
865 List<RoleValue> rvls = new ArrayList<RoleValue>();
867 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
868 pv, rvls, true, true);
869 PermissionRoleClient client = new PermissionRoleClient();
870 UserInfo ui = tenantAdminUsers.get(tenantId);
871 client.setAuth(true, ui.userName, true, ui.password, true);
872 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
873 int statusCode = res.getStatus();
875 if (logger.isDebugEnabled()) {
876 logger.debug("createPermissionRole: status = " + statusCode);
878 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
879 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
880 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
881 res.releaseConnection();
882 return extractId(res);
885 private void deletePermissionRole(String tenantId, PermissionValue pv, List<RoleValue> rvls) {
890 // Submit the request to the service and store the response.
891 PermissionRoleClient client = new PermissionRoleClient();
892 UserInfo ui = tenantAdminUsers.get(tenantId);
893 client.setAuth(true, ui.userName, true, ui.password, true);
894 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
895 pv, rvls, true, true);
896 ClientResponse<Response> res = client.delete(pv.getPermissionId());
897 int statusCode = res.getStatus();
899 // Check the status code of the response: does it match
900 // the expected response(s)?
901 if (logger.isDebugEnabled()) {
902 logger.debug("deletePermissionRole : status = " + statusCode);
904 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
905 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
906 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
907 res.releaseConnection();
911 protected String getServiceName() {
912 // TODO Auto-generated method stub
913 throw new UnsupportedOperationException();