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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.authorization.client.test;
25 //import java.util.ArrayList;
26 //import java.util.List;
27 import javax.ws.rs.core.Response;
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;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * RoleServiceTest, carries out tests against a
44 * deployed and running Role Service.
46 * $LastChangedRevision: 917 $
47 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
49 public class RoleServiceTest extends AbstractServiceTestImpl<RolesList, Role, Role, Role> {
52 private final static String CLASS_NAME = RoleServiceTest.class.getName();
53 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
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>();
64 public String getServiceName() {
65 return RoleClient.SERVICE_NAME;
69 protected String getServicePathComponent() {
70 return new RoleClient().getServicePathComponent();
74 * The entity type expected from the JAX-RS Response object
76 public Class<Role> getEntityResponseType() {
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
84 protected CollectionSpaceClient getClientInstance() {
85 return new RoleClient();
89 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
92 public void readPaginatedList(String testName) throws Exception {
93 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
96 // ---------------------------------------------------------------
97 // CRUD tests : CREATE tests
98 // ---------------------------------------------------------------
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).
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",
112 Response res = client.create(role);
114 int statusCode = res.getStatus();
115 // Check the status code of the response: does it match
116 // the expected response(s)?
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);
124 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
125 invalidStatusCodeMessage(testRequestType, statusCode));
126 Assert.assertEquals(statusCode, testExpectedStatusCode);
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);
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).
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);
155 int statusCode = res.getStatus();
156 // Check the status code of the response: does it match
157 // the expected response(s)?
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);
165 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
166 invalidStatusCodeMessage(testRequestType, statusCode));
167 Assert.assertEquals(statusCode, testExpectedStatusCode);
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);
183 * Creates the for unique role.
185 * @param testName the test name
186 * @throws Exception the exception
188 @Test(dataProvider = "testName",
189 dependsOnMethods = {"CRUDTests"})
190 public void createForUniqueRole(String testName) throws Exception {
193 // Submit the request to the service and store the response.
194 RoleClient client = new RoleClient();
195 Role role = createRoleInstance(knownRoleName,
197 Response res = client.create(role);
199 int statusCode = res.getStatus();
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);
207 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
208 invalidStatusCodeMessage(testRequestType, statusCode));
209 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
216 * Creates the for unique display name of role.
218 * @param testName the test name
219 * @throws Exception the exception
221 @Test(dataProvider = "testName",
222 dependsOnMethods = {"createWithDisplayname"})
223 public void createForUniqueDisplayRole(String testName) throws Exception {
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",
231 role.setDisplayName(knownRoleDisplayName);
232 Response res = client.create(role);
234 int statusCode = res.getStatus();
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);
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);
252 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
260 * Creates the without role name.
262 * @param testName the test name
263 * @throws Exception the exception
265 @Test(dataProvider = "testName",
266 dependsOnMethods = {"CRUDTests"})
267 public void createWithoutRoleName(String testName) throws Exception {
270 // Submit the request to the service and store the response.
271 RoleClient client = new RoleClient();
272 Role role = createRoleInstance("",
275 Response res = client.create(role);
277 int statusCode = res.getStatus();
278 // Does it exactly match the expected status code?
279 if (logger.isDebugEnabled()) {
280 logger.debug(testName + ": status = " + statusCode);
282 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
283 invalidStatusCodeMessage(testRequestType, statusCode));
284 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
290 //to not cause uniqueness violation for role, createList is removed
292 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
295 // @Test(dataProvider = "testName",
296 // dependsOnMethods = {"createWithDisplayname"})
297 public void createList(String testName) throws Exception {
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);
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);
318 Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
319 "collections curator", true);
320 res = client.create(role2);
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));
332 Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
333 "moving image admin", true);
334 res = client.create(role3);
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));
348 // Placeholders until the three tests below can be uncommented.
349 // See Issue CSPACE-401.
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
354 public void createWithEmptyEntityBody(String testName) throws Exception {
355 //FIXME: Should this test really be empty? If so, please comment accordingly.
359 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
362 public void createWithMalformedXml(String testName) throws Exception {
363 //FIXME: Should this test really be empty? If so, please comment accordingly.
367 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
370 public void createWithWrongXmlSchema(String testName) throws Exception {
371 //FIXME: Should this test really be empty? If so, please comment accordingly.
374 // ---------------------------------------------------------------
375 // CRUD tests : READ tests
376 // ---------------------------------------------------------------
379 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
382 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
383 // dependsOnMethods = {"createForUniqueRole"})
384 public void read(String testName) throws Exception {
388 // Submit the request to the service and store the response.
389 RoleClient client = new RoleClient();
390 Response res = client.read(knownResourceId);
392 int statusCode = res.getStatus();
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);
399 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
400 invalidStatusCodeMessage(testRequestType, statusCode));
401 Assert.assertEquals(statusCode, testExpectedStatusCode);
403 Role output = res.readEntity(Role.class);
404 Assert.assertNotNull(output);
410 @Test(dataProvider = "testName",
411 dependsOnMethods = {"CRUDTests"})
412 public void readToVerify(String testName) throws Exception {
416 // Submit the request to the service and store the response.
417 RoleClient client = new RoleClient();
418 Response res = client.read(verifyResourceId);
420 int statusCode = res.getStatus();
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);
427 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
428 invalidStatusCodeMessage(testRequestType, statusCode));
429 Assert.assertEquals(statusCode, testExpectedStatusCode);
431 Role output = res.readEntity(Role.class);
432 Assert.assertNotNull(output);
434 //FIXME: Tenant ID of "1" should not be hard coded
435 String roleNameToVerify = "ROLE_" +
437 verifyRoleName.toUpperCase();
438 Assert.assertEquals(output.getRoleName(), roleNameToVerify,
439 "RoleName fix did not work!");
446 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
450 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
451 // dependsOnMethods = {"read"})
452 public void readNonExistent(String testName) throws Exception {
454 setupReadNonExistent();
456 // Submit the request to the service and store the response.
457 RoleClient client = new RoleClient();
458 Response res = client.read(NON_EXISTENT_ID);
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);
466 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
467 invalidStatusCodeMessage(testRequestType, statusCode));
468 Assert.assertEquals(statusCode, testExpectedStatusCode);
474 // ---------------------------------------------------------------
475 // CRUD tests : READ_LIST tests
476 // ---------------------------------------------------------------
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
482 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
483 // dependsOnMethods = {"createList", "read"})
484 public void readList(String testName) throws Exception {
488 // Submit the request to the service and store the response.
489 RoleClient client = new RoleClient();
490 Response res = client.readList();
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);
511 * @param testName the test name
512 * @throws Exception the exception
514 @Test(dataProvider = "testName",
515 dependsOnMethods = {"CRUDTests"})
516 public void searchRoleName(String testName) throws Exception {
520 // Submit the request to the service and store the response.
521 RoleClient client = new RoleClient();
522 Response res = client.readSearchList("movingImage");
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);
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);
546 // ---------------------------------------------------------------
547 // CRUD tests : UPDATE tests
548 // ---------------------------------------------------------------
551 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
554 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
555 // dependsOnMethods = {"read", "readList", "readNonExistent"})
556 public void update(String testName) throws Exception {
560 Role roleToUpdate = new Role();
561 roleToUpdate.setCsid(knownResourceId);
562 roleToUpdate.setRoleName(knownRoleName);
563 roleToUpdate.setDisplayName(knownRoleName);
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),
573 RoleClient client = new RoleClient();
574 // Submit the request to the service and store the response.
575 Response res = client.update(knownResourceId, roleToUpdate);
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);
582 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(testRequestType, statusCode));
584 Assert.assertEquals(statusCode, testExpectedStatusCode);
587 Role roleUpdated = res.readEntity(Role.class);
588 Assert.assertNotNull(roleUpdated);
590 Assert.assertEquals(roleUpdated.getDescription(),
591 roleToUpdate.getDescription(),
592 "Data in updated object did not match submitted data.");
598 @Test(dataProvider = "testName",
599 dependsOnMethods = {"CRUDTests"})
600 public void verifyProtectionReadOnly(String testName) throws Exception {
601 // Setup to create a new role
603 Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
604 role.setMetadataProtection(RoleClient.IMMUTABLE);
605 role.setPermsProtection(RoleClient.IMMUTABLE);
607 // Submit the create request to the service and store the response.
609 RoleClient client = new RoleClient();
610 Response res = client.create(role);
611 String testResourceId = null;
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);
628 // Next, read back the role we just created.
630 // Submit the request to the service and store the response.
631 Response roleRes = client.read(testResourceId);
633 int statusCode = roleRes.getStatus();
634 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
635 invalidStatusCodeMessage(testRequestType, statusCode));
636 Assert.assertEquals(statusCode, testExpectedStatusCode);
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);
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.");
653 // Finally, update the role with changes and verify
656 Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
657 roleToUpdate.setMetadataProtection(RoleClient.IMMUTABLE);
658 roleToUpdate.setPermsProtection(RoleClient.IMMUTABLE);
660 // Submit the request to the service and store the response.
661 roleRes = client.update(testResourceId, roleToUpdate);
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);
668 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
669 invalidStatusCodeMessage(testRequestType, statusCode));
670 Assert.assertEquals(statusCode, testExpectedStatusCode);
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),
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.");
691 @Test(dataProvider = "testName",
692 dependsOnMethods = {"CRUDTests"})
693 public void updateNotAllowed(String testName) throws Exception {
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),
709 RoleClient client = new RoleClient();
710 // Submit the request to the service and store the response.
711 Response res = client.update(knownResourceId, roleToUpdate);
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);
718 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
719 invalidStatusCodeMessage(testRequestType, statusCode));
720 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
727 // Placeholders until the three tests below can be uncommented.
728 // See Issue CSPACE-401.
730 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
733 public void updateWithEmptyEntityBody(String testName) throws Exception {
734 //FIXME: Should this test really be empty? If so, please comment accordingly.
738 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
741 public void updateWithMalformedXml(String testName) throws Exception {
742 //FIXME: Should this test really be empty? If so, please comment accordingly.
746 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
749 public void updateWithWrongXmlSchema(String testName) throws Exception {
750 //FIXME: Should this test really be empty? If so, please comment accordingly.
754 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
758 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
759 // dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
760 public void updateNonExistent(String testName) throws Exception {
762 setupUpdateNonExistent();
764 // Submit the request to the service and store the response.
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",
772 Response res = client.update(NON_EXISTENT_ID, role);
774 int statusCode = res.getStatus();
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);
781 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
782 invalidStatusCodeMessage(testRequestType, statusCode));
783 Assert.assertEquals(statusCode, testExpectedStatusCode);
789 // ---------------------------------------------------------------
790 // CRUD tests : DELETE tests
791 // ---------------------------------------------------------------
794 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
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".
803 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
804 dependsOnMethods = {"updateNotAllowed", "createForUniqueRole", "createForUniqueDisplayRole"})
805 public void localDelete(String testName) throws Exception {
806 super.delete(testName);
811 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
814 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
815 // dependsOnMethods = {"delete"})
816 public void deleteNonExistent(String testName) throws Exception {
818 setupDeleteNonExistent();
820 // Submit the request to the service and store the response.
821 RoleClient client = new RoleClient();
822 Response res = client.delete(NON_EXISTENT_ID);
824 int statusCode = res.getStatus();
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);
831 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
832 invalidStatusCodeMessage(testRequestType, statusCode));
833 Assert.assertEquals(statusCode, testExpectedStatusCode);
839 // ---------------------------------------------------------------
841 // ---------------------------------------------------------------
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
849 // ---------------------------------------------------------------
850 // Utility tests : tests of code used in tests above
851 // ---------------------------------------------------------------
853 * Tests the code for manually submitting data that is used by several
854 * of the methods above.
858 // ---------------------------------------------------------------
859 // Utility methods used by tests above
860 // ---------------------------------------------------------------
862 * create role instance
868 public Role createRoleInstance(String roleName,
870 boolean useRoleName) {
872 Role role = RoleFactory.createRoleInstance(roleName,
873 roleName, //the display name
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),
889 * @param testName the test name
890 * @param list the list
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());
902 protected Role createInstance(String commonPartName, String identifier) {
903 // TODO Auto-generated method stub
908 protected Role updateInstance(Role commonPartObject) {
909 // TODO Auto-generated method stub
914 protected void compareUpdatedInstances(Role original, Role updated)
916 // TODO Auto-generated method stub
921 protected Class<RolesList> getCommonListType() {
922 // TODO Auto-generated method stub
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.
931 @Test(dataProvider = "testName",
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
939 protected long getSizeOfList(RolesList list) {
940 return list.getRole().size();