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