]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
2c620442e0f3c2407fd8f08f7f0acf90ee26fc78
[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_" + "1_" + 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 }