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.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.RoleClient;
61 import org.collectionspace.services.client.RoleFactory;
62 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
63 import org.collectionspace.services.dimension.DimensionsCommon;
64 import org.collectionspace.services.jaxb.AbstractCommonList;
65 import org.jboss.resteasy.client.ClientResponse;
66 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
67 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
68 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
70 import org.testng.Assert;
71 import org.testng.annotations.Test;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75 import org.testng.annotations.AfterClass;
76 import org.testng.annotations.BeforeClass;
79 * AuthorizationServiceTest, carries out tests against a
80 * deployed and running Permission, Role, AccountRole, PermissionRole and
81 * CollectionObject Services.
83 * Pre-requisite : authorization-mgt/client tests seed some permissions used
86 * $LastChangedRevision: 917 $
87 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
89 public class MultiTenancyTest extends AbstractServiceTestImpl {
91 private final String CLASS_NAME = MultiTenancyTest.class.getName();
92 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
93 private final static String TENANT_1_ADMIN_USER = "admin@collectionspace.org";
94 private final static String TENANT_2_ADMIN_USER = "admin@hearstmuseum.berkeley.edu";
95 private final static String TENANT_ADMIN_PASS = "Administrator";
96 private final static String TENANT_1_USER = "user1@museum1.org";
97 private final static String TENANT_2_USER = "user2@museum2.org";
98 private final static String TENANT_1 = "1";
99 private final static String TENANT_2 = "2";
100 private final static String TEST_ROLE_NAME = "ROLE_TEST_REGISTRAR";
101 private final static String TEST_SERVICE_A = "dimensions";
103 private static class UserInfo {
108 UserInfo(String u, String p) {
113 // Instance variables specific to this test.
114 private String TENANT_RESOURCE_1 = null;
115 private String TENANT_RESOURCE_2 = null;
116 private List<String> allResourceIdsCreated = new ArrayList();
117 //key for userAccounts is userId
118 private Hashtable<String, AccountValue> userAccounts = new Hashtable<String, AccountValue>();
119 //key for permValues is id as there could be several perms for the same resource
120 private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
121 //key for all tenantXXX tables is tenant id, expecting only one entity per tenant for this test
122 private Hashtable<String, UserInfo> tenantAdminUsers = new Hashtable<String, UserInfo>();
123 private Hashtable<String, AccountValue> tenantAccounts = new Hashtable<String, AccountValue>();
124 private Hashtable<String, RoleValue> tenantRoles = new Hashtable<String, RoleValue>();
125 private Hashtable<String, Role> tenantAdminRoles = new Hashtable<String, Role>();
126 private Hashtable<String, PermissionValue> tenantPermissions = new Hashtable<String, PermissionValue>();
128 // private String permId1;
129 // private String permId2;
132 * This method is called only by the parent class, AbstractServiceTestImpl
135 protected String getServicePathComponent() {
139 @BeforeClass(alwaysRun = true)
140 public void seedData() {
141 if (logger.isDebugEnabled()) {
142 testBanner("seedData", CLASS_NAME);
145 //tenant admin users are used to create accounts, roles and permissions and relationships
146 //assumption : two tenant admin users exist before running this test
147 tenantAdminUsers.put(TENANT_1, new UserInfo(TENANT_1_ADMIN_USER, TENANT_ADMIN_PASS));
148 tenantAdminUsers.put(TENANT_2, new UserInfo(TENANT_2_ADMIN_USER, TENANT_ADMIN_PASS));
154 seedPermissionRoles();
157 private void seedAccounts() {
158 seedAccount(TENANT_1, TENANT_1_USER);
159 seedAccount(TENANT_2, TENANT_2_USER);
162 private void seedAccount(String tenantId, String userId) {
163 //create account using default user in admin role but assign tenant id
164 //create username, email and password same for simplicity
165 String accId = createAccount(tenantId, userId, userId);
166 AccountValue ava = new AccountValue();
167 ava.setScreenName(userId);
168 ava.setUserId(userId);
169 ava.setAccountId(accId);
170 userAccounts.put(ava.getUserId(), ava);
171 tenantAccounts.put(tenantId, ava);
172 if (logger.isDebugEnabled()) {
173 logger.debug("seedAccount tenantId=" + tenantId + " userId=" + userId);
177 private void seedPermissions() {
178 String resource = TEST_SERVICE_A;
180 PermissionAction pac = new PermissionAction();
181 pac.setName(ActionType.CREATE);
182 PermissionAction par = new PermissionAction();
183 par.setName(ActionType.READ);
184 PermissionAction pau = new PermissionAction();
185 pau.setName(ActionType.UPDATE);
186 PermissionAction pad = new PermissionAction();
187 pad.setName(ActionType.DELETE);
189 //both users can create, read and update and delete
190 List<PermissionAction> testActions = new ArrayList<PermissionAction>();
191 testActions.add(pac);
192 testActions.add(par);
193 testActions.add(pau);
194 testActions.add(pad);
196 seedPermission(TENANT_1, resource, testActions, EffectType.PERMIT);
197 seedPermission(TENANT_2, resource, testActions, EffectType.PERMIT);
200 private void seedPermission(String tenantId,
201 String resource, List<PermissionAction> testActions, EffectType effect) {
202 //create permission using default user in admin role but assign tenant id
203 String id = createPermission(tenantId, resource, testActions, effect);
204 PermissionValue pv = new PermissionValue();
205 pv.setResourceName(resource);
206 pv.setPermissionId(id);
207 permValues.put(pv.getPermissionId(), pv);
208 tenantPermissions.put(tenantId, pv);
209 if (logger.isDebugEnabled()) {
210 logger.debug("seedPermission tenantId=" + tenantId
211 + " permId=" + id + " resource=" + resource);
215 private void seedRoles() {
216 //create role using default user in admin role but assign tenant id
217 //use the same role name to check constraints
218 seedRole(TENANT_1, TEST_ROLE_NAME);
219 seedRole(TENANT_2, TEST_ROLE_NAME);
222 private void seedRole(String tenantId, String roleName) {
223 String rid = createRole(tenantId, roleName);
224 RoleValue rv = new RoleValue();
226 rv.setRoleName(roleName);
227 tenantRoles.put(tenantId, rv);
228 if (logger.isDebugEnabled()) {
229 logger.debug("seedRole tenantId=" + tenantId + " roleName=" + roleName);
233 private void seedAccountRoles() {
235 for (String tenantId : tenantAccounts.keySet()) {
236 AccountValue av = (AccountValue) tenantAccounts.get(tenantId);
237 seedAccountRole(tenantId, av.getUserId());
241 private void seedAccountRole(String tenantId, String userId) {
242 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
243 tenantRoleValues.add(tenantRoles.get(tenantId));
244 createAccountRole(tenantId, userAccounts.get(userId), tenantRoleValues);
245 if (logger.isDebugEnabled()) {
246 logger.debug("seedAccountRole tenantId=" + tenantId + " userId=" + userId);
250 private void seedPermissionRoles() {
252 for (String tenantId : tenantPermissions.keySet()) {
253 PermissionValue pv = tenantPermissions.get(tenantId);
254 seedPermissionRole(tenantId, pv.getPermissionId());
258 private void seedPermissionRole(String tenantId, String permId) {
259 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
260 tenantRoleValues.add(tenantRoles.get(tenantId));
261 PermissionValue pv = permValues.get(permId);
262 createPermissionRole(tenantId, permValues.get(permId), tenantRoleValues);
263 if (logger.isDebugEnabled()) {
264 logger.debug("seedPermissionRole tenantId=" + tenantId
265 + " permId=" + permId + " resource=" + pv.getResourceName());
271 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
274 protected CollectionSpaceClient getClientInstance() {
279 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
282 protected AbstractCommonList getAbstractCommonList(
283 ClientResponse<AbstractCommonList> response) {
284 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
285 throw new UnsupportedOperationException();
288 @Test(dataProvider = "testName")
290 public void readPaginatedList(String testName) throws Exception {
291 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
293 // ---------------------------------------------------------------
294 // CRUD tests : CREATE tests
295 // ---------------------------------------------------------------
299 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
300 public void create(String testName) throws Exception {
301 if (logger.isDebugEnabled()) {
302 logger.debug(testBanner(testName, CLASS_NAME));
305 ClientResponse<Response> res = create(testName, TENANT_1_USER, TENANT_1);
307 TENANT_RESOURCE_1 = extractId(res);
309 if (logger.isDebugEnabled()) {
310 logger.debug(testName + ": tenantId= " + TENANT_1
311 + " userId=" + TENANT_1_USER
312 + " TENANT_RESOURCE_1 id=" + TENANT_RESOURCE_1);
316 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
317 public void create2(String testName) throws Exception {
318 if (logger.isDebugEnabled()) {
319 logger.debug(testBanner(testName, CLASS_NAME));
322 ClientResponse<Response> res = create(testName, TENANT_2_USER, TENANT_2);
324 TENANT_RESOURCE_2 = extractId(res);
325 if (logger.isDebugEnabled()) {
326 logger.debug(testName + ": tenantId= " + TENANT_2
327 + " userId=" + TENANT_2_USER
328 + " TENANT_RESOURCE_2 id=" + TENANT_RESOURCE_2);
332 private ClientResponse<Response> create(String testName, String userName, String tenatnId) {
334 // Submit the request to the service and store the response.
335 DimensionClient client = new DimensionClient();
336 client.setAuth(true, userName, true, userName, true);
337 String identifier = createIdentifier();
338 DimensionsCommon dimension = new DimensionsCommon();
339 dimension.setDimension("dimensionType");
340 dimension.setValue("value-" + identifier);
341 dimension.setValueDate(new Date().toString());
342 MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
344 ClientResponse<Response> res = client.create(multipart);
345 int statusCode = res.getStatus();
347 if (logger.isDebugEnabled()) {
348 logger.debug(testName + ": status = " + statusCode);
350 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
351 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
352 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
357 //to not cause uniqueness violation for permRole, createList is removed
359 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
360 dependsOnMethods = {"create"})
361 public void createList(String testName) throws Exception {
365 // Placeholders until the three tests below can be uncommented.
366 // See Issue CSPACE-401.
368 public void createWithEmptyEntityBody(String testName) throws Exception {
372 public void createWithMalformedXml(String testName) throws Exception {
376 public void createWithWrongXmlSchema(String testName) throws Exception {
379 // ---------------------------------------------------------------
380 // CRUD tests : READ tests
381 // ---------------------------------------------------------------
384 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
385 dependsOnMethods = {"create"})
386 public void read(String testName) throws Exception {
388 if (logger.isDebugEnabled()) {
389 logger.debug(testBanner(testName, CLASS_NAME));
391 DimensionsCommon dimension = read(testName, TENANT_RESOURCE_1, TENANT_1_USER);
392 Assert.assertNotNull(dimension);
393 if (logger.isDebugEnabled()) {
394 logger.debug(testName + ": tenantId= " + TENANT_1
395 + " userId=" + TENANT_1_USER
396 + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
400 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
401 dependsOnMethods = {"create2"})
402 public void read2(String testName) throws Exception {
404 if (logger.isDebugEnabled()) {
405 logger.debug(testBanner(testName, CLASS_NAME));
407 DimensionsCommon dimension = read(testName, TENANT_RESOURCE_2, TENANT_2_USER);
408 Assert.assertNotNull(dimension);
409 if (logger.isDebugEnabled()) {
410 logger.debug(testName + ": tenantId= " + TENANT_2
411 + " userId=" + TENANT_2_USER
412 + " TENANT_RESOURCE_1 retrieved id=" + dimension.getCsid());
416 private DimensionsCommon read(String testName, String id, String userName) throws Exception {
418 // Submit the request to the service and store the response.
419 DimensionClient client = new DimensionClient();
420 client.setAuth(true, userName, true, userName, true);
421 ClientResponse<MultipartInput> res = client.read(id);
422 int statusCode = res.getStatus();
424 // Check the status code of the response: does it match
425 // the expected response(s)?
426 if (logger.isDebugEnabled()) {
427 logger.debug(testName + ": status = " + statusCode);
429 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
430 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
431 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
433 MultipartInput input = (MultipartInput) res.getEntity();
434 return (DimensionsCommon) extractPart(input,
435 client.getCommonPartName(), DimensionsCommon.class);
440 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
441 public void readNonExistent(String testName) throws Exception {
444 setupReadNonExistent();
447 // ---------------------------------------------------------------
448 // CRUD tests : READ_LIST tests
449 // ---------------------------------------------------------------
452 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
453 dependsOnMethods = {"createList", "read"})
454 public void readList(String testName) throws Exception {
460 // ---------------------------------------------------------------
461 // CRUD tests : UPDATE tests
462 // ---------------------------------------------------------------
465 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
466 dependsOnMethods = {"read", "readList", "readNonExistent"})
467 public void update(String testName) throws Exception {
473 // Placeholders until the three tests below can be uncommented.
474 // See Issue CSPACE-401.
476 public void updateWithEmptyEntityBody(String testName) throws Exception {
480 public void updateWithMalformedXml(String testName) throws Exception {
484 public void updateWithWrongXmlSchema(String testName) throws Exception {
488 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
489 dependsOnMethods = {"read2", "readNonExistent", "testSubmitRequest"})
490 public void updateNonExistent(String testName) throws Exception {
492 DimensionClient client = new DimensionClient();
493 //TENANT_1_USER is not allowed to update the resource of TENANT_2
494 client.setAuth(true, TENANT_1_USER, true, TENANT_1_USER, true);
496 DimensionsCommon dimension = new DimensionsCommon();
497 dimension.setDimension("dimensionType");
498 // Update the content of this resource.
499 dimension.setValue("updated-" + dimension.getValue());
500 dimension.setValueDate("updated-" + dimension.getValueDate());
501 // Submit the request to the service and store the response.
502 MultipartOutput output = new MultipartOutput();
503 OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
504 commonPart.getHeaders().add("label", client.getCommonPartName());
506 ClientResponse<MultipartInput> res = client.update(TENANT_RESOURCE_2, output);
507 int statusCode = res.getStatus();
508 // Check the status code of the response: does it match the expected response(s)?
509 if (logger.isDebugEnabled()) {
510 logger.debug(testName + " resource = " + TENANT_RESOURCE_2
511 + " status = " + statusCode);
513 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
514 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
515 //going to incorrect Nuxeo domain would give DocumentNotFoundException
516 //instead of giving FORBIDDEN
517 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
520 // ---------------------------------------------------------------
521 // CRUD tests : DELETE tests
522 // ---------------------------------------------------------------
525 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
526 dependsOnMethods = {"deleteNonExistent"})
527 public void delete(String testName) throws Exception {
529 if (logger.isDebugEnabled()) {
530 logger.debug(testBanner(testName, CLASS_NAME));
533 int statusCode = delete(testName, TENANT_RESOURCE_1, TENANT_1_USER);
536 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
537 dependsOnMethods = {"updateNonExistent"})
538 public void delete2(String testName) throws Exception {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
543 int statusCode = delete(testName, TENANT_RESOURCE_2, TENANT_2_USER);
547 private int delete(String testName, String id, String userName) throws Exception {
550 // Submit the request to the service and store the response.
551 DimensionClient client = new DimensionClient();
552 client.setAuth(true, userName, true, userName, true);
553 ClientResponse<Response> res = client.delete(id);
554 int statusCode = res.getStatus();
556 // Check the status code of the response: does it match
557 // the expected response(s)?
558 if (logger.isDebugEnabled()) {
559 logger.debug(testName + ": status = " + statusCode);
561 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
562 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
563 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
569 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
570 dependsOnMethods = {"read"})
571 public void deleteNonExistent(String testName) throws Exception {
572 //ignoring this test as the service side returns 200 now even if it does
573 //not find a record in the db
575 if (logger.isDebugEnabled()) {
576 logger.debug(testBanner(testName, CLASS_NAME));
581 // Submit the request to the service and store the response.
582 DimensionClient client = new DimensionClient();
583 //TENANT_2_USER of TENANT_2 is not allowed to delete the resource of TENANT_1
584 client.setAuth(true, TENANT_2_USER, true, TENANT_2_USER, true);
585 ClientResponse<Response> res = client.delete(TENANT_RESOURCE_1);
586 int statusCode = res.getStatus();
588 // Check the status code of the response: does it match
589 // the expected response(s)?
590 if (logger.isDebugEnabled()) {
591 logger.debug(testName + ": status = " + statusCode);
593 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
594 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
595 //going to incorrect Nuxeo domain would give DocumentNotFoundException
596 //instead of giving FORBIDDEN
597 Assert.assertEquals(statusCode, Response.Status.NOT_FOUND.getStatusCode());
600 // ---------------------------------------------------------------
601 // Utility tests : tests of code used in tests above
602 // ---------------------------------------------------------------
604 * Tests the code for manually submitting data that is used by several
605 * of the methods above.
607 @Test(dependsOnMethods = {"create"})
608 public void testSubmitRequest() throws Exception {
611 // ---------------------------------------------------------------
612 // Utility methods used by tests above
613 // ---------------------------------------------------------------
614 @AfterClass(alwaysRun = true)
615 public void cleanUp() {
616 if (logger.isDebugEnabled()) {
617 testBanner("cleanUp", CLASS_NAME);
620 String noTest = System.getProperty("noTestCleanup");
621 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
622 if (logger.isDebugEnabled()) {
623 logger.debug("Skipping Cleanup phase ...");
627 if (logger.isDebugEnabled()) {
628 logger.debug("Cleaning up temporary resources created for testing ...");
631 //tenant admin users are used to create accounts, roles and permissions and relationships
632 //assumption : two tenant admin users exist before running this test
634 deletePermissionRoles();
635 deleteAccountRoles();
636 //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
637 //deletePermissions();
642 private void deletePermissionRoles() {
644 for (String tenantId : tenantPermissions.keySet()) {
645 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
646 tenantRoleValues.add(tenantRoles.get(tenantId));
647 PermissionValue pv = tenantPermissions.get(tenantId);
648 deletePermissionRole(tenantId, pv, tenantRoleValues);
652 private void deleteAccountRoles() {
653 for (String tenantId : tenantAccounts.keySet()) {
654 List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
655 tenantRoleValues.add(tenantRoles.get(tenantId));
656 AccountValue av = tenantAccounts.get(tenantId);
657 deleteAccountRole(tenantId, av, tenantRoleValues);
661 private void deletePermissions() {
662 for (String tenantId : tenantPermissions.keySet()) {
663 PermissionValue pv = tenantPermissions.get(tenantId);
664 deletePermission(tenantId, pv.getPermissionId());
668 private void deleteRoles() {
669 for (String tenantId : tenantRoles.keySet()) {
670 RoleValue rv = tenantRoles.get(tenantId);
671 deleteRole(tenantId, rv.getRoleId());
675 private void deleteAccounts() {
677 for (String tenantId : tenantAccounts.keySet()) {
678 AccountValue av = tenantAccounts.get(tenantId);
679 deleteAccount(tenantId, av.getAccountId());
683 private String createPermission(String tenantId, String resName,
684 List<PermissionAction> actions, EffectType effect) {
686 PermissionClient permClient = new PermissionClient();
687 UserInfo ui = tenantAdminUsers.get(tenantId);
688 permClient.setAuth(true, ui.userName, true, ui.password, true);
689 Permission permission = PermissionFactory.createPermissionInstance(resName,
690 "default permissions for " + resName,
691 actions, effect, true, true, true);
692 permission.setTenantId(tenantId);
693 ClientResponse<Response> res = permClient.create(permission);
694 int statusCode = res.getStatus();
695 if (logger.isDebugEnabled()) {
696 logger.debug("createPermission: resName=" + resName
697 + " status = " + statusCode);
699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702 res.releaseConnection();
703 return extractId(res);
706 private void deletePermission(String tenantId, String permId) {
708 PermissionClient permClient = new PermissionClient();
709 UserInfo ui = tenantAdminUsers.get(tenantId);
710 permClient.setAuth(true, ui.userName, true, ui.password, true);
711 ClientResponse<Response> res = permClient.delete(permId);
712 int statusCode = res.getStatus();
713 if (logger.isDebugEnabled()) {
714 logger.debug("deletePermission: delete permission id="
715 + permId + " status=" + statusCode);
717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 res.releaseConnection();
723 private String createRole(String tenantId, String roleName) {
725 RoleClient roleClient = new RoleClient();
726 UserInfo ui = tenantAdminUsers.get(tenantId);
727 roleClient.setAuth(true, ui.userName, true, ui.password, true);
728 Role role = RoleFactory.createRoleInstance(roleName,
729 roleName, //the display name
730 "role for " + roleName, true);
731 role.setTenantId(tenantId);
732 ClientResponse<Response> res = roleClient.create(role);
733 int statusCode = res.getStatus();
734 if (logger.isDebugEnabled()) {
735 logger.debug("createRole: name=" + roleName
736 + " status = " + statusCode);
738 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
739 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
740 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
741 res.releaseConnection();
742 return extractId(res);
745 private void deleteRole(String tenantId, String roleId) {
747 RoleClient roleClient = new RoleClient();
748 UserInfo ui = tenantAdminUsers.get(tenantId);
749 roleClient.setAuth(true, ui.userName, true, ui.password, true);
750 ClientResponse<Response> res = roleClient.delete(roleId);
751 int statusCode = res.getStatus();
752 if (logger.isDebugEnabled()) {
753 logger.debug("deleteRole: delete role id=" + roleId
754 + " status=" + statusCode);
756 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
757 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
758 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
759 res.releaseConnection();
762 private String createAccount(String tenantId, String userName, String email) {
764 AccountClient accountClient = new AccountClient();
765 UserInfo ui = tenantAdminUsers.get(tenantId);
766 accountClient.setAuth(true, ui.userName, true, ui.password, true);
767 AccountsCommon account = AccountFactory.createAccountInstance(
768 userName, userName, userName, email, tenantId,
769 true, false, true, true);
770 ClientResponse<Response> res = accountClient.create(account);
771 int statusCode = res.getStatus();
772 if (logger.isDebugEnabled()) {
773 logger.debug("createAccount: tenantId=" + tenantId + " userName=" + userName
774 + " status = " + statusCode);
776 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
777 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
778 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
779 res.releaseConnection();
780 return extractId(res);
783 private void deleteAccount(String tenantId, String accId) {
785 AccountClient accClient = new AccountClient();
786 UserInfo ui = tenantAdminUsers.get(tenantId);
787 accClient.setAuth(true, ui.userName, true, ui.password, true);
788 ClientResponse<Response> res = accClient.delete(accId);
789 int statusCode = res.getStatus();
790 if (logger.isDebugEnabled()) {
791 logger.debug("deleteAccount: delete account id="
792 + accId + " status=" + statusCode);
794 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
795 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
796 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
797 res.releaseConnection();
800 private String createAccountRole(String tenantId, AccountValue av,
801 Collection<RoleValue> rvs) {
804 // Submit the request to the service and store the response.
805 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
806 av, rvs, true, true);
807 AccountRoleClient client = new AccountRoleClient();
808 UserInfo ui = tenantAdminUsers.get(tenantId);
809 client.setAuth(true, ui.userName, true, ui.password, true);
810 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
811 int statusCode = res.getStatus();
813 if (logger.isDebugEnabled()) {
814 logger.debug("createAccountRole: status = " + statusCode);
816 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
817 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
818 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
819 res.releaseConnection();
820 return extractId(res);
823 private void deleteAccountRole(String tenantId, AccountValue av,
824 List<RoleValue> rvs) {
828 // Submit the request to the service and store the response.
829 AccountRoleClient client = new AccountRoleClient();
830 UserInfo ui = tenantAdminUsers.get(tenantId);
831 client.setAuth(true, ui.userName, true, ui.password, true);
832 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
833 av, rvs, true, true);
834 ClientResponse<Response> res = client.delete(
836 int statusCode = res.getStatus();
838 // Check the status code of the response: does it match
839 // the expected response(s)?
840 if (logger.isDebugEnabled()) {
841 logger.debug("deleteAccountRole: status = " + statusCode);
843 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
844 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
845 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
846 res.releaseConnection();
849 private String createPermissionRole(String tenantId, PermissionValue pv,
850 Collection<RoleValue> rvs) {
852 List<RoleValue> rvls = new ArrayList<RoleValue>();
854 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
855 pv, rvls, true, true);
856 PermissionRoleClient client = new PermissionRoleClient();
857 UserInfo ui = tenantAdminUsers.get(tenantId);
858 client.setAuth(true, ui.userName, true, ui.password, true);
859 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
860 int statusCode = res.getStatus();
862 if (logger.isDebugEnabled()) {
863 logger.debug("createPermissionRole: status = " + statusCode);
865 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
866 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
867 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
868 res.releaseConnection();
869 return extractId(res);
872 private void deletePermissionRole(String tenantId, PermissionValue pv, List<RoleValue> rvls) {
877 // Submit the request to the service and store the response.
878 PermissionRoleClient client = new PermissionRoleClient();
879 UserInfo ui = tenantAdminUsers.get(tenantId);
880 client.setAuth(true, ui.userName, true, ui.password, true);
881 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
882 pv, rvls, true, true);
883 ClientResponse<Response> res = client.delete(pv.getPermissionId());
884 int statusCode = res.getStatus();
886 // Check the status code of the response: does it match
887 // the expected response(s)?
888 if (logger.isDebugEnabled()) {
889 logger.debug("deletePermissionRole : status = " + statusCode);
891 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
892 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
893 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
894 res.releaseConnection();