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