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