]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
8cfb9964c8f07354a4150b89cf4211f0184b441e
[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 © 2009 Regents of the University of California
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  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.authorization.client.test;
24
25 //import java.util.ArrayList;
26 import java.util.List;
27 import javax.ws.rs.core.Response;
28 //import org.collectionspace.services.authorization.ActionType;
29 import org.collectionspace.services.authorization.EffectType;
30
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.PermissionClient;
33 import org.collectionspace.services.authorization.Permission;
34 import org.collectionspace.services.authorization.PermissionAction;
35 import org.collectionspace.services.authorization.PermissionsList;
36 import org.collectionspace.services.client.PermissionFactory;
37 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
38 import org.collectionspace.services.client.test.ServiceRequestType;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.jboss.resteasy.client.ClientResponse;
41
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 /**
49  * PermissionServiceTest, carries out tests against a
50  * deployed and running Permission Service.
51  * 
52  * $LastChangedRevision: 917 $
53  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
54  */
55 public class PermissionServiceTest extends AbstractServiceTestImpl {
56
57     /** The Constant logger. */
58     static private final Logger logger =
59             LoggerFactory.getLogger(PermissionServiceTest.class);
60     // Instance variables specific to this test.
61     /** The known resource id. */
62     private String knownResourceId = null;
63     private String knownResource = "accounts-test";
64     /** The add tenant. */
65     boolean addTenant = true;
66     /*
67      * This method is called only by the parent class, AbstractServiceTestImpl
68      */
69
70     /* (non-Javadoc)
71      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
72      */
73     @Override
74     protected String getServicePathComponent() {
75         return new PermissionClient().getServicePathComponent();
76     }
77
78     /* (non-Javadoc)
79      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
80      */
81     @Override
82     protected CollectionSpaceClient getClientInstance() {
83         return new PermissionClient();
84     }
85
86     /* (non-Javadoc)
87      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
88      */
89     @Override
90     protected AbstractCommonList getAbstractCommonList(
91             ClientResponse<AbstractCommonList> response) {
92         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
93         throw new UnsupportedOperationException();
94     }
95
96     /* (non-Javadoc)
97      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
98      */
99     @Test(dataProvider = "testName")
100     @Override
101     public void readPaginatedList(String testName) throws Exception {
102         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
103     }
104
105     // ---------------------------------------------------------------
106     // CRUD tests : CREATE tests
107     // ---------------------------------------------------------------
108     // Success outcomes
109     /* (non-Javadoc)
110      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
111      */
112     @Override
113     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
114     public void create(String testName) throws Exception {
115
116         // Perform setup, such as initializing the type of service request
117         // (e.g. CREATE, DELETE), its valid and expected status codes, and
118         // its associated HTTP method name (e.g. POST, DELETE).
119         setupCreate(testName);
120
121         // Submit the request to the service and store the response.
122         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
123         Permission permission = createPermissionInstance(knownResource,
124                 "default permissions for account",
125                 actions,
126                 EffectType.PERMIT,
127                 true,
128                 true,
129                 true);
130         PermissionClient client = new PermissionClient();
131         ClientResponse<Response> res = client.create(permission);
132         int statusCode = res.getStatus();
133
134         // Check the status code of the response: does it match
135         // the expected response(s)?
136         //
137         // Specifically:
138         // Does it fall within the set of valid status codes?
139         // Does it exactly match the expected status code?
140         if (logger.isDebugEnabled()) {
141             logger.debug(testName + ": status = " + statusCode);
142         }
143         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
144                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
145         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
146
147         // Store the ID returned from this create operation
148         // for additional tests below.
149         knownResourceId = extractId(res);
150         if (logger.isDebugEnabled()) {
151             logger.debug(testName + ": knownResourceId=" + knownResourceId);
152         }
153     }
154
155     /**
156      * Creates the without resource name.
157      *
158      * @param testName the test name
159      * @throws Exception the exception
160      */
161     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
162     dependsOnMethods = {"create"})
163     public void createWithoutResourceName(String testName) throws Exception {
164
165         setupCreate(testName);
166
167         // Submit the request to the service and store the response.
168         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
169         Permission permission = createPermissionInstance(null,
170                 "default permissions for account",
171                 actions,
172                 EffectType.PERMIT,
173                 false,
174                 true,
175                 true);
176         PermissionClient client = new PermissionClient();
177         ClientResponse<Response> res = client.create(permission);
178         int statusCode = res.getStatus();
179         // Does it exactly match the expected status code?
180         if (logger.isDebugEnabled()) {
181             logger.debug(testName + ": status = " + statusCode);
182         }
183         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
184                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
185         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
186     }
187
188     //to not cause uniqueness violation for permission, createList is removed
189     /* (non-Javadoc)
190      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
191      */
192     @Override
193     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
194     dependsOnMethods = {"create"})
195     public void createList(String testName) throws Exception {
196
197         setupCreate(testName);
198         // Submit the request to the service and store the response.
199         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
200         Permission permission1 = createPermissionInstance("test-objects",
201                 "default permissions for test-objects",
202                 actions,
203                 EffectType.PERMIT,
204                 true,
205                 true,
206                 true);
207         PermissionClient client = new PermissionClient();
208         ClientResponse<Response> res = client.create(permission1);
209         int statusCode = res.getStatus();
210         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
211                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
212         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
213         allResourceIdsCreated.add(extractId(res));
214
215         Permission permission2 = createPermissionInstance("test-acquisitions",
216                 "default permissions for test-acquisitions",
217                 actions,
218                 EffectType.PERMIT,
219                 true,
220                 true,
221                 true);
222         res = client.create(permission2);
223         statusCode = res.getStatus();
224         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
225                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
226         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
227         allResourceIdsCreated.add(extractId(res));
228
229         Permission permission3 = createPermissionInstance("test-ids",
230                 "default permissions for id service",
231                 actions,
232                 EffectType.PERMIT,
233                 true,
234                 true,
235                 true);
236         res = client.create(permission3);
237         statusCode = res.getStatus();
238         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
239                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
240         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
241         allResourceIdsCreated.add(extractId(res));
242     }
243
244     // Failure outcomes
245     // Placeholders until the three tests below can be uncommented.
246     // See Issue CSPACE-401.
247     /* (non-Javadoc)
248      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
249      */
250     @Override
251     public void createWithEmptyEntityBody(String testName) throws Exception {
252         //FIXME: Should this test really be empty?  If so, please comment accordingly.
253     }
254
255     /* (non-Javadoc)
256      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
257      */
258     @Override
259     public void createWithMalformedXml(String testName) throws Exception {
260         //FIXME: Should this test really be empty?  If so, please comment accordingly.
261     }
262
263     /* (non-Javadoc)
264      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
265      */
266     @Override
267     public void createWithWrongXmlSchema(String testName) throws Exception {
268         //FIXME: Should this test really be empty?  If so, please comment accordingly.
269     }
270
271     // ---------------------------------------------------------------
272     // CRUD tests : READ tests
273     // ---------------------------------------------------------------
274     // Success outcomes
275     /* (non-Javadoc)
276      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
277      */
278     @Override
279     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
280     dependsOnMethods = {"create"})
281     public void read(String testName) throws Exception {
282
283         // Perform setup.
284         setupRead(testName);
285
286         // Submit the request to the service and store the response.
287         PermissionClient client = new PermissionClient();
288         ClientResponse<Permission> res = client.read(knownResourceId);
289         int statusCode = res.getStatus();
290
291         // Check the status code of the response: does it match
292         // the expected response(s)?
293         if (logger.isDebugEnabled()) {
294             logger.debug(testName + ": status = " + statusCode);
295         }
296         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
297                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
298         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
299
300         Permission output = (Permission) res.getEntity();
301         Assert.assertNotNull(output);
302     }
303
304     // Failure outcomes
305     /* (non-Javadoc)
306      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
307      */
308     @Override
309     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
310     dependsOnMethods = {"read"})
311     public void readNonExistent(String testName) throws Exception {
312
313         // Perform setup.
314         setupReadNonExistent(testName);
315
316         // Submit the request to the service and store the response.
317         PermissionClient client = new PermissionClient();
318         ClientResponse<Permission> res = client.read(NON_EXISTENT_ID);
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
331     // ---------------------------------------------------------------
332     // CRUD tests : READ_LIST tests
333     // ---------------------------------------------------------------
334     // Success outcomes
335     /* (non-Javadoc)
336      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
337      */
338     @Override
339     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
340     dependsOnMethods = {"createList", "read"})
341     public void readList(String testName) throws Exception {
342
343         // Perform setup.
344         setupReadList(testName);
345
346         // Submit the request to the service and store the response.
347         PermissionClient client = new PermissionClient();
348         ClientResponse<PermissionsList> res = client.readList();
349         PermissionsList list = res.getEntity();
350         int statusCode = res.getStatus();
351
352         // Check the status code of the response: does it match
353         // the expected response(s)?
354         if (logger.isDebugEnabled()) {
355             logger.debug(testName + ": status = " + statusCode);
356         }
357         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
358                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
359         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
360
361         // Optionally output additional data about list members for debugging.
362         boolean iterateThroughList = true;
363         if (iterateThroughList && logger.isDebugEnabled()) {
364             printList(testName, list);
365         }
366     }
367
368     /**
369      * Search resource name.
370      *
371      * @param testName the test name
372      * @throws Exception the exception
373      */
374     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
375     dependsOnMethods = {"createList", "read"})
376     public void searchResourceName(String testName) throws Exception {
377
378         // Perform setup.
379         setupReadList(testName);
380
381         // Submit the request to the service and store the response.
382         PermissionClient client = new PermissionClient();
383         ClientResponse<PermissionsList> res = client.readSearchList("acquisition");
384         PermissionsList list = res.getEntity();
385         int statusCode = res.getStatus();
386         // Check the status code of the response: does it match
387         // the expected response(s)?
388         if (logger.isDebugEnabled()) {
389             logger.debug(testName + ": status = " + statusCode);
390         }
391         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
392                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
393         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
394         int EXPECTED_ITEMS = 1;
395         if (logger.isDebugEnabled()) {
396             logger.debug(testName + ": received = " + list.getPermissions().size()
397                     + " expected=" + EXPECTED_ITEMS);
398         }
399         Assert.assertEquals(EXPECTED_ITEMS, list.getPermissions().size());
400         // Optionally output additional data about list members for debugging.
401         boolean iterateThroughList = true;
402         if (iterateThroughList && logger.isDebugEnabled()) {
403             printList(testName, list);
404         }
405     }
406
407     // Failure outcomes
408     // None at present.
409     // ---------------------------------------------------------------
410     // CRUD tests : UPDATE tests
411     // ---------------------------------------------------------------
412     // Success outcomes
413     /* (non-Javadoc)
414      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
415      */
416     @Override
417     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
418     dependsOnMethods = {"read", "readList", "readNonExistent"})
419     public void update(String testName) throws Exception {
420
421         // Perform setup.
422         setupUpdate(testName);
423
424         Permission permToUpdate = new Permission();
425         permToUpdate.setCsid(knownResourceId);
426         permToUpdate.setResourceName(knownResource);
427         // Update the content of this resource.
428         permToUpdate.setDescription("updated description");
429         if (logger.isDebugEnabled()) {
430             logger.debug("updated object");
431             logger.debug(objectAsXmlString(permToUpdate,
432                     Permission.class));
433         }
434         PermissionClient client = new PermissionClient();
435         // Submit the request to the service and store the response.
436         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
437         int statusCode = res.getStatus();
438         // Check the status code of the response: does it match the expected response(s)?
439         if (logger.isDebugEnabled()) {
440             logger.debug(testName + ": status = " + statusCode);
441         }
442         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445
446
447         Permission permUpdated = (Permission) res.getEntity();
448         Assert.assertNotNull(permUpdated);
449
450         Assert.assertEquals(permUpdated.getDescription(),
451                 permToUpdate.getDescription(),
452                 "Data in updated object did not match submitted data.");
453     }
454
455     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456     dependsOnMethods = {"read", "readList", "readNonExistent"})
457     public void updateNotAllowed(String testName) throws Exception {
458
459         // Perform setup.
460         setupUpdate(testName);
461
462         Permission permToUpdate = new Permission();
463         permToUpdate.setCsid(knownResourceId);
464         // Update the content of this resource.
465         permToUpdate.setResourceName("updated-resource");
466         if (logger.isDebugEnabled()) {
467             logger.debug("updated object");
468             logger.debug(objectAsXmlString(permToUpdate,
469                     Permission.class));
470         }
471         PermissionClient client = new PermissionClient();
472         // Submit the request to the service and store the response.
473         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
474         int statusCode = res.getStatus();
475         // Check the status code of the response: does it match the expected response(s)?
476         if (logger.isDebugEnabled()) {
477             logger.debug(testName + ": status = " + statusCode);
478         }
479         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
480                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
481         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
482
483     }
484
485     /**
486      * Update actions.
487      *
488      * @param testName the test name
489      * @throws Exception the exception
490      */
491     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
492     dependsOnMethods = {"updateNotAllowed"})
493     public void updateActions(String testName) throws Exception {
494
495         // Perform setup.
496         setupUpdate(testName);
497
498         Permission permToUpdate = new Permission();
499         permToUpdate.setCsid(knownResourceId);
500         permToUpdate.setResourceName(knownResource);
501         // Update the content of this resource.
502         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
503         int default_actions = actions.size();
504         actions.remove(0);
505         actions.remove(0);
506         int toUpdate_actions = actions.size();
507         if (logger.isDebugEnabled()) {
508             logger.debug(testName + " no. of actions default=" + default_actions
509                     + " to update =" + toUpdate_actions);
510         }
511         permToUpdate.setActions(actions);
512         if (logger.isDebugEnabled()) {
513             logger.debug(testName + " updated object\n"
514                     + objectAsXmlString(permToUpdate, Permission.class));
515         }
516         PermissionClient client = new PermissionClient();
517         // Submit the request to the service and store the response.
518         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
519         int statusCode = res.getStatus();
520         // Check the status code of the response: does it match the expected response(s)?
521         if (logger.isDebugEnabled()) {
522             logger.debug(testName + ": status = " + statusCode);
523         }
524         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
527
528         Permission permUpdated = (Permission) res.getEntity();
529         Assert.assertNotNull(permUpdated);
530         int updated_actions = permToUpdate.getActions().size();
531         if (logger.isDebugEnabled()) {
532             logger.debug(testName + " no. of actions to update=" + toUpdate_actions
533                     + " updated =" + updated_actions);
534         }
535         Assert.assertEquals(toUpdate_actions,
536                 updated_actions,
537                 "Data in updated object did not match submitted data.");
538     }
539     // Failure outcomes
540     // Placeholders until the three tests below can be uncommented.
541     // See Issue CSPACE-401.
542
543     /* (non-Javadoc)
544      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
545      */
546     @Override
547     public void updateWithEmptyEntityBody(String testName) throws Exception {
548         //FIXME: Should this test really be empty?  If so, please comment accordingly.
549     }
550
551     /* (non-Javadoc)
552      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
553      */
554     @Override
555     public void updateWithMalformedXml(String testName) throws Exception {
556         //FIXME: Should this test really be empty?  If so, please comment accordingly.
557     }
558
559     /* (non-Javadoc)
560      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
561      */
562     @Override
563     public void updateWithWrongXmlSchema(String testName) throws Exception {
564         //FIXME: Should this test really be empty?  If so, please comment accordingly.
565     }
566
567     /* (non-Javadoc)
568      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
569      */
570     @Override
571     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
572     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
573     public void updateNonExistent(String testName) throws Exception {
574
575         // Perform setup.
576         setupUpdateNonExistent(testName);
577
578         // Submit the request to the service and store the response.
579         //
580         // Note: The ID used in this 'create' call may be arbitrary.
581         // The only relevant ID may be the one used in updatePermission(), below.
582         PermissionClient client = new PermissionClient();
583         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
584         Permission permission = createPermissionInstance("test-acquisitions",
585                 "default permissions for test-acquisitions",
586                 actions,
587                 EffectType.PERMIT,
588                 true,
589                 true,
590                 true);
591         ClientResponse<Permission> res =
592                 client.update(NON_EXISTENT_ID, permission);
593         int statusCode = res.getStatus();
594
595         // Check the status code of the response: does it match
596         // the expected response(s)?
597         if (logger.isDebugEnabled()) {
598             logger.debug(testName + ": status = " + statusCode);
599         }
600         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
601                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
602         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
603     }
604
605     // ---------------------------------------------------------------
606     // CRUD tests : DELETE tests
607     // ---------------------------------------------------------------
608     // Success outcomes
609     /* (non-Javadoc)
610      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
611      */
612     @Override
613     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
614     dependsOnMethods = {"updateActions", "testSubmitRequest"})
615     public void delete(String testName) throws Exception {
616
617         // Perform setup.
618         setupDelete(testName);
619
620         // Submit the request to the service and store the response.
621         PermissionClient client = new PermissionClient();
622         ClientResponse<Response> res = client.delete(knownResourceId);
623         int statusCode = res.getStatus();
624
625         // Check the status code of the response: does it match
626         // the expected response(s)?
627         if (logger.isDebugEnabled()) {
628             logger.debug(testName + ": status = " + statusCode);
629         }
630         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
631                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
632         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
633     }
634
635     // Failure outcomes
636     /* (non-Javadoc)
637      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
638      */
639     @Override
640     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
641     dependsOnMethods = {"delete"})
642     public void deleteNonExistent(String testName) throws Exception {
643
644         // Perform setup.
645         setupDeleteNonExistent(testName);
646
647         // Submit the request to the service and store the response.
648         PermissionClient client = new PermissionClient();
649         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
650         int statusCode = res.getStatus();
651
652         // Check the status code of the response: does it match
653         // the expected response(s)?
654         if (logger.isDebugEnabled()) {
655             logger.debug(testName + ": status = " + statusCode);
656         }
657         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
660     }
661
662     // ---------------------------------------------------------------
663     // Utility tests : tests of code used in tests above
664     // ---------------------------------------------------------------
665     /**
666      * Tests the code for manually submitting data that is used by several
667      * of the methods above.
668      * @throws Exception 
669      */
670     @Test(dependsOnMethods = {"create"})
671     public void testSubmitRequest() throws Exception {
672
673         // Expected status code: 200 OK
674         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
675
676         // Submit the request to the service and store the response.
677         String method = ServiceRequestType.READ.httpMethodName();
678         String url = getResourceURL(knownResourceId);
679         int statusCode = submitRequest(method, url);
680
681         // Check the status code of the response: does it match
682         // the expected response(s)?
683         if (logger.isDebugEnabled()) {
684             logger.debug("testSubmitRequest: url=" + url
685                     + " status=" + statusCode);
686         }
687         Assert.assertEquals(statusCode, EXPECTED_STATUS);
688
689     }
690
691     // ---------------------------------------------------------------
692     // Utility methods used by tests above
693     // ---------------------------------------------------------------
694     /**
695      * create permission instance
696      * @param resourceName
697      * @param description
698      * @param actionList list of actions for this permission
699      * @param effect effect of the permission
700      * @param useResourceName
701      * @param useAction
702      * @param useEffect
703      * @return permission
704      */
705     public static Permission createPermissionInstance(String resourceName,
706             String description,
707             List<PermissionAction> actionList,
708             EffectType effect,
709             boolean useResourceName,
710             boolean useAction,
711             boolean useEffect) {
712
713         Permission permission = PermissionFactory.createPermissionInstance(resourceName,
714                 description, actionList, effect,
715                 useResourceName, useAction, useEffect);
716
717         if (logger.isDebugEnabled()) {
718             logger.debug("to be created, permission");
719             logger.debug(objectAsXmlString(permission, Permission.class));
720         }
721         return permission;
722     }
723
724     /**
725      * Prints the list.
726      *
727      * @param testName the test name
728      * @param list the list
729      * @return the int
730      */
731     private int printList(String testName, PermissionsList list) {
732
733         int i = 0;
734
735         for (Permission permission : list.getPermissions()) {
736             logger.debug(testName + " permission csid=" + permission.getCsid()
737                     + " name=" + permission.getResourceName()
738                     + " desc=" + permission.getDescription());
739             i++;
740         }
741         return i;
742     }
743 }