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