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