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 static private final Logger logger =
92 LoggerFactory.getLogger(AuthorizationServiceTest.class);
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;
105 * This method is called only by the parent class, AbstractServiceTestImpl
109 protected String getServicePathComponent() {
113 @BeforeClass(alwaysRun = true)
114 public void seedData() {
119 seedPermissionRoles();
122 private void seedPermissions() {
123 String res = "dimensions";
125 PermissionAction pac = new PermissionAction();
126 pac.setName(ActionType.CREATE);
127 PermissionAction par = new PermissionAction();
128 par.setName(ActionType.READ);
129 PermissionAction pau = new PermissionAction();
130 pau.setName(ActionType.UPDATE);
131 PermissionAction pad = new PermissionAction();
132 pad.setName(ActionType.DELETE);
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_MMI_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_MMI_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_MMI_CM"));
193 createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
195 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
196 elmoRoleValues.add(roleValues.get("ROLE_MMI_INTERN"));
197 createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
200 private void seedPermissionRoles() {
202 List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
203 bigbirdRoleValues.add(roleValues.get("ROLE_MMI_CM"));
204 createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
206 List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
207 elmoRoleValues.add(roleValues.get("ROLE_MMI_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 setupCreate(testName);
246 // Submit the request to the service and store the response.
247 DimensionClient client = new DimensionClient();
248 //bigbird allowed to create
249 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
250 String identifier = createIdentifier();
251 DimensionsCommon dimension = new DimensionsCommon();
252 dimension.setDimension("dimensionType");
253 dimension.setValue("value-" + identifier);
254 dimension.setValueDate(new Date().toString());
255 MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
257 ClientResponse<Response> res = client.create(multipart);
259 int statusCode = res.getStatus();
261 if (logger.isDebugEnabled()) {
262 logger.debug(testName + ": status = " + statusCode);
264 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
265 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
266 Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
267 knownResourceId = extractId(res);
268 if (logger.isDebugEnabled()) {
269 logger.debug(testName + ": knownResourceId=" + knownResourceId);
273 //to not cause uniqueness violation for permRole, createList is removed
275 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
276 dependsOnMethods = {"create"})
277 public void createList(String testName) throws Exception {
281 // Placeholders until the three tests below can be uncommented.
282 // See Issue CSPACE-401.
284 public void createWithEmptyEntityBody(String testName) throws Exception {
288 public void createWithMalformedXml(String testName) throws Exception {
292 public void createWithWrongXmlSchema(String testName) throws Exception {
295 // ---------------------------------------------------------------
296 // CRUD tests : READ tests
297 // ---------------------------------------------------------------
300 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
301 dependsOnMethods = {"create"})
302 public void read(String testName) throws Exception {
307 // Submit the request to the service and store the response.
308 DimensionClient client = new DimensionClient();
309 //elmo allowed to read
310 client.setAuth(true, "elmo2010", true, "elmo2010", true);
311 ClientResponse<MultipartInput> res = client.read(knownResourceId);
312 int statusCode = res.getStatus();
314 // Check the status code of the response: does it match
315 // the expected response(s)?
316 if (logger.isDebugEnabled()) {
317 logger.debug(testName + ": status = " + statusCode);
319 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
320 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
321 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
323 MultipartInput input = (MultipartInput) res.getEntity();
324 DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
325 client.getCommonPartName(), DimensionsCommon.class);
326 Assert.assertNotNull(dimension);
332 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
333 public void readNonExistent(String testName) throws Exception {
336 setupReadNonExistent(testName);
339 // ---------------------------------------------------------------
340 // CRUD tests : READ_LIST tests
341 // ---------------------------------------------------------------
344 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
345 dependsOnMethods = {"createList", "read"})
346 public void readList(String testName) throws Exception {
347 setupReadList(testName);
352 // ---------------------------------------------------------------
353 // CRUD tests : UPDATE tests
354 // ---------------------------------------------------------------
357 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358 dependsOnMethods = {"read", "readList", "readNonExistent"})
359 public void update(String testName) throws Exception {
360 setupUpdate(testName);
364 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
365 dependsOnMethods = {"read", "readList", "readNonExistent"})
366 public void updateNotAllowed(String testName) throws Exception {
367 setupUpdate(testName);
369 DimensionClient client = new DimensionClient();
371 //elmo not allowed to update
372 client.setAuth(true, "elmo2010", true, "elmo2010", true);
374 DimensionsCommon dimension = new DimensionsCommon();
375 dimension.setDimension("dimensionType");
376 // Update the content of this resource.
377 dimension.setValue("updated-" + dimension.getValue());
378 dimension.setValueDate("updated-" + dimension.getValueDate());
379 // Submit the request to the service and store the response.
380 MultipartOutput output = new MultipartOutput();
381 OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
382 commonPart.getHeaders().add("label", client.getCommonPartName());
384 ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
385 int statusCode = res.getStatus();
386 // Check the status code of the response: does it match the expected response(s)?
387 if (logger.isDebugEnabled()) {
388 logger.debug(testName + ": status = " + statusCode);
390 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
391 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
392 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
396 // Placeholders until the three tests below can be uncommented.
397 // See Issue CSPACE-401.
399 public void updateWithEmptyEntityBody(String testName) throws Exception {
403 public void updateWithMalformedXml(String testName) throws Exception {
407 public void updateWithWrongXmlSchema(String testName) throws Exception {
411 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
412 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
413 public void updateNonExistent(String testName) throws Exception {
416 // ---------------------------------------------------------------
417 // CRUD tests : DELETE tests
418 // ---------------------------------------------------------------
420 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
421 dependsOnMethods = {"updateNotAllowed"})
422 public void deleteNotAllowed(String testName) throws Exception {
424 setupDelete(testName);
426 // Submit the request to the service and store the response.
427 DimensionClient client = new DimensionClient();
428 //bigbird can not delete
429 client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
430 ClientResponse<Response> res = client.delete(knownResourceId);
431 int statusCode = res.getStatus();
433 // Check the status code of the response: does it match
434 // the expected response(s)?
435 if (logger.isDebugEnabled()) {
436 logger.debug(testName + ": status = " + statusCode);
438 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
439 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
440 Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
445 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
446 dependsOnMethods = {"deleteNotAllowed"})
447 public void delete(String testName) throws Exception {
449 setupDelete(testName);
451 // Submit the request to the service and store the response.
452 DimensionClient client = new DimensionClient();
453 //default user test/test has delete permission
454 client.setAuth(true, "test", true, "test", true);
455 ClientResponse<Response> res = client.delete(knownResourceId);
456 int statusCode = res.getStatus();
458 // Check the status code of the response: does it match
459 // the expected response(s)?
460 if (logger.isDebugEnabled()) {
461 logger.debug(testName + ": status = " + statusCode);
463 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
464 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
465 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
471 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
472 public void deleteNonExistent(String testName) throws Exception {
473 //ignoring this test as the service side returns 200 now even if it does
474 //not find a record in the db
477 // ---------------------------------------------------------------
478 // Utility tests : tests of code used in tests above
479 // ---------------------------------------------------------------
481 * Tests the code for manually submitting data that is used by several
482 * of the methods above.
484 @Test(dependsOnMethods = {"create"})
485 public void testSubmitRequest() throws Exception {
488 // ---------------------------------------------------------------
489 // Utility methods used by tests above
490 // ---------------------------------------------------------------
491 @AfterClass(alwaysRun = true)
492 public void cleanUp() {
493 setupDelete("cleanup");
494 String noTest = System.getProperty("noTestCleanup");
495 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
496 if (logger.isDebugEnabled()) {
497 logger.debug("Skipping Cleanup phase ...");
501 if (logger.isDebugEnabled()) {
502 logger.debug("Cleaning up temporary resources created for testing ...");
505 deletePermissionRoles();
506 deleteAccountRoles();
512 private String createPermission(String resName, EffectType effect) {
513 List<PermissionAction> actions = PermissionFactory.createDefaultActions();
514 return createPermission(resName, actions, effect);
517 private String createPermission(String resName,
518 List<PermissionAction> actions, EffectType effect) {
519 setupCreate("createPermission");
520 PermissionClient permClient = new PermissionClient();
521 Permission permission = PermissionFactory.createPermissionInstance(resName,
522 "default permissions for " + resName,
523 actions, effect, true, true, true);
524 ClientResponse<Response> res = permClient.create(permission);
525 int statusCode = res.getStatus();
526 if (logger.isDebugEnabled()) {
527 logger.debug("createPermission: resName=" + resName
528 + " status = " + statusCode);
530 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
531 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
532 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
533 res.releaseConnection();
534 return extractId(res);
537 private void deletePermission(String permId) {
538 setupDelete("deletePermission");
539 PermissionClient permClient = new PermissionClient();
540 ClientResponse<Response> res = permClient.delete(permId);
541 int statusCode = res.getStatus();
542 if (logger.isDebugEnabled()) {
543 logger.debug("deletePermission: delete permission id="
544 + permId + " status=" + statusCode);
546 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549 res.releaseConnection();
552 private String createRole(String roleName) {
553 setupCreate("createRole");
554 RoleClient roleClient = new RoleClient();
556 Role role = RoleFactory.createRoleInstance(roleName,
557 "role for " + roleName, true);
558 ClientResponse<Response> res = roleClient.create(role);
559 int statusCode = res.getStatus();
560 if (logger.isDebugEnabled()) {
561 logger.debug("createRole: name=" + roleName
562 + " status = " + statusCode);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567 res.releaseConnection();
568 return extractId(res);
571 private void deleteRole(String roleId) {
572 setupDelete("deleteRole");
573 RoleClient roleClient = new RoleClient();
574 ClientResponse<Response> res = roleClient.delete(roleId);
575 int statusCode = res.getStatus();
576 if (logger.isDebugEnabled()) {
577 logger.debug("deleteRole: delete role id=" + roleId
578 + " status=" + statusCode);
580 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
581 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
582 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
583 res.releaseConnection();
586 private String createAccount(String userName, String email) {
587 setupCreate("createAccount");
588 AccountClient accClient = new AccountClient();
589 AccountsCommon account = AccountFactory.createAccountInstance(
590 userName, userName, userName, email,
591 true, true, false, true, true);
592 ClientResponse<Response> res = accClient.create(account);
593 int statusCode = res.getStatus();
594 if (logger.isDebugEnabled()) {
595 logger.debug("createAccount: userName=" + userName
596 + " status = " + statusCode);
598 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
599 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
600 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601 res.releaseConnection();
602 return extractId(res);
605 private void deleteAccount(String accId) {
606 setupDelete("deleteAccount");
607 AccountClient accClient = new AccountClient();
608 ClientResponse<Response> res = accClient.delete(accId);
609 int statusCode = res.getStatus();
610 if (logger.isDebugEnabled()) {
611 logger.debug("deleteAccount: delete account id="
612 + accId + " status=" + statusCode);
614 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617 res.releaseConnection();
620 private String createAccountRole(AccountValue av,
621 Collection<RoleValue> rvs) {
622 setupCreate("createAccountRole");
624 // Submit the request to the service and store the response.
625 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
626 av, rvs, true, true);
627 AccountRoleClient client = new AccountRoleClient();
628 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
629 int statusCode = res.getStatus();
631 if (logger.isDebugEnabled()) {
632 logger.debug("createAccountRole: status = " + statusCode);
634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637 res.releaseConnection();
638 return extractId(res);
641 private void deleteAccountRole(String screenName) {
643 setupDelete("deleteAccountRole");
645 // Submit the request to the service and store the response.
646 AccountRoleClient client = new AccountRoleClient();
647 ClientResponse<Response> res = client.delete(
648 accValues.get(screenName).getAccountId(), "123");
649 int statusCode = res.getStatus();
651 // Check the status code of the response: does it match
652 // the expected response(s)?
653 if (logger.isDebugEnabled()) {
654 logger.debug("deleteAccountRole: status = " + statusCode);
656 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
657 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
658 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659 res.releaseConnection();
662 private String createPermissionRole(PermissionValue pv,
663 Collection<RoleValue> rvs) {
664 setupCreate("createPermissionRole");
665 PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
666 pv, rvs, true, true);
667 PermissionRoleClient client = new PermissionRoleClient();
668 ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
669 int statusCode = res.getStatus();
671 if (logger.isDebugEnabled()) {
672 logger.debug("createPermissionRole: status = " + statusCode);
674 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 res.releaseConnection();
678 return extractId(res);
681 private void deletePermissionRole(String permId) {
684 setupDelete("deletePermissionRole");
686 // Submit the request to the service and store the response.
687 PermissionRoleClient client = new PermissionRoleClient();
688 ClientResponse<Response> res = client.delete(permId, "123");
689 int statusCode = res.getStatus();
691 // Check the status code of the response: does it match
692 // the expected response(s)?
693 if (logger.isDebugEnabled()) {
694 logger.debug("deletePermissionRole : status = " + statusCode);
696 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
699 res.releaseConnection();
702 private void deletePermissionRoles() {
704 //first delete relationships between the entities
705 for (PermissionValue pv : permValues.values()) {
706 deletePermissionRole(pv.getPermissionId());
710 private void deleteAccountRoles() {
711 for (AccountValue av : accValues.values()) {
712 deleteAccountRole(av.getUserId());
716 private void deletePermissions() {
718 for (PermissionValue pv : permValues.values()) {
719 deletePermission(pv.getPermissionId());
723 private void deleteRoles() {
724 for (RoleValue rv : roleValues.values()) {
725 deleteRole(rv.getRoleId());
729 private void deleteAccounts() {
731 for (AccountValue av1 : accValues.values()) {
732 deleteAccount(av1.getAccountId());