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.collectionspace.services.client.test.ServiceRequestType;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.jboss.resteasy.client.ClientResponse;
39 import org.testng.Assert;
40 import org.testng.annotations.Test;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * RoleServiceTest, carries out tests against a
47 * deployed and running Role Service.
49 * $LastChangedRevision: 917 $
50 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
52 public class RoleServiceTest extends AbstractServiceTestImpl {
55 private final static String CLASS_NAME = RoleServiceTest.class.getName();
56 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
58 // Instance variables specific to this test.
59 /** The known resource id. */
60 private String knownResourceId = null;
61 private String knownRoleName = "ROLE_USERS_TEST";
62 private String knownRoleDisplayName = "ROLE_DISPLAYNAME_USERS_TEST";
63 private String verifyResourceId = null;
64 private String verifyRoleName = "collections_manager_test";
65 // private List<String> allResourceIdsCreated = new ArrayList<String>();
68 public String getServiceName() {
69 return RoleClient.SERVICE_NAME;
73 protected String getServicePathComponent() {
74 return new RoleClient().getServicePathComponent();
78 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
81 protected CollectionSpaceClient getClientInstance() {
82 return new RoleClient();
86 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
89 protected AbstractCommonList getAbstractCommonList(
90 ClientResponse<AbstractCommonList> response) {
91 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
92 throw new UnsupportedOperationException();
96 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
98 @Test(dataProvider = "testName")
100 public void readPaginatedList(String testName) throws Exception {
101 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
104 // ---------------------------------------------------------------
105 // CRUD tests : CREATE tests
106 // ---------------------------------------------------------------
109 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
112 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
113 public void create(String testName) throws Exception {
115 if (logger.isDebugEnabled()) {
116 logger.debug(testBanner(testName, CLASS_NAME));
118 // Perform setup, such as initializing the type of service request
119 // (e.g. CREATE, DELETE), its valid and expected status codes, and
120 // its associated HTTP method name (e.g. POST, DELETE).
123 // Submit the request to the service and store the response.
124 RoleClient client = new RoleClient();
125 Role role = createRoleInstance(knownRoleName,
126 "all users are required to be in this role",
128 ClientResponse<Response> res = client.create(role);
129 int statusCode = res.getStatus();
131 // Check the status code of the response: does it match
132 // the expected response(s)?
135 // Does it fall within the set of valid status codes?
136 // Does it exactly match the expected status code?
137 if (logger.isDebugEnabled()) {
138 logger.debug(testName + ": status = " + statusCode);
140 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
141 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
142 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
144 // Store the ID returned from this create operation
145 // for additional tests below.
146 knownResourceId = extractId(res);
147 if (logger.isDebugEnabled()) {
148 logger.debug(testName + ": knownResourceId=" + knownResourceId);
152 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
153 public void createWithDisplayname(String testName) throws Exception {
155 if (logger.isDebugEnabled()) {
156 logger.debug(testBanner(testName, CLASS_NAME));
158 // Perform setup, such as initializing the type of service request
159 // (e.g. CREATE, DELETE), its valid and expected status codes, and
160 // its associated HTTP method name (e.g. POST, DELETE).
163 // Submit the request to the service and store the response.
164 RoleClient client = new RoleClient();
165 Role role = createRoleInstance(knownRoleName + "_" + knownRoleDisplayName,
166 "all users are required to be in this role",
168 role.setDisplayName(knownRoleDisplayName);
169 ClientResponse<Response> res = client.create(role);
170 int statusCode = res.getStatus();
172 // Check the status code of the response: does it match
173 // the expected response(s)?
176 // Does it fall within the set of valid status codes?
177 // Does it exactly match the expected status code?
178 if (logger.isDebugEnabled()) {
179 logger.debug(testName + ": status = " + statusCode);
181 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
182 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
183 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
185 // Store the ID returned from this create operation
186 // for additional tests below.
187 String csid = extractId(res);
188 allResourceIdsCreated.add(csid);
189 if (logger.isDebugEnabled()) {
190 logger.debug(testName + ": csid=" + csid);
196 * Creates the for unique role.
198 * @param testName the test name
199 * @throws Exception the exception
201 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
202 public void createForUniqueRole(String testName) throws Exception {
204 if (logger.isDebugEnabled()) {
205 logger.debug(testBanner(testName, CLASS_NAME));
209 // Submit the request to the service and store the response.
210 RoleClient client = new RoleClient();
211 Role role = createRoleInstance(knownRoleName,
214 ClientResponse<Response> res = client.create(role);
215 int statusCode = res.getStatus();
217 if (logger.isDebugEnabled()) {
218 logger.debug(testName + ": Role with name \"" +
219 knownRoleName + "\" should already exist, so this request should fail.");
220 logger.debug(testName + ": status = " + statusCode);
221 logger.debug(testName + ": " + res);
223 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
224 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
225 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
229 * Creates the for unique display name of role.
231 * @param testName the test name
232 * @throws Exception the exception
234 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createWithDisplayname"})
235 public void createForUniqueDisplayRole(String testName) throws Exception {
237 if (logger.isDebugEnabled()) {
238 logger.debug(testBanner(testName, CLASS_NAME));
242 // Submit the request to the service and store the response.
243 RoleClient client = new RoleClient();
244 Role role = createRoleInstance(knownRoleName + System.currentTimeMillis(),
245 "role users with non-unique display name",
247 role.setDisplayName(knownRoleDisplayName);
248 ClientResponse<Response> res = client.create(role);
249 int statusCode = res.getStatus();
251 if (logger.isDebugEnabled()) {
252 logger.debug(testName + ": Role with name \"" +
253 knownRoleName + "\" should already exist, so this request should fail.");
254 logger.debug(testName + ": status = " + statusCode);
255 logger.debug(testName + ": " + res);
257 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
258 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
259 if (statusCode != Response.Status.BAD_REQUEST.getStatusCode()) {
260 // If the test fails then we've just created a Role that we need to delete, so
261 // store the ID returned from this create operation.
262 String csid = extractId(res);
263 allResourceIdsCreated.add(csid);
264 if (logger.isDebugEnabled()) {
265 logger.debug(testName + ": csid=" + csid);
267 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
272 * Creates the without role name.
274 * @param testName the test name
275 * @throws Exception the exception
277 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
278 dependsOnMethods = {"create"})
279 public void createWithoutRoleName(String testName) throws Exception {
281 if (logger.isDebugEnabled()) {
282 logger.debug(testBanner(testName, CLASS_NAME));
286 // Submit the request to the service and store the response.
287 RoleClient client = new RoleClient();
288 Role role = createRoleInstance("",
291 ClientResponse<Response> res = client.create(role);
292 int statusCode = res.getStatus();
293 // Does it exactly match the expected status code?
294 if (logger.isDebugEnabled()) {
295 logger.debug(testName + ": status = " + statusCode);
297 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
298 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
299 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
302 //to not cause uniqueness violation for role, createList is removed
304 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
307 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
308 dependsOnMethods = {"createWithDisplayname"})
309 public void createList(String testName) throws Exception {
311 if (logger.isDebugEnabled()) {
312 logger.debug(testBanner(testName, CLASS_NAME));
316 // Submit the request to the service and store the response.
317 RoleClient client = new RoleClient();
318 //create a role with lowercase role name without role prefix
319 //the service should make it upper case and add the role prefix
320 Role role1 = createRoleInstance(verifyRoleName,
321 "collection manager",
323 ClientResponse<Response> res = client.create(role1);
324 int statusCode = res.getStatus();
325 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
326 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
327 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328 verifyResourceId = extractId(res);
329 allResourceIdsCreated.add(verifyResourceId);
331 Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
332 "collections curator",
334 res = client.create(role2);
335 statusCode = res.getStatus();
336 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
337 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
338 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
339 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
340 allResourceIdsCreated.add(extractId(res));
342 Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
343 "moving image admin",
345 res = client.create(role3);
346 statusCode = res.getStatus();
347 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
348 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
349 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
350 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
351 allResourceIdsCreated.add(extractId(res));
355 // Placeholders until the three tests below can be uncommented.
356 // See Issue CSPACE-401.
358 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
361 public void createWithEmptyEntityBody(String testName) throws Exception {
362 //FIXME: Should this test really be empty? If so, please comment accordingly.
366 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
369 public void createWithMalformedXml(String testName) throws Exception {
370 //FIXME: Should this test really be empty? If so, please comment accordingly.
374 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
377 public void createWithWrongXmlSchema(String testName) throws Exception {
378 //FIXME: Should this test really be empty? If so, please comment accordingly.
381 // ---------------------------------------------------------------
382 // CRUD tests : READ tests
383 // ---------------------------------------------------------------
386 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
389 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
390 dependsOnMethods = {"createForUniqueRole"})
391 public void read(String testName) throws Exception {
393 if (logger.isDebugEnabled()) {
394 logger.debug(testBanner(testName, CLASS_NAME));
399 // Submit the request to the service and store the response.
400 RoleClient client = new RoleClient();
401 ClientResponse<Role> res = client.read(knownResourceId);
402 int statusCode = res.getStatus();
404 // Check the status code of the response: does it match
405 // the expected response(s)?
406 if (logger.isDebugEnabled()) {
407 logger.debug(testName + ": status = " + statusCode);
409 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
410 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
411 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413 Role output = (Role) res.getEntity();
414 Assert.assertNotNull(output);
417 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
418 dependsOnMethods = {"createList"})
419 public void readToVerify(String testName) throws Exception {
424 // Submit the request to the service and store the response.
425 RoleClient client = new RoleClient();
426 ClientResponse<Role> res = client.read(verifyResourceId);
427 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(REQUEST_TYPE.isValidStatusCode(statusCode),
435 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
436 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
438 Role output = (Role) res.getEntity();
439 Assert.assertNotNull(output);
441 //FIXME: Tenant ID of "1" should not be hard coded
442 String roleNameToVerify = "ROLE_" +
444 verifyRoleName.toUpperCase();
445 Assert.assertEquals(output.getRoleName(), roleNameToVerify,
446 "RoleName fix did not work!");
450 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
454 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
455 dependsOnMethods = {"read"})
456 public void readNonExistent(String testName) throws Exception {
458 if (logger.isDebugEnabled()) {
459 logger.debug(testBanner(testName, CLASS_NAME));
462 setupReadNonExistent();
464 // Submit the request to the service and store the response.
465 RoleClient client = new RoleClient();
466 ClientResponse<Role> res = client.read(NON_EXISTENT_ID);
467 int statusCode = res.getStatus();
469 // Check the status code of the response: does it match
470 // the expected response(s)?
471 if (logger.isDebugEnabled()) {
472 logger.debug(testName + ": status = " + statusCode);
474 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
475 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
476 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
479 // ---------------------------------------------------------------
480 // CRUD tests : READ_LIST tests
481 // ---------------------------------------------------------------
484 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
487 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
488 dependsOnMethods = {"createList", "read"})
489 public void readList(String testName) throws Exception {
491 if (logger.isDebugEnabled()) {
492 logger.debug(testBanner(testName, CLASS_NAME));
497 // Submit the request to the service and store the response.
498 RoleClient client = new RoleClient();
499 ClientResponse<RolesList> res = client.readList();
500 RolesList list = res.getEntity();
501 int statusCode = res.getStatus();
503 // Check the status code of the response: does it match
504 // the expected response(s)?
505 if (logger.isDebugEnabled()) {
506 logger.debug(testName + ": status = " + statusCode);
508 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
509 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
510 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
512 // Optionally output additional data about list members for debugging.
513 boolean iterateThroughList = true;
514 if (iterateThroughList && logger.isDebugEnabled()) {
515 printList(testName, list);
522 * @param testName the test name
523 * @throws Exception the exception
525 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
526 dependsOnMethods = {"createList", "read"})
527 public void searchRoleName(String testName) throws Exception {
529 if (logger.isDebugEnabled()) {
530 logger.debug(testBanner(testName, CLASS_NAME));
535 // Submit the request to the service and store the response.
536 RoleClient client = new RoleClient();
537 ClientResponse<RolesList> res = client.readSearchList("movingImage");
538 RolesList list = res.getEntity();
539 int statusCode = res.getStatus();
540 // Check the status code of the response: does it match
541 // the expected response(s)?
542 if (logger.isDebugEnabled()) {
543 logger.debug(testName + ": status = " + statusCode);
545 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
546 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
547 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
548 int EXPECTED_ITEMS = 1;
549 if (logger.isDebugEnabled()) {
550 logger.debug(testName + ": received = " + list.getRoles().size()
551 + " expected=" + EXPECTED_ITEMS);
553 Assert.assertEquals(EXPECTED_ITEMS, list.getRoles().size());
554 // Optionally output additional data about list members for debugging.
555 boolean iterateThroughList = true;
556 if (iterateThroughList && logger.isDebugEnabled()) {
557 printList(testName, list);
563 // ---------------------------------------------------------------
564 // CRUD tests : UPDATE tests
565 // ---------------------------------------------------------------
568 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
571 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
572 dependsOnMethods = {"read", "readList", "readNonExistent"})
573 public void update(String testName) throws Exception {
575 if (logger.isDebugEnabled()) {
576 logger.debug(testBanner(testName, CLASS_NAME));
581 Role roleToUpdate = new Role();
582 roleToUpdate.setCsid(knownResourceId);
583 roleToUpdate.setRoleName(knownRoleName);
584 roleToUpdate.setDisplayName(knownRoleName);
586 // Update the content of this resource.
587 roleToUpdate.setDescription("updated role description");
588 if (logger.isDebugEnabled()) {
589 logger.debug("updated object");
590 logger.debug(objectAsXmlString(roleToUpdate,
593 RoleClient client = new RoleClient();
594 // Submit the request to the service and store the response.
595 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
596 int statusCode = res.getStatus();
597 // Check the status code of the response: does it match the expected response(s)?
598 if (logger.isDebugEnabled()) {
599 logger.debug(testName + ": status = " + statusCode);
601 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
602 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
603 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
606 Role roleUpdated = (Role) res.getEntity();
607 Assert.assertNotNull(roleUpdated);
609 Assert.assertEquals(roleUpdated.getDescription(),
610 roleToUpdate.getDescription(),
611 "Data in updated object did not match submitted data.");
614 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
615 dependsOnMethods = {"read", "readList", "readNonExistent"})
616 public void verifyProtectionReadOnly(String testName) throws Exception {
618 if (logger.isDebugEnabled()) {
619 logger.debug(testBanner(testName, CLASS_NAME));
624 // Submit the request to the service and store the response.
625 RoleClient client = new RoleClient();
626 Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
627 role.setMetadataProtection(RoleClient.IMMUTABLE);
628 role.setPermsProtection(RoleClient.IMMUTABLE);
629 ClientResponse<Response> res = client.create(role);
630 int statusCode = res.getStatus();
631 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
632 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
633 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
635 // Store the ID returned from this create operation
636 // for additional tests below.
637 String testResourceId = extractId(res);
638 allResourceIdsCreated.add(testResourceId);
639 if (logger.isDebugEnabled()) {
640 logger.debug(testName + ": testResourceId=" + testResourceId);
644 // Submit the request to the service and store the response.
645 ClientResponse<Role> roleRes = client.read(testResourceId);
646 statusCode = roleRes.getStatus();
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 Role roleRead = (Role) roleRes.getEntity();
653 Assert.assertNotNull(roleRead);
654 String mdProtection = roleRead.getMetadataProtection();
655 String permsProtection = roleRead.getPermsProtection();
656 if (logger.isTraceEnabled()) {
657 logger.trace(testName + ": metadataProtection=" + mdProtection);
658 logger.trace(testName + ": permsProtection=" + permsProtection);
660 Assert.assertFalse(role.getMetadataProtection().equals(mdProtection),
661 "Role allowed create to set the metadata protection flag.");
662 Assert.assertFalse(role.getPermsProtection().equals(permsProtection),
663 "Role allowed create to set the perms protection flag.");
667 Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
668 roleToUpdate.setMetadataProtection(RoleClient.IMMUTABLE);
669 roleToUpdate.setPermsProtection(RoleClient.IMMUTABLE);
671 // Submit the request to the service and store the response.
672 roleRes = client.update(testResourceId, roleToUpdate);
673 statusCode = roleRes.getStatus();
674 // Check the status code of the response: does it match the expected response(s)?
675 if (logger.isDebugEnabled()) {
676 logger.debug(testName + ": status = " + statusCode);
678 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
679 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
680 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
683 Role roleUpdated = (Role) roleRes.getEntity();
684 Assert.assertNotNull(roleUpdated);
685 if (logger.isDebugEnabled()) {
686 logger.debug(testName + "Updated role: ");
687 logger.debug(objectAsXmlString(roleUpdated,Role.class));
691 RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getMetadataProtection()),
692 "Role allowed update of the metadata protection flag.");
694 RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getPermsProtection()),
695 "Role allowed update of the perms protection flag.");
700 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
701 dependsOnMethods = {"read", "readList", "readNonExistent"})
702 public void updateNotAllowed(String testName) throws Exception {
707 Role roleToUpdate = new Role();
708 roleToUpdate.setCsid(knownResourceId);
709 // Update the content of this resource.
710 roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
711 roleToUpdate.setDisplayName("UPDATED-ROLE_USERS_TEST");
712 if (logger.isDebugEnabled()) {
713 logger.debug("updated object");
714 logger.debug(objectAsXmlString(roleToUpdate,
717 RoleClient client = new RoleClient();
718 // Submit the request to the service and store the response.
719 ClientResponse<Role> res = client.update(knownResourceId, roleToUpdate);
720 int statusCode = res.getStatus();
721 // Check the status code of the response: does it match the expected response(s)?
722 if (logger.isDebugEnabled()) {
723 logger.debug(testName + ": status = " + statusCode);
725 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
726 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
727 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
732 // Placeholders until the three tests below can be uncommented.
733 // See Issue CSPACE-401.
735 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
738 public void updateWithEmptyEntityBody(String testName) throws Exception {
739 //FIXME: Should this test really be empty? If so, please comment accordingly.
743 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
746 public void updateWithMalformedXml(String testName) throws Exception {
747 //FIXME: Should this test really be empty? If so, please comment accordingly.
751 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
754 public void updateWithWrongXmlSchema(String testName) throws Exception {
755 //FIXME: Should this test really be empty? If so, please comment accordingly.
759 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
762 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
763 dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
764 public void updateNonExistent(String testName) throws Exception {
766 if (logger.isDebugEnabled()) {
767 logger.debug(testBanner(testName, CLASS_NAME));
770 setupUpdateNonExistent();
772 // Submit the request to the service and store the response.
774 // Note: The ID used in this 'create' call may be arbitrary.
775 // The only relevant ID may be the one used in updateRole(), below.
776 RoleClient client = new RoleClient();
777 Role role = createRoleInstance("ROLE_XXX",
780 ClientResponse<Role> res =
781 client.update(NON_EXISTENT_ID, role);
782 int statusCode = res.getStatus();
784 // Check the status code of the response: does it match
785 // the expected response(s)?
786 if (logger.isDebugEnabled()) {
787 logger.debug(testName + ": status = " + statusCode);
789 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
794 // ---------------------------------------------------------------
795 // CRUD tests : DELETE tests
796 // ---------------------------------------------------------------
799 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
802 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
803 dependsOnMethods = {"updateNotAllowed", "testSubmitRequest", "verifyProtectionReadOnly"})
804 public void delete(String testName) throws Exception {
806 if (logger.isDebugEnabled()) {
807 logger.debug(testBanner(testName, CLASS_NAME));
812 // Submit the request to the service and store the response.
813 RoleClient client = new RoleClient();
814 ClientResponse<Response> res = client.delete(knownResourceId);
815 int statusCode = res.getStatus();
817 // Check the status code of the response: does it match
818 // the expected response(s)?
819 if (logger.isDebugEnabled()) {
820 logger.debug(testName + ": status = " + statusCode);
822 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
823 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
824 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
829 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
832 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
833 dependsOnMethods = {"delete"})
834 public void deleteNonExistent(String testName) throws Exception {
836 if (logger.isDebugEnabled()) {
837 logger.debug(testBanner(testName, CLASS_NAME));
840 setupDeleteNonExistent();
842 // Submit the request to the service and store the response.
843 RoleClient client = new RoleClient();
844 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
845 int statusCode = res.getStatus();
847 // Check the status code of the response: does it match
848 // the expected response(s)?
849 if (logger.isDebugEnabled()) {
850 logger.debug(testName + ": status = " + statusCode);
852 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
857 // ---------------------------------------------------------------
859 // ---------------------------------------------------------------
862 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
863 public void searchWorkflowDeleted(String testName) throws Exception {
864 // Fixme: null test for now, overriding test in base class
867 // ---------------------------------------------------------------
868 // Utility tests : tests of code used in tests above
869 // ---------------------------------------------------------------
871 * Tests the code for manually submitting data that is used by several
872 * of the methods above.
876 @Test(dependsOnMethods = {"create"})
877 public void testSubmitRequest() throws Exception {
879 // Expected status code: 200 OK
880 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
882 // Submit the request to the service and store the response.
883 String method = ServiceRequestType.READ.httpMethodName();
884 String url = getResourceURL(knownResourceId);
885 int statusCode = submitRequest(method, url);
887 // Check the status code of the response: does it match
888 // the expected response(s)?
889 if (logger.isDebugEnabled()) {
890 logger.debug("testSubmitRequest: url=" + url
891 + " status=" + statusCode);
893 Assert.assertEquals(statusCode, EXPECTED_STATUS);
897 // ---------------------------------------------------------------
898 // Utility methods used by tests above
899 // ---------------------------------------------------------------
901 * create role instance
907 public Role createRoleInstance(String roleName,
909 boolean useRoleName) {
911 Role role = RoleFactory.createRoleInstance(roleName,
912 roleName, //the display name
915 if (logger.isDebugEnabled()) {
916 logger.debug("to be created, role");
917 logger.debug(objectAsXmlString(role, Role.class));
926 * @param testName the test name
927 * @param list the list
930 private int printList(String testName, RolesList list) {
934 for (Role role : list.getRoles()) {
935 logger.debug(testName + " role csid=" + role.getCsid()
936 + " name=" + role.getRoleName()
937 + " desc=" + role.getDescription());