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