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