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