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;
35 import org.jboss.resteasy.client.ClientResponse;
37 import org.testng.Assert;
38 import org.testng.annotations.Test;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * RoleServiceTest, carries out tests against a
45 * deployed and running Role Service.
47 * $LastChangedRevision: 917 $
48 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
50 public class RoleServiceTest extends AbstractServiceTestImpl<RolesList, Role, Role, Role> {
53 private final static String CLASS_NAME = RoleServiceTest.class.getName();
54 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
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>();
65 public String getServiceName() {
66 return RoleClient.SERVICE_NAME;
70 protected String getServicePathComponent() {
71 return new RoleClient().getServicePathComponent();
75 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
78 protected CollectionSpaceClient getClientInstance() {
79 return new RoleClient();
83 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
86 public void readPaginatedList(String testName) throws Exception {
87 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
90 // ---------------------------------------------------------------
91 // CRUD tests : CREATE tests
92 // ---------------------------------------------------------------
96 public void create(String testName) throws Exception {
97 // Perform setup, such as initializing the type of service request
98 // (e.g. CREATE, DELETE), its valid and expected status codes, and
99 // its associated HTTP method name (e.g. POST, DELETE).
102 // Submit the request to the service and store the response.
103 RoleClient client = new RoleClient();
104 Role role = createRoleInstance(knownRoleName, "All users are required to be in this role",
106 ClientResponse<Response> res = client.create(role);
108 int statusCode = res.getStatus();
109 // Check the status code of the response: does it match
110 // the expected response(s)?
113 // Does it fall within the set of valid status codes?
114 // Does it exactly match the expected status code?
115 if (logger.isDebugEnabled()) {
116 logger.debug(testName + ": status = " + statusCode);
118 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
119 invalidStatusCodeMessage(testRequestType, statusCode));
120 Assert.assertEquals(statusCode, testExpectedStatusCode);
122 // Store the ID returned from this create operation
123 // for additional tests below.
124 knownResourceId = extractId(res);
125 //allResourceIdsCreated.add(knownResourceId);
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": knownResourceId=" + knownResourceId);
134 @Test(dataProvider = "testName",
135 dependsOnMethods = {"CRUDTests"})
136 public void createWithDisplayname(String testName) throws Exception {
137 // Perform setup, such as initializing the type of service request
138 // (e.g. CREATE, DELETE), its valid and expected status codes, and
139 // its associated HTTP method name (e.g. POST, DELETE).
142 // Submit the request to the service and store the response.
143 RoleClient client = new RoleClient();
144 Role role = createRoleInstance(knownRoleName + "_" + knownRoleDisplayName,
145 "all users are required to be in this role",
147 role.setDisplayName(knownRoleDisplayName);
148 ClientResponse<Response> res = client.create(role);
149 int statusCode = res.getStatus();
151 // Check the status code of the response: does it match
152 // the expected response(s)?
155 // Does it fall within the set of valid status codes?
156 // Does it exactly match the expected status code?
157 if (logger.isDebugEnabled()) {
158 logger.debug(testName + ": status = " + statusCode);
160 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
161 invalidStatusCodeMessage(testRequestType, statusCode));
162 Assert.assertEquals(statusCode, testExpectedStatusCode);
164 // Store the ID returned from this create operation
165 // for additional tests below.
166 String csid = extractId(res);
167 allResourceIdsCreated.add(csid);
168 if (logger.isDebugEnabled()) {
169 logger.debug(testName + ": csid=" + csid);
175 * Creates the for unique role.
177 * @param testName the test name
178 * @throws Exception the exception
180 @Test(dataProvider = "testName",
181 dependsOnMethods = {"CRUDTests"})
182 public void createForUniqueRole(String testName) throws Exception {
185 // Submit the request to the service and store the response.
186 RoleClient client = new RoleClient();
187 Role role = createRoleInstance(knownRoleName,
190 ClientResponse<Response> res = client.create(role);
191 int statusCode = res.getStatus();
193 if (logger.isDebugEnabled()) {
194 logger.debug(testName + ": Role with name \"" +
195 knownRoleName + "\" should already exist, so this request should fail.");
196 logger.debug(testName + ": status = " + statusCode);
197 logger.debug(testName + ": " + res);
199 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
200 invalidStatusCodeMessage(testRequestType, statusCode));
201 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
205 * Creates the for unique display name of role.
207 * @param testName the test name
208 * @throws Exception the exception
210 @Test(dataProvider = "testName",
211 dependsOnMethods = {"createWithDisplayname"})
212 public void createForUniqueDisplayRole(String testName) throws Exception {
215 // Submit the request to the service and store the response.
216 RoleClient client = new RoleClient();
217 Role role = createRoleInstance(knownRoleName + System.currentTimeMillis(),
218 "role users with non-unique display name",
220 role.setDisplayName(knownRoleDisplayName);
221 ClientResponse<Response> res = client.create(role);
222 int statusCode = res.getStatus();
224 if (logger.isDebugEnabled()) {
225 logger.debug(testName + ": Role with name \"" +
226 knownRoleName + "\" should already exist, so this request should fail.");
227 logger.debug(testName + ": status = " + statusCode);
228 logger.debug(testName + ": " + res);
230 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
231 invalidStatusCodeMessage(testRequestType, statusCode));
232 if (statusCode != Response.Status.BAD_REQUEST.getStatusCode()) {
233 // If the test fails then we've just created a Role that we need to delete, so
234 // store the ID returned from this create operation.
235 String csid = extractId(res);
236 allResourceIdsCreated.add(csid);
237 if (logger.isDebugEnabled()) {
238 logger.debug(testName + ": csid=" + csid);
240 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
245 * Creates the without role name.
247 * @param testName the test name
248 * @throws Exception the exception
250 @Test(dataProvider = "testName",
251 dependsOnMethods = {"CRUDTests"})
252 public void createWithoutRoleName(String testName) throws Exception {
255 // Submit the request to the service and store the response.
256 RoleClient client = new RoleClient();
257 Role role = createRoleInstance("",
260 ClientResponse<Response> res = client.create(role);
261 int statusCode = res.getStatus();
262 // Does it exactly match the expected status code?
263 if (logger.isDebugEnabled()) {
264 logger.debug(testName + ": status = " + statusCode);
266 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
267 invalidStatusCodeMessage(testRequestType, statusCode));
268 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
271 //to not cause uniqueness violation for role, createList is removed
273 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
276 // @Test(dataProvider = "testName",
277 // dependsOnMethods = {"createWithDisplayname"})
278 public void createList(String testName) throws Exception {
281 // Submit the request to the service and store the response.
282 RoleClient client = new RoleClient();
283 //create a role with lowercase role name without role prefix
284 //the service should make it upper case and add the role prefix
285 Role role1 = createRoleInstance(verifyRoleName,
286 "collection manager",
288 ClientResponse<Response> res = client.create(role1);
289 int statusCode = res.getStatus();
290 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(testRequestType, statusCode));
292 Assert.assertEquals(statusCode, testExpectedStatusCode);
293 verifyResourceId = extractId(res);
294 allResourceIdsCreated.add(verifyResourceId);
296 Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
297 "collections curator",
299 res = client.create(role2);
300 statusCode = res.getStatus();
301 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(testRequestType, statusCode));
303 Assert.assertEquals(statusCode, testExpectedStatusCode);
304 Assert.assertEquals(statusCode, testExpectedStatusCode);
305 allResourceIdsCreated.add(extractId(res));
307 Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
308 "moving image admin",
310 res = client.create(role3);
311 statusCode = res.getStatus();
312 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
313 invalidStatusCodeMessage(testRequestType, statusCode));
314 Assert.assertEquals(statusCode, testExpectedStatusCode);
315 Assert.assertEquals(statusCode, testExpectedStatusCode);
316 allResourceIdsCreated.add(extractId(res));
320 // Placeholders until the three tests below can be uncommented.
321 // See Issue CSPACE-401.
323 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
326 public void createWithEmptyEntityBody(String testName) throws Exception {
327 //FIXME: Should this test really be empty? If so, please comment accordingly.
331 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
334 public void createWithMalformedXml(String testName) throws Exception {
335 //FIXME: Should this test really be empty? If so, please comment accordingly.
339 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
342 public void createWithWrongXmlSchema(String testName) throws Exception {
343 //FIXME: Should this test really be empty? If so, please comment accordingly.
346 // ---------------------------------------------------------------
347 // CRUD tests : READ tests
348 // ---------------------------------------------------------------
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
354 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
355 // dependsOnMethods = {"createForUniqueRole"})
356 public void read(String testName) throws Exception {
360 // Submit the request to the service and store the response.
361 RoleClient client = new RoleClient();
362 ClientResponse<Role> res = client.read(knownResourceId);
363 int statusCode = res.getStatus();
365 // Check the status code of the response: does it match
366 // the expected response(s)?
367 if (logger.isDebugEnabled()) {
368 logger.debug(testName + ": status = " + statusCode);
370 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
371 invalidStatusCodeMessage(testRequestType, statusCode));
372 Assert.assertEquals(statusCode, testExpectedStatusCode);
374 Role output = (Role) res.getEntity();
375 Assert.assertNotNull(output);
378 @Test(dataProvider = "testName",
379 dependsOnMethods = {"CRUDTests"})
380 public void readToVerify(String testName) throws Exception {
384 // Submit the request to the service and store the response.
385 RoleClient client = new RoleClient();
386 ClientResponse<Role> res = client.read(verifyResourceId);
388 int statusCode = res.getStatus();
390 // Check the status code of the response: does it match
391 // the expected response(s)?
392 if (logger.isDebugEnabled()) {
393 logger.debug(testName + ": status = " + statusCode);
395 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
396 invalidStatusCodeMessage(testRequestType, statusCode));
397 Assert.assertEquals(statusCode, testExpectedStatusCode);
399 Role output = (Role) res.getEntity();
400 Assert.assertNotNull(output);
402 //FIXME: Tenant ID of "1" should not be hard coded
403 String roleNameToVerify = "ROLE_" +
405 verifyRoleName.toUpperCase();
406 Assert.assertEquals(output.getRoleName(), roleNameToVerify,
407 "RoleName fix did not work!");
414 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
418 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
419 // dependsOnMethods = {"read"})
420 public void readNonExistent(String testName) throws Exception {
422 setupReadNonExistent();
424 // Submit the request to the service and store the response.
425 RoleClient client = new RoleClient();
426 ClientResponse<Role> res = client.read(NON_EXISTENT_ID);
428 int statusCode = res.getStatus();
429 // Check the status code of the response: does it match
430 // the expected response(s)?
431 if (logger.isDebugEnabled()) {
432 logger.debug(testName + ": status = " + statusCode);
434 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
435 invalidStatusCodeMessage(testRequestType, statusCode));
436 Assert.assertEquals(statusCode, testExpectedStatusCode);
442 // ---------------------------------------------------------------
443 // CRUD tests : READ_LIST tests
444 // ---------------------------------------------------------------
447 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
450 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
451 // dependsOnMethods = {"createList", "read"})
452 public void readList(String testName) throws Exception {
456 // Submit the request to the service and store the response.
457 RoleClient client = new RoleClient();
458 ClientResponse<RolesList> res = client.readList();
460 // Check the status code of the response: does it match
461 // the expected response(s)?
462 assertStatusCode(res, testName);
463 RolesList list = res.getEntity();
464 // Optionally output additional data about list members for debugging.
465 boolean iterateThroughList = true;
466 if (iterateThroughList && logger.isDebugEnabled()) {
467 printList(testName, list);
479 * @param testName the test name
480 * @throws Exception the exception
482 @Test(dataProvider = "testName",
483 dependsOnMethods = {"CRUDTests"})
484 public void searchRoleName(String testName) throws Exception {
488 // Submit the request to the service and store the response.
489 RoleClient client = new RoleClient();
490 ClientResponse<RolesList> res = client.readSearchList("movingImage");
492 assertStatusCode(res, testName);
493 RolesList list = res.getEntity();
494 int EXPECTED_ITEMS = 1;
495 if (logger.isDebugEnabled()) {
496 logger.debug(testName + ": received = " + list.getRole().size()
497 + " expected=" + EXPECTED_ITEMS);
499 Assert.assertEquals(EXPECTED_ITEMS, list.getRole().size());
500 // Optionally output additional data about list members for debugging.
501 boolean iterateThroughList = true;
502 if (iterateThroughList && logger.isDebugEnabled()) {
503 printList(testName, list);
514 // ---------------------------------------------------------------
515 // CRUD tests : UPDATE tests
516 // ---------------------------------------------------------------
519 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
522 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
523 // dependsOnMethods = {"read", "readList", "readNonExistent"})
524 public void update(String testName) throws Exception {
528 Role roleToUpdate = new Role();
529 roleToUpdate.setCsid(knownResourceId);
530 roleToUpdate.setRoleName(knownRoleName);
531 roleToUpdate.setDisplayName(knownRoleName);
533 // Update the content of this resource.
534 roleToUpdate.setDescription("updated role description");
535 if (logger.isDebugEnabled()) {
536 logger.debug("updated object");
537 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
538 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
541 RoleClient client = new RoleClient();
542 // Submit the request to the service and store the response.
543 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
545 // Check the status code of the response: does it match the expected response(s)?
546 int statusCode = res.getStatus();
547 if (logger.isDebugEnabled()) {
548 logger.debug(testName + ": status = " + statusCode);
550 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
551 invalidStatusCodeMessage(testRequestType, statusCode));
552 Assert.assertEquals(statusCode, testExpectedStatusCode);
555 Role roleUpdated = (Role) res.getEntity();
556 Assert.assertNotNull(roleUpdated);
558 Assert.assertEquals(roleUpdated.getDescription(),
559 roleToUpdate.getDescription(),
560 "Data in updated object did not match submitted data.");
566 @Test(dataProvider = "testName",
567 dependsOnMethods = {"CRUDTests"})
568 public void verifyProtectionReadOnly(String testName) throws Exception {
569 // Setup to create a new role
571 Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
572 role.setMetadataProtection(RoleClient.IMMUTABLE);
573 role.setPermsProtection(RoleClient.IMMUTABLE);
575 // Submit the create request to the service and store the response.
577 RoleClient client = new RoleClient();
578 ClientResponse<Response> res = client.create(role);
579 String testResourceId = null;
581 int statusCode = res.getStatus();
582 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(testRequestType, statusCode));
584 Assert.assertEquals(statusCode, testExpectedStatusCode);
585 // Store the ID returned from this create operation
586 // for additional tests below.
587 testResourceId = extractId(res);
588 allResourceIdsCreated.add(testResourceId);
589 if (logger.isDebugEnabled()) {
590 logger.debug(testName + ": testResourceId=" + testResourceId);
596 // Next, read back the role we just created.
598 // Submit the request to the service and store the response.
599 ClientResponse<Role> roleRes = client.read(testResourceId);
601 int statusCode = roleRes.getStatus();
602 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
603 invalidStatusCodeMessage(testRequestType, statusCode));
604 Assert.assertEquals(statusCode, testExpectedStatusCode);
606 Role roleRead = (Role) roleRes.getEntity();
607 Assert.assertNotNull(roleRead);
608 String mdProtection = roleRead.getMetadataProtection();
609 String permsProtection = roleRead.getPermsProtection();
610 if (logger.isTraceEnabled()) {
611 logger.trace(testName + ": metadataProtection=" + mdProtection);
612 logger.trace(testName + ": permsProtection=" + permsProtection);
614 Assert.assertFalse(role.getMetadataProtection().equals(mdProtection),
615 "Role allowed create to set the metadata protection flag.");
616 Assert.assertFalse(role.getPermsProtection().equals(permsProtection),
617 "Role allowed create to set the perms protection flag.");
621 // Finally, update the role with changes and verify
624 Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
625 roleToUpdate.setMetadataProtection(RoleClient.IMMUTABLE);
626 roleToUpdate.setPermsProtection(RoleClient.IMMUTABLE);
628 // Submit the request to the service and store the response.
629 roleRes = client.update(testResourceId, roleToUpdate);
631 // Check the status code of the response: does it match the expected response(s)?
632 int statusCode = roleRes.getStatus();
633 if (logger.isDebugEnabled()) {
634 logger.debug(testName + ": status = " + statusCode);
636 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(testRequestType, statusCode));
638 Assert.assertEquals(statusCode, testExpectedStatusCode);
641 Role roleUpdated = (Role) roleRes.getEntity();
642 Assert.assertNotNull(roleUpdated);
643 if (logger.isDebugEnabled()) {
644 logger.debug(testName + "Updated role: ");
645 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
646 logger.debug(objectAsXmlString(objectFactory.createRole(roleUpdated),
650 Assert.assertFalse(RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getMetadataProtection()),
651 "Role allowed update of the metadata protection flag.");
652 Assert.assertFalse(RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getPermsProtection()),
653 "Role allowed update of the perms protection flag.");
659 @Test(dataProvider = "testName",
660 dependsOnMethods = {"CRUDTests"})
661 public void updateNotAllowed(String testName) throws Exception {
666 Role roleToUpdate = new Role();
667 roleToUpdate.setCsid(knownResourceId);
668 // Update the content of this resource.
669 roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
670 roleToUpdate.setDisplayName("UPDATED-ROLE_USERS_TEST");
671 if (logger.isDebugEnabled()) {
672 logger.debug("updated object");
673 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
674 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
677 RoleClient client = new RoleClient();
678 // Submit the request to the service and store the response.
679 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
681 int statusCode = res.getStatus();
682 // Check the status code of the response: does it match the expected response(s)?
683 if (logger.isDebugEnabled()) {
684 logger.debug(testName + ": status = " + statusCode);
686 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
687 invalidStatusCodeMessage(testRequestType, statusCode));
688 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
695 // Placeholders until the three tests below can be uncommented.
696 // See Issue CSPACE-401.
698 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
701 public void updateWithEmptyEntityBody(String testName) throws Exception {
702 //FIXME: Should this test really be empty? If so, please comment accordingly.
706 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
709 public void updateWithMalformedXml(String testName) throws Exception {
710 //FIXME: Should this test really be empty? If so, please comment accordingly.
714 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
717 public void updateWithWrongXmlSchema(String testName) throws Exception {
718 //FIXME: Should this test really be empty? If so, please comment accordingly.
722 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
726 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
727 // dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
728 public void updateNonExistent(String testName) throws Exception {
730 setupUpdateNonExistent();
732 // Submit the request to the service and store the response.
734 // Note: The ID used in this 'create' call may be arbitrary.
735 // The only relevant ID may be the one used in updateRole(), below.
736 RoleClient client = new RoleClient();
737 Role role = createRoleInstance("ROLE_XXX",
740 ClientResponse<Role> res =
741 client.update(NON_EXISTENT_ID, role);
743 int statusCode = res.getStatus();
745 // Check the status code of the response: does it match
746 // the expected response(s)?
747 if (logger.isDebugEnabled()) {
748 logger.debug(testName + ": status = " + statusCode);
750 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
751 invalidStatusCodeMessage(testRequestType, statusCode));
752 Assert.assertEquals(statusCode, testExpectedStatusCode);
758 // ---------------------------------------------------------------
759 // CRUD tests : DELETE tests
760 // ---------------------------------------------------------------
763 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
766 public void delete(String testName) throws Exception {
767 // Do nothing since other tests like "updateNotAllowed" need the "known resource" that this test
768 // deletes. Once all those tests get run, the "localDelete" method will call the base class' delete
769 // method that will delete the "known resource".
772 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
773 dependsOnMethods = {"updateNotAllowed", "createForUniqueRole", "createForUniqueDisplayRole"})
774 public void localDelete(String testName) throws Exception {
775 super.delete(testName);
780 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
783 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
784 // dependsOnMethods = {"delete"})
785 public void deleteNonExistent(String testName) throws Exception {
787 setupDeleteNonExistent();
789 // Submit the request to the service and store the response.
790 RoleClient client = new RoleClient();
791 Response res = client.delete(NON_EXISTENT_ID);
793 int statusCode = res.getStatus();
795 // Check the status code of the response: does it match
796 // the expected response(s)?
797 if (logger.isDebugEnabled()) {
798 logger.debug(testName + ": status = " + statusCode);
800 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
801 invalidStatusCodeMessage(testRequestType, statusCode));
802 Assert.assertEquals(statusCode, testExpectedStatusCode);
808 // ---------------------------------------------------------------
810 // ---------------------------------------------------------------
813 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
814 public void searchWorkflowDeleted(String testName) throws Exception {
815 // Fixme: null test for now, overriding test in base class
818 // ---------------------------------------------------------------
819 // Utility tests : tests of code used in tests above
820 // ---------------------------------------------------------------
822 * Tests the code for manually submitting data that is used by several
823 * of the methods above.
827 // ---------------------------------------------------------------
828 // Utility methods used by tests above
829 // ---------------------------------------------------------------
831 * create role instance
837 public Role createRoleInstance(String roleName,
839 boolean useRoleName) {
841 Role role = RoleFactory.createRoleInstance(roleName,
842 roleName, //the display name
845 if (logger.isDebugEnabled()) {
846 logger.debug("to be created, role");
847 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
848 logger.debug(objectAsXmlString(objectFactory.createRole(role),
858 * @param testName the test name
859 * @param list the list
862 protected void printList(String testName, RolesList list) {
863 for (Role role : list.getRole()) {
864 logger.debug(testName + " role csid=" + role.getCsid()
865 + " name=" + role.getRoleName()
866 + " desc=" + role.getDescription());
871 protected Role createInstance(String commonPartName, String identifier) {
872 // TODO Auto-generated method stub
877 protected Role updateInstance(Role commonPartObject) {
878 // TODO Auto-generated method stub
883 protected void compareUpdatedInstances(Role original, Role updated)
885 // TODO Auto-generated method stub
890 protected Class<RolesList> getCommonListType() {
891 // TODO Auto-generated method stub
896 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
897 * refer to this method in their @Test annotation declarations.
900 @Test(dataProvider = "testName",
902 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
903 public void CRUDTests(String testName) {
904 // Do nothing. Simply here to for a TestNG execution order for our tests