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 AuthorizationServiceTest extends AbstractServiceTestImpl {
91 private final String CLASS_NAME = AuthorizationServiceTest.class.getName();
92 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
94 // Instance variables specific to this test.
95 private String knownResourceId = null;
96 private List<String> allResourceIdsCreated = new ArrayList();
97 //key for accValues is userId
98 private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
99 //key for permValues is id as there could be several perms for the same resource
100 private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
101 //key for roleValues is roleName
102 private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
103 private String bigbirdPermId;
104 private String elmoPermId;
105 private final static String TEST_SERVICE_NAME = "dimensions";
107 * This method is called only by the parent class, AbstractServiceTestImpl
111 protected String getServicePathComponent() {
115 @BeforeClass(alwaysRun = true)
116 public void seedData() {
121 seedPermissionRoles();
124 private void seedPermissions() {
125 String res = TEST_SERVICE_NAME;
127 PermissionAction pac = new PermissionAction();
128 pac.setName(ActionType.CREATE);
129 PermissionAction par = new PermissionAction();
130 par.setName(ActionType.READ);
131 PermissionAction pau = new PermissionAction();
132 pau.setName(ActionType.UPDATE);
135 //bigbird can create, read and update but not delete
136 List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
140 bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
141 PermissionValue bbpv = new PermissionValue();
142 bbpv.setResourceName(res);
143 bbpv.setPermissionId(bigbirdPermId);
144 permValues.put(bbpv.getPermissionId(), bbpv);
147 List<PermissionAction> eactions = new ArrayList<PermissionAction>();
149 elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
150 PermissionValue epv = new PermissionValue();
151 epv.setResourceName(res);
152 epv.setPermissionId(elmoPermId);
153 permValues.put(epv.getPermissionId(), epv);
156 private void seedRoles() {
157 String rn1 = "ROLE_TEST_CM";
158 String r1RoleId = createRole(rn1);
159 RoleValue rv1 = new RoleValue();
160 rv1.setRoleId(r1RoleId);
161 rv1.setRoleName(rn1);
162 roleValues.put(rv1.getRoleName(), rv1);
164 String rn2 = "ROLE_TEST_INTERN";
165 String r2RoleId = createRole(rn2);
166 RoleValue rv2 = new RoleValue();
167 rv2.setRoleId(r2RoleId);
168 rv2.setRoleName(rn2);
169 roleValues.put(rv2.getRoleName(), rv2);
172 private void seedAccounts() {
173 String userId = "bigbird2010";
174 String accId = createAccount(userId, "bigbird@cspace.org");
175 AccountValue ava = new AccountValue();
176 ava.setScreenName(userId);
177 ava.setUserId(userId);
178 ava.setAccountId(accId);
179 accValues.put(ava.getUserId(), ava);
181 String userId2 = "elmo2010";
182 String coAccId = createAccount(userId2, "elmo@cspace.org");
183 AccountValue avc = new AccountValue();
184 avc.setScreenName(userId2);
185 avc.setUserId(userId2);
186 avc.setAccountId(coAccId);
187 accValues.put(avc.getUserId(), avc);
190 private void seedAccountRoles() {
192 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
193 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
194 createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
196 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
197 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
198 createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
201 private void seedPermissionRoles() {
203 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
204 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
205 createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
207 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
208 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
209 createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
215 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
218 protected CollectionSpaceClient getClientInstance() {
223 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
226 protected AbstractCommonList getAbstractCommonList(
227 ClientResponse<AbstractCommonList> response) {
228 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
229 throw new UnsupportedOperationException();
232 @Test(dataProvider = "testName")
234 public void readPaginatedList(String testName) throws Exception {
235 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
237 // ---------------------------------------------------------------
238 // CRUD tests : CREATE tests
239 // ---------------------------------------------------------------
243 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
244 public void create(String testName) throws Exception {
245 if (logger.isDebugEnabled()) {
246 logger.debug(testBanner(testName, CLASS_NAME));
250 // Submit the request to the service and store the response.
251 DimensionClient client = new DimensionClient();
252 //bigbird allowed to create
253 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
254 String identifier = createIdentifier();
255 DimensionsCommon dimension = new DimensionsCommon();
256 dimension.setDimension("dimensionType");
257 dimension.setValue("value-" + identifier);
258 dimension.setValueDate(new Date().toString());
259 MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
261 ClientResponse<Response> res = client.create(multipart);
263 int statusCode = res.getStatus();
265 if (logger.isDebugEnabled()) {
266 logger.debug(testName + ": status = " + statusCode);
268 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
269 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
270 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
271 knownResourceId = extractId(res);
272 if (logger.isDebugEnabled()) {
273 logger.debug(testName + ": knownResourceId=" + knownResourceId);
277 //to not cause uniqueness violation for permRole, createList is removed
279 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
280 dependsOnMethods = {"create"})
281 public void createList(String testName) throws Exception {
285 // Placeholders until the three tests below can be uncommented.
286 // See Issue CSPACE-401.
288 public void createWithEmptyEntityBody(String testName) throws Exception {
292 public void createWithMalformedXml(String testName) throws Exception {
296 public void createWithWrongXmlSchema(String testName) throws Exception {
299 // ---------------------------------------------------------------
300 // CRUD tests : READ tests
301 // ---------------------------------------------------------------
304 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
305 dependsOnMethods = {"create"})
306 public void read(String testName) throws Exception {
308 if (logger.isDebugEnabled()) {
309 logger.debug(testBanner(testName, CLASS_NAME));
314 // Submit the request to the service and store the response.
315 DimensionClient client = new DimensionClient();
316 //elmo allowed to read
317 client.setAuth(true, "elmo2010", true, "elmo2010", true);
318 ClientResponse<MultipartInput> res = client.read(knownResourceId);
319 int statusCode = res.getStatus();
321 // Check the status code of the response: does it match
322 // the expected response(s)?
323 if (logger.isDebugEnabled()) {
324 logger.debug(testName + ": status = " + statusCode);
326 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
328 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
330 MultipartInput input = (MultipartInput) res.getEntity();
331 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
332 client.getCommonPartName(), DimensionsCommon.class);
333 Assert.assertNotNull(dimension);
339 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
340 public void readNonExistent(String testName) throws Exception {
343 setupReadNonExistent();
346 // ---------------------------------------------------------------
347 // CRUD tests : READ_LIST tests
348 // ---------------------------------------------------------------
351 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 dependsOnMethods = {"createList", "read"})
353 public void readList(String testName) throws Exception {
359 // ---------------------------------------------------------------
360 // CRUD tests : UPDATE tests
361 // ---------------------------------------------------------------
364 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
365 dependsOnMethods = {"read", "readList", "readNonExistent"})
366 public void update(String testName) throws Exception {
371 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
372 dependsOnMethods = {"read", "readList", "readNonExistent"})
373 public void updateNotAllowed(String testName) throws Exception {
375 if (logger.isDebugEnabled()) {
376 logger.debug(testBanner(testName, CLASS_NAME));
380 DimensionClient client = new DimensionClient();
382 //elmo not allowed to update
383 client.setAuth(true, "elmo2010", true, "elmo2010", true);
385 DimensionsCommon dimension = new DimensionsCommon();
386 dimension.setDimension("dimensionType");
387 // Update the content of this resource.
388 dimension.setValue("updated-" + dimension.getValue());
389 dimension.setValueDate("updated-" + dimension.getValueDate());
390 // Submit the request to the service and store the response.
391 MultipartOutput output = new MultipartOutput();
392 OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
393 commonPart.getHeaders().add("label", client.getCommonPartName());
395 ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
396 int statusCode = res.getStatus();
397 // Check the status code of the response: does it match the expected response(s)?
398 if (logger.isDebugEnabled()) {
399 logger.debug(testName + ": status = " + statusCode);
401 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
402 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
403 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
407 // Placeholders until the three tests below can be uncommented.
408 // See Issue CSPACE-401.
410 public void updateWithEmptyEntityBody(String testName) throws Exception {
414 public void updateWithMalformedXml(String testName) throws Exception {
418 public void updateWithWrongXmlSchema(String testName) throws Exception {
422 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
423 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
424 public void updateNonExistent(String testName) throws Exception {
427 // ---------------------------------------------------------------
428 // CRUD tests : DELETE tests
429 // ---------------------------------------------------------------
431 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
432 dependsOnMethods = {"updateNotAllowed"})
433 public void deleteNotAllowed(String testName) throws Exception {
435 if (logger.isDebugEnabled()) {
436 logger.debug(testBanner(testName, CLASS_NAME));
441 // Submit the request to the service and store the response.
442 DimensionClient client = new DimensionClient();
443 //bigbird can not delete
444 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
445 ClientResponse<Response> res = client.delete(knownResourceId);
446 int statusCode = res.getStatus();
448 // Check the status code of the response: does it match
449 // the expected response(s)?
450 if (logger.isDebugEnabled()) {
451 logger.debug(testName + ": status = " + statusCode);
453 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
454 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
455 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
460 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
461 dependsOnMethods = {"deleteNotAllowed"})
462 public void delete(String testName) throws Exception {
464 if (logger.isDebugEnabled()) {
465 logger.debug(testBanner(testName, CLASS_NAME));
470 // Submit the request to the service and store the response.
471 DimensionClient client = new DimensionClient();
473 ClientResponse<Response> res = client.delete(knownResourceId);
474 int statusCode = res.getStatus();
476 // Check the status code of the response: does it match
477 // the expected response(s)?
478 if (logger.isDebugEnabled()) {
479 logger.debug(testName + ": status = " + statusCode);
481 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
482 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
483 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
489 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
490 public void deleteNonExistent(String testName) throws Exception {
491 //ignoring this test as the service side returns 200 now even if it does
492 //not find a record in the db
495 // ---------------------------------------------------------------
496 // Utility tests : tests of code used in tests above
497 // ---------------------------------------------------------------
499 * Tests the code for manually submitting data that is used by several
500 * of the methods above.
502 @Test(dependsOnMethods = {"create"})
503 public void testSubmitRequest() throws Exception {
506 // ---------------------------------------------------------------
507 // Utility methods used by tests above
508 // ---------------------------------------------------------------
509 @AfterClass(alwaysRun = true)
510 public void cleanUp() {
512 String noTest = System.getProperty("noTestCleanup");
513 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
514 if (logger.isDebugEnabled()) {
515 logger.debug("Skipping Cleanup phase ...");
519 if (logger.isDebugEnabled()) {
520 logger.debug("Cleaning up temporary resources created for testing ...");
523 //FIXME delete on permission role deletes all roles associated with the permission
524 //this would delete association with ROLE_ADMINISTRATION too
525 //deletePermissionRoles();
526 deleteAccountRoles();
527 //FIXME delete on permission role deletes all roles associated with the permission
528 //this would delete association with ROLE_ADMINISTRATION too
529 //deletePermissions();
534 private String createPermission(String resName, EffectType effect) {
535 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
536 return createPermission(resName, actions, effect);
539 private String createPermission(String resName,
540 List<PermissionAction> actions, EffectType effect) {
542 PermissionClient permClient = new PermissionClient();
543 Permission permission = PermissionFactory.createPermissionInstance(resName,
544 "default permissions for " + resName,
545 actions, effect, true, true, true);
546 ClientResponse<Response> res = permClient.create(permission);
547 int statusCode = res.getStatus();
548 if (logger.isDebugEnabled()) {
549 logger.debug("createPermission: resName=" + resName
550 + " status = " + statusCode);
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
555 res.releaseConnection();
556 return extractId(res);
559 private void deletePermission(String permId) {
561 PermissionClient permClient = new PermissionClient();
562 ClientResponse<Response> res = permClient.delete(permId);
563 int statusCode = res.getStatus();
564 if (logger.isDebugEnabled()) {
565 logger.debug("deletePermission: delete permission id="
566 + permId + " status=" + statusCode);
568 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
569 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
570 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
571 res.releaseConnection();
574 private String createRole(String roleName) {
576 RoleClient roleClient = new RoleClient();
578 Role role = RoleFactory.createRoleInstance(roleName,
579 "role for " + roleName, true);
580 ClientResponse<Response> res = roleClient.create(role);
581 int statusCode = res.getStatus();
582 if (logger.isDebugEnabled()) {
583 logger.debug("createRole: name=" + roleName
584 + " status = " + statusCode);
586 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
587 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
588 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
589 res.releaseConnection();
590 return extractId(res);
593 private void deleteRole(String roleId) {
595 RoleClient roleClient = new RoleClient();
596 ClientResponse<Response> res = roleClient.delete(roleId);
597 int statusCode = res.getStatus();
598 if (logger.isDebugEnabled()) {
599 logger.debug("deleteRole: delete role id=" + roleId
600 + " status=" + statusCode);
602 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
605 res.releaseConnection();
608 private String createAccount(String userName, String email) {
610 AccountClient accountClient = new AccountClient();
611 AccountsCommon account = AccountFactory.createAccountInstance(
612 userName, userName, userName, email, accountClient.getTenantId(),
613 true, false, true, true);
614 ClientResponse<Response> res = accountClient.create(account);
615 int statusCode = res.getStatus();
616 if (logger.isDebugEnabled()) {
617 logger.debug("createAccount: userName=" + userName
618 + " status = " + statusCode);
620 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
621 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
622 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
623 res.releaseConnection();
624 return extractId(res);
627 private void deleteAccount(String accId) {
629 AccountClient accClient = new AccountClient();
630 ClientResponse<Response> res = accClient.delete(accId);
631 int statusCode = res.getStatus();
632 if (logger.isDebugEnabled()) {
633 logger.debug("deleteAccount: delete account id="
634 + accId + " status=" + statusCode);
636 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
638 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
639 res.releaseConnection();
642 private String createAccountRole(AccountValue av,
643 Collection<RoleValue> rvs) {
646 // Submit the request to the service and store the response.
647 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
648 av, rvs, true, true);
649 AccountRoleClient client = new AccountRoleClient();
650 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
651 int statusCode = res.getStatus();
653 if (logger.isDebugEnabled()) {
654 logger.debug("createAccountRole: status = " + statusCode);
656 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
657 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
658 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 res.releaseConnection();
660 return extractId(res);
663 private void deleteAccountRole(String screenName) {
667 // Submit the request to the service and store the response.
668 AccountRoleClient client = new AccountRoleClient();
669 ClientResponse<Response> res = client.delete(
670 accValues.get(screenName).getAccountId(), "123");
671 int statusCode = res.getStatus();
673 // Check the status code of the response: does it match
674 // the expected response(s)?
675 if (logger.isDebugEnabled()) {
676 logger.debug("deleteAccountRole: status = " + statusCode);
678 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
679 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
680 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
681 res.releaseConnection();
684 private String createPermissionRole(PermissionValue pv,
685 Collection<RoleValue> rvs) {
687 List<RoleValue> rvls = new ArrayList<RoleValue>();
689 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
690 pv, rvls, true, true);
691 PermissionRoleClient client = new PermissionRoleClient();
692 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
693 int statusCode = res.getStatus();
695 if (logger.isDebugEnabled()) {
696 logger.debug("createPermissionRole: status = " + statusCode);
698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701 res.releaseConnection();
702 return extractId(res);
705 private void deletePermissionRole(String permId) {
710 // Submit the request to the service and store the response.
711 PermissionRoleClient client = new PermissionRoleClient();
712 ClientResponse<Response> res = client.delete(permId, "123");
713 int statusCode = res.getStatus();
715 // Check the status code of the response: does it match
716 // the expected response(s)?
717 if (logger.isDebugEnabled()) {
718 logger.debug("deletePermissionRole : status = " + statusCode);
720 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
721 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
722 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
723 res.releaseConnection();
726 private void deletePermissionRoles() {
728 //first delete relationships between the entities
729 for (PermissionValue pv : permValues.values()) {
730 deletePermissionRole(pv.getPermissionId());
734 private void deleteAccountRoles() {
735 for (AccountValue av : accValues.values()) {
736 deleteAccountRole(av.getUserId());
740 private void deletePermissions() {
742 for (PermissionValue pv : permValues.values()) {
743 deletePermission(pv.getPermissionId());
747 private void deleteRoles() {
748 for (RoleValue rv : roleValues.values()) {
749 deleteRole(rv.getRoleId());
753 private void deleteAccounts() {
755 for (AccountValue av1 : accValues.values()) {
756 deleteAccount(av1.getAccountId());
761 private String getTenantId(AccountClient client) {
762 return client.getProperty(AccountClient.TENANT_PROPERTY);