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 int statusCode = res.getStatus();
269 // Check the status code of the response: does it match
270 // the expected response(s)?
271 if (logger.isDebugEnabled()) {
272 logger.debug(testName + ": status = " + statusCode);
274 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
275 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
276 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
278 AccountRole output = res.getEntity();
279 Assert.assertNotNull(output);
281 res.releaseConnection();
287 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
290 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
291 public void readNonExistent(String testName) throws Exception {
293 if (logger.isDebugEnabled()) {
294 testBanner(testName, CLASS_NAME);
298 setupReadNonExistent();
300 // Submit the request to the service and store the response.
301 AccountRoleClient client = new AccountRoleClient();
302 ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID);
303 int statusCode = res.getStatus();
305 // Check the status code of the response: does it match
306 // the expected response(s)?
307 if (logger.isDebugEnabled()) {
308 logger.debug(testName + ": status = " + statusCode);
310 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
311 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
312 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
314 res.releaseConnection();
318 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
319 dependsOnMethods = {"create"})
320 public void readNoRelationship(String testName) throws Exception {
322 if (logger.isDebugEnabled()) {
323 testBanner(testName, CLASS_NAME);
329 // Submit the request to the service and store the response.
330 AccountRoleClient client = new AccountRoleClient();
331 ClientResponse<AccountRole> res = client.read(
332 accValues.get("acc-role-user2").getAccountId());
333 int statusCode = res.getStatus();
335 // Check the status code of the response: does it match
336 // the expected response(s)?
337 if (logger.isDebugEnabled()) {
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
343 AccountRole output = res.getEntity();
345 if(logger.isDebugEnabled()) {
346 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
347 String sOutput = objectAsXmlString(objectFactory.createAccountRole(output), AccountRole.class);
348 logger.debug(testName + " received " + sOutput);
351 res.releaseConnection();
356 * In this test, for setup, we associate both test roles ("ROLE_CO1", "ROLE_CO2") with the test account "acc-role-user2".
357 * After we've performed this setup, our call to "/role/{csid}/accountroles" should contain an AccountRole that has
358 * a list of 1 account -the test user account we associated during setup.
360 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
361 dependsOnMethods = {"delete"})
362 public void readRoleAccounts(String testName) throws Exception {
364 if (logger.isDebugEnabled()) {
365 testBanner(testName, CLASS_NAME);
369 * Setup a temp local scope for local variables that we need to create the AccountRole for
370 * the setup of the read tests.
375 // Associate "acc-role-user2" with all the roles.
376 AccountValue av = accValues.get("acc-role-user2");
377 AccountRole accRole = createAccountRoleInstance(av,
378 roleValues.values(), true, true);
379 AccountRoleClient client = new AccountRoleClient();
380 ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
381 int statusCode = res.getStatus();
382 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
383 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
384 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
388 // Now read the list of accounts associated with the role "ROLE_CO1".
389 // There should be just the "acc-role-user2" account.
392 RoleClient roleClient = new RoleClient();
394 // Submit the request to the service and store the response.
395 ClientResponse<AccountRole> res = roleClient.readRoleAccounts(
396 roleValues.get("ROLE_CO1").getRoleId());
397 int statusCode = res.getStatus();
399 // Check the status code of the response: does it match
400 // the expected response(s)?
401 if (logger.isDebugEnabled()) {
402 logger.debug(testName + ": status = " + statusCode);
404 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
405 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
406 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
407 AccountRole output = res.getEntity();
409 // Now verify that the role has 2 accounts associate to it.
410 Assert.assertEquals(output.getAccount().size(), 1);
412 String sOutput = objectAsXmlString(output, AccountRole.class);
413 if(logger.isDebugEnabled()) {
414 logger.debug(testName + " received " + sOutput);
417 res.releaseConnection();
421 // ---------------------------------------------------------------
422 // CRUD tests : READ_LIST tests
423 // ---------------------------------------------------------------
426 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
429 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
430 dependsOnMethods = {"createList", "read"})
431 public void readList(String testName) throws Exception {
432 //FIXME: Should this test really be empty? If so, please comment accordingly.
437 // ---------------------------------------------------------------
438 // CRUD tests : UPDATE tests
439 // ---------------------------------------------------------------
442 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
445 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
446 dependsOnMethods = {"read", "readList", "readNonExistent"})
447 public void update(String testName) throws Exception {
448 //FIXME: Should this test really be empty? If so, please comment accordingly.
452 // Placeholders until the three tests below can be uncommented.
453 // See Issue CSPACE-401.
455 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
458 public void updateWithEmptyEntityBody(String testName) throws Exception {
459 //FIXME: Should this test really be empty? If so, please comment accordingly.
463 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
466 public void updateWithMalformedXml(String testName) throws Exception {
467 //FIXME: Should this test really be empty? If so, please comment accordingly.
471 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
474 public void updateWithWrongXmlSchema(String testName) throws Exception {
475 //FIXME: Should this test really be empty? If so, please comment accordingly.
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
482 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
483 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
484 public void updateNonExistent(String testName) throws Exception {
485 //FIXME: Should this test really be empty? If so, please comment accordingly.
488 // ---------------------------------------------------------------
489 // CRUD tests : DELETE tests
490 // ---------------------------------------------------------------
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
496 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
497 dependsOnMethods = {"read"})
498 public void delete(String testName) throws Exception {
500 if (logger.isDebugEnabled()) {
501 testBanner(testName, CLASS_NAME);
508 // Lookup a know account, and delete all of its role relationships
510 AccountRoleClient client = new AccountRoleClient();
511 ClientResponse<AccountRole> readResponse = client.read(
512 accValues.get("acc-role-user1").getAccountId());
513 AccountRole toDelete = null;
515 toDelete = readResponse.getEntity();
516 } catch (Throwable e) {
519 readResponse.releaseConnection();
522 ClientResponse<Response> res = client.delete(
523 toDelete.getAccount().get(0).getAccountId(), toDelete);
525 int statusCode = res.getStatus();
526 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
527 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
528 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
530 res.releaseConnection();
534 // recreate 'acc-role-user1' account and roles
542 // Lookup a know account, and delete all of its role relationships
544 readResponse = client.read(
545 accValues.get("acc-role-user1").getAccountId());
548 toDelete = readResponse.getEntity();
549 } catch (Throwable e) {
552 readResponse.releaseConnection();
555 res = client.delete(toDelete.getAccount().get(0).getAccountId());
557 int statusCode = res.getStatus();
558 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
559 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
560 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
562 res.releaseConnection();
568 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
569 dependsOnMethods = {"read"})
570 public void deleteLockedAccount(String testName) throws Exception {
572 if (logger.isDebugEnabled()) {
573 testBanner(testName, CLASS_NAME);
576 findPrebuiltAdminAccount();
579 EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
580 REQUEST_TYPE = ServiceRequestType.DELETE;
581 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
583 AccountRoleClient client = new AccountRoleClient();
584 ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
586 int statusCode = res.getStatus();
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 res.releaseConnection();
597 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
600 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
601 public void deleteNonExistent(String testName) throws Exception {
602 //ignoring this test as the service side returns 200 now even if it does
603 //not find a record in the db
606 // ---------------------------------------------------------------
608 // ---------------------------------------------------------------
611 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
612 public void searchWorkflowDeleted(String testName) throws Exception {
613 // Fixme: null test for now, overriding test in base class
616 // ---------------------------------------------------------------
617 // Utility tests : tests of code used in tests above
618 // ---------------------------------------------------------------
620 * Tests the code for manually submitting data that is used by several
621 * of the methods above.
624 @Test(dependsOnMethods = {"create"})
625 public void testSubmitRequest() throws Exception { //FIXME: REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
627 // Expected status code: 200 OK
628 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
630 // Submit the request to the service and store the response.
631 String method = ServiceRequestType.READ.httpMethodName();
632 String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
633 int statusCode = submitRequest(method, url);
635 // Check the status code of the response: does it match
636 // the expected response(s)?
637 if (logger.isDebugEnabled()) {
638 logger.debug("testSubmitRequest: url=" + url
639 + " status=" + statusCode);
641 Assert.assertEquals(statusCode, EXPECTED_STATUS);
645 // ---------------------------------------------------------------
646 // Utility methods used by tests above
647 // ---------------------------------------------------------------
649 * Creates the account role instance.
653 * @param usePermId the use perm id
654 * @param useRoleId the use role id
655 * @return the account role
657 static public AccountRole createAccountRoleInstance(AccountValue pv,
658 Collection<RoleValue> rvs,
662 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
663 pv, rvs, usePermId, useRoleId);
665 if (logger.isDebugEnabled()) {
666 logger.debug("to be created, accRole common");
667 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
668 logger.debug(objectAsXmlString(objectFactory.createAccountRole(accRole), AccountRole.class));
676 @AfterClass(alwaysRun = true)
678 public void cleanUp() {
682 String noTest = System.getProperty("noTestCleanup");
683 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
684 if (logger.isDebugEnabled()) {
685 logger.debug("Skipping Cleanup phase ...");
689 if (logger.isDebugEnabled()) {
690 logger.debug("Cleaning up temporary resources created for testing ...");
694 for (AccountValue pv : accValues.values()) {
695 deleteAccount(pv.getAccountId());
698 for (RoleValue rv : roleValues.values()) {
699 deleteRole(rv.getRoleId());
704 * Creates the account.
706 * @param userName the user name
707 * @param email the email
710 private String createAccount(String userName, String email) {
712 if (logger.isDebugEnabled()) {
713 testBanner("createAccount");
718 AccountClient accClient = new AccountClient();
719 AccountsCommon account = AccountFactory.createAccountInstance(
720 userName, userName, userName, email, accClient.getTenantId(),
721 true, false, true, true);
722 ClientResponse<Response> res = accClient.create(account);
723 int statusCode = res.getStatus();
724 if (logger.isDebugEnabled()) {
725 logger.debug("createAccount: userName=" + userName
726 + " status = " + statusCode);
728 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
729 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
730 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
731 res.releaseConnection();
732 return extractId(res);
735 private void findPrebuiltAdminAccount() {
736 // Search for the prebuilt admin user and then hold its CSID
737 if(prebuiltAdminCSID == null) {
739 AccountClient client = new AccountClient();
740 ClientResponse<AccountsCommonList> res =
741 client.readSearchList(null, this.prebuiltAdminUserId, null);
742 AccountsCommonList list = res.getEntity();
743 int statusCode = res.getStatus();
745 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
746 List<AccountListItem> items = list.getAccountListItem();
747 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
748 AccountListItem item = items.get(0);
749 prebuiltAdminCSID = item.getCsid();
750 if (logger.isDebugEnabled()) {
751 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
759 * @param accId the acc id
761 private void deleteAccount(String accId) {
763 if (logger.isDebugEnabled()) {
764 testBanner("deleteAccount");
769 AccountClient accClient = new AccountClient();
770 ClientResponse<Response> res = accClient.delete(accId);
771 int statusCode = res.getStatus();
773 if (logger.isDebugEnabled()) {
774 logger.debug("deleteAccount: delete account id="
775 + accId + " status=" + statusCode);
777 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
778 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
779 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
781 res.releaseConnection();
788 * @param roleName the role name
791 private String createRole(String roleName) {
792 if (logger.isDebugEnabled()) {
793 testBanner("createRole");
796 RoleClient roleClient = new RoleClient();
798 Role role = RoleFactory.createRoleInstance(roleName,
799 roleName, //the display name
800 "role for " + roleName, true);
801 ClientResponse<Response> res = roleClient.create(role);
802 int statusCode = res.getStatus();
803 if (logger.isDebugEnabled()) {
804 logger.debug("createRole: name=" + roleName
805 + " status = " + statusCode);
807 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
808 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
809 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
810 res.releaseConnection();
811 return extractId(res);
817 * @param roleId the role id
819 private void deleteRole(String roleId) {
820 if (logger.isDebugEnabled()) {
821 testBanner("deleteRole");
824 RoleClient roleClient = new RoleClient();
825 ClientResponse<Response> res = roleClient.delete(roleId);
826 int statusCode = res.getStatus();
828 if (logger.isDebugEnabled()) {
829 logger.debug("deleteRole: delete role id=" + roleId
830 + " status=" + statusCode);
832 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
833 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
834 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
836 res.releaseConnection();
841 protected String getServiceName() {
842 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
843 return AccountClient.SERVICE_NAME;