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