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