]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
bdcd65f0b54a36079b25c86b22ba9a4b3db0049e
[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     @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         int statusCode = res.getStatus();
303
304         // Check the status code of the response: does it match
305         // the expected response(s)?
306         if (logger.isDebugEnabled()) {
307             logger.debug(testName + ": status = " + statusCode);
308         }
309         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
310                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
311         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
312
313         Permission output = (Permission) res.getEntity();
314         Assert.assertNotNull(output);
315     }
316
317     // Failure outcomes
318     /* (non-Javadoc)
319      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
320      */
321     @Override
322     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
323     dependsOnMethods = {"read"})
324     public void readNonExistent(String testName) throws Exception {
325
326         if (logger.isDebugEnabled()) {
327             logger.debug(testBanner(testName, CLASS_NAME));
328         }
329         // Perform setup.
330         setupReadNonExistent();
331
332         // Submit the request to the service and store the response.
333         PermissionClient client = new PermissionClient();
334         ClientResponse<Permission> res = client.read(NON_EXISTENT_ID);
335         int statusCode = res.getStatus();
336
337         // Check the status code of the response: does it match
338         // the expected response(s)?
339         if (logger.isDebugEnabled()) {
340             logger.debug(testName + ": status = " + statusCode);
341         }
342         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
343                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
344         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
345     }
346
347     // ---------------------------------------------------------------
348     // CRUD tests : READ_LIST tests
349     // ---------------------------------------------------------------
350     // Success outcomes
351     /* (non-Javadoc)
352      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
353      */
354     @Override
355     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
356     dependsOnMethods = {"createList", "read"})
357     public void readList(String testName) throws Exception {
358
359         if (logger.isDebugEnabled()) {
360             logger.debug(testBanner(testName, CLASS_NAME));
361         }
362         // Perform setup.
363         setupReadList();
364
365         // Submit the request to the service and store the response.
366         PermissionClient client = new PermissionClient();
367         ClientResponse<PermissionsList> res = client.readList();
368         PermissionsList list = res.getEntity();
369         int statusCode = res.getStatus();
370
371         // Check the status code of the response: does it match
372         // the expected response(s)?
373         if (logger.isDebugEnabled()) {
374             logger.debug(testName + ": status = " + statusCode);
375         }
376         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
379
380         // Optionally output additional data about list members for debugging.
381         boolean iterateThroughList = true;
382         if (iterateThroughList && logger.isDebugEnabled()) {
383             printList(testName, list);
384         }
385     }
386
387     /**
388      * Search resource name.
389      *
390      * @param testName the test name
391      * @throws Exception the exception
392      */
393     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
394     dependsOnMethods = {"createList", "read"})
395     public void searchResourceName(String testName) throws Exception {
396
397         if (logger.isDebugEnabled()) {
398             logger.debug(testBanner(testName, CLASS_NAME));
399         }
400         // Perform setup.
401         setupReadList();
402
403         // Submit the request to the service and store the response.
404         PermissionClient client = new PermissionClient();
405         ClientResponse<PermissionsList> res = client.readSearchList("acquisition");
406         PermissionsList list = res.getEntity();
407         int statusCode = res.getStatus();
408         // Check the status code of the response: does it match
409         // the expected response(s)?
410         if (logger.isDebugEnabled()) {
411             logger.debug(testName + ": status = " + statusCode);
412         }
413         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
414                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
415         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416         int EXPECTED_ITEMS = 3; //seeded permissions
417         int actual = list.getPermissions().size();
418         if (logger.isDebugEnabled()) {
419             logger.debug(testName + ": received = " + actual
420                     + " expected=" + EXPECTED_ITEMS);
421         }
422         // Optionally output additional data about list members for debugging.
423         boolean iterateThroughList = true;
424         if (iterateThroughList && logger.isDebugEnabled()) {
425             printList(testName, list);
426         }
427         Assert.assertEquals(EXPECTED_ITEMS, list.getPermissions().size());
428
429     }
430
431     // Failure outcomes
432     // None at present.
433     // ---------------------------------------------------------------
434     // CRUD tests : UPDATE tests
435     // ---------------------------------------------------------------
436     // Success outcomes
437     /* (non-Javadoc)
438      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
439      */
440     @Override
441     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
442     dependsOnMethods = {"read", "readList", "readNonExistent"})
443     public void update(String testName) throws Exception {
444
445         if (logger.isDebugEnabled()) {
446             logger.debug(testBanner(testName, CLASS_NAME));
447         }
448         // Perform setup.
449         setupUpdate();
450
451         Permission permToUpdate = new Permission();
452         permToUpdate.setCsid(knownResourceId);
453         permToUpdate.setResourceName(knownResource);
454         // Update the content of this resource.
455         permToUpdate.setDescription("updated description");
456         if (logger.isDebugEnabled()) {
457             logger.debug("updated object");
458             logger.debug(objectAsXmlString(permToUpdate,
459                     Permission.class));
460         }
461         PermissionClient client = new PermissionClient();
462         // Submit the request to the service and store the response.
463         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
464         int statusCode = res.getStatus();
465         // Check the status code of the response: does it match the expected response(s)?
466         if (logger.isDebugEnabled()) {
467             logger.debug(testName + ": status = " + statusCode);
468         }
469         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
470                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
471         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472
473
474         Permission permUpdated = (Permission) res.getEntity();
475         Assert.assertNotNull(permUpdated);
476
477         Assert.assertEquals(permUpdated.getDescription(),
478                 permToUpdate.getDescription(),
479                 "Data in updated object did not match submitted data.");
480     }
481
482     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
483     dependsOnMethods = {"read", "readList", "readNonExistent"})
484     public void updateNotAllowed(String testName) throws Exception {
485
486         // Perform setup.
487         setupUpdate();
488
489         Permission permToUpdate = new Permission();
490         permToUpdate.setCsid(knownResourceId);
491         // Update the content of this resource.
492         permToUpdate.setResourceName("updated-resource");
493         if (logger.isDebugEnabled()) {
494             logger.debug("updated object");
495             logger.debug(objectAsXmlString(permToUpdate,
496                     Permission.class));
497         }
498         PermissionClient client = new PermissionClient();
499         // Submit the request to the service and store the response.
500         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
501         int statusCode = res.getStatus();
502         // Check the status code of the response: does it match the expected response(s)?
503         if (logger.isDebugEnabled()) {
504             logger.debug(testName + ": status = " + statusCode);
505         }
506         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
507                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
508         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
509
510     }
511
512     /**
513      * Update actions.
514      *
515      * @param testName the test name
516      * @throws Exception the exception
517      */
518     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
519     dependsOnMethods = {"updateNotAllowed"})
520     public void updateActions(String testName) throws Exception {
521
522         if (logger.isDebugEnabled()) {
523             logger.debug(testBanner(testName, CLASS_NAME));
524         }
525         // Perform setup.
526         setupUpdate();
527
528         Permission permToUpdate = new Permission();
529         permToUpdate.setCsid(knownResourceId);
530         permToUpdate.setResourceName(knownResource);
531         // Update the content of this resource.
532         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
533         int default_actions = actions.size();
534         actions.remove(0);
535         actions.remove(0);
536         int toUpdate_actions = actions.size();
537         if (logger.isDebugEnabled()) {
538             logger.debug(testName + " no. of actions default=" + default_actions
539                     + " to update =" + toUpdate_actions);
540         }
541         permToUpdate.setActions(actions);
542         if (logger.isDebugEnabled()) {
543             logger.debug(testName + " updated object\n"
544                     + objectAsXmlString(permToUpdate, Permission.class));
545         }
546         PermissionClient client = new PermissionClient();
547         // Submit the request to the service and store the response.
548         ClientResponse<Permission> res = client.update(knownResourceId, permToUpdate);
549         int statusCode = res.getStatus();
550         // Check the status code of the response: does it match the expected response(s)?
551         if (logger.isDebugEnabled()) {
552             logger.debug(testName + ": status = " + statusCode);
553         }
554         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
557
558         Permission permUpdated = (Permission) res.getEntity();
559         Assert.assertNotNull(permUpdated);
560         int updated_actions = permToUpdate.getActions().size();
561         if (logger.isDebugEnabled()) {
562             logger.debug(testName + " no. of actions to update=" + toUpdate_actions
563                     + " updated =" + updated_actions);
564         }
565         Assert.assertEquals(toUpdate_actions,
566                 updated_actions,
567                 "Data in updated object did not match submitted data.");
568     }
569     // Failure outcomes
570     // Placeholders until the three tests below can be uncommented.
571     // See Issue CSPACE-401.
572
573     /* (non-Javadoc)
574      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
575      */
576     @Override
577     public void updateWithEmptyEntityBody(String testName) throws Exception {
578         //FIXME: Should this test really be empty?  If so, please comment accordingly.
579     }
580
581     /* (non-Javadoc)
582      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
583      */
584     @Override
585     public void updateWithMalformedXml(String testName) throws Exception {
586         //FIXME: Should this test really be empty?  If so, please comment accordingly.
587     }
588
589     /* (non-Javadoc)
590      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
591      */
592     @Override
593     public void updateWithWrongXmlSchema(String testName) throws Exception {
594         //FIXME: Should this test really be empty?  If so, please comment accordingly.
595     }
596
597     /* (non-Javadoc)
598      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
599      */
600     @Override
601     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
602     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
603     public void updateNonExistent(String testName) throws Exception {
604
605         if (logger.isDebugEnabled()) {
606             logger.debug(testBanner(testName, CLASS_NAME));
607         }
608         // Perform setup.
609         setupUpdateNonExistent();
610
611         // Submit the request to the service and store the response.
612         //
613         // Note: The ID used in this 'create' call may be arbitrary.
614         // The only relevant ID may be the one used in updatePermission(), below.
615         PermissionClient client = new PermissionClient();
616         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
617         Permission permission = createPermissionInstance("test-acquisitions",
618                 "default permissions for test-acquisitions",
619                 actions,
620                 EffectType.PERMIT,
621                 true,
622                 true,
623                 true);
624         ClientResponse<Permission> res =
625                 client.update(NON_EXISTENT_ID, permission);
626         int statusCode = res.getStatus();
627
628         // Check the status code of the response: does it match
629         // the expected response(s)?
630         if (logger.isDebugEnabled()) {
631             logger.debug(testName + ": status = " + statusCode);
632         }
633         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
634                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
635         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
636     }
637
638     // ---------------------------------------------------------------
639     // CRUD tests : DELETE tests
640     // ---------------------------------------------------------------
641     // Success outcomes
642     /* (non-Javadoc)
643      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
644      */
645     @Override
646     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
647     dependsOnMethods = {"update", "updateActions", "testSubmitRequest"})
648     public void delete(String testName) throws Exception {
649
650         if (logger.isDebugEnabled()) {
651             logger.debug(testBanner(testName, CLASS_NAME));
652         }
653         // Perform setup.
654         setupDelete();
655
656         // Submit the request to the service and store the response.
657         PermissionClient client = new PermissionClient();
658         ClientResponse<Response> res = client.delete(knownResourceId);
659         int statusCode = res.getStatus();
660
661         // Check the status code of the response: does it match
662         // the expected response(s)?
663         if (logger.isDebugEnabled()) {
664             logger.debug(testName + ": status = " + statusCode);
665         }
666         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
667                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
668         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669     }
670
671     // Failure outcomes
672     /* (non-Javadoc)
673      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
674      */
675     @Override
676     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
677     dependsOnMethods = {"delete"})
678     public void deleteNonExistent(String testName) throws Exception {
679
680         if (logger.isDebugEnabled()) {
681             logger.debug(testBanner(testName, CLASS_NAME));
682         }
683         // Perform setup.
684         setupDeleteNonExistent();
685
686         // Submit the request to the service and store the response.
687         PermissionClient client = new PermissionClient();
688         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
689         int statusCode = res.getStatus();
690
691         // Check the status code of the response: does it match
692         // the expected response(s)?
693         if (logger.isDebugEnabled()) {
694             logger.debug(testName + ": status = " + statusCode);
695         }
696         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
699     }
700
701     // ---------------------------------------------------------------
702     // Utility tests : tests of code used in tests above
703     // ---------------------------------------------------------------
704     /**
705      * Tests the code for manually submitting data that is used by several
706      * of the methods above.
707      * @throws Exception 
708      */
709     @Test(dependsOnMethods = {"create"})
710     public void testSubmitRequest() throws Exception {
711
712         // Expected status code: 200 OK
713         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
714
715         // Submit the request to the service and store the response.
716         String method = ServiceRequestType.READ.httpMethodName();
717         String url = getResourceURL(knownResourceId);
718         int statusCode = submitRequest(method, url);
719
720         // Check the status code of the response: does it match
721         // the expected response(s)?
722         if (logger.isDebugEnabled()) {
723             logger.debug("testSubmitRequest: url=" + url
724                     + " status=" + statusCode);
725         }
726         Assert.assertEquals(statusCode, EXPECTED_STATUS);
727
728     }
729
730     // ---------------------------------------------------------------
731     // Utility methods used by tests above
732     // ---------------------------------------------------------------
733     /**
734      * create permission instance
735      * @param resourceName
736      * @param description
737      * @param actionList list of actions for this permission
738      * @param effect effect of the permission
739      * @param useResourceName
740      * @param useAction
741      * @param useEffect
742      * @return permission
743      */
744     public static Permission createPermissionInstance(String resourceName,
745             String description,
746             List<PermissionAction> actionList,
747             EffectType effect,
748             boolean useResourceName,
749             boolean useAction,
750             boolean useEffect) {
751
752         Permission permission = PermissionFactory.createPermissionInstance(resourceName,
753                 description, actionList, effect,
754                 useResourceName, useAction, useEffect);
755
756         if (logger.isDebugEnabled()) {
757             logger.debug("to be created, permission");
758             logger.debug(objectAsXmlString(permission, Permission.class));
759         }
760         return permission;
761     }
762
763     /**
764      * Prints the list.
765      *
766      * @param testName the test name
767      * @param list the list
768      * @return the int
769      */
770     private int printList(String testName, PermissionsList list) {
771
772         int i = 0;
773
774         for (Permission permission : list.getPermissions()) {
775             logger.debug(testName + " permission csid=" + permission.getCsid()
776                     + " name=" + permission.getResourceName()
777                     + " desc=" + permission.getDescription());
778             i++;
779         }
780         return i;
781     }
782 }