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 © 2009 Regents of the University of California
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
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.account.client.test;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Hashtable;
28 import java.util.List;
29 import javax.ws.rs.core.Response;
31 //import org.collectionspace.services.authorization.AccountRolesList;
32 import org.collectionspace.services.account.AccountsCommon;
33 import org.collectionspace.services.account.AccountsCommonList;
34 import org.collectionspace.services.account.AccountListItem;
36 import org.collectionspace.services.authorization.AccountRole;
37 import org.collectionspace.services.authorization.AccountValue;
38 import org.collectionspace.services.authorization.Role;
39 import org.collectionspace.services.authorization.RoleValue;
40 import org.collectionspace.services.client.AccountClient;
41 import org.collectionspace.services.client.AccountFactory;
42 import org.collectionspace.services.client.AccountRoleClient;
43 import org.collectionspace.services.client.AccountRoleFactory;
44 import org.collectionspace.services.client.CollectionSpaceClient;
45 import org.collectionspace.services.client.RoleClient;
46 import org.collectionspace.services.client.RoleFactory;
47 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
48 import org.collectionspace.services.client.test.ServiceRequestType;
49 import org.collectionspace.services.jaxb.AbstractCommonList;
50 import org.jboss.resteasy.client.ClientResponse;
53 import org.testng.Assert;
54 import org.testng.annotations.Test;
56 import org.slf4j.Logger;
57 import org.slf4j.LoggerFactory;
58 import org.testng.annotations.AfterClass;
59 import org.testng.annotations.BeforeClass;
62 * AccountServiceTest, carries out tests against a
63 * deployed and running Account, Role and AccountRole Services.
65 * $LastChangedRevision: 917 $
66 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
68 public class AccountRoleServiceTest extends AbstractServiceTestImpl {
70 /** The Constant logger. */
71 private final static String CLASS_NAME = AccountRoleServiceTest.class.getName();
72 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
73 // Instance variables specific to this test.
74 /** The known resource id. */
75 private String knownResourceId = null;
76 private String prebuiltAdminCSID = null;
77 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
78 /** The all resource ids created. */
79 private List<String> allResourceIdsCreated = new ArrayList<String>();
80 /** The acc values. */
81 private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
82 /** The role values. */
83 private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
85 * This method is called only by the parent class, AbstractServiceTestImpl
89 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
92 protected String getServicePathComponent() {
93 return new AccountRoleClient().getServicePathComponent();
99 @BeforeClass(alwaysRun = true)
100 public void seedData() {
101 String userId = "acc-role-user1";
102 String accId = createAccount(userId, "acc-role-user1-test@cspace.org");
103 AccountValue ava = new AccountValue();
104 ava.setScreenName(userId);
105 ava.setUserId(userId);
106 ava.setAccountId(accId);
107 accValues.put(ava.getScreenName(), ava);
109 String userId2 = "acc-role-user2";
110 String coAccId = createAccount(userId2, "acc-role-user2-test@cspace.org");
111 AccountValue avc = new AccountValue();
112 avc.setScreenName(userId2);
113 avc.setUserId(userId2);
114 avc.setAccountId(coAccId);
115 accValues.put(avc.getScreenName(), avc);
117 String rn1 = "ROLE_CO1";
118 String r1RoleId = createRole(rn1);
119 RoleValue rv1 = new RoleValue();
120 rv1.setRoleId(r1RoleId);
121 rv1.setRoleName(rn1);
122 roleValues.put(rv1.getRoleName(), rv1);
124 String rn2 = "ROLE_CO2";
125 String r2RoleId = createRole(rn2);
126 RoleValue rv2 = new RoleValue();
127 rv2.setRoleId(r2RoleId);
128 rv2.setRoleName(rn2);
129 roleValues.put(rv2.getRoleName(), rv2);
133 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
136 protected CollectionSpaceClient getClientInstance() {
137 return new AccountRoleClient();
141 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
144 protected AbstractCommonList getAbstractCommonList(
145 ClientResponse<AbstractCommonList> response) {
146 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
147 throw new UnsupportedOperationException();
151 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
153 @Test(dataProvider = "testName")
155 public void readPaginatedList(String testName) throws Exception {
156 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
159 // ---------------------------------------------------------------
160 // CRUD tests : CREATE tests
161 // ---------------------------------------------------------------
164 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
167 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
168 public void create(String testName) throws Exception {
170 if (logger.isDebugEnabled()) {
171 testBanner(testName, CLASS_NAME);
173 // Perform setup, such as initializing the type of service request
174 // (e.g. CREATE, DELETE), its valid and expected status codes, and
175 // its associated HTTP method name (e.g. POST, DELETE).
178 // Submit the request to the service and store the response.
179 AccountValue av = accValues.get("acc-role-user1");
180 AccountRole accRole = createAccountRoleInstance(av,
181 roleValues.values(), true, true);
182 AccountRoleClient client = new AccountRoleClient();
183 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
185 int statusCode = res.getStatus();
187 if (logger.isDebugEnabled()) {
188 logger.debug(testName + ": status = " + statusCode);
190 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
191 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
192 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
194 // Store the ID returned from this create operation
195 // for additional tests below.
196 //this is is not important in case of this relationship
197 knownResourceId = extractId(res);
198 if (logger.isDebugEnabled()) {
199 logger.debug(testName + ": knownResourceId=" + knownResourceId);
202 res.releaseConnection();
206 //to not cause uniqueness violation for accRole, createList is removed
208 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
210 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
211 dependsOnMethods = {"create"})
213 public void createList(String testName) throws Exception {
214 //FIXME: Should this test really be empty? If so, please comment accordingly.
218 // Placeholders until the three tests below can be uncommented.
219 // See Issue CSPACE-401.
221 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
224 public void createWithEmptyEntityBody(String testName) throws Exception {
225 //FIXME: Should this test really be empty? If so, please comment accordingly.
229 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
232 public void createWithMalformedXml(String testName) throws Exception {
233 //FIXME: Should this test really be empty? If so, please comment accordingly.
237 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
240 public void createWithWrongXmlSchema(String testName) throws Exception {
241 //FIXME: Should this test really be empty? If so, please comment accordingly.
244 // ---------------------------------------------------------------
245 // CRUD tests : READ tests
246 // ---------------------------------------------------------------
249 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
252 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
253 dependsOnMethods = {"create"})
254 public void read(String testName) throws Exception {
256 if (logger.isDebugEnabled()) {
257 testBanner(testName, CLASS_NAME);
263 // Submit the request to the service and store the response.
264 AccountRoleClient client = new AccountRoleClient();
265 ClientResponse<AccountRole> res = client.read(
266 accValues.get("acc-role-user1").getAccountId());
267 assertStatusCode(res, testName);
269 AccountRole output = res.getEntity();
270 Assert.assertNotNull(output);
272 res.releaseConnection();
278 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
281 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
282 public void readNonExistent(String testName) throws Exception {
284 if (logger.isDebugEnabled()) {
285 testBanner(testName, CLASS_NAME);
289 setupReadNonExistent();
291 // Submit the request to the service and store the response.
292 AccountRoleClient client = new AccountRoleClient();
293 ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID);
294 int statusCode = res.getStatus();
296 // Check the status code of the response: does it match
297 // the expected response(s)?
298 if (logger.isDebugEnabled()) {
299 logger.debug(testName + ": status = " + statusCode);
301 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
303 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
305 res.releaseConnection();
309 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
310 dependsOnMethods = {"create"})
311 public void readNoRelationship(String testName) throws Exception {
313 if (logger.isDebugEnabled()) {
314 testBanner(testName, CLASS_NAME);
320 // Submit the request to the service and store the response.
321 AccountRoleClient client = new AccountRoleClient();
322 ClientResponse<AccountRole> res = client.read(
323 accValues.get("acc-role-user2").getAccountId());
324 assertStatusCode(res, testName);
326 AccountRole output = res.getEntity();
328 if(logger.isDebugEnabled()) {
329 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
330 String sOutput = objectAsXmlString(objectFactory.createAccountRole(output), AccountRole.class);
331 logger.debug(testName + " received " + sOutput);
334 res.releaseConnection();
339 * In this test, for setup, we associate both test roles ("ROLE_CO1", "ROLE_CO2") with the test account "acc-role-user2".
340 * After we've performed this setup, our call to "/role/{csid}/accountroles" should contain an AccountRole that has
341 * a list of 1 account -the test user account we associated during setup.
343 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
344 dependsOnMethods = {"delete"})
345 public void readRoleAccounts(String testName) throws Exception {
347 if (logger.isDebugEnabled()) {
348 testBanner(testName, CLASS_NAME);
352 * Setup a temp local scope for local variables that we need to create the AccountRole for
353 * the setup of the read tests.
358 // Associate "acc-role-user2" with all the roles.
359 AccountValue av = accValues.get("acc-role-user2");
360 AccountRole accRole = createAccountRoleInstance(av,
361 roleValues.values(), true, true);
362 AccountRoleClient client = new AccountRoleClient();
363 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
364 int statusCode = res.getStatus();
365 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
371 // Now read the list of accounts associated with the role "ROLE_CO1".
372 // There should be just the "acc-role-user2" account.
375 RoleClient roleClient = new RoleClient();
377 // Submit the request to the service and store the response.
378 ClientResponse<AccountRole> res = roleClient.readRoleAccounts(
379 roleValues.get("ROLE_CO1").getRoleId());
380 assertStatusCode(res, testName);
382 AccountRole output = res.getEntity();
384 // Now verify that the role has 2 accounts associate to it.
385 Assert.assertEquals(output.getAccount().size(), 1);
387 String sOutput = objectAsXmlString(output, AccountRole.class);
388 if(logger.isDebugEnabled()) {
389 logger.debug(testName + " received " + sOutput);
392 res.releaseConnection();
396 // ---------------------------------------------------------------
397 // CRUD tests : READ_LIST tests
398 // ---------------------------------------------------------------
401 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
404 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
405 dependsOnMethods = {"createList", "read"})
406 public void readList(String testName) throws Exception {
407 //FIXME: Should this test really be empty? If so, please comment accordingly.
412 // ---------------------------------------------------------------
413 // CRUD tests : UPDATE tests
414 // ---------------------------------------------------------------
417 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
420 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
421 dependsOnMethods = {"read", "readList", "readNonExistent"})
422 public void update(String testName) throws Exception {
423 //FIXME: Should this test really be empty? If so, please comment accordingly.
427 // Placeholders until the three tests below can be uncommented.
428 // See Issue CSPACE-401.
430 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
433 public void updateWithEmptyEntityBody(String testName) throws Exception {
434 //FIXME: Should this test really be empty? If so, please comment accordingly.
438 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
441 public void updateWithMalformedXml(String testName) throws Exception {
442 //FIXME: Should this test really be empty? If so, please comment accordingly.
446 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
449 public void updateWithWrongXmlSchema(String testName) throws Exception {
450 //FIXME: Should this test really be empty? If so, please comment accordingly.
454 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
457 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
458 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
459 public void updateNonExistent(String testName) throws Exception {
460 //FIXME: Should this test really be empty? If so, please comment accordingly.
463 // ---------------------------------------------------------------
464 // CRUD tests : DELETE tests
465 // ---------------------------------------------------------------
468 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
471 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
472 dependsOnMethods = {"read"})
473 public void delete(String testName) throws Exception {
475 if (logger.isDebugEnabled()) {
476 testBanner(testName, CLASS_NAME);
483 // Lookup a know account, and delete all of its role relationships
485 AccountRoleClient client = new AccountRoleClient();
486 ClientResponse<AccountRole> readResponse = client.read(
487 accValues.get("acc-role-user1").getAccountId());
488 AccountRole toDelete = null;
490 toDelete = readResponse.getEntity();
491 } catch (Throwable e) {
494 readResponse.releaseConnection();
497 ClientResponse<Response> res = client.delete(
498 toDelete.getAccount().get(0).getAccountId(), toDelete);
500 int statusCode = res.getStatus();
501 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
502 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
503 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
505 res.releaseConnection();
509 // recreate 'acc-role-user1' account and roles
517 // Lookup a know account, and delete all of its role relationships
519 readResponse = client.read(
520 accValues.get("acc-role-user1").getAccountId());
523 toDelete = readResponse.getEntity();
524 } catch (Throwable e) {
527 readResponse.releaseConnection();
530 res = client.delete(toDelete.getAccount().get(0).getAccountId());
532 int statusCode = res.getStatus();
533 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
537 res.releaseConnection();
543 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
544 dependsOnMethods = {"read"})
545 public void deleteLockedAccount(String testName) throws Exception {
547 if (logger.isDebugEnabled()) {
548 testBanner(testName, CLASS_NAME);
551 findPrebuiltAdminAccount();
554 EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
555 REQUEST_TYPE = ServiceRequestType.DELETE;
556 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
558 AccountRoleClient client = new AccountRoleClient();
559 ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
561 int statusCode = res.getStatus();
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
566 res.releaseConnection();
572 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
575 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
576 public void deleteNonExistent(String testName) throws Exception {
577 //ignoring this test as the service side returns 200 now even if it does
578 //not find a record in the db
581 // ---------------------------------------------------------------
583 // ---------------------------------------------------------------
586 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
587 public void searchWorkflowDeleted(String testName) throws Exception {
588 // Fixme: null test for now, overriding test in base class
591 // ---------------------------------------------------------------
592 // Utility tests : tests of code used in tests above
593 // ---------------------------------------------------------------
595 * Tests the code for manually submitting data that is used by several
596 * of the methods above.
599 @Test(dependsOnMethods = {"create"})
600 public void testSubmitRequest() throws Exception { //FIXME: REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
602 // Expected status code: 200 OK
603 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
605 // Submit the request to the service and store the response.
606 String method = ServiceRequestType.READ.httpMethodName();
607 String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
608 int statusCode = submitRequest(method, url);
610 // Check the status code of the response: does it match
611 // the expected response(s)?
612 if (logger.isDebugEnabled()) {
613 logger.debug("testSubmitRequest: url=" + url
614 + " status=" + statusCode);
616 Assert.assertEquals(statusCode, EXPECTED_STATUS);
620 // ---------------------------------------------------------------
621 // Utility methods used by tests above
622 // ---------------------------------------------------------------
624 * Creates the account role instance.
628 * @param usePermId the use perm id
629 * @param useRoleId the use role id
630 * @return the account role
632 static public AccountRole createAccountRoleInstance(AccountValue pv,
633 Collection<RoleValue> rvs,
637 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
638 pv, rvs, usePermId, useRoleId);
640 if (logger.isDebugEnabled()) {
641 logger.debug("to be created, accRole common");
642 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
643 logger.debug(objectAsXmlString(objectFactory.createAccountRole(accRole), AccountRole.class));
651 @AfterClass(alwaysRun = true)
653 public void cleanUp() {
657 String noTest = System.getProperty("noTestCleanup");
658 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
659 if (logger.isDebugEnabled()) {
660 logger.debug("Skipping Cleanup phase ...");
664 if (logger.isDebugEnabled()) {
665 logger.debug("Cleaning up temporary resources created for testing ...");
669 for (AccountValue pv : accValues.values()) {
670 deleteAccount(pv.getAccountId());
673 for (RoleValue rv : roleValues.values()) {
674 deleteRole(rv.getRoleId());
679 * Creates the account.
681 * @param userName the user name
682 * @param email the email
685 private String createAccount(String userName, String email) {
687 if (logger.isDebugEnabled()) {
688 testBanner("createAccount");
693 AccountClient accClient = new AccountClient();
694 AccountsCommon account = AccountFactory.createAccountInstance(
695 userName, userName, userName, email, accClient.getTenantId(),
696 true, false, true, true);
697 ClientResponse<Response> res = accClient.create(account);
698 int statusCode = res.getStatus();
699 if (logger.isDebugEnabled()) {
700 logger.debug("createAccount: userName=" + userName
701 + " status = " + statusCode);
703 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
704 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
705 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
706 res.releaseConnection();
707 return extractId(res);
710 private void findPrebuiltAdminAccount() {
711 // Search for the prebuilt admin user and then hold its CSID
712 if(prebuiltAdminCSID == null) {
714 AccountClient client = new AccountClient();
715 ClientResponse<AccountsCommonList> res =
716 client.readSearchList(null, this.prebuiltAdminUserId, null);
717 assertStatusCode(res, "findPrebuiltAdminAccount");
718 AccountsCommonList list = res.getEntity();
720 List<AccountListItem> items = list.getAccountListItem();
721 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
722 AccountListItem item = items.get(0);
723 prebuiltAdminCSID = item.getCsid();
724 if (logger.isDebugEnabled()) {
725 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
733 * @param accId the acc id
735 private void deleteAccount(String accId) {
737 if (logger.isDebugEnabled()) {
738 testBanner("deleteAccount");
743 AccountClient accClient = new AccountClient();
744 ClientResponse<Response> res = accClient.delete(accId);
745 int statusCode = res.getStatus();
747 if (logger.isDebugEnabled()) {
748 logger.debug("deleteAccount: delete account id="
749 + accId + " status=" + statusCode);
751 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
752 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
753 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
755 res.releaseConnection();
762 * @param roleName the role name
765 private String createRole(String roleName) {
766 if (logger.isDebugEnabled()) {
767 testBanner("createRole");
770 RoleClient roleClient = new RoleClient();
772 Role role = RoleFactory.createRoleInstance(roleName,
773 roleName, //the display name
774 "role for " + roleName, true);
775 ClientResponse<Response> res = roleClient.create(role);
776 int statusCode = res.getStatus();
777 if (logger.isDebugEnabled()) {
778 logger.debug("createRole: name=" + roleName
779 + " status = " + statusCode);
781 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
782 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
783 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
784 res.releaseConnection();
785 return extractId(res);
791 * @param roleId the role id
793 private void deleteRole(String roleId) {
794 if (logger.isDebugEnabled()) {
795 testBanner("deleteRole");
798 RoleClient roleClient = new RoleClient();
799 ClientResponse<Response> res = roleClient.delete(roleId);
800 int statusCode = res.getStatus();
802 if (logger.isDebugEnabled()) {
803 logger.debug("deleteRole: delete role id=" + roleId
804 + " status=" + statusCode);
806 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
807 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
808 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
810 res.releaseConnection();
815 protected String getServiceName() {
816 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
817 return AccountClient.SERVICE_NAME;