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.account.client.test;
25 import java.util.List;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.AccountClient;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.account.AccountsCommon;
32 import org.collectionspace.services.account.AccountsCommonList;
33 import org.collectionspace.services.account.AccountListItem;
34 import org.collectionspace.services.account.Status;
35 import org.collectionspace.services.client.AccountFactory;
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 * AccountServiceTest, carries out tests against a
44 * deployed and running Account Service.
46 * $LastChangedRevision: 917 $
47 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
49 public class AccountServiceTest extends AbstractServiceTestImpl<AccountsCommonList, AccountsCommon, AccountsCommon, AccountsCommon> {
51 /** The Constant logger. */
52 private final String CLASS_NAME = AccountServiceTest.class.getName();
53 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
55 // Instance variables specific to this test.
56 private String prebuiltAdminCSID = null;
57 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
58 private String knownUserId = "barney";
59 private String knownUserPassword = "hithere08";
60 /** The add tenant. */
61 static boolean addTenant = true;
64 public String getServiceName() {
65 return AccountClient.SERVICE_NAME;
69 * The entity type expected from the JAX-RS Response object
71 public Class<AccountsCommon> getEntityResponseType() {
72 return AccountsCommon.class;
76 * This method is called only by the parent class, AbstractServiceTestImpl
79 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
82 protected String getServicePathComponent() throws Exception {
83 return new AccountClient().getServicePathComponent();
87 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
90 protected CollectionSpaceClient getClientInstance() throws Exception {
91 return new AccountClient();
95 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
96 return new AccountClient(clientPropertiesFilename);
100 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
103 protected AccountsCommonList getCommonList(Response response) {
104 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
105 throw new UnsupportedOperationException();
108 protected Class<AccountsCommonList> getCommonListType() {
109 return (Class<AccountsCommonList>) AccountsCommonList.class;
113 public void readPaginatedList(String testName) throws Exception {
114 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
117 // ---------------------------------------------------------------
118 // CRUD tests : CREATE tests
119 // ---------------------------------------------------------------
123 * Creates the for unique user.
125 * @param testName the test name
126 * @throws Exception the exception
128 @Test(dataProvider = "testName",
129 dependsOnMethods = {"CRUDTests"})
130 public void createForUniqueUser(String testName) throws Exception {
133 // Submit the request to the service and store the response.
134 AccountClient client = new AccountClient();
135 AccountsCommon account =
136 createAccountInstance("barney1", knownUserId, knownUserPassword,
137 "barney@dinoland.com",
138 client.getTenantId(), true, false, true, true);
140 Response res = client.create(account);
142 int statusCode = res.getStatus();
143 if (logger.isDebugEnabled()) {
144 logger.debug(testName + ": status = " + statusCode);
146 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
147 invalidStatusCodeMessage(testRequestType, statusCode));
148 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
155 * Creates the with invalid tenant.
157 * @param testName the test name
158 * @throws Exception the exception
160 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
161 public void createWithInvalidTenant(String testName) throws Exception {
164 // Submit the request to the service and store the response.
165 AccountClient client = new AccountClient();
166 AccountsCommon account =
167 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
168 client.getTenantId(), true, true, true, true);
169 Response res = client.create(account);
171 int statusCode = res.getStatus();
172 // Does it exactly match the expected status code?
173 if (logger.isDebugEnabled()) {
174 logger.debug(testName + ": status = " + statusCode);
176 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
177 invalidStatusCodeMessage(testRequestType, statusCode));
178 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
185 * Creates the without user.
187 * @param testName the test name
188 * @throws Exception the exception
190 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
191 public void createWithoutUser(String testName) throws Exception {
194 // Submit the request to the service and store the response.
195 AccountClient client = new AccountClient();
196 AccountsCommon account =
197 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
198 client.getTenantId(), true, false, false, true);
199 Response res = client.create(account);
201 int statusCode = res.getStatus();
202 // Does it exactly match the expected status code?
203 if (logger.isDebugEnabled()) {
204 logger.debug(testName + ": status = " + statusCode);
206 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
207 invalidStatusCodeMessage(testRequestType, statusCode));
208 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
215 * Creates the with invalid email.
217 * @param testName the test name
218 * @throws Exception the exception
220 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
221 public void createWithInvalidEmail(String testName) throws Exception {
224 // Submit the request to the service and store the response.
225 AccountClient client = new AccountClient();
226 AccountsCommon account =
227 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
228 client.getTenantId(), true, false, true, true);
229 Response res = client.create(account);
231 int statusCode = res.getStatus();
232 // Does it exactly match the expected status code?
233 if (logger.isDebugEnabled()) {
234 logger.debug(testName + ": status = " + statusCode);
236 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
237 invalidStatusCodeMessage(testRequestType, statusCode));
238 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
245 * Creates the without screen name.
247 * @param testName the test name
248 * @throws Exception the exception
250 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
251 public void createWithoutScreenName(String testName) throws Exception {
254 // Submit the request to the service and store the response.
255 AccountClient client = new AccountClient();
256 AccountsCommon account =
257 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
258 client.getTenantId(), false, false, true, true);
259 Response res = client.create(account);
261 int statusCode = res.getStatus();
262 // Does it exactly match the expected status code?
263 if (logger.isDebugEnabled()) {
264 logger.debug(testName + ": status = " + statusCode);
266 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
267 invalidStatusCodeMessage(testRequestType, statusCode));
268 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
275 * Creates the with invalid password.
277 * @param testName the test name
278 * @throws Exception the exception
280 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
281 public void createWithInvalidPassword(String testName) throws Exception {
284 // Submit the request to the service and store the response.
285 AccountClient client = new AccountClient();
286 AccountsCommon account =
287 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
288 client.getTenantId(), true, false, true, true);
289 Response res = client.create(account);
291 int statusCode = res.getStatus();
292 // Does it exactly match the expected status code?
293 if (logger.isDebugEnabled()) {
294 logger.debug(testName + ": status = " + statusCode);
296 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
297 invalidStatusCodeMessage(testRequestType, statusCode));
298 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
305 * Creates the with most invalid.
307 * @param testName the test name
308 * @throws Exception the exception
310 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
311 public void createWithMostInvalid(String testName) throws Exception {
314 // Submit the request to the service and store the response.
315 AccountClient client = new AccountClient();
316 AccountsCommon account =
317 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
318 client.getTenantId(), false, true, false, false);
319 Response res = client.create(account);
321 int statusCode = res.getStatus();
322 // Does it exactly match the expected status code?
323 if (logger.isDebugEnabled()) {
324 logger.debug(testName + ": status = " + statusCode);
326 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(testRequestType, statusCode));
328 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
335 // To avoid uniqueness violations for accounts, createList is removed
338 public void createList(String testName) throws Exception {
340 // Submit the request to the service and store the response.
341 AccountClient client = new AccountClient();
342 AccountsCommon account1 =
343 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
344 client.getTenantId(), true, false, true, true);
345 Response res = client.create(account1);
347 int statusCode = res.getStatus();
348 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
349 invalidStatusCodeMessage(testRequestType, statusCode));
350 Assert.assertEquals(statusCode, testExpectedStatusCode);
351 allResourceIdsCreated.add(extractId(res));
356 AccountsCommon account2 =
357 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
358 client.getTenantId(), true, false, true, true);
359 res = client.create(account2);
361 int statusCode = res.getStatus();
362 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
363 invalidStatusCodeMessage(testRequestType, statusCode));
364 Assert.assertEquals(statusCode, testExpectedStatusCode);
365 Assert.assertEquals(statusCode, testExpectedStatusCode);
366 allResourceIdsCreated.add(extractId(res));
371 AccountsCommon account3 =
372 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
373 client.getTenantId(), true, false, true, true);
374 res = client.create(account3);
376 int statusCode = res.getStatus();
377 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
378 invalidStatusCodeMessage(testRequestType, statusCode));
379 Assert.assertEquals(statusCode, testExpectedStatusCode);
380 Assert.assertEquals(statusCode, testExpectedStatusCode);
381 allResourceIdsCreated.add(extractId(res));
388 // Tests with expected failure outcomes
390 // Placeholders until the three tests below can be uncommented.
391 // See Issue CSPACE-401.
393 public void createWithEmptyEntityBody(String testName) throws Exception {
394 //FIXME: Should this test really be empty? If so, please comment accordingly.
398 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
401 public void createWithMalformedXml(String testName) throws Exception {
402 //FIXME: Should this test really be empty? If so, please comment accordingly.
406 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
409 public void createWithWrongXmlSchema(String testName) throws Exception {
410 //FIXME: Should this test really be empty? If so, please comment accordingly.
413 // ---------------------------------------------------------------
414 // CRUD tests : READ_LIST tests
415 // ---------------------------------------------------------------
419 * Search screen name.
421 * @param testName the test name
422 * @throws Exception the exception
424 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
425 public void searchScreenName(String testName) throws Exception {
429 // Submit the request to the service and store the response.
430 AccountClient client = new AccountClient();
432 client.readSearchList("tom", null, null);
434 assertStatusCode(res, testName);
435 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
436 Assert.assertEquals(1, list.getAccountListItem().size());
437 // Optionally output additional data about list members for debugging.
438 boolean iterateThroughList = true;
439 if (iterateThroughList && logger.isDebugEnabled()) {
440 printList(testName, list);
450 @Test(dataProvider = "testName")
451 public void searchWorkflowDeleted(String testName) throws Exception {
452 // Fixme: null test for now, overriding test in base class
458 * @param testName the test name
459 * @throws Exception the exception
461 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
462 public void searchUserId(String testName) throws Exception {
466 // Submit the request to the service and store the response.
467 AccountClient client = new AccountClient();
468 Response res = client.readSearchList(null, "tom", null);
470 assertStatusCode(res, testName);
471 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
472 Assert.assertEquals(1, list.getAccountListItem().size());
473 // Optionally output additional data about list members for debugging.
474 boolean iterateThroughList = true;
475 if (iterateThroughList && logger.isDebugEnabled()) {
476 printList(testName, list);
488 * @param testName the test name
489 * @throws Exception the exception
491 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
492 public void searchEmail(String testName) throws Exception {
496 // Submit the request to the service and store the response.
497 AccountClient client = new AccountClient();
498 Response res = client.readSearchList(null, null, "dinoland");
500 assertStatusCode(res, testName);
501 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
502 Assert.assertEquals(2, list.getAccountListItem().size());
503 // Optionally output additional data about list members for debugging.
504 boolean iterateThroughList = true;
505 if (iterateThroughList && logger.isDebugEnabled()) {
506 printList(testName, list);
516 * Search screen name email.
518 * @param testName the test name
519 * @throws Exception the exception
521 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
522 public void searchScreenNameEmail(String testName) throws Exception {
526 // Submit the request to the service and store the response.
527 AccountClient client = new AccountClient();
528 Response res = client.readSearchList("tom", null, "jerry");
530 assertStatusCode(res, testName);
531 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
532 Assert.assertEquals(1, list.getAccountListItem().size());
533 // Optionally output additional data about list members for debugging.
534 boolean iterateThroughList = true;
535 if (iterateThroughList && logger.isDebugEnabled()) {
536 printList(testName, list);
545 // ---------------------------------------------------------------
546 // CRUD tests : UPDATE tests
547 // ---------------------------------------------------------------
552 * @param testName the test name
553 * @throws Exception the exception
555 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
556 public void updatePassword(String testName) throws Exception {
560 AccountClient client = new AccountClient();
561 Response res = client.read(knownResourceId);
562 AccountsCommon accountFound = null;
564 if (logger.isDebugEnabled()) {
565 logger.debug(testName + ": read status = " + res.getStatus());
567 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
569 if (logger.isDebugEnabled()) {
570 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
572 accountFound = res.readEntity(AccountsCommon.class);
573 Assert.assertNotNull(accountFound);
578 //create a new account object to test partial updates
579 AccountsCommon accountToUpdate = new AccountsCommon();
580 accountToUpdate.setCsid(knownResourceId);
581 accountToUpdate.setUserId(accountFound.getUserId());
583 accountToUpdate.setPassword("imagination".getBytes());
584 if (logger.isDebugEnabled()) {
585 logger.debug(testName + ": updated object");
586 logger.debug(objectAsXmlString(accountToUpdate,
587 AccountsCommon.class));
590 // Submit the request to the service and store the response.
591 res = client.update(knownResourceId, accountToUpdate);
592 int statusCode = res.getStatus();
594 // Check the status code of the response: does it match the expected response(s)?
595 if (logger.isDebugEnabled()) {
596 logger.debug(testName + ": status = " + statusCode);
598 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
599 invalidStatusCodeMessage(testRequestType, statusCode));
600 Assert.assertEquals(statusCode, testExpectedStatusCode);
602 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
603 Assert.assertNotNull(accountUpdated);
605 // Assert.assertEquals(accountUpdated.getPassword(),
606 // accountFound.getPassword(),
607 // "Data in updated object did not match submitted data.");
614 * Update password without user.
616 * @param testName the test name
617 * @throws Exception the exception
619 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
620 public void updatePasswordWithoutUser(String testName) throws Exception {
624 AccountsCommon accountToUpdate = new AccountsCommon();
625 accountToUpdate.setCsid(knownResourceId);
626 accountToUpdate.setUserId(null);
628 accountToUpdate.setPassword("imagination".getBytes());
629 if (logger.isDebugEnabled()) {
630 logger.debug(testName + " : updated object");
631 logger.debug(objectAsXmlString(accountToUpdate,
632 AccountsCommon.class));
635 AccountClient client = new AccountClient();
636 // Submit the request to the service and store the response.
637 Response res = client.update(knownResourceId, accountToUpdate);
639 int statusCode = res.getStatus();
640 // Check the status code of the response: does it match the expected response(s)?
641 if (logger.isDebugEnabled()) {
642 logger.debug(testName + ": status = " + statusCode);
644 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(testRequestType, statusCode));
646 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
653 * Update invalid password.
655 * @param testName the test name
656 * @throws Exception the exception
658 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
659 public void updateInvalidPassword(String testName) throws Exception {
662 AccountClient client = new AccountClient();
663 Response res = client.read(knownResourceId);
664 AccountsCommon accountFound = null;
666 if (logger.isDebugEnabled()) {
667 logger.debug(testName + ": read status = " + res.getStatus());
669 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
671 if (logger.isDebugEnabled()) {
672 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
674 accountFound = res.readEntity(AccountsCommon.class);
679 AccountsCommon accountToUpdate = new AccountsCommon();
680 accountToUpdate.setCsid(knownResourceId);
681 accountToUpdate.setUserId(accountFound.getUserId());
682 Assert.assertNotNull(accountToUpdate);
685 accountToUpdate.setPassword("abc123".getBytes());
686 if (logger.isDebugEnabled()) {
687 logger.debug(testName + ": updated object");
688 logger.debug(objectAsXmlString(accountToUpdate,
689 AccountsCommon.class));
692 // Submit the request to the service and store the response.
693 res = client.update(knownResourceId, accountToUpdate);
695 int statusCode = res.getStatus();
696 // Check the status code of the response: does it match the expected response(s)?
697 if (logger.isDebugEnabled()) {
698 logger.debug(testName + ": status = " + statusCode);
700 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
701 invalidStatusCodeMessage(testRequestType, statusCode));
702 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
708 private void findPrebuiltAdminAccount() throws Exception {
709 // Search for the prebuilt admin user and then hold its CSID
710 if (prebuiltAdminCSID == null) {
712 AccountClient client = new AccountClient();
713 Response res = client.readSearchList(null, this.prebuiltAdminUserId, null);
715 assertStatusCode(res, "findPrebuiltAdminAccount");
716 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
717 List<AccountListItem> items = list.getAccountListItem();
718 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
719 AccountListItem item = items.get(0);
720 prebuiltAdminCSID = item.getCsid();
721 if (logger.isDebugEnabled()) {
722 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
732 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
733 public void verifyMetadataProtection(String testName) throws Exception {
734 findPrebuiltAdminAccount();
735 // Try to update the metadata - it should just get ignored
739 AccountClient client = new AccountClient();
740 Response res = client.read(prebuiltAdminCSID);
741 AccountsCommon accountFound = null;
743 if (logger.isDebugEnabled()) {
744 logger.debug(testName + ": read status = " + res.getStatus());
746 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
748 if (logger.isDebugEnabled()) {
749 logger.debug("Did get on Admin Account to update with ID: " + prebuiltAdminCSID);
751 accountFound = res.readEntity(AccountsCommon.class);
752 Assert.assertNotNull(accountFound);
757 //create a new account object to test partial updates
758 AccountsCommon accountToUpdate = new AccountsCommon();
759 accountToUpdate.setCsid(prebuiltAdminCSID);
760 accountToUpdate.setUserId(accountFound.getUserId());
761 // Update the content of this resource.
762 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
763 if (logger.isDebugEnabled()) {
764 logger.debug("updated object");
765 logger.debug(objectAsXmlString(accountFound,
766 AccountsCommon.class));
769 // Submit the request to the service and store the response.
770 res = client.update(prebuiltAdminCSID, accountToUpdate);
772 int statusCode = res.getStatus();
773 // Check the status code of the response: does it match the expected response(s)?
774 if (logger.isDebugEnabled()) {
775 logger.debug(testName + ": status = " + statusCode);
777 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
778 invalidStatusCodeMessage(testRequestType, statusCode));
779 // Note that the error is not returned, it is just ignored
780 Assert.assertEquals(statusCode, testExpectedStatusCode);
782 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
783 Assert.assertNotNull(accountUpdated);
785 Assert.assertFalse(accountUpdated.getEmail().equals(accountToUpdate.getEmail()),
786 "Admin Account (with metadata lock) allowed update to change the email!");
793 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
794 public void verifyProtectionReadOnly(String testName) throws Exception {
797 // Submit the request to the service and store the response.
798 AccountClient client = new AccountClient();
799 AccountsCommon account = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
800 client.getTenantId(), true, false, true, true);
801 account.setMetadataProtection(AccountClient.IMMUTABLE);
802 account.setRolesProtection(AccountClient.IMMUTABLE);
803 Response res = client.create(account);
804 String testResourceId = null;
806 assertStatusCode(res, testName);
807 // Store the ID returned from this create operation
808 // for additional tests below.
809 testResourceId = extractId(res);
810 allResourceIdsCreated.add(testResourceId);
811 if (logger.isDebugEnabled()) {
812 logger.debug(testName + ": testResourceId=" + testResourceId);
822 // Submit the request to the service and store the response.
823 Response accountRes = client.read(testResourceId);
825 assertStatusCode(accountRes, testName);
826 AccountsCommon accountRead = accountRes.readEntity(AccountsCommon.class);
827 Assert.assertNotNull(accountRead);
828 String mdProtection = accountRead.getMetadataProtection();
829 String rolesProtection = accountRead.getRolesProtection();
830 if (logger.isTraceEnabled()) {
831 logger.trace(testName + ": metadataProtection=" + mdProtection);
832 logger.trace(testName + ": rolesProtection=" + rolesProtection);
834 Assert.assertFalse(account.getMetadataProtection().equals(mdProtection),
835 "Account allowed create to set the metadata protection flag.");
836 Assert.assertFalse(account.getRolesProtection().equals(rolesProtection),
837 "Account allowed create to set the perms protection flag.");
839 if (accountRes != null) {
846 AccountsCommon accountToUpdate = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
847 client.getTenantId(), true, false, true, true);
848 accountToUpdate.setMetadataProtection(AccountClient.IMMUTABLE);
849 accountToUpdate.setRolesProtection(AccountClient.IMMUTABLE);
851 // Submit the request to the service and store the response.
852 accountRes = client.update(testResourceId, accountToUpdate);
854 assertStatusCode(accountRes, testName);
855 AccountsCommon accountUpdated = accountRes.readEntity(AccountsCommon.class);
856 Assert.assertNotNull(accountUpdated);
857 if (logger.isDebugEnabled()) {
858 logger.debug(testName + "Updated account: ");
859 logger.debug(objectAsXmlString(accountUpdated, AccountsCommon.class));
862 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()),
863 "Account allowed update of the metadata protection flag.");
865 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()),
866 "Account allowed update of the roles protection flag.");
868 if (accountRes != null) {
877 * @param testName the test name
878 * @throws Exception the exception
880 @Test(dataProvider = "testName", dependsOnMethods = {"updatePasswordWithoutUser"})
881 public void deactivate(String testName) throws Exception {
885 AccountClient client = new AccountClient();
886 Response res = client.read(knownResourceId);
887 AccountsCommon accountFound = null;
889 if (logger.isDebugEnabled()) {
890 logger.debug(testName + ": read status = " + res.getStatus());
892 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
894 if (logger.isDebugEnabled()) {
895 logger.debug("got object to update with ID: " + knownResourceId);
897 accountFound = res.readEntity(AccountsCommon.class);
902 //create a new account object to test partial updates
903 AccountsCommon accountToUpdate = new AccountsCommon();
904 accountToUpdate.setCsid(knownResourceId);
905 accountToUpdate.setUserId(accountFound.getUserId());
907 // Update the content of this resource.
908 accountToUpdate.setStatus(Status.INACTIVE);
909 if (logger.isDebugEnabled()) {
910 logger.debug("updated object");
911 logger.debug(objectAsXmlString(accountToUpdate,
912 AccountsCommon.class));
915 // Submit the request to the service and store the response.
916 res = client.update(knownResourceId, accountToUpdate);
918 int statusCode = res.getStatus();
919 // Check the status code of the response: does it match the expected response(s)?
920 if (logger.isDebugEnabled()) {
921 logger.debug(testName + ": status = " + statusCode);
923 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
924 invalidStatusCodeMessage(testRequestType, statusCode));
925 Assert.assertEquals(statusCode, testExpectedStatusCode);
927 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
928 Assert.assertNotNull(accountUpdated);
930 Assert.assertEquals(accountUpdated.getStatus(),
931 accountToUpdate.getStatus(),
932 "Data in updated object did not match submitted data.");
939 // Placeholders until the three tests below can be uncommented.
940 // See Issue CSPACE-401.
942 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
945 public void updateWithEmptyEntityBody(String testName) throws Exception {
946 //FIXME: Should this test really be empty? If so, please comment accordingly.
950 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
953 public void updateWithMalformedXml(String testName) throws Exception {
954 //FIXME: Should this test really be empty? If so, please comment accordingly.
958 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
961 public void updateWithWrongXmlSchema(String testName) throws Exception {
962 //FIXME: Should this test really be empty? If so, please comment accordingly.
966 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
967 public void updateNonExistent(String testName) throws Exception {
969 setupUpdateNonExistent();
971 // Submit the request to the service and store the response.
973 // Note: The ID used in this 'create' call may be arbitrary.
974 // The only relevant ID may be the one used in updateAccount(), below.
975 AccountClient client = new AccountClient();
976 AccountsCommon account = createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
977 client.getTenantId(), true, false, true, true);
978 Response res = client.update(NON_EXISTENT_ID, account);
980 int statusCode = res.getStatus();
982 // Check the status code of the response: does it match
983 // the expected response(s)?
984 if (logger.isDebugEnabled()) {
985 logger.debug(testName + ": status = " + statusCode);
987 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
988 invalidStatusCodeMessage(testRequestType, statusCode));
989 Assert.assertEquals(statusCode, testExpectedStatusCode);
998 * @param testName the test name
999 * @throws Exception the exception
1001 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
1002 public void updateWrongUser(String testName) throws Exception {
1005 // Submit the request to the service and store the response.
1007 // Note: The ID used in this 'create' call may be arbitrary.
1008 // The only relevant ID may be the one used in updateAccount(), below.
1009 AccountClient client = new AccountClient();
1010 Response res = client.read(knownResourceId);
1011 AccountsCommon accountToUpdate = null;
1013 if (logger.isDebugEnabled()) {
1014 logger.debug(testName + ": read status = " + res.getStatus());
1016 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1018 if (logger.isDebugEnabled()) {
1019 logger.debug("got object to update with ID: " + knownResourceId);
1021 accountToUpdate = res.readEntity(AccountsCommon.class);
1022 Assert.assertNotNull(accountToUpdate);
1027 accountToUpdate.setUserId("barneyFake");
1028 if (logger.isDebugEnabled()) {
1029 logger.debug("updated object with wrongUser");
1030 logger.debug(objectAsXmlString(accountToUpdate,
1031 AccountsCommon.class));
1034 res = client.update(knownResourceId, accountToUpdate);
1036 int statusCode = res.getStatus();
1038 // Check the status code of the response: does it match
1039 // the expected response(s)?
1040 if (logger.isDebugEnabled()) {
1041 logger.debug(testName + ": status = " + statusCode);
1043 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1044 invalidStatusCodeMessage(testRequestType, statusCode));
1045 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1051 // ---------------------------------------------------------------
1052 // CRUD tests : DELETE tests
1053 // ---------------------------------------------------------------
1057 public void delete(String testName) throws Exception {
1058 // Do nothing because this test is not ready to delete the "knownResourceId".
1059 // Instead, the method localDelete() will get called later in the dependency chain. The
1060 // method localDelete() has a dependency on the test "updateWrongUser". Once the "updateWrongUser"
1061 // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn
1062 // calls the inherited delete() test/method.
1065 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "updateWrongUser"})
1066 public void localDelete(String testName) throws Exception {
1067 // Because of issues with TestNG not allowing @Test annotations on on override methods,
1068 // and because we want the "updateWrongUser" to run before the "delete" test, we need
1069 // this method. This method will call super.delete() after all the dependencies have been
1071 super.delete(testName);
1074 // ---------------------------------------------------------------
1075 // Utility methods used by tests above
1076 // ---------------------------------------------------------------
1078 * create account instance
1083 * @param useScreenName
1084 * @param invalidTenant
1086 * @param usePassword
1089 AccountsCommon createAccountInstance(String screenName,
1090 String userName, String passwd, String email, String tenantId,
1091 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1093 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1094 userName, passwd, email, tenantId, useScreenName,
1095 invalidTenant, useUser, usePassword);
1096 if (logger.isDebugEnabled()) {
1097 logger.debug("to be created, account common");
1098 logger.debug(objectAsXmlString(account,
1099 AccountsCommon.class));
1109 * @param testName the test name
1110 * @param list the list
1113 protected void printList(String testName, AccountsCommonList list) {
1114 AccountsCommonList acl = (AccountsCommonList)list;
1115 List<AccountListItem> items =
1116 acl.getAccountListItem();
1118 for (AccountListItem item : items) {
1119 logger.debug(testName + ": list-item[" + i + "] csid="
1121 logger.debug(testName + ": list-item[" + i + "] screenName="
1122 + item.getScreenName());
1123 logger.debug(testName + ": list-item[" + i + "] URI="
1130 protected AccountsCommon createInstance(String commonPartName,
1131 String identifier) throws Exception {
1132 AccountClient client = new AccountClient();
1133 AccountsCommon account =
1134 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
1135 "barney@dinoland.com", client.getTenantId(),
1136 true, false, true, true);
1141 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
1142 * refer to this method in their @Test annotation declarations.
1145 @Test(dataProvider = "testName",
1146 dependsOnMethods = {
1147 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
1148 public void CRUDTests(String testName) {
1149 // Do nothing. Simply here to for a TestNG execution order for our tests
1153 protected AccountsCommon updateInstance(AccountsCommon accountsCommon) {
1154 AccountsCommon result = new AccountsCommon();
1156 result.setCsid(knownResourceId);
1157 result.setUserId(accountsCommon.getUserId());
1158 // Update the content of this resource.
1159 result.setEmail("updated-" + accountsCommon.getEmail());
1165 protected void compareUpdatedInstances(AccountsCommon original,
1166 AccountsCommon updated) throws Exception {
1167 Assert.assertEquals(original.getEmail(), updated.getEmail(),
1168 "Data in updated object did not match submitted data.");
1172 protected long getSizeOfList(AccountsCommonList list) {
1173 return list.getTotalItems();