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,
105 "all users are required to be in this role",
107 ClientResponse<Response> res = client.create(role);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if (logger.isDebugEnabled()) {
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(testRequestType, statusCode));
121 Assert.assertEquals(statusCode, testExpectedStatusCode);
123 // Store the ID returned from this create operation
124 // for additional tests below.
125 knownResourceId = extractId(res);
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": knownResourceId=" + knownResourceId);
131 @Test(dataProvider = "testName",
132 dependsOnMethods = {"CRUDTests"})
133 public void createWithDisplayname(String testName) throws Exception {
134 // Perform setup, such as initializing the type of service request
135 // (e.g. CREATE, DELETE), its valid and expected status codes, and
136 // its associated HTTP method name (e.g. POST, DELETE).
139 // Submit the request to the service and store the response.
140 RoleClient client = new RoleClient();
141 Role role = createRoleInstance(knownRoleName + "_" + knownRoleDisplayName,
142 "all users are required to be in this role",
144 role.setDisplayName(knownRoleDisplayName);
145 ClientResponse<Response> res = client.create(role);
146 int statusCode = res.getStatus();
148 // Check the status code of the response: does it match
149 // the expected response(s)?
152 // Does it fall within the set of valid status codes?
153 // Does it exactly match the expected status code?
154 if (logger.isDebugEnabled()) {
155 logger.debug(testName + ": status = " + statusCode);
157 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
158 invalidStatusCodeMessage(testRequestType, statusCode));
159 Assert.assertEquals(statusCode, testExpectedStatusCode);
161 // Store the ID returned from this create operation
162 // for additional tests below.
163 String csid = extractId(res);
164 allResourceIdsCreated.add(csid);
165 if (logger.isDebugEnabled()) {
166 logger.debug(testName + ": csid=" + csid);
172 * Creates the for unique role.
174 * @param testName the test name
175 * @throws Exception the exception
177 @Test(dataProvider = "testName",
178 dependsOnMethods = {"CRUDTests"})
179 public void createForUniqueRole(String testName) throws Exception {
182 // Submit the request to the service and store the response.
183 RoleClient client = new RoleClient();
184 Role role = createRoleInstance(knownRoleName,
187 ClientResponse<Response> res = client.create(role);
188 int statusCode = res.getStatus();
190 if (logger.isDebugEnabled()) {
191 logger.debug(testName + ": Role with name \"" +
192 knownRoleName + "\" should already exist, so this request should fail.");
193 logger.debug(testName + ": status = " + statusCode);
194 logger.debug(testName + ": " + res);
196 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
197 invalidStatusCodeMessage(testRequestType, statusCode));
198 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
202 * Creates the for unique display name of role.
204 * @param testName the test name
205 * @throws Exception the exception
207 @Test(dataProvider = "testName",
208 dependsOnMethods = {"createWithDisplayname"})
209 public void createForUniqueDisplayRole(String testName) throws Exception {
212 // Submit the request to the service and store the response.
213 RoleClient client = new RoleClient();
214 Role role = createRoleInstance(knownRoleName + System.currentTimeMillis(),
215 "role users with non-unique display name",
217 role.setDisplayName(knownRoleDisplayName);
218 ClientResponse<Response> res = client.create(role);
219 int statusCode = res.getStatus();
221 if (logger.isDebugEnabled()) {
222 logger.debug(testName + ": Role with name \"" +
223 knownRoleName + "\" should already exist, so this request should fail.");
224 logger.debug(testName + ": status = " + statusCode);
225 logger.debug(testName + ": " + res);
227 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
228 invalidStatusCodeMessage(testRequestType, statusCode));
229 if (statusCode != Response.Status.BAD_REQUEST.getStatusCode()) {
230 // If the test fails then we've just created a Role that we need to delete, so
231 // store the ID returned from this create operation.
232 String csid = extractId(res);
233 allResourceIdsCreated.add(csid);
234 if (logger.isDebugEnabled()) {
235 logger.debug(testName + ": csid=" + csid);
237 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
242 * Creates the without role name.
244 * @param testName the test name
245 * @throws Exception the exception
247 @Test(dataProvider = "testName",
248 dependsOnMethods = {"CRUDTests"})
249 public void createWithoutRoleName(String testName) throws Exception {
252 // Submit the request to the service and store the response.
253 RoleClient client = new RoleClient();
254 Role role = createRoleInstance("",
257 ClientResponse<Response> res = client.create(role);
258 int statusCode = res.getStatus();
259 // Does it exactly match the expected status code?
260 if (logger.isDebugEnabled()) {
261 logger.debug(testName + ": status = " + statusCode);
263 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
264 invalidStatusCodeMessage(testRequestType, statusCode));
265 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
268 //to not cause uniqueness violation for role, createList is removed
270 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
273 // @Test(dataProvider = "testName",
274 // dependsOnMethods = {"createWithDisplayname"})
275 public void createList(String testName) throws Exception {
278 // Submit the request to the service and store the response.
279 RoleClient client = new RoleClient();
280 //create a role with lowercase role name without role prefix
281 //the service should make it upper case and add the role prefix
282 Role role1 = createRoleInstance(verifyRoleName,
283 "collection manager",
285 ClientResponse<Response> res = client.create(role1);
286 int statusCode = res.getStatus();
287 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
288 invalidStatusCodeMessage(testRequestType, statusCode));
289 Assert.assertEquals(statusCode, testExpectedStatusCode);
290 verifyResourceId = extractId(res);
291 allResourceIdsCreated.add(verifyResourceId);
293 Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
294 "collections curator",
296 res = client.create(role2);
297 statusCode = res.getStatus();
298 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
299 invalidStatusCodeMessage(testRequestType, statusCode));
300 Assert.assertEquals(statusCode, testExpectedStatusCode);
301 Assert.assertEquals(statusCode, testExpectedStatusCode);
302 allResourceIdsCreated.add(extractId(res));
304 Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
305 "moving image admin",
307 res = client.create(role3);
308 statusCode = res.getStatus();
309 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
310 invalidStatusCodeMessage(testRequestType, statusCode));
311 Assert.assertEquals(statusCode, testExpectedStatusCode);
312 Assert.assertEquals(statusCode, testExpectedStatusCode);
313 allResourceIdsCreated.add(extractId(res));
317 // Placeholders until the three tests below can be uncommented.
318 // See Issue CSPACE-401.
320 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
323 public void createWithEmptyEntityBody(String testName) throws Exception {
324 //FIXME: Should this test really be empty? If so, please comment accordingly.
328 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
331 public void createWithMalformedXml(String testName) throws Exception {
332 //FIXME: Should this test really be empty? If so, please comment accordingly.
336 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
339 public void createWithWrongXmlSchema(String testName) throws Exception {
340 //FIXME: Should this test really be empty? If so, please comment accordingly.
343 // ---------------------------------------------------------------
344 // CRUD tests : READ tests
345 // ---------------------------------------------------------------
348 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
351 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 // dependsOnMethods = {"createForUniqueRole"})
353 public void read(String testName) throws Exception {
357 // Submit the request to the service and store the response.
358 RoleClient client = new RoleClient();
359 ClientResponse<Role> res = client.read(knownResourceId);
360 int statusCode = res.getStatus();
362 // Check the status code of the response: does it match
363 // the expected response(s)?
364 if (logger.isDebugEnabled()) {
365 logger.debug(testName + ": status = " + statusCode);
367 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
368 invalidStatusCodeMessage(testRequestType, statusCode));
369 Assert.assertEquals(statusCode, testExpectedStatusCode);
371 Role output = (Role) res.getEntity();
372 Assert.assertNotNull(output);
375 @Test(dataProvider = "testName",
376 dependsOnMethods = {"CRUDTests"})
377 public void readToVerify(String testName) throws Exception {
381 // Submit the request to the service and store the response.
382 RoleClient client = new RoleClient();
383 ClientResponse<Role> res = client.read(verifyResourceId);
384 int statusCode = res.getStatus();
386 // Check the status code of the response: does it match
387 // the expected response(s)?
388 if (logger.isDebugEnabled()) {
389 logger.debug(testName + ": status = " + statusCode);
391 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
392 invalidStatusCodeMessage(testRequestType, statusCode));
393 Assert.assertEquals(statusCode, testExpectedStatusCode);
395 Role output = (Role) res.getEntity();
396 Assert.assertNotNull(output);
398 //FIXME: Tenant ID of "1" should not be hard coded
399 String roleNameToVerify = "ROLE_" +
401 verifyRoleName.toUpperCase();
402 Assert.assertEquals(output.getRoleName(), roleNameToVerify,
403 "RoleName fix did not work!");
407 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
411 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
412 // dependsOnMethods = {"read"})
413 public void readNonExistent(String testName) throws Exception {
415 setupReadNonExistent();
417 // Submit the request to the service and store the response.
418 RoleClient client = new RoleClient();
419 ClientResponse<Role> res = client.read(NON_EXISTENT_ID);
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);
432 // ---------------------------------------------------------------
433 // CRUD tests : READ_LIST tests
434 // ---------------------------------------------------------------
437 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
440 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
441 // dependsOnMethods = {"createList", "read"})
442 public void readList(String testName) throws Exception {
446 // Submit the request to the service and store the response.
447 RoleClient client = new RoleClient();
448 ClientResponse<RolesList> res = client.readList();
450 // Check the status code of the response: does it match
451 // the expected response(s)?
452 assertStatusCode(res, testName);
453 RolesList list = res.getEntity();
454 // Optionally output additional data about list members for debugging.
455 boolean iterateThroughList = true;
456 if (iterateThroughList && logger.isDebugEnabled()) {
457 printList(testName, list);
461 res.releaseConnection();
469 * @param testName the test name
470 * @throws Exception the exception
472 @Test(dataProvider = "testName",
473 dependsOnMethods = {"CRUDTests"})
474 public void searchRoleName(String testName) throws Exception {
478 // Submit the request to the service and store the response.
479 RoleClient client = new RoleClient();
480 ClientResponse<RolesList> res = client.readSearchList("movingImage");
482 assertStatusCode(res, testName);
483 RolesList list = res.getEntity();
484 int EXPECTED_ITEMS = 1;
485 if (logger.isDebugEnabled()) {
486 logger.debug(testName + ": received = " + list.getRole().size()
487 + " expected=" + EXPECTED_ITEMS);
489 Assert.assertEquals(EXPECTED_ITEMS, list.getRole().size());
490 // Optionally output additional data about list members for debugging.
491 boolean iterateThroughList = true;
492 if (iterateThroughList && logger.isDebugEnabled()) {
493 printList(testName, list);
497 res.releaseConnection();
504 // ---------------------------------------------------------------
505 // CRUD tests : UPDATE tests
506 // ---------------------------------------------------------------
509 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
512 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
513 // dependsOnMethods = {"read", "readList", "readNonExistent"})
514 public void update(String testName) throws Exception {
518 Role roleToUpdate = new Role();
519 roleToUpdate.setCsid(knownResourceId);
520 roleToUpdate.setRoleName(knownRoleName);
521 roleToUpdate.setDisplayName(knownRoleName);
523 // Update the content of this resource.
524 roleToUpdate.setDescription("updated role description");
525 if (logger.isDebugEnabled()) {
526 logger.debug("updated object");
527 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
528 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
531 RoleClient client = new RoleClient();
532 // Submit the request to the service and store the response.
533 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
534 int statusCode = res.getStatus();
535 // Check the status code of the response: does it match the expected response(s)?
536 if (logger.isDebugEnabled()) {
537 logger.debug(testName + ": status = " + statusCode);
539 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
540 invalidStatusCodeMessage(testRequestType, statusCode));
541 Assert.assertEquals(statusCode, testExpectedStatusCode);
544 Role roleUpdated = (Role) res.getEntity();
545 Assert.assertNotNull(roleUpdated);
547 Assert.assertEquals(roleUpdated.getDescription(),
548 roleToUpdate.getDescription(),
549 "Data in updated object did not match submitted data.");
552 @Test(dataProvider = "testName",
553 dependsOnMethods = {"CRUDTests"})
554 public void verifyProtectionReadOnly(String testName) throws Exception {
558 // Submit the request to the service and store the response.
559 RoleClient client = new RoleClient();
560 Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
561 role.setMetadataProtection(RoleClient.IMMUTABLE);
562 role.setPermsProtection(RoleClient.IMMUTABLE);
563 ClientResponse<Response> res = client.create(role);
564 int statusCode = res.getStatus();
565 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
566 invalidStatusCodeMessage(testRequestType, statusCode));
567 Assert.assertEquals(statusCode, testExpectedStatusCode);
569 // Store the ID returned from this create operation
570 // for additional tests below.
571 String testResourceId = extractId(res);
572 allResourceIdsCreated.add(testResourceId);
573 if (logger.isDebugEnabled()) {
574 logger.debug(testName + ": testResourceId=" + testResourceId);
578 // Submit the request to the service and store the response.
579 ClientResponse<Role> roleRes = client.read(testResourceId);
580 statusCode = roleRes.getStatus();
582 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
583 invalidStatusCodeMessage(testRequestType, statusCode));
584 Assert.assertEquals(statusCode, testExpectedStatusCode);
586 Role roleRead = (Role) roleRes.getEntity();
587 Assert.assertNotNull(roleRead);
588 String mdProtection = roleRead.getMetadataProtection();
589 String permsProtection = roleRead.getPermsProtection();
590 if (logger.isTraceEnabled()) {
591 logger.trace(testName + ": metadataProtection=" + mdProtection);
592 logger.trace(testName + ": permsProtection=" + permsProtection);
594 Assert.assertFalse(role.getMetadataProtection().equals(mdProtection),
595 "Role allowed create to set the metadata protection flag.");
596 Assert.assertFalse(role.getPermsProtection().equals(permsProtection),
597 "Role allowed create to set the perms protection flag.");
601 Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
602 roleToUpdate.setMetadataProtection(RoleClient.IMMUTABLE);
603 roleToUpdate.setPermsProtection(RoleClient.IMMUTABLE);
605 // Submit the request to the service and store the response.
606 roleRes = client.update(testResourceId, roleToUpdate);
607 statusCode = roleRes.getStatus();
608 // Check the status code of the response: does it match the expected response(s)?
609 if (logger.isDebugEnabled()) {
610 logger.debug(testName + ": status = " + statusCode);
612 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
613 invalidStatusCodeMessage(testRequestType, statusCode));
614 Assert.assertEquals(statusCode, testExpectedStatusCode);
617 Role roleUpdated = (Role) roleRes.getEntity();
618 Assert.assertNotNull(roleUpdated);
619 if (logger.isDebugEnabled()) {
620 logger.debug(testName + "Updated role: ");
621 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
622 logger.debug(objectAsXmlString(objectFactory.createRole(roleUpdated),
627 RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getMetadataProtection()),
628 "Role allowed update of the metadata protection flag.");
630 RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getPermsProtection()),
631 "Role allowed update of the perms protection flag.");
634 @Test(dataProvider = "testName",
635 dependsOnMethods = {"CRUDTests"})
636 public void updateNotAllowed(String testName) throws Exception {
641 Role roleToUpdate = new Role();
642 roleToUpdate.setCsid(knownResourceId);
643 // Update the content of this resource.
644 roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
645 roleToUpdate.setDisplayName("UPDATED-ROLE_USERS_TEST");
646 if (logger.isDebugEnabled()) {
647 logger.debug("updated object");
648 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
649 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
652 RoleClient client = new RoleClient();
653 // Submit the request to the service and store the response.
654 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
655 int statusCode = res.getStatus();
656 // Check the status code of the response: does it match the expected response(s)?
657 if (logger.isDebugEnabled()) {
658 logger.debug(testName + ": status = " + statusCode);
660 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
661 invalidStatusCodeMessage(testRequestType, statusCode));
662 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
667 // Placeholders until the three tests below can be uncommented.
668 // See Issue CSPACE-401.
670 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
673 public void updateWithEmptyEntityBody(String testName) throws Exception {
674 //FIXME: Should this test really be empty? If so, please comment accordingly.
678 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
681 public void updateWithMalformedXml(String testName) throws Exception {
682 //FIXME: Should this test really be empty? If so, please comment accordingly.
686 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
689 public void updateWithWrongXmlSchema(String testName) throws Exception {
690 //FIXME: Should this test really be empty? If so, please comment accordingly.
694 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
698 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
699 // dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
700 public void updateNonExistent(String testName) throws Exception {
702 setupUpdateNonExistent();
704 // Submit the request to the service and store the response.
706 // Note: The ID used in this 'create' call may be arbitrary.
707 // The only relevant ID may be the one used in updateRole(), below.
708 RoleClient client = new RoleClient();
709 Role role = createRoleInstance("ROLE_XXX",
712 ClientResponse<Role> res =
713 client.update(NON_EXISTENT_ID, role);
714 int statusCode = res.getStatus();
716 // Check the status code of the response: does it match
717 // the expected response(s)?
718 if (logger.isDebugEnabled()) {
719 logger.debug(testName + ": status = " + statusCode);
721 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
722 invalidStatusCodeMessage(testRequestType, statusCode));
723 Assert.assertEquals(statusCode, testExpectedStatusCode);
726 // ---------------------------------------------------------------
727 // CRUD tests : DELETE tests
728 // ---------------------------------------------------------------
731 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
734 public void delete(String testName) throws Exception {
735 // Do nothing since other tests like "updateNotAllowed" need the "known resource" that this test
736 // deletes. Once all those tests get run, the "localDelete" method will call the base class' delete
737 // method that will delete the "known resource".
740 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
741 dependsOnMethods = {"updateNotAllowed", "createForUniqueRole", "createForUniqueDisplayRole"})
742 public void localDelete(String testName) throws Exception {
743 super.delete(testName);
748 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
751 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
752 // dependsOnMethods = {"delete"})
753 public void deleteNonExistent(String testName) throws Exception {
755 setupDeleteNonExistent();
757 // Submit the request to the service and store the response.
758 RoleClient client = new RoleClient();
759 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
760 int statusCode = res.getStatus();
762 // Check the status code of the response: does it match
763 // the expected response(s)?
764 if (logger.isDebugEnabled()) {
765 logger.debug(testName + ": status = " + statusCode);
767 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
768 invalidStatusCodeMessage(testRequestType, statusCode));
769 Assert.assertEquals(statusCode, testExpectedStatusCode);
772 // ---------------------------------------------------------------
774 // ---------------------------------------------------------------
777 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
778 public void searchWorkflowDeleted(String testName) throws Exception {
779 // Fixme: null test for now, overriding test in base class
782 // ---------------------------------------------------------------
783 // Utility tests : tests of code used in tests above
784 // ---------------------------------------------------------------
786 * Tests the code for manually submitting data that is used by several
787 * of the methods above.
791 // ---------------------------------------------------------------
792 // Utility methods used by tests above
793 // ---------------------------------------------------------------
795 * create role instance
801 public Role createRoleInstance(String roleName,
803 boolean useRoleName) {
805 Role role = RoleFactory.createRoleInstance(roleName,
806 roleName, //the display name
809 if (logger.isDebugEnabled()) {
810 logger.debug("to be created, role");
811 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
812 logger.debug(objectAsXmlString(objectFactory.createRole(role),
822 * @param testName the test name
823 * @param list the list
826 protected void printList(String testName, RolesList list) {
827 for (Role role : list.getRole()) {
828 logger.debug(testName + " role csid=" + role.getCsid()
829 + " name=" + role.getRoleName()
830 + " desc=" + role.getDescription());
835 protected Role createInstance(String commonPartName, String identifier) {
836 // TODO Auto-generated method stub
841 protected Role updateInstance(Role commonPartObject) {
842 // TODO Auto-generated method stub
847 protected void compareUpdatedInstances(Role original, Role updated)
849 // TODO Auto-generated method stub
854 protected Class<RolesList> getCommonListType() {
855 // TODO Auto-generated method stub
860 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
861 * refer to this method in their @Test annotation declarations.
864 @Test(dataProvider = "testName",
866 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
867 public void CRUDTests(String testName) {
868 // Do nothing. Simply here to for a TestNG execution order for our tests