]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9818eda81fa25e590fca0addb241b50921a83eb8
[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
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.client.RoleClient;
31 import org.collectionspace.services.authorization.Role;
32 import org.collectionspace.services.authorization.RolesList;
33 import org.collectionspace.services.client.RoleFactory;
34 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
35 import org.collectionspace.services.client.test.ServiceRequestType;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.jboss.resteasy.client.ClientResponse;
38
39 import org.testng.Assert;
40 import org.testng.annotations.Test;
41
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * RoleServiceTest, carries out tests against a
47  * deployed and running Role Service.
48  * 
49  * $LastChangedRevision: 917 $
50  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
51  */
52 public class RoleServiceTest extends AbstractServiceTestImpl {
53
54     /** The logger. */
55     private final static String CLASS_NAME = RoleServiceTest.class.getName();
56     private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
57     
58     // Instance variables specific to this test.
59     /** The known resource id. */
60     private String knownResourceId = null;
61     private String knownRoleName = "ROLE_USERS_TEST";
62     private String verifyResourceId = null;
63     private String verifyRoleName = "collections_manager_test";
64 //    private List<String> allResourceIdsCreated = new ArrayList<String>();
65     /** The add tenant. */
66     boolean addTenant = true;
67     /*
68      * This method is called only by the parent class, AbstractServiceTestImpl
69      */
70
71     /* (non-Javadoc)
72      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
73      */
74     @Override
75     protected String getServicePathComponent() {
76         return new RoleClient().getServicePathComponent();
77     }
78
79     /* (non-Javadoc)
80      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
81      */
82     @Override
83     protected CollectionSpaceClient getClientInstance() {
84         return new RoleClient();
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         RoleClient client = new RoleClient();
127         Role role = createRoleInstance(knownRoleName,
128                 "all users are required to be in this role",
129                 true);
130         ClientResponse<Response> res = client.create(role);
131         int statusCode = res.getStatus();
132
133         // Check the status code of the response: does it match
134         // the expected response(s)?
135         //
136         // Specifically:
137         // Does it fall within the set of valid status codes?
138         // Does it exactly match the expected status code?
139         if (logger.isDebugEnabled()) {
140             logger.debug(testName + ": status = " + statusCode);
141         }
142         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
143                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
144         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
145
146         // Store the ID returned from this create operation
147         // for additional tests below.
148         knownResourceId = extractId(res);
149         if (logger.isDebugEnabled()) {
150             logger.debug(testName + ": knownResourceId=" + knownResourceId);
151         }
152     }
153
154     /**
155      * Creates the for unique role.
156      *
157      * @param testName the test name
158      * @throws Exception the exception
159      */
160     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
161     dependsOnMethods = {"create"})
162     public void createForUniqueRole(String testName) throws Exception {
163
164         if (logger.isDebugEnabled()) {
165             logger.debug(testBanner(testName, CLASS_NAME));
166         }
167         setupCreate();
168
169         // Submit the request to the service and store the response.
170         RoleClient client = new RoleClient();
171         Role role = createRoleInstance("ROLE_USERS",
172                 "role users",
173                 true);
174         ClientResponse<Response> res = client.create(role);
175         int statusCode = res.getStatus();
176
177         if (logger.isDebugEnabled()) {
178             logger.debug(testName + ": status = " + statusCode);
179         }
180         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
181                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
182         Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
183     }
184
185     /**
186      * Creates the without role name.
187      *
188      * @param testName the test name
189      * @throws Exception the exception
190      */
191     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
192     dependsOnMethods = {"create"})
193     public void createWithoutRoleName(String testName) throws Exception {
194
195         if (logger.isDebugEnabled()) {
196             logger.debug(testBanner(testName, CLASS_NAME));
197         }
198         setupCreate();
199
200         // Submit the request to the service and store the response.
201         RoleClient client = new RoleClient();
202         Role role = createRoleInstance("ROLE_USERS",
203                 "role for users",
204                 false);
205         ClientResponse<Response> res = client.create(role);
206         int statusCode = res.getStatus();
207         // Does it exactly match the expected status code?
208         if (logger.isDebugEnabled()) {
209             logger.debug(testName + ": status = " + statusCode);
210         }
211         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
212                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
213         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
214     }
215
216     //to not cause uniqueness violation for role, createList is removed
217     /* (non-Javadoc)
218      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
219      */
220     @Override
221     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
222     dependsOnMethods = {"create"})
223     public void createList(String testName) throws Exception {
224
225         if (logger.isDebugEnabled()) {
226             logger.debug(testBanner(testName, CLASS_NAME));
227         }
228         setupCreate();
229
230         // Submit the request to the service and store the response.
231         RoleClient client = new RoleClient();
232         //create a role with lowercase role name without role prefix
233         //the service should make it upper case and add the role prefix
234         Role role1 = createRoleInstance(verifyRoleName,
235                 "collection manager",
236                 true);
237         ClientResponse<Response> res = client.create(role1);
238         int statusCode = res.getStatus();
239         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
240                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
241         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
242         verifyResourceId = extractId(res);
243         allResourceIdsCreated.add(verifyResourceId);
244
245         Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
246                 "collections curator",
247                 true);
248         res = client.create(role2);
249         statusCode = res.getStatus();
250         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
251                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
252         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
253         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
254         allResourceIdsCreated.add(extractId(res));
255
256         Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
257                 "moving image admin",
258                 true);
259         res = client.create(role3);
260         statusCode = res.getStatus();
261         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
262                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
263         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
264         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265         allResourceIdsCreated.add(extractId(res));
266     }
267
268     // Failure outcomes
269     // Placeholders until the three tests below can be uncommented.
270     // See Issue CSPACE-401.
271     /* (non-Javadoc)
272      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
273      */
274     @Override
275     public void createWithEmptyEntityBody(String testName) throws Exception {
276         //FIXME: Should this test really be empty?  If so, please comment accordingly.
277     }
278
279     /* (non-Javadoc)
280      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
281      */
282     @Override
283     public void createWithMalformedXml(String testName) throws Exception {
284         //FIXME: Should this test really be empty?  If so, please comment accordingly.
285     }
286
287     /* (non-Javadoc)
288      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
289      */
290     @Override
291     public void createWithWrongXmlSchema(String testName) throws Exception {
292         //FIXME: Should this test really be empty?  If so, please comment accordingly.
293     }
294
295     // ---------------------------------------------------------------
296     // CRUD tests : READ tests
297     // ---------------------------------------------------------------
298     // Success outcomes
299     /* (non-Javadoc)
300      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
301      */
302     @Override
303     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
304     dependsOnMethods = {"create"})
305     public void read(String testName) throws Exception {
306
307         if (logger.isDebugEnabled()) {
308             logger.debug(testBanner(testName, CLASS_NAME));
309         }
310         // Perform setup.
311         setupRead();
312
313         // Submit the request to the service and store the response.
314         RoleClient client = new RoleClient();
315         ClientResponse<Role> res = client.read(knownResourceId);
316         int statusCode = res.getStatus();
317
318         // Check the status code of the response: does it match
319         // the expected response(s)?
320         if (logger.isDebugEnabled()) {
321             logger.debug(testName + ": status = " + statusCode);
322         }
323         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
324                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
325         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
326
327         Role output = (Role) res.getEntity();
328         Assert.assertNotNull(output);
329     }
330
331     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
332     dependsOnMethods = {"createList"})
333     public void readToVerify(String testName) throws Exception {
334
335         // Perform setup.
336         setupRead();
337
338         // Submit the request to the service and store the response.
339         RoleClient client = new RoleClient();
340         ClientResponse<Role> res = client.read(verifyResourceId);
341         int statusCode = res.getStatus();
342
343         // Check the status code of the response: does it match
344         // the expected response(s)?
345         if (logger.isDebugEnabled()) {
346             logger.debug(testName + ": status = " + statusCode);
347         }
348         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
349                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
350         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
351
352         Role output = (Role) res.getEntity();
353         Assert.assertNotNull(output);
354
355         String roleNameToVerify = "ROLE_" + verifyRoleName.toUpperCase();
356         Assert.assertEquals(output.getRoleName(), roleNameToVerify,
357                 "RoleName fix did not work!");
358     }
359     // Failure outcomes
360     /* (non-Javadoc)
361      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
362      */
363
364     @Override
365     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
366     dependsOnMethods = {"read"})
367     public void readNonExistent(String testName) throws Exception {
368
369         if (logger.isDebugEnabled()) {
370             logger.debug(testBanner(testName, CLASS_NAME));
371         }
372         // Perform setup.
373         setupReadNonExistent();
374
375         // Submit the request to the service and store the response.
376         RoleClient client = new RoleClient();
377         ClientResponse<Role> res = client.read(NON_EXISTENT_ID);
378         int statusCode = res.getStatus();
379
380         // Check the status code of the response: does it match
381         // the expected response(s)?
382         if (logger.isDebugEnabled()) {
383             logger.debug(testName + ": status = " + statusCode);
384         }
385         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
386                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
387         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
388     }
389
390     // ---------------------------------------------------------------
391     // CRUD tests : READ_LIST tests
392     // ---------------------------------------------------------------
393     // Success outcomes
394     /* (non-Javadoc)
395      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
396      */
397     @Override
398     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
399     dependsOnMethods = {"createList", "read"})
400     public void readList(String testName) throws Exception {
401
402         if (logger.isDebugEnabled()) {
403             logger.debug(testBanner(testName, CLASS_NAME));
404         }
405         // Perform setup.
406         setupReadList();
407
408         // Submit the request to the service and store the response.
409         RoleClient client = new RoleClient();
410         ClientResponse<RolesList> res = client.readList();
411         RolesList list = res.getEntity();
412         int statusCode = res.getStatus();
413
414         // Check the status code of the response: does it match
415         // the expected response(s)?
416         if (logger.isDebugEnabled()) {
417             logger.debug(testName + ": status = " + statusCode);
418         }
419         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
420                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
421         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
422
423         // Optionally output additional data about list members for debugging.
424         boolean iterateThroughList = true;
425         if (iterateThroughList && logger.isDebugEnabled()) {
426             printList(testName, list);
427         }
428     }
429
430     /**
431      * Search role name.
432      *
433      * @param testName the test name
434      * @throws Exception the exception
435      */
436     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
437     dependsOnMethods = {"createList", "read"})
438     public void searchRoleName(String testName) throws Exception {
439
440         if (logger.isDebugEnabled()) {
441             logger.debug(testBanner(testName, CLASS_NAME));
442         }
443         // Perform setup.
444         setupReadList();
445
446         // Submit the request to the service and store the response.
447         RoleClient client = new RoleClient();
448         ClientResponse<RolesList> res = client.readSearchList("movingImage");
449         RolesList list = res.getEntity();
450         int statusCode = res.getStatus();
451         // Check the status code of the response: does it match
452         // the expected response(s)?
453         if (logger.isDebugEnabled()) {
454             logger.debug(testName + ": status = " + statusCode);
455         }
456         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
457                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
458         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
459         int EXPECTED_ITEMS = 1;
460         if (logger.isDebugEnabled()) {
461             logger.debug(testName + ": received = " + list.getRoles().size()
462                     + " expected=" + EXPECTED_ITEMS);
463         }
464         Assert.assertEquals(EXPECTED_ITEMS, list.getRoles().size());
465         // Optionally output additional data about list members for debugging.
466         boolean iterateThroughList = true;
467         if (iterateThroughList && logger.isDebugEnabled()) {
468             printList(testName, list);
469         }
470     }
471
472     // Failure outcomes
473     // None at present.
474     // ---------------------------------------------------------------
475     // CRUD tests : UPDATE tests
476     // ---------------------------------------------------------------
477     // Success outcomes
478     /* (non-Javadoc)
479      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
480      */
481     @Override
482     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
483     dependsOnMethods = {"read", "readList", "readNonExistent"})
484     public void update(String testName) throws Exception {
485
486         if (logger.isDebugEnabled()) {
487             logger.debug(testBanner(testName, CLASS_NAME));
488         }
489         // Perform setup.
490         setupUpdate();
491
492         Role roleToUpdate = new Role();
493         roleToUpdate.setCsid(knownResourceId);
494         roleToUpdate.setRoleName(knownRoleName);
495         
496         // Update the content of this resource.
497         roleToUpdate.setDescription("updated role description");
498         if (logger.isDebugEnabled()) {
499             logger.debug("updated object");
500             logger.debug(objectAsXmlString(roleToUpdate,
501                     Role.class));
502         }
503         RoleClient client = new RoleClient();
504         // Submit the request to the service and store the response.
505         ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
506         int statusCode = res.getStatus();
507         // Check the status code of the response: does it match the expected response(s)?
508         if (logger.isDebugEnabled()) {
509             logger.debug(testName + ": status = " + statusCode);
510         }
511         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
512                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
513         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
514
515
516         Role roleUpdated = (Role) res.getEntity();
517         Assert.assertNotNull(roleUpdated);
518
519         Assert.assertEquals(roleUpdated.getDescription(),
520                 roleToUpdate.getDescription(),
521                 "Data in updated object did not match submitted data.");
522     }
523
524     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
525     dependsOnMethods = {"read", "readList", "readNonExistent"})
526     public void updateNotAllowed(String testName) throws Exception {
527
528         // Perform setup.
529         setupUpdate();
530
531         Role roleToUpdate = new Role();
532         roleToUpdate.setCsid(knownResourceId);
533         // Update the content of this resource.
534         roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
535         if (logger.isDebugEnabled()) {
536             logger.debug("updated object");
537             logger.debug(objectAsXmlString(roleToUpdate,
538                     Role.class));
539         }
540         RoleClient client = new RoleClient();
541         // Submit the request to the service and store the response.
542         ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
543         int statusCode = res.getStatus();
544         // Check the status code of the response: does it match the expected response(s)?
545         if (logger.isDebugEnabled()) {
546             logger.debug(testName + ": status = " + statusCode);
547         }
548         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
549                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
550         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
551
552     }
553
554     // Failure outcomes
555     // Placeholders until the three tests below can be uncommented.
556     // See Issue CSPACE-401.
557     /* (non-Javadoc)
558      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
559      */
560     @Override
561     public void updateWithEmptyEntityBody(String testName) throws Exception {
562         //FIXME: Should this test really be empty?  If so, please comment accordingly.
563     }
564
565     /* (non-Javadoc)
566      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
567      */
568     @Override
569     public void updateWithMalformedXml(String testName) throws Exception {
570         //FIXME: Should this test really be empty?  If so, please comment accordingly.
571     }
572
573     /* (non-Javadoc)
574      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
575      */
576     @Override
577     public void updateWithWrongXmlSchema(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#updateNonExistent(java.lang.String)
583      */
584     @Override
585     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
586     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
587     public void updateNonExistent(String testName) throws Exception {
588
589         if (logger.isDebugEnabled()) {
590             logger.debug(testBanner(testName, CLASS_NAME));
591         }
592         // Perform setup.
593         setupUpdateNonExistent();
594
595         // Submit the request to the service and store the response.
596         //
597         // Note: The ID used in this 'create' call may be arbitrary.
598         // The only relevant ID may be the one used in updateRole(), below.
599         RoleClient client = new RoleClient();
600         Role role = createRoleInstance("ROLE_XXX",
601                 "xxx",
602                 true);
603         ClientResponse<Role> res =
604                 client.update(NON_EXISTENT_ID, role);
605         int statusCode = res.getStatus();
606
607         // Check the status code of the response: does it match
608         // the expected response(s)?
609         if (logger.isDebugEnabled()) {
610             logger.debug(testName + ": status = " + statusCode);
611         }
612         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
613                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
614         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
615     }
616
617     // ---------------------------------------------------------------
618     // CRUD tests : DELETE tests
619     // ---------------------------------------------------------------
620     // Success outcomes
621     /* (non-Javadoc)
622      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
623      */
624     @Override
625     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
626     dependsOnMethods = {"updateNotAllowed", "testSubmitRequest"})
627     public void delete(String testName) throws Exception {
628
629         if (logger.isDebugEnabled()) {
630             logger.debug(testBanner(testName, CLASS_NAME));
631         }
632         // Perform setup.
633         setupDelete();
634
635         // Submit the request to the service and store the response.
636         RoleClient client = new RoleClient();
637         ClientResponse<Response> res = client.delete(knownResourceId);
638         int statusCode = res.getStatus();
639
640         // Check the status code of the response: does it match
641         // the expected response(s)?
642         if (logger.isDebugEnabled()) {
643             logger.debug(testName + ": status = " + statusCode);
644         }
645         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
648     }
649
650     // Failure outcomes
651     /* (non-Javadoc)
652      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
653      */
654     @Override
655     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
656     dependsOnMethods = {"delete"})
657     public void deleteNonExistent(String testName) throws Exception {
658
659         if (logger.isDebugEnabled()) {
660             logger.debug(testBanner(testName, CLASS_NAME));
661         }
662         // Perform setup.
663         setupDeleteNonExistent();
664
665         // Submit the request to the service and store the response.
666         RoleClient client = new RoleClient();
667         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
668         int statusCode = res.getStatus();
669
670         // Check the status code of the response: does it match
671         // the expected response(s)?
672         if (logger.isDebugEnabled()) {
673             logger.debug(testName + ": status = " + statusCode);
674         }
675         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
676                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
677         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678     }
679
680     // ---------------------------------------------------------------
681     // Utility tests : tests of code used in tests above
682     // ---------------------------------------------------------------
683     /**
684      * Tests the code for manually submitting data that is used by several
685      * of the methods above.
686      * @throws Exception 
687      */
688
689     @Test(dependsOnMethods = {"create"})
690     public void testSubmitRequest() throws Exception {
691
692         // Expected status code: 200 OK
693         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
694
695         // Submit the request to the service and store the response.
696         String method = ServiceRequestType.READ.httpMethodName();
697         String url = getResourceURL(knownResourceId);
698         int statusCode = submitRequest(method, url);
699
700         // Check the status code of the response: does it match
701         // the expected response(s)?
702         if (logger.isDebugEnabled()) {
703             logger.debug("testSubmitRequest: url=" + url
704                     + " status=" + statusCode);
705         }
706         Assert.assertEquals(statusCode, EXPECTED_STATUS);
707
708     }
709
710     // ---------------------------------------------------------------
711     // Utility methods used by tests above
712     // ---------------------------------------------------------------
713     /**
714      * create role instance
715      * @param roleName
716      * @param description
717      * @param useRoleName
718      * @return role
719      */
720     public Role createRoleInstance(String roleName,
721             String description,
722             boolean useRoleName) {
723
724         Role role = RoleFactory.createRoleInstance(roleName, description,
725                 useRoleName);
726         if (logger.isDebugEnabled()) {
727             logger.debug("to be created, role");
728             logger.debug(objectAsXmlString(role, Role.class));
729         }
730         return role;
731
732     }
733
734     /**
735      * Prints the list.
736      *
737      * @param testName the test name
738      * @param list the list
739      * @return the int
740      */
741     private int printList(String testName, RolesList list) {
742
743         int i = 0;
744
745         for (Role role : list.getRoles()) {
746             logger.debug(testName + " role csid=" + role.getCsid()
747                     + " name=" + role.getRoleName()
748                     + " desc=" + role.getDescription());
749             i++;
750         }
751         return i;
752     }
753 }