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