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