]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
159e0f4049f5b044cb9382897215578c2f6a6aaa
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.account.client.test;
24
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;
30
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;
49
50
51 import org.testng.Assert;
52 import org.testng.annotations.Test;
53
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.BeforeClass;
58
59 /**
60  * AccountServiceTest, carries out tests against a
61  * deployed and running Account, Role and AccountRole Services.
62  * 
63  * $LastChangedRevision: 917 $
64  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
65  */
66 public class AccountRoleServiceTest extends AbstractServiceTestImpl {
67
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>();
82     /*
83      * This method is called only by the parent class, AbstractServiceTestImpl
84      */
85
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
88      */
89     @Override
90     protected String getServicePathComponent() {
91         return new AccountRoleClient().getServicePathComponent();
92     }
93
94     /**
95      * Seed data.
96      */
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);
106
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);
114
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);
121
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);
128     }
129
130     /* (non-Javadoc)
131      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
132      */
133     @Override
134     protected CollectionSpaceClient getClientInstance() {
135         return new AccountRoleClient();
136     }
137
138     /* (non-Javadoc)
139      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
140      */
141     @Override
142     protected AbstractCommonList getAbstractCommonList(
143             ClientResponse<AbstractCommonList> response) {
144         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
145         throw new UnsupportedOperationException();
146     }
147
148     /* (non-Javadoc)
149      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
150      */
151     @Test(dataProvider = "testName")
152     @Override
153     public void readPaginatedList(String testName) throws Exception {
154         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
155     }
156
157     // ---------------------------------------------------------------
158     // CRUD tests : CREATE tests
159     // ---------------------------------------------------------------
160     // Success outcomes
161     /* (non-Javadoc)
162      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
163      */
164     @Override
165     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
166     public void create(String testName) throws Exception {
167
168         if (logger.isDebugEnabled()) {
169             testBanner(testName, CLASS_NAME);
170         }
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).
174         setupCreate();
175
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);
182         try {
183             int statusCode = res.getStatus();
184
185             if (logger.isDebugEnabled()) {
186                 logger.debug(testName + ": status = " + statusCode);
187             }
188             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
189                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
190             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
191
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);
198             }
199         } finally {
200             res.releaseConnection();
201         }
202     }
203
204     //to not cause uniqueness violation for accRole, createList is removed
205     /* (non-Javadoc)
206      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
207      */
208     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
209     dependsOnMethods = {"create"})
210     @Override
211     public void createList(String testName) throws Exception {
212         //FIXME: Should this test really be empty?  If so, please comment accordingly.
213     }
214
215     // Failure outcomes
216     // Placeholders until the three tests below can be uncommented.
217     // See Issue CSPACE-401.
218     /* (non-Javadoc)
219      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
220      */
221     @Override
222     public void createWithEmptyEntityBody(String testName) throws Exception {
223         //FIXME: Should this test really be empty?  If so, please comment accordingly.
224     }
225
226     /* (non-Javadoc)
227      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
228      */
229     @Override
230     public void createWithMalformedXml(String testName) throws Exception {
231         //FIXME: Should this test really be empty?  If so, please comment accordingly.
232     }
233
234     /* (non-Javadoc)
235      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
236      */
237     @Override
238     public void createWithWrongXmlSchema(String testName) throws Exception {
239         //FIXME: Should this test really be empty?  If so, please comment accordingly.
240     }
241
242     // ---------------------------------------------------------------
243     // CRUD tests : READ tests
244     // ---------------------------------------------------------------
245     // Success outcomes
246     /* (non-Javadoc)
247      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
248      */
249     @Override
250     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
251     dependsOnMethods = {"create"})
252     public void read(String testName) throws Exception {
253
254         if (logger.isDebugEnabled()) {
255             testBanner(testName, CLASS_NAME);
256         }
257
258         // Perform setup.
259         setupRead();
260
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();
266         try {
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);
271             }
272             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
275
276             AccountRole output = res.getEntity();
277             Assert.assertNotNull(output);
278         } finally {
279             res.releaseConnection();
280         }
281     }
282
283     // Failure outcomes
284     /* (non-Javadoc)
285      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
286      */
287     @Override
288     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
289     public void readNonExistent(String testName) throws Exception {
290
291         if (logger.isDebugEnabled()) {
292             testBanner(testName, CLASS_NAME);
293         }
294
295         // Perform setup.
296         setupReadNonExistent();
297
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();
302         try {
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);
307             }
308             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
309                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
310             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
311         } finally {
312             res.releaseConnection();
313         }
314     }
315
316     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
317     dependsOnMethods = {"create"})
318     public void readNoRelationship(String testName) throws Exception {
319
320         if (logger.isDebugEnabled()) {
321             testBanner(testName, CLASS_NAME);
322         }
323
324         // Perform setup.
325         setupRead();
326
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();
332         try {
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);
337             }
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();
342
343             String sOutput = objectAsXmlString(output, AccountRole.class);
344             if(logger.isDebugEnabled()) {
345                 logger.debug(testName + " received " + sOutput);
346             }
347         } finally {
348             res.releaseConnection();
349         }
350     }
351
352     // ---------------------------------------------------------------
353     // CRUD tests : READ_LIST tests
354     // ---------------------------------------------------------------
355     // Success outcomes
356     /* (non-Javadoc)
357      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
358      */
359     @Override
360     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
361     dependsOnMethods = {"createList", "read"})
362     public void readList(String testName) throws Exception {
363         //FIXME: Should this test really be empty?  If so, please comment accordingly.
364     }
365
366     // Failure outcomes
367     // None at present.
368     // ---------------------------------------------------------------
369     // CRUD tests : UPDATE tests
370     // ---------------------------------------------------------------
371     // Success outcomes
372     /* (non-Javadoc)
373      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
374      */
375     @Override
376     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
377     dependsOnMethods = {"read", "readList", "readNonExistent"})
378     public void update(String testName) throws Exception {
379         //FIXME: Should this test really be empty?  If so, please comment accordingly.
380     }
381
382     // Failure outcomes
383     // Placeholders until the three tests below can be uncommented.
384     // See Issue CSPACE-401.
385     /* (non-Javadoc)
386      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
387      */
388     @Override
389     public void updateWithEmptyEntityBody(String testName) throws Exception {
390         //FIXME: Should this test really be empty?  If so, please comment accordingly.
391     }
392
393     /* (non-Javadoc)
394      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
395      */
396     @Override
397     public void updateWithMalformedXml(String testName) throws Exception {
398         //FIXME: Should this test really be empty?  If so, please comment accordingly.
399     }
400
401     /* (non-Javadoc)
402      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
403      */
404     @Override
405     public void updateWithWrongXmlSchema(String testName) throws Exception {
406         //FIXME: Should this test really be empty?  If so, please comment accordingly.
407     }
408
409     /* (non-Javadoc)
410      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
411      */
412     @Override
413     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
414     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
415     public void updateNonExistent(String testName) throws Exception {
416         //FIXME: Should this test really be empty?  If so, please comment accordingly.
417     }
418
419     // ---------------------------------------------------------------
420     // CRUD tests : DELETE tests
421     // ---------------------------------------------------------------
422     // Success outcomes
423     /* (non-Javadoc)
424      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
425      */
426     @Override
427     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
428     dependsOnMethods = {"read"})
429     public void delete(String testName) throws Exception {
430
431         if (logger.isDebugEnabled()) {
432             testBanner(testName, CLASS_NAME);
433         }
434
435         // Perform setup.
436         setupDelete();
437         
438         //
439         // Lookup a know account, and delete all of its role relationships
440         //
441         AccountRoleClient client = new AccountRoleClient();
442         ClientResponse<AccountRole> readResponse = client.read(
443                 accValues.get("acc-role-user1").getAccountId());
444         AccountRole toDelete = null;
445         try {
446                 toDelete = readResponse.getEntity();
447         } finally {
448                 readResponse.releaseConnection();
449         }
450
451         ClientResponse<Response> res = client.delete(
452                 toDelete.getAccounts().get(0).getAccountId(), toDelete);
453         try {
454             int statusCode = res.getStatus();
455             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
456                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
457             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
458         } finally {
459             res.releaseConnection();
460         }
461         
462         //
463         // recreate 'acc-role-user1' account and roles
464         //
465         create(testName);
466         setupDelete();
467         
468         //
469         // Lookup a know account, and delete all of its role relationships
470         //
471         readResponse = client.read(
472                 accValues.get("acc-role-user1").getAccountId());
473         toDelete = null;
474         try {
475                 toDelete = readResponse.getEntity();
476         } finally {
477                 readResponse.releaseConnection();
478         }
479
480         res = client.delete(toDelete.getAccounts().get(0).getAccountId());
481         try {
482             int statusCode = res.getStatus();
483             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
484                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
485             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
486         } finally {
487             res.releaseConnection();
488         }
489         
490     }
491
492     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
493             dependsOnMethods = {"read"})
494         public void deleteLockedAccount(String testName) throws Exception {
495
496         if (logger.isDebugEnabled()) {
497                 testBanner(testName, CLASS_NAME);
498         }
499         
500         findPrebuiltAdminAccount();
501
502         // Perform setup.
503         EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
504         REQUEST_TYPE = ServiceRequestType.DELETE;
505         testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
506
507         AccountRoleClient client = new AccountRoleClient();
508         ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
509         try {
510                 int statusCode = res.getStatus();
511                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
512                                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
513                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
514         } finally {
515                 res.releaseConnection();
516         }
517     }
518
519     // Failure outcomes
520     /* (non-Javadoc)
521      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
522      */
523     @Override
524     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
525     public void deleteNonExistent(String testName) throws Exception {
526         //ignoring this test as the service side returns 200 now even if it does
527         //not find a record in the db
528     }
529     
530     // ---------------------------------------------------------------
531     // Search tests
532     // ---------------------------------------------------------------
533     
534     @Override
535     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
536     public void searchWorkflowDeleted(String testName) throws Exception {
537         // Fixme: null test for now, overriding test in base class
538     }    
539
540     // ---------------------------------------------------------------
541     // Utility tests : tests of code used in tests above
542     // ---------------------------------------------------------------
543     /**
544      * Tests the code for manually submitting data that is used by several
545      * of the methods above.
546      * @throws Exception 
547      */
548     @Test(dependsOnMethods = {"create"})
549     public void testSubmitRequest() throws Exception {  //FIXME:  REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
550
551         // Expected status code: 200 OK
552         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
553
554         // Submit the request to the service and store the response.
555         String method = ServiceRequestType.READ.httpMethodName();
556         String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
557         int statusCode = submitRequest(method, url);
558
559         // Check the status code of the response: does it match
560         // the expected response(s)?
561         if (logger.isDebugEnabled()) {
562             logger.debug("testSubmitRequest: url=" + url
563                     + " status=" + statusCode);
564         }
565         Assert.assertEquals(statusCode, EXPECTED_STATUS);
566
567     }
568
569     // ---------------------------------------------------------------
570     // Utility methods used by tests above
571     // ---------------------------------------------------------------
572     /**
573      * Creates the account role instance.
574      *
575      * @param av the av
576      * @param rvs the rvs
577      * @param usePermId the use perm id
578      * @param useRoleId the use role id
579      * @return the account role
580      */
581     static public AccountRole createAccountRoleInstance(AccountValue pv,
582             Collection<RoleValue> rvs,
583             boolean usePermId,
584             boolean useRoleId) {
585
586         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
587                 pv, rvs, usePermId, useRoleId);
588
589         if (logger.isDebugEnabled()) {
590             logger.debug("to be created, accRole common");
591             logger.debug(objectAsXmlString(accRole, AccountRole.class));
592         }
593         return accRole;
594     }
595
596     /**
597      * Clean up.
598      */
599     @AfterClass(alwaysRun = true)
600     @Override
601     public void cleanUp() {
602
603         setupDelete();
604
605         String noTest = System.getProperty("noTestCleanup");
606         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
607             if (logger.isDebugEnabled()) {
608                 logger.debug("Skipping Cleanup phase ...");
609             }
610             return;
611         }
612         if (logger.isDebugEnabled()) {
613             logger.debug("Cleaning up temporary resources created for testing ...");
614         }
615
616
617         for (AccountValue pv : accValues.values()) {
618             deleteAccount(pv.getAccountId());
619         }
620
621         for (RoleValue rv : roleValues.values()) {
622             deleteRole(rv.getRoleId());
623         }
624     }
625
626     /**
627      * Creates the account.
628      *
629      * @param userName the user name
630      * @param email the email
631      * @return the string
632      */
633     private String createAccount(String userName, String email) {
634
635         if (logger.isDebugEnabled()) {
636             testBanner("createAccount");
637         }
638
639         setupCreate();
640
641         AccountClient accClient = new AccountClient();
642         AccountsCommon account = AccountFactory.createAccountInstance(
643                 userName, userName, userName, email, accClient.getTenantId(),
644                 true, false, true, true);
645         ClientResponse<Response> res = accClient.create(account);
646         int statusCode = res.getStatus();
647         if (logger.isDebugEnabled()) {
648             logger.debug("createAccount: userName=" + userName
649                     + " status = " + statusCode);
650         }
651         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
654         res.releaseConnection();
655         return extractId(res);
656     }
657
658     private void findPrebuiltAdminAccount() {
659         // Search for the prebuilt admin user and then hold its CSID
660         if(prebuiltAdminCSID == null) {
661             setupReadList();
662             AccountClient client = new AccountClient();
663             ClientResponse<AccountsCommonList> res =
664                     client.readSearchList(null, this.prebuiltAdminUserId, null);
665             AccountsCommonList list = res.getEntity();
666             int statusCode = res.getStatus();
667
668             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669             List<AccountsCommonList.AccountListItem> items = list.getAccountListItem();
670             Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
671             AccountsCommonList.AccountListItem item = items.get(0);
672             prebuiltAdminCSID = item.getCsid();
673             if (logger.isDebugEnabled()) {
674                 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
675             }
676         }
677     }
678     
679     /**
680      * Delete account.
681      *
682      * @param accId the acc id
683      */
684     private void deleteAccount(String accId) {
685
686         if (logger.isDebugEnabled()) {
687             testBanner("deleteAccount");
688         }
689
690         setupDelete();
691
692         AccountClient accClient = new AccountClient();
693         ClientResponse<Response> res = accClient.delete(accId);
694         int statusCode = res.getStatus();
695         try {
696             if (logger.isDebugEnabled()) {
697                 logger.debug("deleteAccount: delete account id="
698                         + accId + " status=" + statusCode);
699             }
700             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
701                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
702             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
703         } finally {
704             res.releaseConnection();
705         }
706     }
707
708     /**
709      * Creates the role.
710      *
711      * @param roleName the role name
712      * @return the string
713      */
714     private String createRole(String roleName) {
715         if (logger.isDebugEnabled()) {
716             testBanner("createRole");
717         }
718         setupCreate();
719         RoleClient roleClient = new RoleClient();
720
721         Role role = RoleFactory.createRoleInstance(roleName,
722                         roleName, //the display name
723                 "role for " + roleName, true);
724         ClientResponse<Response> res = roleClient.create(role);
725         int statusCode = res.getStatus();
726         if (logger.isDebugEnabled()) {
727             logger.debug("createRole: name=" + roleName
728                     + " status = " + statusCode);
729         }
730         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
733         res.releaseConnection();
734         return extractId(res);
735     }
736
737     /**
738      * Delete role.
739      *
740      * @param roleId the role id
741      */
742     private void deleteRole(String roleId) {
743         if (logger.isDebugEnabled()) {
744             testBanner("deleteRole");
745         }
746         setupDelete();
747         RoleClient roleClient = new RoleClient();
748         ClientResponse<Response> res = roleClient.delete(roleId);
749         int statusCode = res.getStatus();
750         try {
751             if (logger.isDebugEnabled()) {
752                 logger.debug("deleteRole: delete role id=" + roleId
753                         + " status=" + statusCode);
754             }
755             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
756                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
757             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
758         } finally {
759             res.releaseConnection();
760         }
761     }
762
763         @Override
764         protected String getServiceName() {
765                 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
766                 return AccountClient.SERVICE_NAME;
767         }
768 }