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