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 java.util.Random;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.RoleClient;
33 import org.collectionspace.services.authorization.Role;
34 import org.collectionspace.services.authorization.RolesList;
35 import org.collectionspace.services.client.RoleFactory;
36 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
37 import org.testng.Assert;
38 import org.testng.annotations.Test;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
43 * RoleServiceTest, carries out tests against a
44 * deployed and running Role Service.
46 * $LastChangedRevision: 917 $
47 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
49 public class RoleServiceTest extends AbstractServiceTestImpl<RolesList, Role, Role, Role> {
52 private final static String CLASS_NAME = RoleServiceTest.class.getName();
53 private final static Logger logger = LoggerFactory.getLogger(CLASS_NAME);
55 // Used to create unique identifiers
56 static private final Random random = new Random(System.currentTimeMillis());
58 // Instance variables specific to this test.
59 /** The known resource id. */
60 private String knownRoleName = "ROLE_USERS_MOCK-1";
61 private String knownRoleDisplayName = "ROLE_DISPLAYNAME_USERS_MOCK-1";
62 private String verifyResourceId = null;
63 private String verifyRoleName = "collections_manager_mock-1";
64 // private List<String> allResourceIdsCreated = new ArrayList<String>();
67 public String getServiceName() {
68 return RoleClient.SERVICE_NAME;
72 protected String getServicePathComponent() throws Exception {
73 return new RoleClient().getServicePathComponent();
77 * The entity type expected from the JAX-RS Response object
79 public Class<Role> getEntityResponseType() {
84 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
87 protected CollectionSpaceClient getClientInstance() throws Exception {
88 return new RoleClient();
92 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
93 return new RoleClient(clientPropertiesFilename);
97 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
100 public void readPaginatedList(String testName) throws Exception {
101 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
104 // ---------------------------------------------------------------
105 // CRUD tests : CREATE tests
106 // ---------------------------------------------------------------
110 public void create(String testName) throws Exception {
111 // Perform setup, such as initializing the type of service request
112 // (e.g. CREATE, DELETE), its valid and expected status codes, and
113 // its associated HTTP method name (e.g. POST, DELETE).
116 // Submit the request to the service and store the response.
117 RoleClient client = new RoleClient();
118 Role role = createRoleInstance(knownRoleName, "All users are required to be in this role",
120 Response res = client.create(role);
122 int statusCode = res.getStatus();
123 // Check the status code of the response: does it match
124 // the expected response(s)?
127 // Does it fall within the set of valid status codes?
128 // Does it exactly match the expected status code?
129 if (logger.isDebugEnabled()) {
130 logger.debug(testName + ": status = " + statusCode);
132 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
133 invalidStatusCodeMessage(testRequestType, statusCode));
134 Assert.assertEquals(statusCode, testExpectedStatusCode);
136 // Store the ID returned from this create operation
137 // for additional tests below.
138 knownResourceId = extractId(res);
139 //allResourceIdsCreated.add(knownResourceId);
140 if (logger.isDebugEnabled()) {
141 logger.debug(testName + ": knownResourceId=" + knownResourceId);
148 @Test(dataProvider = "testName",
149 dependsOnMethods = {"CRUDTests"})
150 public void createWithDisplayname(String testName) throws Exception {
151 // Perform setup, such as initializing the type of service request
152 // (e.g. CREATE, DELETE), its valid and expected status codes, and
153 // its associated HTTP method name (e.g. POST, DELETE).
156 // Submit the request to the service and store the response.
157 RoleClient client = new RoleClient();
158 Role role = createRoleInstance(knownRoleName + "_" + knownRoleDisplayName,
159 "all users are required to be in this role", true);
160 role.setDisplayName(knownRoleDisplayName);
161 Response res = client.create(role);
163 int statusCode = res.getStatus();
164 // Check the status code of the response: does it match
165 // the expected response(s)?
168 // Does it fall within the set of valid status codes?
169 // Does it exactly match the expected status code?
170 if (logger.isDebugEnabled()) {
171 logger.debug(testName + ": status = " + statusCode);
173 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
174 invalidStatusCodeMessage(testRequestType, statusCode));
175 Assert.assertEquals(statusCode, testExpectedStatusCode);
177 // Store the ID returned from this create operation
178 // for additional tests below.
179 String csid = extractId(res);
180 allResourceIdsCreated.add(csid);
181 if (logger.isDebugEnabled()) {
182 logger.debug(testName + ": csid=" + csid);
191 * Creates the for unique role.
193 * @param testName the test name
194 * @throws Exception the exception
196 @Test(dataProvider = "testName",
197 dependsOnMethods = {"CRUDTests"})
198 public void createForUniqueRole(String testName) throws Exception {
201 // Submit the request to the service and store the response.
202 RoleClient client = new RoleClient();
203 Role role = createRoleInstance(knownRoleName,
205 Response res = client.create(role);
207 int statusCode = res.getStatus();
209 if (logger.isDebugEnabled()) {
210 logger.debug(testName + ": Role with name \"" +
211 knownRoleName + "\" should already exist, so this request should fail.");
212 logger.debug(testName + ": status = " + statusCode);
213 logger.debug(testName + ": " + res);
215 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(testRequestType, statusCode));
217 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
224 * Creates the for unique display name of role.
226 * @param testName the test name
227 * @throws Exception the exception
229 @Test(dataProvider = "testName",
230 dependsOnMethods = {"createWithDisplayname"})
231 public void createForUniqueDisplayRole(String testName) throws Exception {
234 // Submit the request to the service and store the response.
235 RoleClient client = new RoleClient();
236 Role role = createRoleInstance(knownRoleName + createIdentifier(),
237 "role users with non-unique display name",
239 role.setDisplayName(knownRoleDisplayName);
240 Response res = client.create(role);
242 int statusCode = res.getStatus();
244 if (logger.isDebugEnabled()) {
245 logger.debug(testName + ": Role with name \"" +
246 knownRoleName + "\" should already exist, so this request should fail.");
247 logger.debug(testName + ": status = " + statusCode);
248 logger.debug(testName + ": " + res);
250 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
251 invalidStatusCodeMessage(testRequestType, statusCode));
252 if (statusCode != Response.Status.BAD_REQUEST.getStatusCode()) {
253 // If the test fails then we've just created a Role that we need to delete, so
254 // store the ID returned from this create operation.
255 String csid = extractId(res);
256 allResourceIdsCreated.add(csid);
257 if (logger.isDebugEnabled()) {
258 logger.debug(testName + ": csid=" + csid);
260 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
267 protected String createIdentifier() {
268 long identifier = System.currentTimeMillis() + random.nextInt();
269 return Long.toString(identifier);
273 * Creates the without role name.
275 * @param testName the test name
276 * @throws Exception the exception
278 @Test(dataProvider = "testName",
279 dependsOnMethods = {"CRUDTests"})
280 public void createWithoutRoleName(String testName) throws Exception {
283 // Submit the request to the service and store the response.
284 RoleClient client = new RoleClient();
285 Role role = createRoleInstance("",
288 Response res = client.create(role);
290 int statusCode = res.getStatus();
291 // Does it exactly match the expected status code?
292 if (logger.isDebugEnabled()) {
293 logger.debug(testName + ": status = " + statusCode);
295 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
296 invalidStatusCodeMessage(testRequestType, statusCode));
297 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
303 //to not cause uniqueness violation for role, createList is removed
305 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
308 // @Test(dataProvider = "testName",
309 // dependsOnMethods = {"createWithDisplayname"})
310 public void createList(String testName) throws Exception {
313 // Submit the request to the service and store the response.
314 RoleClient client = new RoleClient();
315 //create a role with lowercase role name without role prefix
316 //the service should make it upper case and add the role prefix
317 Role role1 = createRoleInstance(verifyRoleName,
318 "collection manager", true);
319 Response res = client.create(role1);
321 int statusCode = res.getStatus();
322 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
323 invalidStatusCodeMessage(testRequestType, statusCode));
324 Assert.assertEquals(statusCode, testExpectedStatusCode);
325 verifyResourceId = extractId(res);
326 allResourceIdsCreated.add(verifyResourceId);
331 Role role2 = createRoleInstance("ROLE_COLLECTIONS_CURATOR_TEST",
332 "collections curator", true);
333 res = client.create(role2);
335 int statusCode = res.getStatus();
336 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
337 invalidStatusCodeMessage(testRequestType, statusCode));
338 Assert.assertEquals(statusCode, testExpectedStatusCode);
339 Assert.assertEquals(statusCode, testExpectedStatusCode);
340 allResourceIdsCreated.add(extractId(res));
345 Role role3 = createRoleInstance("ROLE_MOVINGIMAGE_ADMIN_TEST",
346 "moving image admin", true);
347 res = client.create(role3);
349 int statusCode = res.getStatus();
350 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
351 invalidStatusCodeMessage(testRequestType, statusCode));
352 Assert.assertEquals(statusCode, testExpectedStatusCode);
353 Assert.assertEquals(statusCode, testExpectedStatusCode);
354 allResourceIdsCreated.add(extractId(res));
361 // Placeholders until the three tests below can be uncommented.
362 // See Issue CSPACE-401.
364 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
367 public void createWithEmptyEntityBody(String testName) throws Exception {
368 //FIXME: Should this test really be empty? If so, please comment accordingly.
372 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
375 public void createWithMalformedXml(String testName) throws Exception {
376 //FIXME: Should this test really be empty? If so, please comment accordingly.
380 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
383 public void createWithWrongXmlSchema(String testName) throws Exception {
384 //FIXME: Should this test really be empty? If so, please comment accordingly.
387 // ---------------------------------------------------------------
388 // CRUD tests : READ tests
389 // ---------------------------------------------------------------
392 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
395 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
396 // dependsOnMethods = {"createForUniqueRole"})
397 public void read(String testName) throws Exception {
401 // Submit the request to the service and store the response.
402 RoleClient client = new RoleClient();
403 Response res = client.read(knownResourceId);
405 int statusCode = res.getStatus();
407 // Check the status code of the response: does it match
408 // the expected response(s)?
409 if (logger.isDebugEnabled()) {
410 logger.debug(testName + ": status = " + statusCode);
412 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(testRequestType, statusCode));
414 Assert.assertEquals(statusCode, testExpectedStatusCode);
416 Role output = res.readEntity(Role.class);
417 Assert.assertNotNull(output);
423 @Test(dataProvider = "testName",
424 dependsOnMethods = {"CRUDTests"})
425 public void readToVerify(String testName) throws Exception {
429 // Submit the request to the service and store the response.
430 RoleClient client = new RoleClient();
431 Response res = client.read(verifyResourceId);
433 int statusCode = res.getStatus();
435 // Check the status code of the response: does it match
436 // the expected response(s)?
437 if (logger.isDebugEnabled()) {
438 logger.debug(testName + ": status = " + statusCode);
440 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
441 invalidStatusCodeMessage(testRequestType, statusCode));
442 Assert.assertEquals(statusCode, testExpectedStatusCode);
444 Role output = res.readEntity(Role.class);
445 Assert.assertNotNull(output);
447 //FIXME: Tenant ID of "1" should not be hard coded
448 String roleNameToVerify = "ROLE_" +
450 verifyRoleName.toUpperCase();
451 Assert.assertEquals(output.getRoleName(), roleNameToVerify,
452 "RoleName fix did not work!");
459 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
463 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
464 // dependsOnMethods = {"read"})
465 public void readNonExistent(String testName) throws Exception {
467 setupReadNonExistent();
469 // Submit the request to the service and store the response.
470 RoleClient client = new RoleClient();
471 Response res = client.read(NON_EXISTENT_ID);
473 int statusCode = res.getStatus();
474 // Check the status code of the response: does it match
475 // the expected response(s)?
476 if (logger.isDebugEnabled()) {
477 logger.debug(testName + ": status = " + statusCode);
479 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
480 invalidStatusCodeMessage(testRequestType, statusCode));
481 Assert.assertEquals(statusCode, testExpectedStatusCode);
487 // ---------------------------------------------------------------
488 // CRUD tests : READ_LIST tests
489 // ---------------------------------------------------------------
492 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
495 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
496 // dependsOnMethods = {"createList", "read"})
497 public void readList(String testName) throws Exception {
501 // Submit the request to the service and store the response.
502 RoleClient client = new RoleClient();
503 Response res = client.readList();
505 // Check the status code of the response: does it match
506 // the expected response(s)?
507 assertStatusCode(res, testName);
508 RolesList list = res.readEntity(RolesList.class);
509 // Optionally output additional data about list members for debugging.
510 boolean iterateThroughList = true;
511 if (iterateThroughList && logger.isDebugEnabled()) {
512 printList(testName, list);
524 * @param testName the test name
525 * @throws Exception the exception
527 @Test(dataProvider = "testName",
528 dependsOnMethods = {"CRUDTests"})
529 public void searchRoleName(String testName) throws Exception {
533 // Submit the request to the service and store the response.
534 RoleClient client = new RoleClient();
535 Response res = client.readSearchList("movingImage");
537 assertStatusCode(res, testName);
538 RolesList list = res.readEntity(RolesList.class);
539 int EXPECTED_ITEMS = 1;
540 if (logger.isDebugEnabled()) {
541 logger.debug(testName + ": received = " + list.getRole().size()
542 + " expected=" + EXPECTED_ITEMS);
544 Assert.assertEquals(EXPECTED_ITEMS, list.getRole().size());
545 // Optionally output additional data about list members for debugging.
546 boolean iterateThroughList = true;
547 if (iterateThroughList && logger.isDebugEnabled()) {
548 printList(testName, list);
559 // ---------------------------------------------------------------
560 // CRUD tests : UPDATE tests
561 // ---------------------------------------------------------------
564 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
567 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
568 // dependsOnMethods = {"read", "readList", "readNonExistent"})
569 public void update(String testName) throws Exception {
573 Role roleToUpdate = new Role();
574 roleToUpdate.setCsid(knownResourceId);
575 roleToUpdate.setRoleName(knownRoleName);
576 roleToUpdate.setDisplayName(knownRoleName);
578 // Update the content of this resource.
579 roleToUpdate.setDescription("updated role description");
580 if (logger.isDebugEnabled()) {
581 logger.debug("updated object");
582 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
583 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
586 RoleClient client = new RoleClient();
587 // Submit the request to the service and store the response.
588 Response res = client.update(knownResourceId, roleToUpdate);
590 // Check the status code of the response: does it match the expected response(s)?
591 int statusCode = res.getStatus();
592 if (logger.isDebugEnabled()) {
593 logger.debug(testName + ": status = " + statusCode);
595 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
596 invalidStatusCodeMessage(testRequestType, statusCode));
597 Assert.assertEquals(statusCode, testExpectedStatusCode);
600 Role roleUpdated = res.readEntity(Role.class);
601 Assert.assertNotNull(roleUpdated);
603 Assert.assertEquals(roleUpdated.getDescription(),
604 roleToUpdate.getDescription(),
605 "Data in updated object did not match submitted data.");
611 @Test(dataProvider = "testName",
612 dependsOnMethods = {"CRUDTests"})
613 public void verifyProtectionReadOnly(String testName) throws Exception {
614 // Setup to create a new role
616 Role role = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
617 role.setMetadataProtection(RoleClient.IMMUTABLE);
618 role.setPermsProtection(RoleClient.IMMUTABLE);
620 // Submit the create request to the service and store the response.
622 RoleClient client = new RoleClient();
623 Response res = client.create(role);
624 String testResourceId = null;
626 int statusCode = res.getStatus();
627 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
628 invalidStatusCodeMessage(testRequestType, statusCode));
629 Assert.assertEquals(statusCode, testExpectedStatusCode);
630 // Store the ID returned from this create operation
631 // for additional tests below.
632 testResourceId = extractId(res);
633 allResourceIdsCreated.add(testResourceId);
634 if (logger.isDebugEnabled()) {
635 logger.debug(testName + ": testResourceId=" + testResourceId);
641 // Next, read back the role we just created.
643 // Submit the request to the service and store the response.
644 Response roleRes = client.read(testResourceId);
646 int statusCode = roleRes.getStatus();
647 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
648 invalidStatusCodeMessage(testRequestType, statusCode));
649 Assert.assertEquals(statusCode, testExpectedStatusCode);
651 Role roleRead = roleRes.readEntity(Role.class);
652 Assert.assertNotNull(roleRead);
653 String mdProtection = roleRead.getMetadataProtection();
654 String permsProtection = roleRead.getPermsProtection();
655 if (logger.isTraceEnabled()) {
656 logger.trace(testName + ": metadataProtection=" + mdProtection);
657 logger.trace(testName + ": permsProtection=" + permsProtection);
659 Assert.assertFalse(role.getMetadataProtection().equals(mdProtection),
660 "Role allowed create to set the metadata protection flag.");
661 Assert.assertFalse(role.getPermsProtection().equals(permsProtection),
662 "Role allowed create to set the perms protection flag.");
666 // Finally, update the role with changes and verify
669 Role roleToUpdate = createRoleInstance(knownRoleName+"_PT", "Just a temp", true);
670 roleToUpdate.setMetadataProtection(RoleClient.IMMUTABLE);
671 roleToUpdate.setPermsProtection(RoleClient.IMMUTABLE);
673 // Submit the request to the service and store the response.
674 roleRes = client.update(testResourceId, roleToUpdate);
676 // Check the status code of the response: does it match the expected response(s)?
677 int statusCode = roleRes.getStatus();
678 if (logger.isDebugEnabled()) {
679 logger.debug(testName + ": status = " + statusCode);
681 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(testRequestType, statusCode));
683 Assert.assertEquals(statusCode, testExpectedStatusCode);
686 Role roleUpdated = roleRes.readEntity(Role.class);
687 Assert.assertNotNull(roleUpdated);
688 if (logger.isDebugEnabled()) {
689 logger.debug(testName + "Updated role: ");
690 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
691 logger.debug(objectAsXmlString(objectFactory.createRole(roleUpdated),
695 Assert.assertFalse(RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getMetadataProtection()),
696 "Role allowed update of the metadata protection flag.");
697 Assert.assertFalse(RoleClient.IMMUTABLE.equalsIgnoreCase(roleUpdated.getPermsProtection()),
698 "Role allowed update of the perms protection flag.");
704 @Test(dataProvider = "testName",
705 dependsOnMethods = {"CRUDTests"})
706 public void updateNotAllowed(String testName) throws Exception {
711 Role roleToUpdate = new Role();
712 roleToUpdate.setCsid(knownResourceId);
713 // Update the content of this resource.
714 roleToUpdate.setRoleName("UPDATED-ROLE_USERS_TEST");
715 roleToUpdate.setDisplayName("UPDATED-ROLE_USERS_TEST");
716 if (logger.isDebugEnabled()) {
717 logger.debug("updated object");
718 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
719 logger.debug(objectAsXmlString(objectFactory.createRole(roleToUpdate),
722 RoleClient client = new RoleClient();
723 // Submit the request to the service and store the response.
724 Response res = client.update(knownResourceId, roleToUpdate);
726 int statusCode = res.getStatus();
727 // Check the status code of the response: does it match the expected response(s)?
728 if (logger.isDebugEnabled()) {
729 logger.debug(testName + ": status = " + statusCode);
731 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
732 invalidStatusCodeMessage(testRequestType, statusCode));
733 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
740 // Placeholders until the three tests below can be uncommented.
741 // See Issue CSPACE-401.
743 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
746 public void updateWithEmptyEntityBody(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#updateWithMalformedXml(java.lang.String)
754 public void updateWithMalformedXml(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#updateWithWrongXmlSchema(java.lang.String)
762 public void updateWithWrongXmlSchema(String testName) throws Exception {
763 //FIXME: Should this test really be empty? If so, please comment accordingly.
767 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
771 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
772 // dependsOnMethods = {"readNonExistent", "testSubmitRequest"})
773 public void updateNonExistent(String testName) throws Exception {
775 setupUpdateNonExistent();
777 // Submit the request to the service and store the response.
779 // Note: The ID used in this 'create' call may be arbitrary.
780 // The only relevant ID may be the one used in updateRole(), below.
781 RoleClient client = new RoleClient();
782 Role role = createRoleInstance("ROLE_XXX",
785 Response res = client.update(NON_EXISTENT_ID, role);
787 int statusCode = res.getStatus();
789 // Check the status code of the response: does it match
790 // the expected response(s)?
791 if (logger.isDebugEnabled()) {
792 logger.debug(testName + ": status = " + statusCode);
794 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
795 invalidStatusCodeMessage(testRequestType, statusCode));
796 Assert.assertEquals(statusCode, testExpectedStatusCode);
802 // ---------------------------------------------------------------
803 // CRUD tests : DELETE tests
804 // ---------------------------------------------------------------
807 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
810 public void delete(String testName) throws Exception {
811 // Do nothing since other tests like "updateNotAllowed" need the "known resource" that this test
812 // deletes. Once all those tests get run, the "localDelete" method will call the base class' delete
813 // method that will delete the "known resource".
816 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
817 dependsOnMethods = {"updateNotAllowed", "createForUniqueRole", "createForUniqueDisplayRole"})
818 public void localDelete(String testName) throws Exception {
819 super.delete(testName);
824 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
827 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
828 // dependsOnMethods = {"delete"})
829 public void deleteNonExistent(String testName) throws Exception {
831 setupDeleteNonExistent();
833 // Submit the request to the service and store the response.
834 RoleClient client = new RoleClient();
835 Response res = client.delete(NON_EXISTENT_ID);
837 int statusCode = res.getStatus();
839 // Check the status code of the response: does it match
840 // the expected response(s)?
841 if (logger.isDebugEnabled()) {
842 logger.debug(testName + ": status = " + statusCode);
844 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
845 invalidStatusCodeMessage(testRequestType, statusCode));
846 Assert.assertEquals(statusCode, testExpectedStatusCode);
852 // ---------------------------------------------------------------
854 // ---------------------------------------------------------------
857 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
858 public void searchWorkflowDeleted(String testName) throws Exception {
859 // Fixme: null test for now, overriding test in base class
862 // ---------------------------------------------------------------
863 // Utility tests : tests of code used in tests above
864 // ---------------------------------------------------------------
866 * Tests the code for manually submitting data that is used by several
867 * of the methods above.
871 // ---------------------------------------------------------------
872 // Utility methods used by tests above
873 // ---------------------------------------------------------------
875 * create role instance
881 public Role createRoleInstance(String roleName,
883 boolean useRoleName) {
885 Role role = RoleFactory.createRoleInstance(roleName,
886 roleName, //the display name
889 if (logger.isDebugEnabled()) {
890 logger.debug("to be created, role");
891 org.collectionspace.services.authorization.ObjectFactory objectFactory = new org.collectionspace.services.authorization.ObjectFactory();
892 logger.debug(objectAsXmlString(objectFactory.createRole(role),
902 * @param testName the test name
903 * @param list the list
906 protected void printList(String testName, RolesList list) {
907 for (Role role : list.getRole()) {
908 logger.debug(testName + " role csid=" + role.getCsid()
909 + " name=" + role.getRoleName()
910 + " desc=" + role.getDescription());
915 protected Role createInstance(String commonPartName, String identifier) {
916 // TODO Auto-generated method stub
921 protected Role updateInstance(Role commonPartObject) {
922 // TODO Auto-generated method stub
927 protected void compareUpdatedInstances(Role original, Role updated)
929 // TODO Auto-generated method stub
934 protected Class<RolesList> getCommonListType() {
935 // TODO Auto-generated method stub
940 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
941 * refer to this method in their @Test annotation declarations.
944 @Test(dataProvider = "testName",
946 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
947 public void CRUDTests(String testName) {
948 // Do nothing. Simply here to for a TestNG execution order for our tests
952 protected long getSizeOfList(RolesList list) {
953 return list.getRole().size();