]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
cf7179ef5ea71f90a95ad4313da9dd5960512cf8
[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     static private final Logger logger =
92             LoggerFactory.getLogger(AuthorizationServiceTest.class);
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     /*
105      * This method is called only by the parent class, AbstractServiceTestImpl
106      */
107
108     @Override
109     protected String getServicePathComponent() {
110         return null;
111     }
112
113     @BeforeClass(alwaysRun = true)
114     public void seedData() {
115         seedPermissions();
116         seedRoles();
117         seedAccounts();
118         seedAccountRoles();
119         seedPermissionRoles();
120     }
121
122     private void seedPermissions() {
123         String res = "dimensions";
124
125         PermissionAction pac = new PermissionAction();
126         pac.setName(ActionType.CREATE);
127         PermissionAction par = new PermissionAction();
128         par.setName(ActionType.READ);
129         PermissionAction pau = new PermissionAction();
130         pau.setName(ActionType.UPDATE);
131         PermissionAction pad = new PermissionAction();
132         pad.setName(ActionType.DELETE);
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_MMI_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_MMI_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_MMI_CM"));
193         createAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
194
195         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
196         elmoRoleValues.add(roleValues.get("ROLE_MMI_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_MMI_CM"));
204         createPermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
205
206         List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
207         elmoRoleValues.add(roleValues.get("ROLE_MMI_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         setupCreate(testName);
245
246         // Submit the request to the service and store the response.
247         DimensionClient client = new DimensionClient();
248         //bigbird allowed to create
249         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
250         String identifier = createIdentifier();
251         DimensionsCommon dimension = new DimensionsCommon();
252         dimension.setDimension("dimensionType");
253         dimension.setValue("value-" + identifier);
254         dimension.setValueDate(new Date().toString());
255         MultipartOutput multipart = DimensionFactory.createDimensionInstance(client.getCommonPartName(),
256                 dimension);
257         ClientResponse<Response> res = client.create(multipart);
258
259         int statusCode = res.getStatus();
260
261         if (logger.isDebugEnabled()) {
262             logger.debug(testName + ": status = " + statusCode);
263         }
264         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
265                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
266         Assert.assertEquals(statusCode, Response.Status.CREATED.getStatusCode());
267         knownResourceId = extractId(res);
268         if (logger.isDebugEnabled()) {
269             logger.debug(testName + ": knownResourceId=" + knownResourceId);
270         }
271     }
272
273     //to not cause uniqueness violation for permRole, createList is removed
274     @Override
275     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
276     dependsOnMethods = {"create"})
277     public void createList(String testName) throws Exception {
278     }
279
280     // Failure outcomes
281     // Placeholders until the three tests below can be uncommented.
282     // See Issue CSPACE-401.
283     @Override
284     public void createWithEmptyEntityBody(String testName) throws Exception {
285     }
286
287     @Override
288     public void createWithMalformedXml(String testName) throws Exception {
289     }
290
291     @Override
292     public void createWithWrongXmlSchema(String testName) throws Exception {
293     }
294
295     // ---------------------------------------------------------------
296     // CRUD tests : READ tests
297     // ---------------------------------------------------------------
298     // Success outcomes
299     @Override
300     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
301     dependsOnMethods = {"create"})
302     public void read(String testName) throws Exception {
303
304         // Perform setup.
305         setupRead(testName);
306
307         // Submit the request to the service and store the response.
308         DimensionClient client = new DimensionClient();
309         //elmo allowed to read
310         client.setAuth(true, "elmo2010", true, "elmo2010", true);
311         ClientResponse<MultipartInput> res = client.read(knownResourceId);
312         int statusCode = res.getStatus();
313
314         // Check the status code of the response: does it match
315         // the expected response(s)?
316         if (logger.isDebugEnabled()) {
317             logger.debug(testName + ": status = " + statusCode);
318         }
319         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
320                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
321         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
322
323         MultipartInput input = (MultipartInput) res.getEntity();
324         DimensionsCommon dimension = (DimensionsCommon) extractPart(input,
325                 client.getCommonPartName(), DimensionsCommon.class);
326         Assert.assertNotNull(dimension);
327
328     }
329
330     // Failure outcomes
331     @Override
332     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
333     public void readNonExistent(String testName) throws Exception {
334
335         // Perform setup.
336         setupReadNonExistent(testName);
337     }
338
339     // ---------------------------------------------------------------
340     // CRUD tests : READ_LIST tests
341     // ---------------------------------------------------------------
342     // Success outcomes
343     @Override
344     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
345     dependsOnMethods = {"createList", "read"})
346     public void readList(String testName) throws Exception {
347         setupReadList(testName);
348     }
349
350     // Failure outcomes
351     // None at present.
352     // ---------------------------------------------------------------
353     // CRUD tests : UPDATE tests
354     // ---------------------------------------------------------------
355     // Success outcomes
356     @Override
357     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
358     dependsOnMethods = {"read", "readList", "readNonExistent"})
359     public void update(String testName) throws Exception {
360         setupUpdate(testName);
361
362     }
363
364     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
365     dependsOnMethods = {"read", "readList", "readNonExistent"})
366     public void updateNotAllowed(String testName) throws Exception {
367         setupUpdate(testName);
368
369         DimensionClient client = new DimensionClient();
370
371         //elmo not allowed to update
372         client.setAuth(true, "elmo2010", true, "elmo2010", true);
373
374         DimensionsCommon dimension = new DimensionsCommon();
375         dimension.setDimension("dimensionType");
376         // Update the content of this resource.
377         dimension.setValue("updated-" + dimension.getValue());
378         dimension.setValueDate("updated-" + dimension.getValueDate());
379         // Submit the request to the service and store the response.
380         MultipartOutput output = new MultipartOutput();
381         OutputPart commonPart = output.addPart(dimension, MediaType.APPLICATION_XML_TYPE);
382         commonPart.getHeaders().add("label", client.getCommonPartName());
383
384         ClientResponse<MultipartInput> res = client.update(knownResourceId, output);
385         int statusCode = res.getStatus();
386         // Check the status code of the response: does it match the expected response(s)?
387         if (logger.isDebugEnabled()) {
388             logger.debug(testName + ": status = " + statusCode);
389         }
390         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
391                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
392         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
393     }
394
395     // Failure outcomes
396     // Placeholders until the three tests below can be uncommented.
397     // See Issue CSPACE-401.
398     @Override
399     public void updateWithEmptyEntityBody(String testName) throws Exception {
400     }
401
402     @Override
403     public void updateWithMalformedXml(String testName) throws Exception {
404     }
405
406     @Override
407     public void updateWithWrongXmlSchema(String testName) throws Exception {
408     }
409
410     @Override
411     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
412     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
413     public void updateNonExistent(String testName) throws Exception {
414     }
415
416     // ---------------------------------------------------------------
417     // CRUD tests : DELETE tests
418     // ---------------------------------------------------------------
419     // Success outcomes
420     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
421     dependsOnMethods = {"updateNotAllowed"})
422     public void deleteNotAllowed(String testName) throws Exception {
423         // Perform setup.
424         setupDelete(testName);
425
426         // Submit the request to the service and store the response.
427         DimensionClient client = new DimensionClient();
428         //bigbird can not delete
429         client.setAuth(true, "bigbird2010", true, "bigbird2010", true);
430         ClientResponse<Response> res = client.delete(knownResourceId);
431         int statusCode = res.getStatus();
432
433         // Check the status code of the response: does it match
434         // the expected response(s)?
435         if (logger.isDebugEnabled()) {
436             logger.debug(testName + ": status = " + statusCode);
437         }
438         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
439                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
440         Assert.assertEquals(statusCode, Response.Status.FORBIDDEN.getStatusCode());
441
442     }
443
444     @Override
445     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
446     dependsOnMethods = {"deleteNotAllowed"})
447     public void delete(String testName) throws Exception {
448         // Perform setup.
449         setupDelete(testName);
450
451         // Submit the request to the service and store the response.
452         DimensionClient client = new DimensionClient();
453         //default user test/test has delete permission
454         client.setAuth(true, "test", true, "test", true);
455         ClientResponse<Response> res = client.delete(knownResourceId);
456         int statusCode = res.getStatus();
457
458         // Check the status code of the response: does it match
459         // the expected response(s)?
460         if (logger.isDebugEnabled()) {
461             logger.debug(testName + ": status = " + statusCode);
462         }
463         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
464                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
465         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466
467     }
468
469     // Failure outcomes
470     @Override
471     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
472     public void deleteNonExistent(String testName) throws Exception {
473         //ignoring this test as the service side returns 200 now even if it does
474         //not find a record in the db
475     }
476
477     // ---------------------------------------------------------------
478     // Utility tests : tests of code used in tests above
479     // ---------------------------------------------------------------
480     /**
481      * Tests the code for manually submitting data that is used by several
482      * of the methods above.
483      */
484     @Test(dependsOnMethods = {"create"})
485     public void testSubmitRequest() throws Exception {
486     }
487
488     // ---------------------------------------------------------------
489     // Utility methods used by tests above
490     // ---------------------------------------------------------------
491     @AfterClass(alwaysRun = true)
492     public void cleanUp() {
493         setupDelete("cleanup");
494         String noTest = System.getProperty("noTestCleanup");
495         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
496             if (logger.isDebugEnabled()) {
497                 logger.debug("Skipping Cleanup phase ...");
498             }
499             return;
500         }
501         if (logger.isDebugEnabled()) {
502             logger.debug("Cleaning up temporary resources created for testing ...");
503         }
504
505         deletePermissionRoles();
506         deleteAccountRoles();
507         deletePermissions();
508         deleteRoles();
509         deleteAccounts();
510     }
511
512     private String createPermission(String resName, EffectType effect) {
513         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
514         return createPermission(resName, actions, effect);
515     }
516
517     private String createPermission(String resName,
518             List<PermissionAction> actions, EffectType effect) {
519         setupCreate("createPermission");
520         PermissionClient permClient = new PermissionClient();
521         Permission permission = PermissionFactory.createPermissionInstance(resName,
522                 "default permissions for " + resName,
523                 actions, effect, true, true, true);
524         ClientResponse<Response> res = permClient.create(permission);
525         int statusCode = res.getStatus();
526         if (logger.isDebugEnabled()) {
527             logger.debug("createPermission: resName=" + resName
528                     + " status = " + statusCode);
529         }
530         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
531                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
532         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
533         res.releaseConnection();
534         return extractId(res);
535     }
536
537     private void deletePermission(String permId) {
538         setupDelete("deletePermission");
539         PermissionClient permClient = new PermissionClient();
540         ClientResponse<Response> res = permClient.delete(permId);
541         int statusCode = res.getStatus();
542         if (logger.isDebugEnabled()) {
543             logger.debug("deletePermission: delete permission id="
544                     + permId + " status=" + statusCode);
545         }
546         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549         res.releaseConnection();
550     }
551
552     private String createRole(String roleName) {
553         setupCreate("createRole");
554         RoleClient roleClient = new RoleClient();
555
556         Role role = RoleFactory.createRoleInstance(roleName,
557                 "role for " + roleName, true);
558         ClientResponse<Response> res = roleClient.create(role);
559         int statusCode = res.getStatus();
560         if (logger.isDebugEnabled()) {
561             logger.debug("createRole: name=" + roleName
562                     + " status = " + statusCode);
563         }
564         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
567         res.releaseConnection();
568         return extractId(res);
569     }
570
571     private void deleteRole(String roleId) {
572         setupDelete("deleteRole");
573         RoleClient roleClient = new RoleClient();
574         ClientResponse<Response> res = roleClient.delete(roleId);
575         int statusCode = res.getStatus();
576         if (logger.isDebugEnabled()) {
577             logger.debug("deleteRole: delete role id=" + roleId
578                     + " status=" + statusCode);
579         }
580         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
581                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
582         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
583         res.releaseConnection();
584     }
585
586     private String createAccount(String userName, String email) {
587         setupCreate("createAccount");
588         AccountClient accClient = new AccountClient();
589         AccountsCommon account = AccountFactory.createAccountInstance(
590                 userName, userName, userName, email,
591                 true, true, false, true, true);
592         ClientResponse<Response> res = accClient.create(account);
593         int statusCode = res.getStatus();
594         if (logger.isDebugEnabled()) {
595             logger.debug("createAccount: userName=" + userName
596                     + " status = " + statusCode);
597         }
598         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
599                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
600         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601         res.releaseConnection();
602         return extractId(res);
603     }
604
605     private void deleteAccount(String accId) {
606         setupDelete("deleteAccount");
607         AccountClient accClient = new AccountClient();
608         ClientResponse<Response> res = accClient.delete(accId);
609         int statusCode = res.getStatus();
610         if (logger.isDebugEnabled()) {
611             logger.debug("deleteAccount: delete account id="
612                     + accId + " status=" + statusCode);
613         }
614         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
615                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
616         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
617         res.releaseConnection();
618     }
619
620     private String createAccountRole(AccountValue av,
621             Collection<RoleValue> rvs) {
622         setupCreate("createAccountRole");
623
624         // Submit the request to the service and store the response.
625         AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
626                 av, rvs, true, true);
627         AccountRoleClient client = new AccountRoleClient();
628         ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
629         int statusCode = res.getStatus();
630
631         if (logger.isDebugEnabled()) {
632             logger.debug("createAccountRole: status = " + statusCode);
633         }
634         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
635                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
636         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637         res.releaseConnection();
638         return extractId(res);
639     }
640
641     private void deleteAccountRole(String screenName) {
642         // Perform setup.
643         setupDelete("deleteAccountRole");
644
645         // Submit the request to the service and store the response.
646         AccountRoleClient client = new AccountRoleClient();
647         ClientResponse<Response> res = client.delete(
648                 accValues.get(screenName).getAccountId(), "123");
649         int statusCode = res.getStatus();
650
651         // Check the status code of the response: does it match
652         // the expected response(s)?
653         if (logger.isDebugEnabled()) {
654             logger.debug("deleteAccountRole: status = " + statusCode);
655         }
656         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
657                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
658         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
659         res.releaseConnection();
660     }
661
662     private String createPermissionRole(PermissionValue pv,
663             Collection<RoleValue> rvs) {
664         setupCreate("createPermissionRole");
665         PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(
666                 pv, rvs, true, true);
667         PermissionRoleClient client = new PermissionRoleClient();
668         ClientResponse<Response> res = client.create(pv.getPermissionId(), permRole);
669         int statusCode = res.getStatus();
670
671         if (logger.isDebugEnabled()) {
672             logger.debug("createPermissionRole: status = " + statusCode);
673         }
674         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677         res.releaseConnection();
678         return extractId(res);
679     }
680
681     private void deletePermissionRole(String permId) {
682
683         // Perform setup.
684         setupDelete("deletePermissionRole");
685
686         // Submit the request to the service and store the response.
687         PermissionRoleClient client = new PermissionRoleClient();
688         ClientResponse<Response> res = client.delete(permId, "123");
689         int statusCode = res.getStatus();
690
691         // Check the status code of the response: does it match
692         // the expected response(s)?
693         if (logger.isDebugEnabled()) {
694             logger.debug("deletePermissionRole : 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     }
701
702     private void deletePermissionRoles() {
703
704         //first delete relationships between the entities
705         for (PermissionValue pv : permValues.values()) {
706             deletePermissionRole(pv.getPermissionId());
707         }
708     }
709
710     private void deleteAccountRoles() {
711         for (AccountValue av : accValues.values()) {
712             deleteAccountRole(av.getUserId());
713         }
714     }
715
716     private void deletePermissions() {
717         //delete entities
718         for (PermissionValue pv : permValues.values()) {
719             deletePermission(pv.getPermissionId());
720         }
721     }
722
723     private void deleteRoles() {
724         for (RoleValue rv : roleValues.values()) {
725             deleteRole(rv.getRoleId());
726         }
727     }
728
729     private void deleteAccounts() {
730
731         for (AccountValue av1 : accValues.values()) {
732             deleteAccount(av1.getAccountId());
733         }
734     }
735 }