]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
d5feb9ede7ffd3d2d2da5c1f08224f5afc1462ff
[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 2010 University of California at Berkeley
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
16  *  https://source.collectionspace.org/collection-space/LICENSE.txt
17
18  *  Unless required by applicable law or agreed to in writing, software
19  *  distributed under the License is distributed on an "AS IS" BASIS,
20  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  *  See the License for the specific language governing permissions and
22  *  limitations under the License.
23  */
24 /*
25  * To change this template, choose Tools | Templates
26  * and open the template in the editor.
27  */
28 package org.collectionspace.services.security.client.test;
29
30 import java.util.ArrayList;
31 import java.util.Collection;
32 import java.util.Date;
33 import java.util.Hashtable;
34 import java.util.List;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
37 import org.collectionspace.services.account.AccountsCommon;
38 import org.collectionspace.services.authorization.AccountRole;
39 import org.collectionspace.services.authorization.AccountValue;
40 import org.collectionspace.services.authorization.ActionType;
41 import org.collectionspace.services.authorization.EffectType;
42
43 import org.collectionspace.services.authorization.Permission;
44 import org.collectionspace.services.authorization.PermissionAction;
45 import org.collectionspace.services.authorization.PermissionRole;
46 import org.collectionspace.services.authorization.PermissionValue;
47 import org.collectionspace.services.authorization.Role;
48 import org.collectionspace.services.authorization.RoleValue;
49 import org.collectionspace.services.client.AccountClient;
50 import org.collectionspace.services.client.AccountFactory;
51 import org.collectionspace.services.client.AccountRoleClient;
52 import org.collectionspace.services.client.AccountRoleFactory;
53 import org.collectionspace.services.client.CollectionSpaceClient;
54 import org.collectionspace.services.client.DimensionClient;
55 import org.collectionspace.services.client.DimensionFactory;
56 import org.collectionspace.services.client.PermissionClient;
57 import org.collectionspace.services.client.PermissionFactory;
58 import org.collectionspace.services.client.PermissionRoleClient;
59 import org.collectionspace.services.client.PermissionRoleFactory;
60 import org.collectionspace.services.client.RoleClient;
61 import org.collectionspace.services.client.RoleFactory;
62 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
63 import org.collectionspace.services.dimension.DimensionsCommon;
64 import org.collectionspace.services.jaxb.AbstractCommonList;
65 import org.jboss.resteasy.client.ClientResponse;
66 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
67 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
68 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
69
70 import org.testng.Assert;
71 import org.testng.annotations.Test;
72
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75 import org.testng.annotations.AfterClass;
76 import org.testng.annotations.BeforeClass;
77
78 /**
79  * AuthorizationServiceTest, carries out tests against a
80  * deployed and running Permission, Role, AccountRole, PermissionRole and
81  * CollectionObject Services.
82  *
83  * Pre-requisite : authorization-mgt/client tests seed some permissions used
84  * by this test
85  *
86  * $LastChangedRevision: 917 $
87  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
88  */
89 public class AuthorizationServiceTest extends AbstractServiceTestImpl {
90
91     private final String CLASS_NAME = AuthorizationServiceTest.class.getName();
92     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
93     // Instance variables specific to this test.
94     private String knownResourceId = null;
95     private List<String> allResourceIdsCreated = new ArrayList();
96     //key for accValues is userId
97     private Hashtable<String, AccountValue> accValues = new Hashtable<String, AccountValue>();
98     //key for permValues is id as there could be several perms for the same resource
99     private Hashtable<String, PermissionValue> permValues = new Hashtable<String, PermissionValue>();
100     //key for roleValues is roleName
101     private Hashtable<String, RoleValue> roleValues = new Hashtable<String, RoleValue>();
102     private String bigbirdPermId;
103     private String elmoPermId;
104     private final static String TEST_SERVICE_NAME = "dimensions";
105     /*
106      * This method is called only by the parent class, AbstractServiceTestImpl
107      */
108
109     @Override
110     protected String getServicePathComponent() {
111         return null;
112     }
113
114     @BeforeClass(alwaysRun = true)
115     public void seedData() {
116         seedPermissions();
117         seedRoles();
118         seedAccounts();
119         seedAccountRoles();
120         seedPermissionRoles();
121     }
122
123     private void seedPermissions() {
124         String res = TEST_SERVICE_NAME;
125
126         PermissionAction pac = new PermissionAction();
127         pac.setName(ActionType.CREATE);
128         PermissionAction par = new PermissionAction();
129         par.setName(ActionType.READ);
130         PermissionAction pau = new PermissionAction();
131         pau.setName(ActionType.UPDATE);
132
133
134         //bigbird can create, read and update but not delete
135         List<PermissionAction> bbactions = new ArrayList<PermissionAction>();
136         bbactions.add(pac);
137         bbactions.add(par);
138         bbactions.add(pau);
139         bigbirdPermId = createPermission(res, bbactions, EffectType.PERMIT);
140         PermissionValue bbpv = new PermissionValue();
141         bbpv.setResourceName(res);
142         bbpv.setPermissionId(bigbirdPermId);
143         permValues.put(bbpv.getPermissionId(), bbpv);
144
145         //elmo can only read
146         List<PermissionAction> eactions = new ArrayList<PermissionAction>();
147         eactions.add(par);
148         elmoPermId = createPermission(res, eactions, EffectType.PERMIT);
149         PermissionValue epv = new PermissionValue();
150         epv.setResourceName(res);
151         epv.setPermissionId(elmoPermId);
152         permValues.put(epv.getPermissionId(), epv);
153     }
154
155     private void seedRoles() {
156         String rn1 = "ROLE_TEST_CM";
157         String r1RoleId = createRole(rn1);
158         RoleValue rv1 = new RoleValue();
159         rv1.setRoleId(r1RoleId);
160         rv1.setRoleName(rn1);
161         roleValues.put(rv1.getRoleName(), rv1);
162
163         String rn2 = "ROLE_TEST_INTERN";
164         String r2RoleId = createRole(rn2);
165         RoleValue rv2 = new RoleValue();
166         rv2.setRoleId(r2RoleId);
167         rv2.setRoleName(rn2);
168         roleValues.put(rv2.getRoleName(), rv2);
169     }
170
171     private void seedAccounts() {
172         String userId = "bigbird2010";
173         String accId = createAccount(userId, "bigbird@cspace.org");
174         AccountValue ava = new AccountValue();
175         ava.setScreenName(userId);
176         ava.setUserId(userId);
177         ava.setAccountId(accId);
178         accValues.put(ava.getUserId(), ava);
179
180         String userId2 = "elmo2010";
181         String coAccId = createAccount(userId2, "elmo@cspace.org");
182         AccountValue avc = new AccountValue();
183         avc.setScreenName(userId2);
184         avc.setUserId(userId2);
185         avc.setAccountId(coAccId);
186         accValues.put(avc.getUserId(), avc);
187     }
188
189     private void seedAccountRoles() {
190
191         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
192         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
193         createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
194
195         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
196         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
197         createAccountRole(accValues.get("elmo2010"), elmoRoleValues);
198     }
199
200     private void seedPermissionRoles() {
201
202         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
203         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
204         createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
205
206         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
207         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
208         createPermissionRole(permValues.get(elmoPermId), elmoRoleValues);
209
210     }
211
212
213     /* (non-Javadoc)
214      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
215      */
216     @Override
217     protected CollectionSpaceClient getClientInstance() {
218         return null;
219     }
220
221     /* (non-Javadoc)
222      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
223      */
224     @Override
225     protected AbstractCommonList getAbstractCommonList(
226             ClientResponse<AbstractCommonList> response) {
227         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
228         throw new UnsupportedOperationException();
229     }
230
231     @Test(dataProvider = "testName")
232     @Override
233     public void readPaginatedList(String testName) throws Exception {
234         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
235     }
236     // ---------------------------------------------------------------
237     // CRUD tests : CREATE tests
238     // ---------------------------------------------------------------
239     // Success outcomes
240
241     @Override
242     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
243     public void create(String testName) throws Exception {
244         if (logger.isDebugEnabled()) {
245             logger.debug(testBanner(testName, CLASS_NAME));
246         }
247         setupCreate();
248
249         // Submit the request to the service and store the response.
250         DimensionClient client = new DimensionClient();
251         //bigbird allowed to create
252         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
253         String identifier = createIdentifier();
254         DimensionsCommon dimension = new DimensionsCommon();
255         dimension.setDimension("dimensionType");
256         dimension.setValue("value-" + identifier);
257         dimension.setValueDate(new Date().toString());
258         MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
259                 dimension);
260         ClientResponse<Response> res = client.create(multipart);
261
262         int statusCode = res.getStatus();
263
264         if (logger.isDebugEnabled()) {
265             logger.debug(testName + ": status = " + statusCode);
266         }
267         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269         Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
270         knownResourceId = extractId(res);
271         if (logger.isDebugEnabled()) {
272             logger.debug(testName + ": knownResourceId=" + knownResourceId);
273         }
274     }
275
276     //to not cause uniqueness violation for permRole, createList is removed
277     @Override
278     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
279     dependsOnMethods = {"create"})
280     public void createList(String testName) throws Exception {
281     }
282
283     // Failure outcomes
284     // Placeholders until the three tests below can be uncommented.
285     // See Issue CSPACE-401.
286     @Override
287     public void createWithEmptyEntityBody(String testName) throws Exception {
288     }
289
290     @Override
291     public void createWithMalformedXml(String testName) throws Exception {
292     }
293
294     @Override
295     public void createWithWrongXmlSchema(String testName) throws Exception {
296     }
297
298     // ---------------------------------------------------------------
299     // CRUD tests : READ tests
300     // ---------------------------------------------------------------
301     // Success outcomes
302     @Override
303     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
304     dependsOnMethods = {"create"})
305     public void read(String testName) throws Exception {
306
307         if (logger.isDebugEnabled()) {
308             logger.debug(testBanner(testName, CLASS_NAME));
309         }
310         // Perform setup.
311         setupRead();
312
313         // Submit the request to the service and store the response.
314         DimensionClient client = new DimensionClient();
315         //elmo allowed to read
316         client.setAuth(true, "elmo2010", true, "elmo2010", true);
317         ClientResponse<MultipartInput> res = client.read(knownResourceId);
318         int statusCode = res.getStatus();
319
320         // Check the status code of the response: does it match
321         // the expected response(s)?
322         if (logger.isDebugEnabled()) {
323             logger.debug(testName + ": status = " + statusCode);
324         }
325         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328
329         MultipartInput input = (MultipartInput) res.getEntity();
330         DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
331                 client.getCommonPartName(), DimensionsCommon.class);
332         Assert.assertNotNull(dimension);
333
334     }
335
336     // Failure outcomes
337     @Override
338     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
339     public void readNonExistent(String testName) throws Exception {
340
341         // Perform setup.
342         setupReadNonExistent();
343     }
344
345     // ---------------------------------------------------------------
346     // CRUD tests : READ_LIST tests
347     // ---------------------------------------------------------------
348     // Success outcomes
349     @Override
350     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351     dependsOnMethods = {"createList", "read"})
352     public void readList(String testName) throws Exception {
353         setupReadList();
354     }
355
356     // Failure outcomes
357     // None at present.
358     // ---------------------------------------------------------------
359     // CRUD tests : UPDATE tests
360     // ---------------------------------------------------------------
361     // Success outcomes
362     @Override
363     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
364     dependsOnMethods = {"read", "readList", "readNonExistent"})
365     public void update(String testName) throws Exception {
366         setupUpdate();
367
368     }
369
370     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
371     dependsOnMethods = {"read", "readList", "readNonExistent"})
372     public void updateNotAllowed(String testName) throws Exception {
373
374         if (logger.isDebugEnabled()) {
375             logger.debug(testBanner(testName, CLASS_NAME));
376         }
377         setupUpdate();
378
379         DimensionClient client = new DimensionClient();
380
381         //elmo not allowed to update
382         client.setAuth(true, "elmo2010", true, "elmo2010", true);
383
384         DimensionsCommon dimension = new DimensionsCommon();
385         dimension.setDimension("dimensionType");
386         // Update the content of this resource.
387         dimension.setValue("updated-" + dimension.getValue());
388         dimension.setValueDate("updated-" + dimension.getValueDate());
389         // Submit the request to the service and store the response.
390         MultipartOutput output = new MultipartOutput();
391         OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
392         commonPart.getHeaders().add("label", client.getCommonPartName());
393
394         ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
395         int statusCode = res.getStatus();
396         // Check the status code of the response: does it match the expected response(s)?
397         if (logger.isDebugEnabled()) {
398             logger.debug(testName + ": status = " + statusCode);
399         }
400         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
401                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
402         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
403     }
404
405     // Failure outcomes
406     // Placeholders until the three tests below can be uncommented.
407     // See Issue CSPACE-401.
408     @Override
409     public void updateWithEmptyEntityBody(String testName) throws Exception {
410     }
411
412     @Override
413     public void updateWithMalformedXml(String testName) throws Exception {
414     }
415
416     @Override
417     public void updateWithWrongXmlSchema(String testName) throws Exception {
418     }
419
420     @Override
421     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
422     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
423     public void updateNonExistent(String testName) throws Exception {
424     }
425
426     // ---------------------------------------------------------------
427     // CRUD tests : DELETE tests
428     // ---------------------------------------------------------------
429     // Success outcomes
430     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
431     dependsOnMethods = {"updateNotAllowed"})
432     public void deleteNotAllowed(String testName) throws Exception {
433
434         if (logger.isDebugEnabled()) {
435             logger.debug(testBanner(testName, CLASS_NAME));
436         }
437         // Perform setup.
438         setupDelete();
439
440         // Submit the request to the service and store the response.
441         DimensionClient client = new DimensionClient();
442         //bigbird can not delete
443         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
444         ClientResponse<Response> res = client.delete(knownResourceId);
445         int statusCode = res.getStatus();
446
447         // Check the status code of the response: does it match
448         // the expected response(s)?
449         if (logger.isDebugEnabled()) {
450             logger.debug(testName + ": status = " + statusCode);
451         }
452         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
453                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
454         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
455
456     }
457
458     @Override
459     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
460     dependsOnMethods = {"deleteNotAllowed"})
461     public void delete(String testName) throws Exception {
462
463         if (logger.isDebugEnabled()) {
464             logger.debug(testBanner(testName, CLASS_NAME));
465         }
466         // Perform setup.
467         setupDelete();
468
469         // Submit the request to the service and store the response.
470         DimensionClient client = new DimensionClient();
471
472         ClientResponse<Response> res = client.delete(knownResourceId);
473         int statusCode = res.getStatus();
474
475         // Check the status code of the response: does it match
476         // the expected response(s)?
477         if (logger.isDebugEnabled()) {
478             logger.debug(testName + ": status = " + statusCode);
479         }
480         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
483
484     }
485
486     // Failure outcomes
487     @Override
488     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
489     public void deleteNonExistent(String testName) throws Exception {
490         //ignoring this test as the service side returns 200 now even if it does
491         //not find a record in the db
492     }
493
494     // ---------------------------------------------------------------
495     // Utility tests : tests of code used in tests above
496     // ---------------------------------------------------------------
497     /**
498      * Tests the code for manually submitting data that is used by several
499      * of the methods above.
500      */
501     @Test(dependsOnMethods = {"create"})
502     public void testSubmitRequest() throws Exception {
503     }
504
505     // ---------------------------------------------------------------
506     // Utility methods used by tests above
507     // ---------------------------------------------------------------
508     @AfterClass(alwaysRun = true)
509     public void cleanUp() {
510         setupDelete();
511         String noTest = System.getProperty("noTestCleanup");
512         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
513             if (logger.isDebugEnabled()) {
514                 logger.debug("Skipping Cleanup phase ...");
515             }
516             return;
517         }
518         if (logger.isDebugEnabled()) {
519             logger.debug("Cleaning up temporary resources created for testing ...");
520         }
521
522         deletePermissionRoles();
523         deleteAccountRoles();
524         //FIXME delete on permission deletes all associations with roles
525         //this would delete association with ROLE_ADMINISTRATOR too
526         //deletePermissions();
527         deleteRoles();
528         deleteAccounts();
529     }
530
531     private void deletePermissionRoles() {
532
533         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
534         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
535         deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
536
537         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
538         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
539         deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
540
541     }
542
543     private void deleteAccountRoles() {
544         List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
545         bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
546         deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
547
548         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
549         elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
550         deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues);
551     }
552
553     private void deletePermissions() {
554         //delete entities
555         for (PermissionValue pv : permValues.values()) {
556             deletePermission(pv.getPermissionId());
557         }
558     }
559
560     private void deleteRoles() {
561         for (RoleValue rv : roleValues.values()) {
562             deleteRole(rv.getRoleId());
563         }
564     }
565
566     private void deleteAccounts() {
567
568         for (AccountValue av1 : accValues.values()) {
569             deleteAccount(av1.getAccountId());
570         }
571     }
572
573     private String createPermission(String resName, EffectType effect) {
574         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
575         return createPermission(resName, actions, effect);
576     }
577
578     private String createPermission(String resName,
579             List<PermissionAction> actions, EffectType effect) {
580         setupCreate();
581         PermissionClient permClient = new PermissionClient();
582         Permission permission = PermissionFactory.createPermissionInstance(resName,
583                 "default permissions for " + resName,
584                 actions, effect, true, true, true);
585         ClientResponse<Response> res = permClient.create(permission);
586         int statusCode = res.getStatus();
587         if (logger.isDebugEnabled()) {
588             logger.debug("createPermission: resName=" + resName
589                     + " status = " + statusCode);
590         }
591         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
592                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
593         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594         res.releaseConnection();
595         return extractId(res);
596     }
597
598     private void deletePermission(String permId) {
599         setupDelete();
600         PermissionClient permClient = new PermissionClient();
601         ClientResponse<Response> res = permClient.delete(permId);
602         int statusCode = res.getStatus();
603         if (logger.isDebugEnabled()) {
604             logger.debug("deletePermission: delete permission id="
605                     + permId + " status=" + statusCode);
606         }
607         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610         res.releaseConnection();
611     }
612
613     private String createRole(String roleName) {
614         setupCreate();
615         RoleClient roleClient = new RoleClient();
616
617         Role role = RoleFactory.createRoleInstance(roleName,
618                         roleName, //the display name
619                 "role for " + roleName, true);
620         ClientResponse<Response> res = roleClient.create(role);
621         int statusCode = res.getStatus();
622         if (logger.isDebugEnabled()) {
623             logger.debug("createRole: name=" + roleName
624                     + " status = " + statusCode);
625         }
626         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
627                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
628         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629         res.releaseConnection();
630         return extractId(res);
631     }
632
633     private void deleteRole(String roleId) {
634         setupDelete();
635         RoleClient roleClient = new RoleClient();
636         ClientResponse<Response> res = roleClient.delete(roleId);
637         int statusCode = res.getStatus();
638         if (logger.isDebugEnabled()) {
639             logger.debug("deleteRole: delete role id=" + roleId
640                     + " status=" + statusCode);
641         }
642         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
643                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
644         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
645         res.releaseConnection();
646     }
647
648     private String createAccount(String userName, String email) {
649         setupCreate();
650         AccountClient accountClient = new AccountClient();
651         AccountsCommon account = AccountFactory.createAccountInstance(
652                 userName, userName, userName, email, accountClient.getTenantId(),
653                 true, false, true, true);
654         ClientResponse<Response> res = accountClient.create(account);
655         int statusCode = res.getStatus();
656         if (logger.isDebugEnabled()) {
657             logger.debug("createAccount: userName=" + userName
658                     + " status = " + statusCode);
659         }
660         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
661                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
662         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
663         res.releaseConnection();
664         return extractId(res);
665     }
666
667     private void deleteAccount(String accId) {
668         setupDelete();
669         AccountClient accClient = new AccountClient();
670         ClientResponse<Response> res = accClient.delete(accId);
671         int statusCode = res.getStatus();
672         if (logger.isDebugEnabled()) {
673             logger.debug("deleteAccount: delete account id="
674                     + accId + " status=" + statusCode);
675         }
676         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
677                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
678         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
679         res.releaseConnection();
680     }
681
682     private String createAccountRole(AccountValue av,
683             Collection<RoleValue> rvs) {
684         setupCreate();
685
686         // Submit the request to the service and store the response.
687         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
688                 av, rvs, true, true);
689         AccountRoleClient client = new AccountRoleClient();
690         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
691         int statusCode = res.getStatus();
692
693         if (logger.isDebugEnabled()) {
694             logger.debug("createAccountRole: status = " + statusCode);
695         }
696         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
699         res.releaseConnection();
700         return extractId(res);
701     }
702
703     private void deleteAccountRole(AccountValue av,
704             Collection<RoleValue> rvs) {
705         // Perform setup.
706         setupDelete();
707
708         // Submit the request to the service and store the response.
709         AccountRoleClient client = new AccountRoleClient();
710         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
711                 av, rvs, true, true);
712         ClientResponse<Response> res = client.delete(
713                 av.getAccountId());
714         int statusCode = res.getStatus();
715
716         // Check the status code of the response: does it match
717         // the expected response(s)?
718         if (logger.isDebugEnabled()) {
719             logger.debug("deleteAccountRole: status = " + statusCode);
720         }
721         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
722                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
723         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724         res.releaseConnection();
725     }
726
727     private String createPermissionRole(PermissionValue pv,
728             Collection<RoleValue> rvs) {
729         setupCreate();
730         List<RoleValue> rvls = new ArrayList<RoleValue>();
731         rvls.addAll(rvs);
732         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
733                 pv, rvls, true, true);
734         PermissionRoleClient client = new PermissionRoleClient();
735         ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
736         int statusCode = res.getStatus();
737
738         if (logger.isDebugEnabled()) {
739             logger.debug("createPermissionRole: status = " + statusCode);
740         }
741         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
742                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
743         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
744         res.releaseConnection();
745         return extractId(res);
746     }
747
748     private void deletePermissionRole(PermissionValue pv,
749             Collection<RoleValue> rvs) {
750         List<RoleValue> rvls = new ArrayList<RoleValue>();
751         rvls.addAll(rvs);
752
753         // Perform setup.
754         setupDelete();
755
756         // Submit the request to the service and store the response.
757         PermissionRoleClient client = new PermissionRoleClient();
758         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
759                 pv, rvls, true, true);
760         ClientResponse<Response> res = client.delete(pv.getPermissionId());
761         int statusCode = res.getStatus();
762
763         // Check the status code of the response: does it match
764         // the expected response(s)?
765         if (logger.isDebugEnabled()) {
766             logger.debug("deletePermissionRole : status = " + statusCode);
767         }
768         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
769                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
770         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
771         res.releaseConnection();
772     }
773 }