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);
133 PermissionAction pad = new PermissionAction();
134 pad.setName(ActionType.DELETE);
136 //bigbird can create, read and update but not delete
137 List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
141 bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
142 PermissionValue bbpv = new PermissionValue();
143 bbpv.setResourceName(res);
144 bbpv.setPermissionId(bigbirdPermId);
145 permValues.put(bbpv.getPermissionId(), bbpv);
148 List<PermissionAction> eactions = new ArrayList<PermissionAction>();
150 elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
151 PermissionValue epv = new PermissionValue();
152 epv.setResourceName(res);
153 epv.setPermissionId(elmoPermId);
154 permValues.put(epv.getPermissionId(), epv);
157 private void seedRoles() {
158 String rn1 = "ROLE_TEST_CM";
159 String r1RoleId = createRole(rn1);
160 RoleValue rv1 = new RoleValue();
161 rv1.setRoleId(r1RoleId);
162 rv1.setRoleName(rn1);
163 roleValues.put(rv1.getRoleName(), rv1);
165 String rn2 = "ROLE_TEST_INTERN";
166 String r2RoleId = createRole(rn2);
167 RoleValue rv2 = new RoleValue();
168 rv2.setRoleId(r2RoleId);
169 rv2.setRoleName(rn2);
170 roleValues.put(rv2.getRoleName(), rv2);
173 private void seedAccounts() {
174 String userId = "bigbird2010";
175 String accId = createAccount(userId, "bigbird@cspace.org");
176 AccountValue ava = new AccountValue();
177 ava.setScreenName(userId);
178 ava.setUserId(userId);
179 ava.setAccountId(accId);
180 accValues.put(ava.getUserId(), ava);
182 String userId2 = "elmo2010";
183 String coAccId = createAccount(userId2, "elmo@cspace.org");
184 AccountValue avc = new AccountValue();
185 avc.setScreenName(userId2);
186 avc.setUserId(userId2);
187 avc.setAccountId(coAccId);
188 accValues.put(avc.getUserId(), avc);
191 private void seedAccountRoles() {
193 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
194 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
195 createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
197 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
198 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
199 createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
202 private void seedPermissionRoles() {
204 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
205 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
206 createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
208 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
209 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
210 createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
216 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
219 protected CollectionSpaceClient getClientInstance() {
224 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
227 protected AbstractCommonList getAbstractCommonList(
228 ClientResponse<AbstractCommonList> response) {
229 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
230 throw new UnsupportedOperationException();
233 @Test(dataProvider = "testName")
235 public void readPaginatedList(String testName) throws Exception {
236 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
238 // ---------------------------------------------------------------
239 // CRUD tests : CREATE tests
240 // ---------------------------------------------------------------
244 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
245 public void create(String testName) throws Exception {
246 if (logger.isDebugEnabled()) {
247 logger.debug(testBanner(testName, CLASS_NAME));
251 // Submit the request to the service and store the response.
252 DimensionClient client = new DimensionClient();
253 //bigbird allowed to create
254 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
255 String identifier = createIdentifier();
256 DimensionsCommon dimension = new DimensionsCommon();
257 dimension.setDimension("dimensionType");
258 dimension.setValue("value-" + identifier);
259 dimension.setValueDate(new Date().toString());
260 MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
262 ClientResponse<Response> res = client.create(multipart);
264 int statusCode = res.getStatus();
266 if (logger.isDebugEnabled()) {
267 logger.debug(testName + ": status = " + statusCode);
269 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
270 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
271 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
272 knownResourceId = extractId(res);
273 if (logger.isDebugEnabled()) {
274 logger.debug(testName + ": knownResourceId=" + knownResourceId);
278 //to not cause uniqueness violation for permRole, createList is removed
280 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
281 dependsOnMethods = {"create"})
282 public void createList(String testName) throws Exception {
286 // Placeholders until the three tests below can be uncommented.
287 // See Issue CSPACE-401.
289 public void createWithEmptyEntityBody(String testName) throws Exception {
293 public void createWithMalformedXml(String testName) throws Exception {
297 public void createWithWrongXmlSchema(String testName) throws Exception {
300 // ---------------------------------------------------------------
301 // CRUD tests : READ tests
302 // ---------------------------------------------------------------
305 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
306 dependsOnMethods = {"create"})
307 public void read(String testName) throws Exception {
309 if (logger.isDebugEnabled()) {
310 logger.debug(testBanner(testName, CLASS_NAME));
315 // Submit the request to the service and store the response.
316 DimensionClient client = new DimensionClient();
317 //elmo allowed to read
318 client.setAuth(true, "elmo2010", true, "elmo2010", true);
319 ClientResponse<MultipartInput> res = client.read(knownResourceId);
320 int statusCode = res.getStatus();
322 // Check the status code of the response: does it match
323 // the expected response(s)?
324 if (logger.isDebugEnabled()) {
325 logger.debug(testName + ": status = " + statusCode);
327 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
328 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
329 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
331 MultipartInput input = (MultipartInput) res.getEntity();
332 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
333 client.getCommonPartName(), DimensionsCommon.class);
334 Assert.assertNotNull(dimension);
340 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
341 public void readNonExistent(String testName) throws Exception {
344 setupReadNonExistent();
347 // ---------------------------------------------------------------
348 // CRUD tests : READ_LIST tests
349 // ---------------------------------------------------------------
352 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
353 dependsOnMethods = {"createList", "read"})
354 public void readList(String testName) throws Exception {
360 // ---------------------------------------------------------------
361 // CRUD tests : UPDATE tests
362 // ---------------------------------------------------------------
365 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
366 dependsOnMethods = {"read", "readList", "readNonExistent"})
367 public void update(String testName) throws Exception {
372 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
373 dependsOnMethods = {"read", "readList", "readNonExistent"})
374 public void updateNotAllowed(String testName) throws Exception {
376 if (logger.isDebugEnabled()) {
377 logger.debug(testBanner(testName, CLASS_NAME));
381 DimensionClient client = new DimensionClient();
383 //elmo not allowed to update
384 client.setAuth(true, "elmo2010", true, "elmo2010", true);
386 DimensionsCommon dimension = new DimensionsCommon();
387 dimension.setDimension("dimensionType");
388 // Update the content of this resource.
389 dimension.setValue("updated-" + dimension.getValue());
390 dimension.setValueDate("updated-" + dimension.getValueDate());
391 // Submit the request to the service and store the response.
392 MultipartOutput output = new MultipartOutput();
393 OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
394 commonPart.getHeaders().add("label", client.getCommonPartName());
396 ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
397 int statusCode = res.getStatus();
398 // Check the status code of the response: does it match the expected response(s)?
399 if (logger.isDebugEnabled()) {
400 logger.debug(testName + ": status = " + statusCode);
402 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
403 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
404 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
408 // Placeholders until the three tests below can be uncommented.
409 // See Issue CSPACE-401.
411 public void updateWithEmptyEntityBody(String testName) throws Exception {
415 public void updateWithMalformedXml(String testName) throws Exception {
419 public void updateWithWrongXmlSchema(String testName) throws Exception {
423 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
424 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
425 public void updateNonExistent(String testName) throws Exception {
428 // ---------------------------------------------------------------
429 // CRUD tests : DELETE tests
430 // ---------------------------------------------------------------
432 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
433 dependsOnMethods = {"updateNotAllowed"})
434 public void deleteNotAllowed(String testName) throws Exception {
436 if (logger.isDebugEnabled()) {
437 logger.debug(testBanner(testName, CLASS_NAME));
442 // Submit the request to the service and store the response.
443 DimensionClient client = new DimensionClient();
444 //bigbird can not delete
445 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
446 ClientResponse<Response> res = client.delete(knownResourceId);
447 int statusCode = res.getStatus();
449 // Check the status code of the response: does it match
450 // the expected response(s)?
451 if (logger.isDebugEnabled()) {
452 logger.debug(testName + ": status = " + statusCode);
454 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
455 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
456 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
461 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
462 dependsOnMethods = {"deleteNotAllowed"})
463 public void delete(String testName) throws Exception {
465 if (logger.isDebugEnabled()) {
466 logger.debug(testBanner(testName, CLASS_NAME));
471 // Submit the request to the service and store the response.
472 DimensionClient client = new DimensionClient();
473 //default user test/test has delete permission
474 client.setAuth(true, "test", true, "test", true);
475 ClientResponse<Response> res = client.delete(knownResourceId);
476 int statusCode = res.getStatus();
478 // Check the status code of the response: does it match
479 // the expected response(s)?
480 if (logger.isDebugEnabled()) {
481 logger.debug(testName + ": status = " + statusCode);
483 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
484 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
485 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
491 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
492 public void deleteNonExistent(String testName) throws Exception {
493 //ignoring this test as the service side returns 200 now even if it does
494 //not find a record in the db
497 // ---------------------------------------------------------------
498 // Utility tests : tests of code used in tests above
499 // ---------------------------------------------------------------
501 * Tests the code for manually submitting data that is used by several
502 * of the methods above.
504 @Test(dependsOnMethods = {"create"})
505 public void testSubmitRequest() throws Exception {
508 // ---------------------------------------------------------------
509 // Utility methods used by tests above
510 // ---------------------------------------------------------------
511 @AfterClass(alwaysRun = true)
512 public void cleanUp() {
514 String noTest = System.getProperty("noTestCleanup");
515 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
516 if (logger.isDebugEnabled()) {
517 logger.debug("Skipping Cleanup phase ...");
521 if (logger.isDebugEnabled()) {
522 logger.debug("Cleaning up temporary resources created for testing ...");
525 //FIXME delete on permission role deletes all roles associated with the permission
526 //this would delete association with ROLE_ADMINISTRATION too
527 //deletePermissionRoles();
528 deleteAccountRoles();
529 //FIXME delete on permission role deletes all roles associated with the permission
530 //this would delete association with ROLE_ADMINISTRATION too
531 //deletePermissions();
536 private String createPermission(String resName, EffectType effect) {
537 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
538 return createPermission(resName, actions, effect);
541 private String createPermission(String resName,
542 List<PermissionAction> actions, EffectType effect) {
544 PermissionClient permClient = new PermissionClient();
545 Permission permission = PermissionFactory.createPermissionInstance(resName,
546 "default permissions for " + resName,
547 actions, effect, true, true, true);
548 ClientResponse<Response> res = permClient.create(permission);
549 int statusCode = res.getStatus();
550 if (logger.isDebugEnabled()) {
551 logger.debug("createPermission: resName=" + resName
552 + " status = " + statusCode);
554 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
557 res.releaseConnection();
558 return extractId(res);
561 private void deletePermission(String permId) {
563 PermissionClient permClient = new PermissionClient();
564 ClientResponse<Response> res = permClient.delete(permId);
565 int statusCode = res.getStatus();
566 if (logger.isDebugEnabled()) {
567 logger.debug("deletePermission: delete permission id="
568 + permId + " status=" + statusCode);
570 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
571 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
572 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
573 res.releaseConnection();
576 private String createRole(String roleName) {
578 RoleClient roleClient = new RoleClient();
580 Role role = RoleFactory.createRoleInstance(roleName,
581 "role for " + roleName, true);
582 ClientResponse<Response> res = roleClient.create(role);
583 int statusCode = res.getStatus();
584 if (logger.isDebugEnabled()) {
585 logger.debug("createRole: name=" + roleName
586 + " status = " + statusCode);
588 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
589 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
590 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 res.releaseConnection();
592 return extractId(res);
595 private void deleteRole(String roleId) {
597 RoleClient roleClient = new RoleClient();
598 ClientResponse<Response> res = roleClient.delete(roleId);
599 int statusCode = res.getStatus();
600 if (logger.isDebugEnabled()) {
601 logger.debug("deleteRole: delete role id=" + roleId
602 + " status=" + statusCode);
604 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607 res.releaseConnection();
610 private String createAccount(String userName, String email) {
612 AccountClient accClient = new AccountClient();
613 AccountsCommon account = AccountFactory.createAccountInstance(
614 userName, userName, userName, email,
615 true, true, false, true, true);
616 ClientResponse<Response> res = accClient.create(account);
617 int statusCode = res.getStatus();
618 if (logger.isDebugEnabled()) {
619 logger.debug("createAccount: userName=" + userName
620 + " status = " + statusCode);
622 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
623 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
624 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
625 res.releaseConnection();
626 return extractId(res);
629 private void deleteAccount(String accId) {
631 AccountClient accClient = new AccountClient();
632 ClientResponse<Response> res = accClient.delete(accId);
633 int statusCode = res.getStatus();
634 if (logger.isDebugEnabled()) {
635 logger.debug("deleteAccount: delete account id="
636 + accId + " status=" + statusCode);
638 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
641 res.releaseConnection();
644 private String createAccountRole(AccountValue av,
645 Collection<RoleValue> rvs) {
648 // Submit the request to the service and store the response.
649 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
650 av, rvs, true, true);
651 AccountRoleClient client = new AccountRoleClient();
652 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
653 int statusCode = res.getStatus();
655 if (logger.isDebugEnabled()) {
656 logger.debug("createAccountRole: status = " + statusCode);
658 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
659 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
660 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
661 res.releaseConnection();
662 return extractId(res);
665 private void deleteAccountRole(String screenName) {
669 // Submit the request to the service and store the response.
670 AccountRoleClient client = new AccountRoleClient();
671 ClientResponse<Response> res = client.delete(
672 accValues.get(screenName).getAccountId(), "123");
673 int statusCode = res.getStatus();
675 // Check the status code of the response: does it match
676 // the expected response(s)?
677 if (logger.isDebugEnabled()) {
678 logger.debug("deleteAccountRole: status = " + statusCode);
680 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
683 res.releaseConnection();
686 private String createPermissionRole(PermissionValue pv,
687 Collection<RoleValue> rvs) {
689 List<RoleValue> rvls = new ArrayList<RoleValue>();
691 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
692 pv, rvls, true, true);
693 PermissionRoleClient client = new PermissionRoleClient();
694 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
695 int statusCode = res.getStatus();
697 if (logger.isDebugEnabled()) {
698 logger.debug("createPermissionRole: status = " + statusCode);
700 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
701 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
702 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
703 res.releaseConnection();
704 return extractId(res);
707 private void deletePermissionRole(String permId) {
712 // Submit the request to the service and store the response.
713 PermissionRoleClient client = new PermissionRoleClient();
714 ClientResponse<Response> res = client.delete(permId, "123");
715 int statusCode = res.getStatus();
717 // Check the status code of the response: does it match
718 // the expected response(s)?
719 if (logger.isDebugEnabled()) {
720 logger.debug("deletePermissionRole : status = " + statusCode);
722 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
723 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
724 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725 res.releaseConnection();
728 private void deletePermissionRoles() {
730 //first delete relationships between the entities
731 for (PermissionValue pv : permValues.values()) {
732 deletePermissionRole(pv.getPermissionId());
736 private void deleteAccountRoles() {
737 for (AccountValue av : accValues.values()) {
738 deleteAccountRole(av.getUserId());
742 private void deletePermissions() {
744 for (PermissionValue pv : permValues.values()) {
745 deletePermission(pv.getPermissionId());
749 private void deleteRoles() {
750 for (RoleValue rv : roleValues.values()) {
751 deleteRole(rv.getRoleId());
755 private void deleteAccounts() {
757 for (AccountValue av1 : accValues.values()) {
758 deleteAccount(av1.getAccountId());