]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0a1485124e166e3e3660ef15b444a916f36a5273
[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      * 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.
356      */
357     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358             dependsOnMethods = {"delete"})
359     public void readRoleAccounts(String testName) throws Exception {
360
361         if (logger.isDebugEnabled()) {
362             testBanner(testName, CLASS_NAME);
363         }
364
365                 /*
366                  * Setup a temp local scope for local variables that we need to create the AccountRole for
367                  * the setup of the read tests.
368                  */
369         {
370                 setupCreate();
371
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);
382         }
383
384         //
385         // Now read the list of accounts associated with the role "ROLE_CO1".
386         // There should be just the "acc-role-user2" account.
387         //
388         setupRead();        
389         RoleClient roleClient = new RoleClient();
390         
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();
395         try {
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);
400             }
401             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
402                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
403             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
404             AccountRole output = res.getEntity();
405             
406             // Now verify that the role has 2 accounts associate to it.
407             Assert.assertEquals(output.getAccounts().size(), 1);
408
409             String sOutput = objectAsXmlString(output, AccountRole.class);
410             if(logger.isDebugEnabled()) {
411                 logger.debug(testName + " received " + sOutput);
412             }
413         } finally {
414             res.releaseConnection();
415         }
416     }    
417
418     // ---------------------------------------------------------------
419     // CRUD tests : READ_LIST tests
420     // ---------------------------------------------------------------
421     // Success outcomes
422     /* (non-Javadoc)
423      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
424      */
425     @Override
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.
430     }
431
432     // Failure outcomes
433     // None at present.
434     // ---------------------------------------------------------------
435     // CRUD tests : UPDATE tests
436     // ---------------------------------------------------------------
437     // Success outcomes
438     /* (non-Javadoc)
439      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
440      */
441     @Override
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.
446     }
447
448     // Failure outcomes
449     // Placeholders until the three tests below can be uncommented.
450     // See Issue CSPACE-401.
451     /* (non-Javadoc)
452      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
453      */
454     @Override
455     public void updateWithEmptyEntityBody(String testName) throws Exception {
456         //FIXME: Should this test really be empty?  If so, please comment accordingly.
457     }
458
459     /* (non-Javadoc)
460      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
461      */
462     @Override
463     public void updateWithMalformedXml(String testName) throws Exception {
464         //FIXME: Should this test really be empty?  If so, please comment accordingly.
465     }
466
467     /* (non-Javadoc)
468      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
469      */
470     @Override
471     public void updateWithWrongXmlSchema(String testName) throws Exception {
472         //FIXME: Should this test really be empty?  If so, please comment accordingly.
473     }
474
475     /* (non-Javadoc)
476      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
477      */
478     @Override
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.
483     }
484
485     // ---------------------------------------------------------------
486     // CRUD tests : DELETE tests
487     // ---------------------------------------------------------------
488     // Success outcomes
489     /* (non-Javadoc)
490      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
491      */
492     @Override
493     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
494     dependsOnMethods = {"read"})
495     public void delete(String testName) throws Exception {
496
497         if (logger.isDebugEnabled()) {
498             testBanner(testName, CLASS_NAME);
499         }
500
501         // Perform setup.
502         setupDelete();
503         
504         //
505         // Lookup a know account, and delete all of its role relationships
506         //
507         AccountRoleClient client = new AccountRoleClient();
508         ClientResponse<AccountRole> readResponse = client.read(
509                 accValues.get("acc-role-user1").getAccountId());
510         AccountRole toDelete = null;
511         try {
512                 toDelete = readResponse.getEntity();
513         } finally {
514                 readResponse.releaseConnection();
515         }
516
517         ClientResponse<Response> res = client.delete(
518                 toDelete.getAccounts().get(0).getAccountId(), toDelete);
519         try {
520             int statusCode = res.getStatus();
521             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
522                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
523             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
524         } finally {
525             res.releaseConnection();
526         }
527         
528         //
529         // recreate 'acc-role-user1' account and roles
530         //
531         create(testName);
532         setupDelete();
533         
534         //
535         // Lookup a know account, and delete all of its role relationships
536         //
537         readResponse = client.read(
538                 accValues.get("acc-role-user1").getAccountId());
539         toDelete = null;
540         try {
541                 toDelete = readResponse.getEntity();
542         } finally {
543                 readResponse.releaseConnection();
544         }
545
546         res = client.delete(toDelete.getAccounts().get(0).getAccountId());
547         try {
548             int statusCode = res.getStatus();
549             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
550                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
551             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
552         } finally {
553             res.releaseConnection();
554         }
555         
556     }
557
558     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
559             dependsOnMethods = {"read"})
560         public void deleteLockedAccount(String testName) throws Exception {
561
562         if (logger.isDebugEnabled()) {
563                 testBanner(testName, CLASS_NAME);
564         }
565         
566         findPrebuiltAdminAccount();
567
568         // Perform setup.
569         EXPECTED_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode();
570         REQUEST_TYPE = ServiceRequestType.DELETE;
571         testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
572
573         AccountRoleClient client = new AccountRoleClient();
574         ClientResponse<Response> res = client.delete(prebuiltAdminCSID);
575         try {
576                 int statusCode = res.getStatus();
577                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
578                                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
579                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
580         } finally {
581                 res.releaseConnection();
582         }
583     }
584
585     // Failure outcomes
586     /* (non-Javadoc)
587      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
588      */
589     @Override
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
594     }
595     
596     // ---------------------------------------------------------------
597     // Search tests
598     // ---------------------------------------------------------------
599     
600     @Override
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
604     }    
605
606     // ---------------------------------------------------------------
607     // Utility tests : tests of code used in tests above
608     // ---------------------------------------------------------------
609     /**
610      * Tests the code for manually submitting data that is used by several
611      * of the methods above.
612      * @throws Exception 
613      */
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
616
617         // Expected status code: 200 OK
618         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
619
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);
624
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);
630         }
631         Assert.assertEquals(statusCode, EXPECTED_STATUS);
632
633     }
634
635     // ---------------------------------------------------------------
636     // Utility methods used by tests above
637     // ---------------------------------------------------------------
638     /**
639      * Creates the account role instance.
640      *
641      * @param av the av
642      * @param rvs the rvs
643      * @param usePermId the use perm id
644      * @param useRoleId the use role id
645      * @return the account role
646      */
647     static public AccountRole createAccountRoleInstance(AccountValue pv,
648             Collection<RoleValue> rvs,
649             boolean usePermId,
650             boolean useRoleId) {
651
652         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
653                 pv, rvs, usePermId, useRoleId);
654
655         if (logger.isDebugEnabled()) {
656             logger.debug("to be created, accRole common");
657             logger.debug(objectAsXmlString(accRole, AccountRole.class));
658         }
659         return accRole;
660     }
661
662     /**
663      * Clean up.
664      */
665     @AfterClass(alwaysRun = true)
666     @Override
667     public void cleanUp() {
668
669         setupDelete();
670
671         String noTest = System.getProperty("noTestCleanup");
672         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
673             if (logger.isDebugEnabled()) {
674                 logger.debug("Skipping Cleanup phase ...");
675             }
676             return;
677         }
678         if (logger.isDebugEnabled()) {
679             logger.debug("Cleaning up temporary resources created for testing ...");
680         }
681
682
683         for (AccountValue pv : accValues.values()) {
684             deleteAccount(pv.getAccountId());
685         }
686
687         for (RoleValue rv : roleValues.values()) {
688             deleteRole(rv.getRoleId());
689         }
690     }
691
692     /**
693      * Creates the account.
694      *
695      * @param userName the user name
696      * @param email the email
697      * @return the string
698      */
699     private String createAccount(String userName, String email) {
700
701         if (logger.isDebugEnabled()) {
702             testBanner("createAccount");
703         }
704
705         setupCreate();
706
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);
716         }
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);
722     }
723
724     private void findPrebuiltAdminAccount() {
725         // Search for the prebuilt admin user and then hold its CSID
726         if(prebuiltAdminCSID == null) {
727             setupReadList();
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();
733
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);
741             }
742         }
743     }
744     
745     /**
746      * Delete account.
747      *
748      * @param accId the acc id
749      */
750     private void deleteAccount(String accId) {
751
752         if (logger.isDebugEnabled()) {
753             testBanner("deleteAccount");
754         }
755
756         setupDelete();
757
758         AccountClient accClient = new AccountClient();
759         ClientResponse<Response> res = accClient.delete(accId);
760         int statusCode = res.getStatus();
761         try {
762             if (logger.isDebugEnabled()) {
763                 logger.debug("deleteAccount: delete account id="
764                         + accId + " status=" + statusCode);
765             }
766             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
767                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
768             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
769         } finally {
770             res.releaseConnection();
771         }
772     }
773
774     /**
775      * Creates the role.
776      *
777      * @param roleName the role name
778      * @return the string
779      */
780     private String createRole(String roleName) {
781         if (logger.isDebugEnabled()) {
782             testBanner("createRole");
783         }
784         setupCreate();
785         RoleClient roleClient = new RoleClient();
786
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);
795         }
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);
801     }
802
803     /**
804      * Delete role.
805      *
806      * @param roleId the role id
807      */
808     private void deleteRole(String roleId) {
809         if (logger.isDebugEnabled()) {
810             testBanner("deleteRole");
811         }
812         setupDelete();
813         RoleClient roleClient = new RoleClient();
814         ClientResponse<Response> res = roleClient.delete(roleId);
815         int statusCode = res.getStatus();
816         try {
817             if (logger.isDebugEnabled()) {
818                 logger.debug("deleteRole: delete role id=" + roleId
819                         + " status=" + statusCode);
820             }
821             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
822                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
823             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
824         } finally {
825             res.releaseConnection();
826         }
827     }
828
829         @Override
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;
833         }
834 }