]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d0c553cb020688f01fc6624fa5fd3cef6ce2c3c7
[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.authorization.AccountRole;
34 import org.collectionspace.services.authorization.AccountValue;
35 import org.collectionspace.services.authorization.Role;
36 import org.collectionspace.services.authorization.RoleValue;
37 import org.collectionspace.services.client.AccountClient;
38 import org.collectionspace.services.client.AccountFactory;
39 import org.collectionspace.services.client.AccountRoleClient;
40 import org.collectionspace.services.client.AccountRoleFactory;
41 import org.collectionspace.services.client.CollectionSpaceClient;
42 import org.collectionspace.services.client.RoleClient;
43 import org.collectionspace.services.client.RoleFactory;
44 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
45 import org.collectionspace.services.client.test.ServiceRequestType;
46 import org.collectionspace.services.jaxb.AbstractCommonList;
47 import org.jboss.resteasy.client.ClientResponse;
48
49
50 import org.testng.Assert;
51 import org.testng.annotations.Test;
52
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.BeforeClass;
57
58 /**
59  * AccountServiceTest, carries out tests against a
60  * deployed and running Account, Role and AccountRole Services.
61  * 
62  * $LastChangedRevision: 917 $
63  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
64  */
65 public class AccountRoleServiceTest extends AbstractServiceTestImpl {
66
67     /** The Constant logger. */
68     private final static String CLASS_NAME = AccountRoleServiceTest.class.getName();
69     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
70     // Instance variables specific to this test.
71     /** The known resource id. */
72     private String knownResourceId = null;
73     /** The all resource ids created. */
74     private List<String> allResourceIdsCreated = new ArrayList<String>();
75     /** The acc values. */
76     private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
77     /** The role values. */
78     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
79     /*
80      * This method is called only by the parent class, AbstractServiceTestImpl
81      */
82
83     /* (non-Javadoc)
84      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
85      */
86     @Override
87     protected String getServicePathComponent() {
88         return new AccountRoleClient().getServicePathComponent();
89     }
90
91     /**
92      * Seed data.
93      */
94     @BeforeClass(alwaysRun = true)
95     public void seedData() {
96         String userId = "acc-role-user1";
97         String accId = createAccount(userId, "acc-role-user1-test@cspace.org");
98         AccountValue ava = new AccountValue();
99         ava.setScreenName(userId);
100         ava.setUserId(userId);
101         ava.setAccountId(accId);
102         accValues.put(ava.getScreenName(), ava);
103
104         String userId2 = "acc-role-user2";
105         String coAccId = createAccount(userId2, "acc-role-user2-test@cspace.org");
106         AccountValue avc = new AccountValue();
107         avc.setScreenName(userId2);
108         avc.setUserId(userId2);
109         avc.setAccountId(coAccId);
110         accValues.put(avc.getScreenName(), avc);
111
112         String rn1 = "ROLE_CO1";
113         String r1RoleId = createRole(rn1);
114         RoleValue rv1 = new RoleValue();
115         rv1.setRoleId(r1RoleId);
116         rv1.setRoleName(rn1);
117         roleValues.put(rv1.getRoleName(), rv1);
118
119         String rn2 = "ROLE_CO2";
120         String r2RoleId = createRole(rn2);
121         RoleValue rv2 = new RoleValue();
122         rv2.setRoleId(r2RoleId);
123         rv2.setRoleName(rn2);
124         roleValues.put(rv2.getRoleName(), rv2);
125     }
126
127     /* (non-Javadoc)
128      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
129      */
130     @Override
131     protected CollectionSpaceClient getClientInstance() {
132         return new AccountRoleClient();
133     }
134
135     /* (non-Javadoc)
136      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
137      */
138     @Override
139     protected AbstractCommonList getAbstractCommonList(
140             ClientResponse<AbstractCommonList> response) {
141         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
142         throw new UnsupportedOperationException();
143     }
144
145     /* (non-Javadoc)
146      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
147      */
148     @Test(dataProvider = "testName")
149     @Override
150     public void readPaginatedList(String testName) throws Exception {
151         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
152     }
153
154     // ---------------------------------------------------------------
155     // CRUD tests : CREATE tests
156     // ---------------------------------------------------------------
157     // Success outcomes
158     /* (non-Javadoc)
159      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
160      */
161     @Override
162     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
163     public void create(String testName) throws Exception {
164
165         if (logger.isDebugEnabled()) {
166             testBanner(testName, CLASS_NAME);
167         }
168         // Perform setup, such as initializing the type of service request
169         // (e.g. CREATE, DELETE), its valid and expected status codes, and
170         // its associated HTTP method name (e.g. POST, DELETE).
171         setupCreate();
172
173         // Submit the request to the service and store the response.
174         AccountValue av = accValues.get("acc-role-user1");
175         AccountRole accRole = createAccountRoleInstance(av,
176                 roleValues.values(), true, true);
177         AccountRoleClient client = new AccountRoleClient();
178         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
179         try {
180             int statusCode = res.getStatus();
181
182             if (logger.isDebugEnabled()) {
183                 logger.debug(testName + ": status = " + statusCode);
184             }
185             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
186                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
187             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
188
189             // Store the ID returned from this create operation
190             // for additional tests below.
191             //this is is not important in case of this relationship
192             knownResourceId = extractId(res);
193             if (logger.isDebugEnabled()) {
194                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
195             }
196         } finally {
197             res.releaseConnection();
198         }
199     }
200
201     //to not cause uniqueness violation for accRole, createList is removed
202     /* (non-Javadoc)
203      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
204      */
205     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
206     dependsOnMethods = {"create"})
207     @Override
208     public void createList(String testName) throws Exception {
209         //FIXME: Should this test really be empty?  If so, please comment accordingly.
210     }
211
212     // Failure outcomes
213     // Placeholders until the three tests below can be uncommented.
214     // See Issue CSPACE-401.
215     /* (non-Javadoc)
216      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
217      */
218     @Override
219     public void createWithEmptyEntityBody(String testName) throws Exception {
220         //FIXME: Should this test really be empty?  If so, please comment accordingly.
221     }
222
223     /* (non-Javadoc)
224      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
225      */
226     @Override
227     public void createWithMalformedXml(String testName) throws Exception {
228         //FIXME: Should this test really be empty?  If so, please comment accordingly.
229     }
230
231     /* (non-Javadoc)
232      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
233      */
234     @Override
235     public void createWithWrongXmlSchema(String testName) throws Exception {
236         //FIXME: Should this test really be empty?  If so, please comment accordingly.
237     }
238
239     // ---------------------------------------------------------------
240     // CRUD tests : READ tests
241     // ---------------------------------------------------------------
242     // Success outcomes
243     /* (non-Javadoc)
244      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
245      */
246     @Override
247     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
248     dependsOnMethods = {"create"})
249     public void read(String testName) throws Exception {
250
251         if (logger.isDebugEnabled()) {
252             testBanner(testName, CLASS_NAME);
253         }
254
255         // Perform setup.
256         setupRead();
257
258         // Submit the request to the service and store the response.
259         AccountRoleClient client = new AccountRoleClient();
260         ClientResponse<AccountRole> res = client.read(
261                 accValues.get("acc-role-user1").getAccountId());
262         int statusCode = res.getStatus();
263         try {
264             // Check the status code of the response: does it match
265             // the expected response(s)?
266             if (logger.isDebugEnabled()) {
267                 logger.debug(testName + ": status = " + statusCode);
268             }
269             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
270                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
271             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
272
273             AccountRole output = res.getEntity();
274             Assert.assertNotNull(output);
275         } finally {
276             res.releaseConnection();
277         }
278     }
279
280     // Failure outcomes
281     /* (non-Javadoc)
282      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
283      */
284     @Override
285     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
286     public void readNonExistent(String testName) throws Exception {
287
288         if (logger.isDebugEnabled()) {
289             testBanner(testName, CLASS_NAME);
290         }
291
292         // Perform setup.
293         setupReadNonExistent();
294
295         // Submit the request to the service and store the response.
296         AccountRoleClient client = new AccountRoleClient();
297         ClientResponse<AccountRole> res = client.read(this.NON_EXISTENT_ID);
298         int statusCode = res.getStatus();
299         try {
300             // Check the status code of the response: does it match
301             // the expected response(s)?
302             if (logger.isDebugEnabled()) {
303                 logger.debug(testName + ": status = " + statusCode);
304             }
305             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
306                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
307             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
308         } finally {
309             res.releaseConnection();
310         }
311     }
312
313     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
314     dependsOnMethods = {"create"})
315     public void readNoRelationship(String testName) throws Exception {
316
317         if (logger.isDebugEnabled()) {
318             testBanner(testName, CLASS_NAME);
319         }
320
321         // Perform setup.
322         setupRead();
323
324         // Submit the request to the service and store the response.
325         AccountRoleClient client = new AccountRoleClient();
326         ClientResponse<AccountRole> res = client.read(
327                 accValues.get("acc-role-user2").getAccountId());
328         int statusCode = res.getStatus();
329         try {
330             // Check the status code of the response: does it match
331             // the expected response(s)?
332             if (logger.isDebugEnabled()) {
333                 logger.debug(testName + ": status = " + statusCode);
334             }
335             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
336                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
337             Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
338             AccountRole output = res.getEntity();
339
340             String sOutput = objectAsXmlString(output, AccountRole.class);
341             if(logger.isDebugEnabled()) {
342                 logger.debug(testName + " received " + sOutput);
343             }
344         } finally {
345             res.releaseConnection();
346         }
347     }
348
349     // ---------------------------------------------------------------
350     // CRUD tests : READ_LIST tests
351     // ---------------------------------------------------------------
352     // Success outcomes
353     /* (non-Javadoc)
354      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
355      */
356     @Override
357     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358     dependsOnMethods = {"createList", "read"})
359     public void readList(String testName) throws Exception {
360         //FIXME: Should this test really be empty?  If so, please comment accordingly.
361     }
362
363     // Failure outcomes
364     // None at present.
365     // ---------------------------------------------------------------
366     // CRUD tests : UPDATE tests
367     // ---------------------------------------------------------------
368     // Success outcomes
369     /* (non-Javadoc)
370      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
371      */
372     @Override
373     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
374     dependsOnMethods = {"read", "readList", "readNonExistent"})
375     public void update(String testName) throws Exception {
376         //FIXME: Should this test really be empty?  If so, please comment accordingly.
377     }
378
379     // Failure outcomes
380     // Placeholders until the three tests below can be uncommented.
381     // See Issue CSPACE-401.
382     /* (non-Javadoc)
383      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
384      */
385     @Override
386     public void updateWithEmptyEntityBody(String testName) throws Exception {
387         //FIXME: Should this test really be empty?  If so, please comment accordingly.
388     }
389
390     /* (non-Javadoc)
391      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
392      */
393     @Override
394     public void updateWithMalformedXml(String testName) throws Exception {
395         //FIXME: Should this test really be empty?  If so, please comment accordingly.
396     }
397
398     /* (non-Javadoc)
399      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
400      */
401     @Override
402     public void updateWithWrongXmlSchema(String testName) throws Exception {
403         //FIXME: Should this test really be empty?  If so, please comment accordingly.
404     }
405
406     /* (non-Javadoc)
407      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
408      */
409     @Override
410     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
411     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
412     public void updateNonExistent(String testName) throws Exception {
413         //FIXME: Should this test really be empty?  If so, please comment accordingly.
414     }
415
416     // ---------------------------------------------------------------
417     // CRUD tests : DELETE tests
418     // ---------------------------------------------------------------
419     // Success outcomes
420     /* (non-Javadoc)
421      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
422      */
423     @Override
424     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
425     dependsOnMethods = {"read"})
426     public void delete(String testName) throws Exception {
427
428         if (logger.isDebugEnabled()) {
429             testBanner(testName, CLASS_NAME);
430         }
431
432         // Perform setup.
433         setupDelete();
434         
435         //
436         // Lookup a know account, and delete all of its role relationships
437         //
438         AccountRoleClient client = new AccountRoleClient();
439         ClientResponse<AccountRole> readResponse = client.read(
440                 accValues.get("acc-role-user1").getAccountId());
441         AccountRole toDelete = null;
442         try {
443                 toDelete = readResponse.getEntity();
444         } finally {
445                 readResponse.releaseConnection();
446         }
447
448         ClientResponse<Response> res = client.delete(
449                 toDelete.getAccounts().get(0).getAccountId(), toDelete);
450         try {
451             int statusCode = res.getStatus();
452             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
453                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
454             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
455         } finally {
456             res.releaseConnection();
457         }
458         
459         //
460         // recreate 'acc-role-user1' account and roles
461         //
462         create(testName);
463         setupDelete();
464         
465         //
466         // Lookup a know account, and delete all of its role relationships
467         //
468         readResponse = client.read(
469                 accValues.get("acc-role-user1").getAccountId());
470         toDelete = null;
471         try {
472                 toDelete = readResponse.getEntity();
473         } finally {
474                 readResponse.releaseConnection();
475         }
476
477         res = client.delete(toDelete.getAccounts().get(0).getAccountId());
478         try {
479             int statusCode = res.getStatus();
480             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
483         } finally {
484             res.releaseConnection();
485         }
486         
487     }
488
489     // Failure outcomes
490     /* (non-Javadoc)
491      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
492      */
493     @Override
494     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
495     public void deleteNonExistent(String testName) throws Exception {
496         //ignoring this test as the service side returns 200 now even if it does
497         //not find a record in the db
498     }
499     
500     // ---------------------------------------------------------------
501     // Search tests
502     // ---------------------------------------------------------------
503     
504     @Override
505     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
506     public void searchWorkflowDeleted(String testName) throws Exception {
507         // Fixme: null test for now, overriding test in base class
508     }    
509
510     // ---------------------------------------------------------------
511     // Utility tests : tests of code used in tests above
512     // ---------------------------------------------------------------
513     /**
514      * Tests the code for manually submitting data that is used by several
515      * of the methods above.
516      * @throws Exception 
517      */
518     @Test(dependsOnMethods = {"create"})
519     public void testSubmitRequest() throws Exception {  //FIXME:  REM - This is not testing a submit /accounts/*/accountroles, but instead just to /accounts
520
521         // Expected status code: 200 OK
522         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
523
524         // Submit the request to the service and store the response.
525         String method = ServiceRequestType.READ.httpMethodName();
526         String url = getResourceURL(accValues.get("acc-role-user1").getAccountId());
527         int statusCode = submitRequest(method, url);
528
529         // Check the status code of the response: does it match
530         // the expected response(s)?
531         if (logger.isDebugEnabled()) {
532             logger.debug("testSubmitRequest: url=" + url
533                     + " status=" + statusCode);
534         }
535         Assert.assertEquals(statusCode, EXPECTED_STATUS);
536
537     }
538
539     // ---------------------------------------------------------------
540     // Utility methods used by tests above
541     // ---------------------------------------------------------------
542     /**
543      * Creates the account role instance.
544      *
545      * @param av the av
546      * @param rvs the rvs
547      * @param usePermId the use perm id
548      * @param useRoleId the use role id
549      * @return the account role
550      */
551     static public AccountRole createAccountRoleInstance(AccountValue pv,
552             Collection<RoleValue> rvs,
553             boolean usePermId,
554             boolean useRoleId) {
555
556         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
557                 pv, rvs, usePermId, useRoleId);
558
559         if (logger.isDebugEnabled()) {
560             logger.debug("to be created, accRole common");
561             logger.debug(objectAsXmlString(accRole, AccountRole.class));
562         }
563         return accRole;
564     }
565
566     /**
567      * Clean up.
568      */
569     @AfterClass(alwaysRun = true)
570     @Override
571     public void cleanUp() {
572
573         setupDelete();
574
575         String noTest = System.getProperty("noTestCleanup");
576         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
577             if (logger.isDebugEnabled()) {
578                 logger.debug("Skipping Cleanup phase ...");
579             }
580             return;
581         }
582         if (logger.isDebugEnabled()) {
583             logger.debug("Cleaning up temporary resources created for testing ...");
584         }
585
586
587         for (AccountValue pv : accValues.values()) {
588             deleteAccount(pv.getAccountId());
589         }
590
591         for (RoleValue rv : roleValues.values()) {
592             deleteRole(rv.getRoleId());
593         }
594     }
595
596     /**
597      * Creates the account.
598      *
599      * @param userName the user name
600      * @param email the email
601      * @return the string
602      */
603     private String createAccount(String userName, String email) {
604
605         if (logger.isDebugEnabled()) {
606             testBanner("createAccount");
607         }
608
609         setupCreate();
610
611         AccountClient accClient = new AccountClient();
612         AccountsCommon account = AccountFactory.createAccountInstance(
613                 userName, userName, userName, email, accClient.getTenantId(),
614                 true, false, true, true);
615         ClientResponse<Response> res = accClient.create(account);
616         int statusCode = res.getStatus();
617         if (logger.isDebugEnabled()) {
618             logger.debug("createAccount: userName=" + userName
619                     + " status = " + statusCode);
620         }
621         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624         res.releaseConnection();
625         return extractId(res);
626     }
627
628     /**
629      * Delete account.
630      *
631      * @param accId the acc id
632      */
633     private void deleteAccount(String accId) {
634
635         if (logger.isDebugEnabled()) {
636             testBanner("deleteAccount");
637         }
638
639         setupDelete();
640
641         AccountClient accClient = new AccountClient();
642         ClientResponse<Response> res = accClient.delete(accId);
643         int statusCode = res.getStatus();
644         try {
645             if (logger.isDebugEnabled()) {
646                 logger.debug("deleteAccount: delete account id="
647                         + accId + " status=" + statusCode);
648             }
649             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
650                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
651             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652         } finally {
653             res.releaseConnection();
654         }
655     }
656
657     /**
658      * Creates the role.
659      *
660      * @param roleName the role name
661      * @return the string
662      */
663     private String createRole(String roleName) {
664         if (logger.isDebugEnabled()) {
665             testBanner("createRole");
666         }
667         setupCreate();
668         RoleClient roleClient = new RoleClient();
669
670         Role role = RoleFactory.createRoleInstance(roleName,
671                         roleName, //the display name
672                 "role for " + roleName, true);
673         ClientResponse<Response> res = roleClient.create(role);
674         int statusCode = res.getStatus();
675         if (logger.isDebugEnabled()) {
676             logger.debug("createRole: name=" + roleName
677                     + " status = " + statusCode);
678         }
679         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
680                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
681         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682         res.releaseConnection();
683         return extractId(res);
684     }
685
686     /**
687      * Delete role.
688      *
689      * @param roleId the role id
690      */
691     private void deleteRole(String roleId) {
692         if (logger.isDebugEnabled()) {
693             testBanner("deleteRole");
694         }
695         setupDelete();
696         RoleClient roleClient = new RoleClient();
697         ClientResponse<Response> res = roleClient.delete(roleId);
698         int statusCode = res.getStatus();
699         try {
700             if (logger.isDebugEnabled()) {
701                 logger.debug("deleteRole: delete role id=" + roleId
702                         + " status=" + statusCode);
703             }
704             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
707         } finally {
708             res.releaseConnection();
709         }
710     }
711
712         @Override
713         protected String getServiceName() {
714                 // AccountRoles service is a sub-service of the Account service, so we return Account's service name
715                 return AccountClient.SERVICE_NAME;
716         }
717 }