]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
41dfe180097832bf3389cd86b0a84aa6c0d4d79a
[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         String roleNameToVerify = "ROLE_" + verifyRoleName.toUpperCase();
355         Assert.assertEquals(output.getRoleName(), roleNameToVerify,
356                 "RoleName fix did not work!");
357     }
358     // Failure outcomes
359     /* (non-Javadoc)
360      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
361      */
362
363     @Override
364     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
365     dependsOnMethods = {"read"})
366     public void readNonExistent(String testName) throws Exception {
367
368         if (logger.isDebugEnabled()) {
369             logger.debug(testBanner(testName, CLASS_NAME));
370         }
371         // Perform setup.
372         setupReadNonExistent();
373
374         // Submit the request to the service and store the response.
375         RoleClient client = new RoleClient();
376         ClientResponse<Role> res = client.read(NON_EXISTENT_ID);
377         int statusCode = res.getStatus();
378
379         // Check the status code of the response: does it match
380         // the expected response(s)?
381         if (logger.isDebugEnabled()) {
382             logger.debug(testName + ": status = " + statusCode);
383         }
384         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
385                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
386         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387     }
388
389     // ---------------------------------------------------------------
390     // CRUD tests : READ_LIST tests
391     // ---------------------------------------------------------------
392     // Success outcomes
393     /* (non-Javadoc)
394      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
395      */
396     @Override
397     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
398     dependsOnMethods = {"createList", "read"})
399     public void readList(String testName) throws Exception {
400
401         if (logger.isDebugEnabled()) {
402             logger.debug(testBanner(testName, CLASS_NAME));
403         }
404         // Perform setup.
405         setupReadList();
406
407         // Submit the request to the service and store the response.
408         RoleClient client = new RoleClient();
409         ClientResponse<RolesList> res = client.readList();
410         RolesList list = res.getEntity();
411         int statusCode = res.getStatus();
412
413         // Check the status code of the response: does it match
414         // the expected response(s)?
415         if (logger.isDebugEnabled()) {
416             logger.debug(testName + ": status = " + statusCode);
417         }
418         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
419                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
420         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
421
422         // Optionally output additional data about list members for debugging.
423         boolean iterateThroughList = true;
424         if (iterateThroughList && logger.isDebugEnabled()) {
425             printList(testName, list);
426         }
427     }
428
429     /**
430      * Search role name.
431      *
432      * @param testName the test name
433      * @throws Exception the exception
434      */
435     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
436     dependsOnMethods = {"createList", "read"})
437     public void searchRoleName(String testName) throws Exception {
438
439         if (logger.isDebugEnabled()) {
440             logger.debug(testBanner(testName, CLASS_NAME));
441         }
442         // Perform setup.
443         setupReadList();
444
445         // Submit the request to the service and store the response.
446         RoleClient client = new RoleClient();
447         ClientResponse<RolesList> res = client.readSearchList("movingImage");
448         RolesList list = res.getEntity();
449         int statusCode = res.getStatus();
450         // Check the status code of the response: does it match
451         // the expected response(s)?
452         if (logger.isDebugEnabled()) {
453             logger.debug(testName + ": status = " + statusCode);
454         }
455         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
456                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
457         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
458         int EXPECTED_ITEMS = 1;
459         if (logger.isDebugEnabled()) {
460             logger.debug(testName + ": received = " + list.getRoles().size()
461                     + " expected=" + EXPECTED_ITEMS);
462         }
463         Assert.assertEquals(EXPECTED_ITEMS, list.getRoles().size());
464         // Optionally output additional data about list members for debugging.
465         boolean iterateThroughList = true;
466         if (iterateThroughList && logger.isDebugEnabled()) {
467             printList(testName, list);
468         }
469     }
470
471     // Failure outcomes
472     // None at present.
473     // ---------------------------------------------------------------
474     // CRUD tests : UPDATE tests
475     // ---------------------------------------------------------------
476     // Success outcomes
477     /* (non-Javadoc)
478      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
479      */
480     @Override
481     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
482     dependsOnMethods = {"read", "readList", "readNonExistent"})
483     public void update(String testName) throws Exception {
484
485         if (logger.isDebugEnabled()) {
486             logger.debug(testBanner(testName, CLASS_NAME));
487         }
488         // Perform setup.
489         setupUpdate();
490
491         Role roleToUpdate = new Role();
492         roleToUpdate.setCsid(knownResourceId);
493         roleToUpdate.setRoleName(knownRoleName);
494         
495         // Update the content of this resource.
496         roleToUpdate.setDescription("updated role description");
497         if (logger.isDebugEnabled()) {
498             logger.debug("updated object");
499             logger.debug(objectAsXmlString(roleToUpdate,
500                     Role.class));
501         }
502         RoleClient client = new RoleClient();
503         // Submit the request to the service and store the response.
504         ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
505         int statusCode = res.getStatus();
506         // Check the status code of the response: does it match the expected response(s)?
507         if (logger.isDebugEnabled()) {
508             logger.debug(testName + ": status = " + statusCode);
509         }
510         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
511                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
512         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
513
514
515         Role roleUpdated = (Role) res.getEntity();
516         Assert.assertNotNull(roleUpdated);
517
518         Assert.assertEquals(roleUpdated.getDescription(),
519                 roleToUpdate.getDescription(),
520                 "Data in updated object did not match submitted data.");
521     }
522
523     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
524     dependsOnMethods = {"read", "readList", "readNonExistent"})
525     public void updateNotAllowed(String testName) throws Exception {
526
527         // Perform setup.
528         setupUpdate();
529
530         Role roleToUpdate = new Role();
531         roleToUpdate.setCsid(knownResourceId);
532         // Update the content of this resource.
533         roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
534         if (logger.isDebugEnabled()) {
535             logger.debug("updated object");
536             logger.debug(objectAsXmlString(roleToUpdate,
537                     Role.class));
538         }
539         RoleClient client = new RoleClient();
540         // Submit the request to the service and store the response.
541         ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
542         int statusCode = res.getStatus();
543         // Check the status code of the response: does it match the expected response(s)?
544         if (logger.isDebugEnabled()) {
545             logger.debug(testName + ": status = " + statusCode);
546         }
547         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
548                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
549         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
550
551     }
552
553     // Failure outcomes
554     // Placeholders until the three tests below can be uncommented.
555     // See Issue CSPACE-401.
556     /* (non-Javadoc)
557      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
558      */
559     @Override
560     public void updateWithEmptyEntityBody(String testName) throws Exception {
561         //FIXME: Should this test really be empty?  If so, please comment accordingly.
562     }
563
564     /* (non-Javadoc)
565      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
566      */
567     @Override
568     public void updateWithMalformedXml(String testName) throws Exception {
569         //FIXME: Should this test really be empty?  If so, please comment accordingly.
570     }
571
572     /* (non-Javadoc)
573      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
574      */
575     @Override
576     public void updateWithWrongXmlSchema(String testName) throws Exception {
577         //FIXME: Should this test really be empty?  If so, please comment accordingly.
578     }
579
580     /* (non-Javadoc)
581      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
582      */
583     @Override
584     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
585     dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
586     public void updateNonExistent(String testName) throws Exception {
587
588         if (logger.isDebugEnabled()) {
589             logger.debug(testBanner(testName, CLASS_NAME));
590         }
591         // Perform setup.
592         setupUpdateNonExistent();
593
594         // Submit the request to the service and store the response.
595         //
596         // Note: The ID used in this 'create' call may be arbitrary.
597         // The only relevant ID may be the one used in updateRole(), below.
598         RoleClient client = new RoleClient();
599         Role role = createRoleInstance("ROLE_XXX",
600                 "xxx",
601                 true);
602         ClientResponse<Role> res =
603                 client.update(NON_EXISTENT_ID, role);
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     // ---------------------------------------------------------------
617     // CRUD tests : DELETE tests
618     // ---------------------------------------------------------------
619     // Success outcomes
620     /* (non-Javadoc)
621      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
622      */
623     @Override
624     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
625     dependsOnMethods = {"updateNotAllowed", "testSubmitRequest"})
626     public void delete(String testName) throws Exception {
627
628         if (logger.isDebugEnabled()) {
629             logger.debug(testBanner(testName, CLASS_NAME));
630         }
631         // Perform setup.
632         setupDelete();
633
634         // Submit the request to the service and store the response.
635         RoleClient client = new RoleClient();
636         ClientResponse<Response> res = client.delete(knownResourceId);
637         int statusCode = res.getStatus();
638
639         // Check the status code of the response: does it match
640         // the expected response(s)?
641         if (logger.isDebugEnabled()) {
642             logger.debug(testName + ": status = " + statusCode);
643         }
644         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
647     }
648
649     // Failure outcomes
650     /* (non-Javadoc)
651      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
652      */
653     @Override
654     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
655     dependsOnMethods = {"delete"})
656     public void deleteNonExistent(String testName) throws Exception {
657
658         if (logger.isDebugEnabled()) {
659             logger.debug(testBanner(testName, CLASS_NAME));
660         }
661         // Perform setup.
662         setupDeleteNonExistent();
663
664         // Submit the request to the service and store the response.
665         RoleClient client = new RoleClient();
666         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
667         int statusCode = res.getStatus();
668
669         // Check the status code of the response: does it match
670         // the expected response(s)?
671         if (logger.isDebugEnabled()) {
672             logger.debug(testName + ": status = " + statusCode);
673         }
674         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677     }
678
679     // ---------------------------------------------------------------
680     // Utility tests : tests of code used in tests above
681     // ---------------------------------------------------------------
682     /**
683      * Tests the code for manually submitting data that is used by several
684      * of the methods above.
685      * @throws Exception 
686      */
687
688     @Test(dependsOnMethods = {"create"})
689     public void testSubmitRequest() throws Exception {
690
691         // Expected status code: 200 OK
692         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
693
694         // Submit the request to the service and store the response.
695         String method = ServiceRequestType.READ.httpMethodName();
696         String url = getResourceURL(knownResourceId);
697         int statusCode = submitRequest(method, url);
698
699         // Check the status code of the response: does it match
700         // the expected response(s)?
701         if (logger.isDebugEnabled()) {
702             logger.debug("testSubmitRequest: url=" + url
703                     + " status=" + statusCode);
704         }
705         Assert.assertEquals(statusCode, EXPECTED_STATUS);
706
707     }
708
709     // ---------------------------------------------------------------
710     // Utility methods used by tests above
711     // ---------------------------------------------------------------
712     /**
713      * create role instance
714      * @param roleName
715      * @param description
716      * @param useRoleName
717      * @return role
718      */
719     public Role createRoleInstance(String roleName,
720             String description,
721             boolean useRoleName) {
722
723         Role role = RoleFactory.createRoleInstance(roleName, description,
724                 useRoleName);
725         if (logger.isDebugEnabled()) {
726             logger.debug("to be created, role");
727             logger.debug(objectAsXmlString(role, Role.class));
728         }
729         return role;
730
731     }
732
733     /**
734      * Prints the list.
735      *
736      * @param testName the test name
737      * @param list the list
738      * @return the int
739      */
740     private int printList(String testName, RolesList list) {
741
742         int i = 0;
743
744         for (Role role : list.getRoles()) {
745             logger.debug(testName + " role csid=" + role.getCsid()
746                     + " name=" + role.getRoleName()
747                     + " desc=" + role.getDescription());
748             i++;
749         }
750         return i;
751     }
752 }