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.authorization.AccountRole;
35 import org.collectionspace.services.authorization.AccountValue;
36 import org.collectionspace.services.authorization.Role;
37 import org.collectionspace.services.authorization.RoleValue;
38 import org.collectionspace.services.client.AccountClient;
39 import org.collectionspace.services.client.AccountFactory;
40 import org.collectionspace.services.client.AccountRoleClient;
41 import org.collectionspace.services.client.AccountRoleFactory;
42 import org.collectionspace.services.client.CollectionSpaceClient;
43 import org.collectionspace.services.client.RoleClient;
44 import org.collectionspace.services.client.RoleFactory;
45 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
46 import org.collectionspace.services.client.test.ServiceRequestType;
47 import org.collectionspace.services.jaxb.AbstractCommonList;
48 import org.jboss.resteasy.client.ClientResponse;
51 import org.testng.Assert;
52 import org.testng.annotations.Test;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.BeforeClass;
60 * AccountServiceTest, carries out tests against a
61 * deployed and running Account, Role and AccountRole Services.
63 * $LastChangedRevision: 917 $
64 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
66 public class AccountRoleServiceTest extends AbstractServiceTestImpl {
68 /** The Constant logger. */
69 private final static String CLASS_NAME = AccountRoleServiceTest.class.getName();
70 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
71 // Instance variables specific to this test.
72 /** The known resource id. */
73 private String knownResourceId = null;
74 private String prebuiltAdminCSID = null;
75 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
76 /** The all resource ids created. */
77 private List<String> allResourceIdsCreated = new ArrayList<String>();
78 /** The acc values. */
79 private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
80 /** The role values. */
81 private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
83 * This method is called only by the parent class, AbstractServiceTestImpl
87 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
90 protected String getServicePathComponent() {
91 return new AccountRoleClient().getServicePathComponent();
97 @BeforeClass(alwaysRun = true)
98 public void seedData() {
99 String userId = "acc-role-user1";
100 String accId = createAccount(userId, "acc-role-user1-test@cspace.org");
101 AccountValue ava = new AccountValue();
102 ava.setScreenName(userId);
103 ava.setUserId(userId);
104 ava.setAccountId(accId);
105 accValues.put(ava.getScreenName(), ava);
107 String userId2 = "acc-role-user2";
108 String coAccId = createAccount(userId2, "acc-role-user2-test@cspace.org");
109 AccountValue avc = new AccountValue();
110 avc.setScreenName(userId2);
111 avc.setUserId(userId2);
112 avc.setAccountId(coAccId);
113 accValues.put(avc.getScreenName(), avc);
115 String rn1 = "ROLE_CO1";
116 String r1RoleId = createRole(rn1);
117 RoleValue rv1 = new RoleValue();
118 rv1.setRoleId(r1RoleId);
119 rv1.setRoleName(rn1);
120 roleValues.put(rv1.getRoleName(), rv1);
122 String rn2 = "ROLE_CO2";
123 String r2RoleId = createRole(rn2);
124 RoleValue rv2 = new RoleValue();
125 rv2.setRoleId(r2RoleId);
126 rv2.setRoleName(rn2);
127 roleValues.put(rv2.getRoleName(), rv2);
131 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
134 protected CollectionSpaceClient getClientInstance() {
135 return new AccountRoleClient();
139 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
142 protected AbstractCommonList getAbstractCommonList(
143 ClientResponse<AbstractCommonList> response) {
144 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
145 throw new UnsupportedOperationException();
149 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
151 @Test(dataProvider = "testName")
153 public void readPaginatedList(String testName) throws Exception {
154 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
157 // ---------------------------------------------------------------
158 // CRUD tests : CREATE tests
159 // ---------------------------------------------------------------
162 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
165 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
166 public void create(String testName) throws Exception {
168 if (logger.isDebugEnabled()) {
169 testBanner(testName, CLASS_NAME);
171 // Perform setup, such as initializing the type of service request
172 // (e.g. CREATE, DELETE), its valid and expected status codes, and
173 // its associated HTTP method name (e.g. POST, DELETE).
176 // Submit the request to the service and store the response.
177 AccountValue av = accValues.get("acc-role-user1");
178 AccountRole accRole = createAccountRoleInstance(av,
179 roleValues.values(), true, true);
180 AccountRoleClient client = new AccountRoleClient();
181 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
183 int statusCode = res.getStatus();
185 if (logger.isDebugEnabled()) {
186 logger.debug(testName + ": status = " + statusCode);
188 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
189 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
190 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
192 // Store the ID returned from this create operation
193 // for additional tests below.
194 //this is is not important in case of this relationship
195 knownResourceId = extractId(res);
196 if (logger.isDebugEnabled()) {
197 logger.debug(testName + ": knownResourceId=" + knownResourceId);
200 res.releaseConnection();
204 //to not cause uniqueness violation for accRole, createList is removed
206 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
208 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
209 dependsOnMethods = {"create"})
211 public void createList(String testName) throws Exception {
212 //FIXME: Should this test really be empty? If so, please comment accordingly.
216 // Placeholders until the three tests below can be uncommented.
217 // See Issue CSPACE-401.
219 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
222 public void createWithEmptyEntityBody(String testName) throws Exception {
223 //FIXME: Should this test really be empty? If so, please comment accordingly.
227 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
230 public void createWithMalformedXml(String testName) throws Exception {
231 //FIXME: Should this test really be empty? If so, please comment accordingly.
235 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
238 public void createWithWrongXmlSchema(String testName) throws Exception {
239 //FIXME: Should this test really be empty? If so, please comment accordingly.
242 // ---------------------------------------------------------------
243 // CRUD tests : READ tests
244 // ---------------------------------------------------------------
247 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
250 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
251 dependsOnMethods = {"create"})
252 public void read(String testName) throws Exception {
254 if (logger.isDebugEnabled()) {
255 testBanner(testName, CLASS_NAME);
261 // Submit the request to the service and store the response.
262 AccountRoleClient client = new AccountRoleClient();
263 ClientResponse<AccountRole> res = client.read(
264 accValues.get("acc-role-user1").getAccountId());
265 int statusCode = res.getStatus();
267 // Check the status code of the response: does it match
268 // the expected response(s)?
269 if (logger.isDebugEnabled()) {
270 logger.debug(testName + ": status = " + statusCode);
272 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276 AccountRole output = res.getEntity();
277 Assert.assertNotNull(output);
279 res.releaseConnection();
285 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
288 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
289 public void readNonExistent(String testName) throws Exception {
291 if (logger.isDebugEnabled()) {
292 testBanner(testName, CLASS_NAME);
296 setupReadNonExistent();
298 // Submit the request to the service and store the response.
299 AccountRoleClient client = new AccountRoleClient();
300 ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID);
301 int statusCode = res.getStatus();
303 // Check the status code of the response: does it match
304 // the expected response(s)?
305 if (logger.isDebugEnabled()) {
306 logger.debug(testName + ": status = " + statusCode);
308 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
309 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
310 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
312 res.releaseConnection();
316 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
317 dependsOnMethods = {"create"})
318 public void readNoRelationship(String testName) throws Exception {
320 if (logger.isDebugEnabled()) {
321 testBanner(testName, CLASS_NAME);
327 // Submit the request to the service and store the response.
328 AccountRoleClient client = new AccountRoleClient();
329 ClientResponse<AccountRole> res = client.read(
330 accValues.get("acc-role-user2").getAccountId());
331 int statusCode = res.getStatus();
333 // Check the status code of the response: does it match
334 // the expected response(s)?
335 if (logger.isDebugEnabled()) {
336 logger.debug(testName + ": status = " + statusCode);
338 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
339 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
340 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
341 AccountRole output = res.getEntity();
343 String sOutput = objectAsXmlString(output, AccountRole.class);
344 if(logger.isDebugEnabled()) {
345 logger.debug(testName + " received " + sOutput);
348 res.releaseConnection();
353 * In this test, for setup, we associate both test roles ("ROLE_CO1", "ROLE_CO2") with the test account "acc-role-user2".
354 * After we've performed this setup, our call to "/role/{csid}/accountroles" should contain an AccountRole that has
355 * a list of 1 account -the test user account we associated during setup.
357 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358 dependsOnMethods = {"delete"})
359 public void readRoleAccounts(String testName) throws Exception {
361 if (logger.isDebugEnabled()) {
362 testBanner(testName, CLASS_NAME);
366 * Setup a temp local scope for local variables that we need to create the AccountRole for
367 * the setup of the read tests.
372 // Associate "acc-role-user2" with all the roles.
373 AccountValue av = accValues.get("acc-role-user2");
374 AccountRole accRole = createAccountRoleInstance(av,
375 roleValues.values(), true, true);
376 AccountRoleClient client = new AccountRoleClient();
377 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
378 int statusCode = res.getStatus();
379 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
380 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
381 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
385 // Now read the list of accounts associated with the role "ROLE_CO1".
386 // There should be just the "acc-role-user2" account.
389 RoleClient roleClient = new RoleClient();
391 // Submit the request to the service and store the response.
392 ClientResponse<AccountRole> res = roleClient.readRoleAccounts(
393 roleValues.get("ROLE_CO1").getRoleId());
394 int statusCode = res.getStatus();
396 // Check the status code of the response: does it match
397 // the expected response(s)?
398 if (logger.isDebugEnabled()) {
399 logger.debug(testName + ": status = " + statusCode);
401 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
402 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
403 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
404 AccountRole output = res.getEntity();
406 // Now verify that the role has 2 accounts associate to it.
407 Assert.assertEquals(output.getAccounts().size(), 1);
409 String sOutput = objectAsXmlString(output, AccountRole.class);
410 if(logger.isDebugEnabled()) {
411 logger.debug(testName + " received " + sOutput);
414 res.releaseConnection();
418 // ---------------------------------------------------------------
419 // CRUD tests : READ_LIST tests
420 // ---------------------------------------------------------------
423 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
426 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
427 dependsOnMethods = {"createList", "read"})
428 public void readList(String testName) throws Exception {
429 //FIXME: Should this test really be empty? If so, please comment accordingly.
434 // ---------------------------------------------------------------
435 // CRUD tests : UPDATE tests
436 // ---------------------------------------------------------------
439 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
442 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
443 dependsOnMethods = {"read", "readList", "readNonExistent"})
444 public void update(String testName) throws Exception {
445 //FIXME: Should this test really be empty? If so, please comment accordingly.
449 // Placeholders until the three tests below can be uncommented.
450 // See Issue CSPACE-401.
452 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
455 public void updateWithEmptyEntityBody(String testName) throws Exception {
456 //FIXME: Should this test really be empty? If so, please comment accordingly.
460 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
463 public void updateWithMalformedXml(String testName) throws Exception {
464 //FIXME: Should this test really be empty? If so, please comment accordingly.
468 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
471 public void updateWithWrongXmlSchema(String testName) throws Exception {
472 //FIXME: Should this test really be empty? If so, please comment accordingly.
476 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
479 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
480 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
481 public void updateNonExistent(String testName) throws Exception {
482 //FIXME: Should this test really be empty? If so, please comment accordingly.
485 // ---------------------------------------------------------------
486 // CRUD tests : DELETE tests
487 // ---------------------------------------------------------------
490 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
493 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
494 dependsOnMethods = {"read"})
495 public void delete(String testName) throws Exception {
497 if (logger.isDebugEnabled()) {
498 testBanner(testName, CLASS_NAME);
505 // Lookup a know account, and delete all of its role relationships
507 AccountRoleClient client = new AccountRoleClient();
508 ClientResponse<AccountRole> readResponse = client.read(
509 accValues.get("acc-role-user1").getAccountId());
510 AccountRole toDelete = null;
512 toDelete = readResponse.getEntity();
514 readResponse.releaseConnection();
517 ClientResponse<Response> res = client.delete(
518 toDelete.getAccounts().get(0).getAccountId(), toDelete);
520 int statusCode = res.getStatus();
521 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
522 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
523 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
525 res.releaseConnection();
529 // recreate 'acc-role-user1' account and roles
535 // Lookup a know account, and delete all of its role relationships
537 readResponse = client.read(
538 accValues.get("acc-role-user1").getAccountId());
541 toDelete = readResponse.getEntity();
543 readResponse.releaseConnection();
546 res = client.delete(toDelete.getAccounts().get(0).getAccountId());
548 int statusCode = res.getStatus();
549 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
550 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
551 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
553 res.releaseConnection();
558 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
559 dependsOnMethods = {"read"})
560 public void deleteLockedAccount(String testName) throws Exception {
562 if (logger.isDebugEnabled()) {
563 testBanner(testName, CLASS_NAME);
566 findPrebuiltAdminAccount();
569 EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
570 REQUEST_TYPE = ServiceRequestType.DELETE;
571 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
573 AccountRoleClient client = new AccountRoleClient();
574 ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
576 int statusCode = res.getStatus();
577 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
578 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
579 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
581 res.releaseConnection();
587 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
590 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
591 public void deleteNonExistent(String testName) throws Exception {
592 //ignoring this test as the service side returns 200 now even if it does
593 //not find a record in the db
596 // ---------------------------------------------------------------
598 // ---------------------------------------------------------------
601 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
602 public void searchWorkflowDeleted(String testName) throws Exception {
603 // Fixme: null test for now, overriding test in base class
606 // ---------------------------------------------------------------
607 // Utility tests : tests of code used in tests above
608 // ---------------------------------------------------------------
610 * Tests the code for manually submitting data that is used by several
611 * of the methods above.
614 @Test(dependsOnMethods = {"create"})
615 public void testSubmitRequest() throws Exception { //FIXME: REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
617 // Expected status code: 200 OK
618 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
620 // Submit the request to the service and store the response.
621 String method = ServiceRequestType.READ.httpMethodName();
622 String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
623 int statusCode = submitRequest(method, url);
625 // Check the status code of the response: does it match
626 // the expected response(s)?
627 if (logger.isDebugEnabled()) {
628 logger.debug("testSubmitRequest: url=" + url
629 + " status=" + statusCode);
631 Assert.assertEquals(statusCode, EXPECTED_STATUS);
635 // ---------------------------------------------------------------
636 // Utility methods used by tests above
637 // ---------------------------------------------------------------
639 * Creates the account role instance.
643 * @param usePermId the use perm id
644 * @param useRoleId the use role id
645 * @return the account role
647 static public AccountRole createAccountRoleInstance(AccountValue pv,
648 Collection<RoleValue> rvs,
652 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
653 pv, rvs, usePermId, useRoleId);
655 if (logger.isDebugEnabled()) {
656 logger.debug("to be created, accRole common");
657 logger.debug(objectAsXmlString(accRole, AccountRole.class));
665 @AfterClass(alwaysRun = true)
667 public void cleanUp() {
671 String noTest = System.getProperty("noTestCleanup");
672 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
673 if (logger.isDebugEnabled()) {
674 logger.debug("Skipping Cleanup phase ...");
678 if (logger.isDebugEnabled()) {
679 logger.debug("Cleaning up temporary resources created for testing ...");
683 for (AccountValue pv : accValues.values()) {
684 deleteAccount(pv.getAccountId());
687 for (RoleValue rv : roleValues.values()) {
688 deleteRole(rv.getRoleId());
693 * Creates the account.
695 * @param userName the user name
696 * @param email the email
699 private String createAccount(String userName, String email) {
701 if (logger.isDebugEnabled()) {
702 testBanner("createAccount");
707 AccountClient accClient = new AccountClient();
708 AccountsCommon account = AccountFactory.createAccountInstance(
709 userName, userName, userName, email, accClient.getTenantId(),
710 true, false, true, true);
711 ClientResponse<Response> res = accClient.create(account);
712 int statusCode = res.getStatus();
713 if (logger.isDebugEnabled()) {
714 logger.debug("createAccount: userName=" + userName
715 + " status = " + statusCode);
717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 res.releaseConnection();
721 return extractId(res);
724 private void findPrebuiltAdminAccount() {
725 // Search for the prebuilt admin user and then hold its CSID
726 if(prebuiltAdminCSID == null) {
728 AccountClient client = new AccountClient();
729 ClientResponse<AccountsCommonList> res =
730 client.readSearchList(null, this.prebuiltAdminUserId, null);
731 AccountsCommonList list = res.getEntity();
732 int statusCode = res.getStatus();
734 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
735 List<AccountsCommonList.AccountListItem> items = list.getAccountListItem();
736 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
737 AccountsCommonList.AccountListItem item = items.get(0);
738 prebuiltAdminCSID = item.getCsid();
739 if (logger.isDebugEnabled()) {
740 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
748 * @param accId the acc id
750 private void deleteAccount(String accId) {
752 if (logger.isDebugEnabled()) {
753 testBanner("deleteAccount");
758 AccountClient accClient = new AccountClient();
759 ClientResponse<Response> res = accClient.delete(accId);
760 int statusCode = res.getStatus();
762 if (logger.isDebugEnabled()) {
763 logger.debug("deleteAccount: delete account id="
764 + accId + " status=" + statusCode);
766 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
767 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
768 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
770 res.releaseConnection();
777 * @param roleName the role name
780 private String createRole(String roleName) {
781 if (logger.isDebugEnabled()) {
782 testBanner("createRole");
785 RoleClient roleClient = new RoleClient();
787 Role role = RoleFactory.createRoleInstance(roleName,
788 roleName, //the display name
789 "role for " + roleName, true);
790 ClientResponse<Response> res = roleClient.create(role);
791 int statusCode = res.getStatus();
792 if (logger.isDebugEnabled()) {
793 logger.debug("createRole: name=" + roleName
794 + " status = " + statusCode);
796 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
797 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
798 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
799 res.releaseConnection();
800 return extractId(res);
806 * @param roleId the role id
808 private void deleteRole(String roleId) {
809 if (logger.isDebugEnabled()) {
810 testBanner("deleteRole");
813 RoleClient roleClient = new RoleClient();
814 ClientResponse<Response> res = roleClient.delete(roleId);
815 int statusCode = res.getStatus();
817 if (logger.isDebugEnabled()) {
818 logger.debug("deleteRole: delete role id=" + roleId
819 + " status=" + statusCode);
821 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
822 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
823 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
825 res.releaseConnection();
830 protected String getServiceName() {
831 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
832 return AccountClient.SERVICE_NAME;