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