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();
472 //default user test/test has delete permission
473 client.setAuth(true, "test", true, "test", true);
474 ClientResponse<Response> res = client.delete(knownResourceId);
475 int statusCode = res.getStatus();
477 // Check the status code of the response: does it match
478 // the expected response(s)?
479 if (logger.isDebugEnabled()) {
480 logger.debug(testName + ": status = " + statusCode);
482 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
483 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
484 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
490 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
491 public void deleteNonExistent(String testName) throws Exception {
492 //ignoring this test as the service side returns 200 now even if it does
493 //not find a record in the db
496 // ---------------------------------------------------------------
497 // Utility tests : tests of code used in tests above
498 // ---------------------------------------------------------------
500 * Tests the code for manually submitting data that is used by several
501 * of the methods above.
503 @Test(dependsOnMethods = {"create"})
504 public void testSubmitRequest() throws Exception {
507 // ---------------------------------------------------------------
508 // Utility methods used by tests above
509 // ---------------------------------------------------------------
510 @AfterClass(alwaysRun = true)
511 public void cleanUp() {
513 String noTest = System.getProperty("noTestCleanup");
514 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
515 if (logger.isDebugEnabled()) {
516 logger.debug("Skipping Cleanup phase ...");
520 if (logger.isDebugEnabled()) {
521 logger.debug("Cleaning up temporary resources created for testing ...");
524 //FIXME delete on permission role deletes all roles associated with the permission
525 //this would delete association with ROLE_ADMINISTRATION too
526 //deletePermissionRoles();
527 deleteAccountRoles();
528 //FIXME delete on permission role deletes all roles associated with the permission
529 //this would delete association with ROLE_ADMINISTRATION too
530 //deletePermissions();
535 private String createPermission(String resName, EffectType effect) {
536 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
537 return createPermission(resName, actions, effect);
540 private String createPermission(String resName,
541 List<PermissionAction> actions, EffectType effect) {
543 PermissionClient permClient = new PermissionClient();
544 Permission permission = PermissionFactory.createPermissionInstance(resName,
545 "default permissions for " + resName,
546 actions, effect, true, true, true);
547 ClientResponse<Response> res = permClient.create(permission);
548 int statusCode = res.getStatus();
549 if (logger.isDebugEnabled()) {
550 logger.debug("createPermission: resName=" + resName
551 + " status = " + statusCode);
553 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556 res.releaseConnection();
557 return extractId(res);
560 private void deletePermission(String permId) {
562 PermissionClient permClient = new PermissionClient();
563 ClientResponse<Response> res = permClient.delete(permId);
564 int statusCode = res.getStatus();
565 if (logger.isDebugEnabled()) {
566 logger.debug("deletePermission: delete permission id="
567 + permId + " status=" + statusCode);
569 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
570 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
571 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
572 res.releaseConnection();
575 private String createRole(String roleName) {
577 RoleClient roleClient = new RoleClient();
579 Role role = RoleFactory.createRoleInstance(roleName,
580 "role for " + roleName, true);
581 ClientResponse<Response> res = roleClient.create(role);
582 int statusCode = res.getStatus();
583 if (logger.isDebugEnabled()) {
584 logger.debug("createRole: name=" + roleName
585 + " status = " + statusCode);
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
590 res.releaseConnection();
591 return extractId(res);
594 private void deleteRole(String roleId) {
596 RoleClient roleClient = new RoleClient();
597 ClientResponse<Response> res = roleClient.delete(roleId);
598 int statusCode = res.getStatus();
599 if (logger.isDebugEnabled()) {
600 logger.debug("deleteRole: delete role id=" + roleId
601 + " status=" + statusCode);
603 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
604 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
605 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
606 res.releaseConnection();
609 private String createAccount(String userName, String email) {
611 AccountClient accClient = new AccountClient();
612 AccountsCommon account = AccountFactory.createAccountInstance(
613 userName, userName, userName, email,
614 true, true, false, true, true);
615 ClientResponse<Response> res = accClient.create(account);
616 int statusCode = res.getStatus();
617 if (logger.isDebugEnabled()) {
618 logger.debug("createAccount: userName=" + userName
619 + " status = " + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624 res.releaseConnection();
625 return extractId(res);
628 private void deleteAccount(String accId) {
630 AccountClient accClient = new AccountClient();
631 ClientResponse<Response> res = accClient.delete(accId);
632 int statusCode = res.getStatus();
633 if (logger.isDebugEnabled()) {
634 logger.debug("deleteAccount: delete account id="
635 + accId + " status=" + statusCode);
637 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
638 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
639 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640 res.releaseConnection();
643 private String createAccountRole(AccountValue av,
644 Collection<RoleValue> rvs) {
647 // Submit the request to the service and store the response.
648 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
649 av, rvs, true, true);
650 AccountRoleClient client = new AccountRoleClient();
651 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
652 int statusCode = res.getStatus();
654 if (logger.isDebugEnabled()) {
655 logger.debug("createAccountRole: status = " + statusCode);
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
660 res.releaseConnection();
661 return extractId(res);
664 private void deleteAccountRole(String screenName) {
668 // Submit the request to the service and store the response.
669 AccountRoleClient client = new AccountRoleClient();
670 ClientResponse<Response> res = client.delete(
671 accValues.get(screenName).getAccountId(), "123");
672 int statusCode = res.getStatus();
674 // Check the status code of the response: does it match
675 // the expected response(s)?
676 if (logger.isDebugEnabled()) {
677 logger.debug("deleteAccountRole: status = " + statusCode);
679 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
680 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
681 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682 res.releaseConnection();
685 private String createPermissionRole(PermissionValue pv,
686 Collection<RoleValue> rvs) {
688 List<RoleValue> rvls = new ArrayList<RoleValue>();
690 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
691 pv, rvls, true, true);
692 PermissionRoleClient client = new PermissionRoleClient();
693 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
694 int statusCode = res.getStatus();
696 if (logger.isDebugEnabled()) {
697 logger.debug("createPermissionRole: 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 deletePermissionRole(String permId) {
711 // Submit the request to the service and store the response.
712 PermissionRoleClient client = new PermissionRoleClient();
713 ClientResponse<Response> res = client.delete(permId, "123");
714 int statusCode = res.getStatus();
716 // Check the status code of the response: does it match
717 // the expected response(s)?
718 if (logger.isDebugEnabled()) {
719 logger.debug("deletePermissionRole : status = " + statusCode);
721 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
722 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
723 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724 res.releaseConnection();
727 private void deletePermissionRoles() {
729 //first delete relationships between the entities
730 for (PermissionValue pv : permValues.values()) {
731 deletePermissionRole(pv.getPermissionId());
735 private void deleteAccountRoles() {
736 for (AccountValue av : accValues.values()) {
737 deleteAccountRole(av.getUserId());
741 private void deletePermissions() {
743 for (PermissionValue pv : permValues.values()) {
744 deletePermission(pv.getPermissionId());
748 private void deleteRoles() {
749 for (RoleValue rv : roleValues.values()) {
750 deleteRole(rv.getRoleId());
754 private void deleteAccounts() {
756 for (AccountValue av1 : accValues.values()) {
757 deleteAccount(av1.getAccountId());