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);
93 // Instance variables specific to this test.
94 private String knownResourceId = null;
95 private List<String> allResourceIdsCreated = new ArrayList();
96 //key for accValues is userId
97 private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
98 //key for permValues is id as there could be several perms for the same resource
99 private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
100 //key for roleValues is roleName
101 private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
102 private String bigbirdPermId;
103 private String elmoPermId;
104 private final static String TEST_SERVICE_NAME = "dimensions";
106 * This method is called only by the parent class, AbstractServiceTestImpl
110 protected String getServicePathComponent() {
114 @BeforeClass(alwaysRun = true)
115 public void seedData() {
120 seedPermissionRoles();
123 private void seedPermissions() {
124 String res = TEST_SERVICE_NAME;
126 PermissionAction pac = new PermissionAction();
127 pac.setName(ActionType.CREATE);
128 PermissionAction par = new PermissionAction();
129 par.setName(ActionType.READ);
130 PermissionAction pau = new PermissionAction();
131 pau.setName(ActionType.UPDATE);
134 //bigbird can create, read and update but not delete
135 List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
139 bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
140 PermissionValue bbpv = new PermissionValue();
141 bbpv.setResourceName(res);
142 bbpv.setPermissionId(bigbirdPermId);
143 permValues.put(bbpv.getPermissionId(), bbpv);
146 List<PermissionAction> eactions = new ArrayList<PermissionAction>();
148 elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
149 PermissionValue epv = new PermissionValue();
150 epv.setResourceName(res);
151 epv.setPermissionId(elmoPermId);
152 permValues.put(epv.getPermissionId(), epv);
155 private void seedRoles() {
156 String rn1 = "ROLE_TEST_CM";
157 String r1RoleId = createRole(rn1);
158 RoleValue rv1 = new RoleValue();
159 rv1.setRoleId(r1RoleId);
160 rv1.setRoleName(rn1);
161 roleValues.put(rv1.getRoleName(), rv1);
163 String rn2 = "ROLE_TEST_INTERN";
164 String r2RoleId = createRole(rn2);
165 RoleValue rv2 = new RoleValue();
166 rv2.setRoleId(r2RoleId);
167 rv2.setRoleName(rn2);
168 roleValues.put(rv2.getRoleName(), rv2);
171 private void seedAccounts() {
172 String userId = "bigbird2010";
173 String accId = createAccount(userId, "bigbird@cspace.org");
174 AccountValue ava = new AccountValue();
175 ava.setScreenName(userId);
176 ava.setUserId(userId);
177 ava.setAccountId(accId);
178 accValues.put(ava.getUserId(), ava);
180 String userId2 = "elmo2010";
181 String coAccId = createAccount(userId2, "elmo@cspace.org");
182 AccountValue avc = new AccountValue();
183 avc.setScreenName(userId2);
184 avc.setUserId(userId2);
185 avc.setAccountId(coAccId);
186 accValues.put(avc.getUserId(), avc);
189 private void seedAccountRoles() {
191 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
192 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
193 createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
195 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
196 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
197 createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
200 private void seedPermissionRoles() {
202 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
203 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
204 createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
206 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
207 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
208 createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
214 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
217 protected CollectionSpaceClient getClientInstance() {
222 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
225 protected AbstractCommonList getAbstractCommonList(
226 ClientResponse<AbstractCommonList> response) {
227 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
228 throw new UnsupportedOperationException();
231 @Test(dataProvider = "testName")
233 public void readPaginatedList(String testName) throws Exception {
234 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
236 // ---------------------------------------------------------------
237 // CRUD tests : CREATE tests
238 // ---------------------------------------------------------------
242 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
243 public void create(String testName) throws Exception {
244 if (logger.isDebugEnabled()) {
245 logger.debug(testBanner(testName, CLASS_NAME));
249 // Submit the request to the service and store the response.
250 DimensionClient client = new DimensionClient();
251 //bigbird allowed to create
252 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
253 String identifier = createIdentifier();
254 DimensionsCommon dimension = new DimensionsCommon();
255 dimension.setDimension("dimensionType");
256 dimension.setValue("value-" + identifier);
257 dimension.setValueDate(new Date().toString());
258 MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
260 ClientResponse<Response> res = client.create(multipart);
262 int statusCode = res.getStatus();
264 if (logger.isDebugEnabled()) {
265 logger.debug(testName + ": status = " + statusCode);
267 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
270 knownResourceId = extractId(res);
271 if (logger.isDebugEnabled()) {
272 logger.debug(testName + ": knownResourceId=" + knownResourceId);
276 //to not cause uniqueness violation for permRole, createList is removed
278 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
279 dependsOnMethods = {"create"})
280 public void createList(String testName) throws Exception {
284 // Placeholders until the three tests below can be uncommented.
285 // See Issue CSPACE-401.
287 public void createWithEmptyEntityBody(String testName) throws Exception {
291 public void createWithMalformedXml(String testName) throws Exception {
295 public void createWithWrongXmlSchema(String testName) throws Exception {
298 // ---------------------------------------------------------------
299 // CRUD tests : READ tests
300 // ---------------------------------------------------------------
303 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
304 dependsOnMethods = {"create"})
305 public void read(String testName) throws Exception {
307 if (logger.isDebugEnabled()) {
308 logger.debug(testBanner(testName, CLASS_NAME));
313 // Submit the request to the service and store the response.
314 DimensionClient client = new DimensionClient();
315 //elmo allowed to read
316 client.setAuth(true, "elmo2010", true, "elmo2010", true);
317 ClientResponse<MultipartInput> res = client.read(knownResourceId);
318 int statusCode = res.getStatus();
320 // Check the status code of the response: does it match
321 // the expected response(s)?
322 if (logger.isDebugEnabled()) {
323 logger.debug(testName + ": status = " + statusCode);
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
329 MultipartInput input = (MultipartInput) res.getEntity();
330 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
331 client.getCommonPartName(), DimensionsCommon.class);
332 Assert.assertNotNull(dimension);
338 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
339 public void readNonExistent(String testName) throws Exception {
342 setupReadNonExistent();
345 // ---------------------------------------------------------------
346 // CRUD tests : READ_LIST tests
347 // ---------------------------------------------------------------
350 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351 dependsOnMethods = {"createList", "read"})
352 public void readList(String testName) throws Exception {
358 // ---------------------------------------------------------------
359 // CRUD tests : UPDATE tests
360 // ---------------------------------------------------------------
363 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
364 dependsOnMethods = {"read", "readList", "readNonExistent"})
365 public void update(String testName) throws Exception {
370 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
371 dependsOnMethods = {"read", "readList", "readNonExistent"})
372 public void updateNotAllowed(String testName) throws Exception {
374 if (logger.isDebugEnabled()) {
375 logger.debug(testBanner(testName, CLASS_NAME));
379 DimensionClient client = new DimensionClient();
381 //elmo not allowed to update
382 client.setAuth(true, "elmo2010", true, "elmo2010", true);
384 DimensionsCommon dimension = new DimensionsCommon();
385 dimension.setDimension("dimensionType");
386 // Update the content of this resource.
387 dimension.setValue("updated-" + dimension.getValue());
388 dimension.setValueDate("updated-" + dimension.getValueDate());
389 // Submit the request to the service and store the response.
390 MultipartOutput output = new MultipartOutput();
391 OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
392 commonPart.getHeaders().add("label", client.getCommonPartName());
394 ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
395 int statusCode = res.getStatus();
396 // Check the status code of the response: does it match the expected response(s)?
397 if (logger.isDebugEnabled()) {
398 logger.debug(testName + ": status = " + statusCode);
400 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
401 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
402 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
406 // Placeholders until the three tests below can be uncommented.
407 // See Issue CSPACE-401.
409 public void updateWithEmptyEntityBody(String testName) throws Exception {
413 public void updateWithMalformedXml(String testName) throws Exception {
417 public void updateWithWrongXmlSchema(String testName) throws Exception {
421 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
422 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
423 public void updateNonExistent(String testName) throws Exception {
426 // ---------------------------------------------------------------
427 // CRUD tests : DELETE tests
428 // ---------------------------------------------------------------
430 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
431 dependsOnMethods = {"updateNotAllowed"})
432 public void deleteNotAllowed(String testName) throws Exception {
434 if (logger.isDebugEnabled()) {
435 logger.debug(testBanner(testName, CLASS_NAME));
440 // Submit the request to the service and store the response.
441 DimensionClient client = new DimensionClient();
442 //bigbird can not delete
443 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
444 ClientResponse<Response> res = client.delete(knownResourceId);
445 int statusCode = res.getStatus();
447 // Check the status code of the response: does it match
448 // the expected response(s)?
449 if (logger.isDebugEnabled()) {
450 logger.debug(testName + ": status = " + statusCode);
452 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
453 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
454 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
459 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
460 dependsOnMethods = {"deleteNotAllowed"})
461 public void delete(String testName) throws Exception {
463 if (logger.isDebugEnabled()) {
464 logger.debug(testBanner(testName, CLASS_NAME));
469 // Submit the request to the service and store the response.
470 DimensionClient client = new DimensionClient();
472 ClientResponse<Response> res = client.delete(knownResourceId);
473 int statusCode = res.getStatus();
475 // Check the status code of the response: does it match
476 // the expected response(s)?
477 if (logger.isDebugEnabled()) {
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
488 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
489 public void deleteNonExistent(String testName) throws Exception {
490 //ignoring this test as the service side returns 200 now even if it does
491 //not find a record in the db
494 // ---------------------------------------------------------------
495 // Utility tests : tests of code used in tests above
496 // ---------------------------------------------------------------
498 * Tests the code for manually submitting data that is used by several
499 * of the methods above.
501 @Test(dependsOnMethods = {"create"})
502 public void testSubmitRequest() throws Exception {
505 // ---------------------------------------------------------------
506 // Utility methods used by tests above
507 // ---------------------------------------------------------------
508 @AfterClass(alwaysRun = true)
509 public void cleanUp() {
511 String noTest = System.getProperty("noTestCleanup");
512 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
513 if (logger.isDebugEnabled()) {
514 logger.debug("Skipping Cleanup phase ...");
518 if (logger.isDebugEnabled()) {
519 logger.debug("Cleaning up temporary resources created for testing ...");
522 deletePermissionRoles();
523 deleteAccountRoles();
524 //FIXME delete on permission deletes all associations with roles
525 //this would delete association with ROLE_ADMINISTRATOR too
526 //deletePermissions();
531 private void deletePermissionRoles() {
533 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
534 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
535 deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
537 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
538 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
539 deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
543 private void deleteAccountRoles() {
544 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
545 bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
546 deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
548 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
549 elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
550 deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues);
553 private void deletePermissions() {
555 for (PermissionValue pv : permValues.values()) {
556 deletePermission(pv.getPermissionId());
560 private void deleteRoles() {
561 for (RoleValue rv : roleValues.values()) {
562 deleteRole(rv.getRoleId());
566 private void deleteAccounts() {
568 for (AccountValue av1 : accValues.values()) {
569 deleteAccount(av1.getAccountId());
573 private String createPermission(String resName, EffectType effect) {
574 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
575 return createPermission(resName, actions, effect);
578 private String createPermission(String resName,
579 List<PermissionAction> actions, EffectType effect) {
581 PermissionClient permClient = new PermissionClient();
582 Permission permission = PermissionFactory.createPermissionInstance(resName,
583 "default permissions for " + resName,
584 actions, effect, true, true, true);
585 ClientResponse<Response> res = permClient.create(permission);
586 int statusCode = res.getStatus();
587 if (logger.isDebugEnabled()) {
588 logger.debug("createPermission: resName=" + resName
589 + " status = " + statusCode);
591 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594 res.releaseConnection();
595 return extractId(res);
598 private void deletePermission(String permId) {
600 PermissionClient permClient = new PermissionClient();
601 ClientResponse<Response> res = permClient.delete(permId);
602 int statusCode = res.getStatus();
603 if (logger.isDebugEnabled()) {
604 logger.debug("deletePermission: delete permission id="
605 + permId + " status=" + statusCode);
607 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 res.releaseConnection();
613 private String createRole(String roleName) {
615 RoleClient roleClient = new RoleClient();
617 Role role = RoleFactory.createRoleInstance(roleName,
618 "role for " + roleName, true);
619 ClientResponse<Response> res = roleClient.create(role);
620 int statusCode = res.getStatus();
621 if (logger.isDebugEnabled()) {
622 logger.debug("createRole: name=" + roleName
623 + " status = " + statusCode);
625 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
626 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
627 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628 res.releaseConnection();
629 return extractId(res);
632 private void deleteRole(String roleId) {
634 RoleClient roleClient = new RoleClient();
635 ClientResponse<Response> res = roleClient.delete(roleId);
636 int statusCode = res.getStatus();
637 if (logger.isDebugEnabled()) {
638 logger.debug("deleteRole: delete role id=" + roleId
639 + " status=" + statusCode);
641 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
642 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
643 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
644 res.releaseConnection();
647 private String createAccount(String userName, String email) {
649 AccountClient accountClient = new AccountClient();
650 AccountsCommon account = AccountFactory.createAccountInstance(
651 userName, userName, userName, email, accountClient.getTenantId(),
652 true, false, true, true);
653 ClientResponse<Response> res = accountClient.create(account);
654 int statusCode = res.getStatus();
655 if (logger.isDebugEnabled()) {
656 logger.debug("createAccount: userName=" + userName
657 + " status = " + statusCode);
659 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
660 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
661 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
662 res.releaseConnection();
663 return extractId(res);
666 private void deleteAccount(String accId) {
668 AccountClient accClient = new AccountClient();
669 ClientResponse<Response> res = accClient.delete(accId);
670 int statusCode = res.getStatus();
671 if (logger.isDebugEnabled()) {
672 logger.debug("deleteAccount: delete account id="
673 + accId + " status=" + statusCode);
675 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
676 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
677 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 res.releaseConnection();
681 private String createAccountRole(AccountValue av,
682 Collection<RoleValue> rvs) {
685 // Submit the request to the service and store the response.
686 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
687 av, rvs, true, true);
688 AccountRoleClient client = new AccountRoleClient();
689 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
690 int statusCode = res.getStatus();
692 if (logger.isDebugEnabled()) {
693 logger.debug("createAccountRole: status = " + statusCode);
695 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
698 res.releaseConnection();
699 return extractId(res);
702 private void deleteAccountRole(AccountValue av,
703 Collection<RoleValue> rvs) {
707 // Submit the request to the service and store the response.
708 AccountRoleClient client = new AccountRoleClient();
709 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
710 av, rvs, true, true);
711 ClientResponse<Response> res = client.delete(
712 av.getAccountId(), accRole);
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("deleteAccountRole: 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 String createPermissionRole(PermissionValue pv,
727 Collection<RoleValue> rvs) {
729 List<RoleValue> rvls = new ArrayList<RoleValue>();
731 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
732 pv, rvls, true, true);
733 PermissionRoleClient client = new PermissionRoleClient();
734 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
735 int statusCode = res.getStatus();
737 if (logger.isDebugEnabled()) {
738 logger.debug("createPermissionRole: status = " + statusCode);
740 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
741 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
742 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743 res.releaseConnection();
744 return extractId(res);
747 private void deletePermissionRole(PermissionValue pv,
748 Collection<RoleValue> rvs) {
749 List<RoleValue> rvls = new ArrayList<RoleValue>();
755 // Submit the request to the service and store the response.
756 PermissionRoleClient client = new PermissionRoleClient();
757 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
758 pv, rvls, true, true);
759 ClientResponse<Response> res = client.delete(pv.getPermissionId(), permRole);
760 int statusCode = res.getStatus();
762 // Check the status code of the response: does it match
763 // the expected response(s)?
764 if (logger.isDebugEnabled()) {
765 logger.debug("deletePermissionRole : status = " + statusCode);
767 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
768 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
769 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
770 res.releaseConnection();