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();
517 readResponse.releaseConnection();
520 ClientResponse<Response> res = client.delete(
521 toDelete.getAccount().get(0).getAccountId(), toDelete);
523 int statusCode = res.getStatus();
524 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
528 res.releaseConnection();
532 // recreate 'acc-role-user1' account and roles
538 // Lookup a know account, and delete all of its role relationships
540 readResponse = client.read(
541 accValues.get("acc-role-user1").getAccountId());
544 toDelete = readResponse.getEntity();
546 readResponse.releaseConnection();
549 res = client.delete(toDelete.getAccount().get(0).getAccountId());
551 int statusCode = res.getStatus();
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556 res.releaseConnection();
561 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
562 dependsOnMethods = {"read"})
563 public void deleteLockedAccount(String testName) throws Exception {
565 if (logger.isDebugEnabled()) {
566 testBanner(testName, CLASS_NAME);
569 findPrebuiltAdminAccount();
572 EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
573 REQUEST_TYPE = ServiceRequestType.DELETE;
574 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
576 AccountRoleClient client = new AccountRoleClient();
577 ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
579 int statusCode = res.getStatus();
580 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
581 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
582 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
584 res.releaseConnection();
590 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
593 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
594 public void deleteNonExistent(String testName) throws Exception {
595 //ignoring this test as the service side returns 200 now even if it does
596 //not find a record in the db
599 // ---------------------------------------------------------------
601 // ---------------------------------------------------------------
604 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
605 public void searchWorkflowDeleted(String testName) throws Exception {
606 // Fixme: null test for now, overriding test in base class
609 // ---------------------------------------------------------------
610 // Utility tests : tests of code used in tests above
611 // ---------------------------------------------------------------
613 * Tests the code for manually submitting data that is used by several
614 * of the methods above.
617 @Test(dependsOnMethods = {"create"})
618 public void testSubmitRequest() throws Exception { //FIXME: REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
620 // Expected status code: 200 OK
621 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
623 // Submit the request to the service and store the response.
624 String method = ServiceRequestType.READ.httpMethodName();
625 String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
626 int statusCode = submitRequest(method, url);
628 // Check the status code of the response: does it match
629 // the expected response(s)?
630 if (logger.isDebugEnabled()) {
631 logger.debug("testSubmitRequest: url=" + url
632 + " status=" + statusCode);
634 Assert.assertEquals(statusCode, EXPECTED_STATUS);
638 // ---------------------------------------------------------------
639 // Utility methods used by tests above
640 // ---------------------------------------------------------------
642 * Creates the account role instance.
646 * @param usePermId the use perm id
647 * @param useRoleId the use role id
648 * @return the account role
650 static public AccountRole createAccountRoleInstance(AccountValue pv,
651 Collection<RoleValue> rvs,
655 AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
656 pv, rvs, usePermId, useRoleId);
658 if (logger.isDebugEnabled()) {
659 logger.debug("to be created, accRole common");
660 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
661 logger.debug(objectAsXmlString(objectFactory.createAccountRole(accRole), AccountRole.class));
669 @AfterClass(alwaysRun = true)
671 public void cleanUp() {
675 String noTest = System.getProperty("noTestCleanup");
676 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
677 if (logger.isDebugEnabled()) {
678 logger.debug("Skipping Cleanup phase ...");
682 if (logger.isDebugEnabled()) {
683 logger.debug("Cleaning up temporary resources created for testing ...");
687 for (AccountValue pv : accValues.values()) {
688 deleteAccount(pv.getAccountId());
691 for (RoleValue rv : roleValues.values()) {
692 deleteRole(rv.getRoleId());
697 * Creates the account.
699 * @param userName the user name
700 * @param email the email
703 private String createAccount(String userName, String email) {
705 if (logger.isDebugEnabled()) {
706 testBanner("createAccount");
711 AccountClient accClient = new AccountClient();
712 AccountsCommon account = AccountFactory.createAccountInstance(
713 userName, userName, userName, email, accClient.getTenantId(),
714 true, false, true, true);
715 ClientResponse<Response> res = accClient.create(account);
716 int statusCode = res.getStatus();
717 if (logger.isDebugEnabled()) {
718 logger.debug("createAccount: userName=" + userName
719 + " status = " + statusCode);
721 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
722 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
723 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724 res.releaseConnection();
725 return extractId(res);
728 private void findPrebuiltAdminAccount() {
729 // Search for the prebuilt admin user and then hold its CSID
730 if(prebuiltAdminCSID == null) {
732 AccountClient client = new AccountClient();
733 ClientResponse<AccountsCommonList> res =
734 client.readSearchList(null, this.prebuiltAdminUserId, null);
735 AccountsCommonList list = res.getEntity();
736 int statusCode = res.getStatus();
738 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
739 List<AccountListItem> items = list.getAccountListItem();
740 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
741 AccountListItem item = items.get(0);
742 prebuiltAdminCSID = item.getCsid();
743 if (logger.isDebugEnabled()) {
744 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
752 * @param accId the acc id
754 private void deleteAccount(String accId) {
756 if (logger.isDebugEnabled()) {
757 testBanner("deleteAccount");
762 AccountClient accClient = new AccountClient();
763 ClientResponse<Response> res = accClient.delete(accId);
764 int statusCode = res.getStatus();
766 if (logger.isDebugEnabled()) {
767 logger.debug("deleteAccount: delete account id="
768 + accId + " status=" + statusCode);
770 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
774 res.releaseConnection();
781 * @param roleName the role name
784 private String createRole(String roleName) {
785 if (logger.isDebugEnabled()) {
786 testBanner("createRole");
789 RoleClient roleClient = new RoleClient();
791 Role role = RoleFactory.createRoleInstance(roleName,
792 roleName, //the display name
793 "role for " + roleName, true);
794 ClientResponse<Response> res = roleClient.create(role);
795 int statusCode = res.getStatus();
796 if (logger.isDebugEnabled()) {
797 logger.debug("createRole: name=" + roleName
798 + " status = " + statusCode);
800 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
801 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
802 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
803 res.releaseConnection();
804 return extractId(res);
810 * @param roleId the role id
812 private void deleteRole(String roleId) {
813 if (logger.isDebugEnabled()) {
814 testBanner("deleteRole");
817 RoleClient roleClient = new RoleClient();
818 ClientResponse<Response> res = roleClient.delete(roleId);
819 int statusCode = res.getStatus();
821 if (logger.isDebugEnabled()) {
822 logger.debug("deleteRole: delete role id=" + roleId
823 + " status=" + statusCode);
825 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
826 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
827 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
829 res.releaseConnection();
834 protected String getServiceName() {
835 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
836 return AccountClient.SERVICE_NAME;