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;
38 import org.testng.Assert;
39 import org.testng.annotations.Test;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
44 * AccountServiceTest, carries out tests against a
45 * deployed and running Account Service.
47 * $LastChangedRevision: 917 $
48 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
50 public class AccountServiceTest extends AbstractServiceTestImpl<AccountsCommonList, AccountsCommon, AccountsCommon, AccountsCommon> {
52 /** The Constant logger. */
53 private final String CLASS_NAME = AccountServiceTest.class.getName();
54 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
56 // Instance variables specific to this test.
57 private String prebuiltAdminCSID = null;
58 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
59 private String knownUserId = "barney";
60 private String knownUserPassword = "hithere08";
61 /** The add tenant. */
62 static boolean addTenant = true;
65 public String getServiceName() {
66 return AccountClient.SERVICE_NAME;
70 * The entity type expected from the JAX-RS Response object
72 public Class<AccountsCommon> getEntityResponseType() {
73 return AccountsCommon.class;
77 * This method is called only by the parent class, AbstractServiceTestImpl
80 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
83 protected String getServicePathComponent() {
84 return new AccountClient().getServicePathComponent();
88 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
91 protected CollectionSpaceClient getClientInstance() {
92 return new AccountClient();
96 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
97 return new AccountClient(clientPropertiesFilename);
101 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
104 protected AccountsCommonList getCommonList(Response response) {
105 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
106 throw new UnsupportedOperationException();
109 protected Class<AccountsCommonList> getCommonListType() {
110 return (Class<AccountsCommonList>) AccountsCommonList.class;
114 public void readPaginatedList(String testName) throws Exception {
115 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
118 // ---------------------------------------------------------------
119 // CRUD tests : CREATE tests
120 // ---------------------------------------------------------------
124 * Creates the for unique user.
126 * @param testName the test name
127 * @throws Exception the exception
129 @Test(dataProvider = "testName",
130 dependsOnMethods = {"CRUDTests"})
131 public void createForUniqueUser(String testName) throws Exception {
134 // Submit the request to the service and store the response.
135 AccountClient client = new AccountClient();
136 AccountsCommon account =
137 createAccountInstance("barney1", knownUserId, knownUserPassword,
138 "barney@dinoland.com",
139 client.getTenantId(), true, false, true, true);
141 Response res = client.create(account);
143 int statusCode = res.getStatus();
144 if (logger.isDebugEnabled()) {
145 logger.debug(testName + ": status = " + statusCode);
147 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
148 invalidStatusCodeMessage(testRequestType, statusCode));
149 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
156 * Creates the with invalid tenant.
158 * @param testName the test name
159 * @throws Exception the exception
161 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
162 public void createWithInvalidTenant(String testName) throws Exception {
165 // Submit the request to the service and store the response.
166 AccountClient client = new AccountClient();
167 AccountsCommon account =
168 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
169 client.getTenantId(), true, true, true, true);
170 Response res = client.create(account);
172 int statusCode = res.getStatus();
173 // Does it exactly match the expected status code?
174 if (logger.isDebugEnabled()) {
175 logger.debug(testName + ": status = " + statusCode);
177 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
178 invalidStatusCodeMessage(testRequestType, statusCode));
179 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
186 * Creates the without user.
188 * @param testName the test name
189 * @throws Exception the exception
191 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
192 public void createWithoutUser(String testName) throws Exception {
195 // Submit the request to the service and store the response.
196 AccountClient client = new AccountClient();
197 AccountsCommon account =
198 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
199 client.getTenantId(), true, false, false, true);
200 Response res = client.create(account);
202 int statusCode = res.getStatus();
203 // Does it exactly match the expected status code?
204 if (logger.isDebugEnabled()) {
205 logger.debug(testName + ": status = " + statusCode);
207 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
208 invalidStatusCodeMessage(testRequestType, statusCode));
209 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
216 * Creates the with invalid email.
218 * @param testName the test name
219 * @throws Exception the exception
221 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
222 public void createWithInvalidEmail(String testName) throws Exception {
225 // Submit the request to the service and store the response.
226 AccountClient client = new AccountClient();
227 AccountsCommon account =
228 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
229 client.getTenantId(), true, false, true, true);
230 Response res = client.create(account);
232 int statusCode = res.getStatus();
233 // Does it exactly match the expected status code?
234 if (logger.isDebugEnabled()) {
235 logger.debug(testName + ": status = " + statusCode);
237 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
238 invalidStatusCodeMessage(testRequestType, statusCode));
239 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
246 * Creates the without screen name.
248 * @param testName the test name
249 * @throws Exception the exception
251 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
252 public void createWithoutScreenName(String testName) throws Exception {
255 // Submit the request to the service and store the response.
256 AccountClient client = new AccountClient();
257 AccountsCommon account =
258 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
259 client.getTenantId(), false, false, true, true);
260 Response res = client.create(account);
262 int statusCode = res.getStatus();
263 // Does it exactly match the expected status code?
264 if (logger.isDebugEnabled()) {
265 logger.debug(testName + ": status = " + statusCode);
267 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
268 invalidStatusCodeMessage(testRequestType, statusCode));
269 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
276 * Creates the with invalid password.
278 * @param testName the test name
279 * @throws Exception the exception
281 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
282 public void createWithInvalidPassword(String testName) throws Exception {
285 // Submit the request to the service and store the response.
286 AccountClient client = new AccountClient();
287 AccountsCommon account =
288 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
289 client.getTenantId(), true, false, true, true);
290 Response res = client.create(account);
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(testRequestType.isValidStatusCode(statusCode),
298 invalidStatusCodeMessage(testRequestType, statusCode));
299 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
306 * Creates the with most invalid.
308 * @param testName the test name
309 * @throws Exception the exception
311 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
312 public void createWithMostInvalid(String testName) throws Exception {
315 // Submit the request to the service and store the response.
316 AccountClient client = new AccountClient();
317 AccountsCommon account =
318 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
319 client.getTenantId(), false, true, false, false);
320 Response res = client.create(account);
322 int statusCode = res.getStatus();
323 // Does it exactly match the expected status code?
324 if (logger.isDebugEnabled()) {
325 logger.debug(testName + ": status = " + statusCode);
327 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
328 invalidStatusCodeMessage(testRequestType, statusCode));
329 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
336 // To avoid uniqueness violations for accounts, createList is removed
339 public void createList(String testName) throws Exception {
341 // Submit the request to the service and store the response.
342 AccountClient client = new AccountClient();
343 AccountsCommon account1 =
344 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
345 client.getTenantId(), true, false, true, true);
346 Response res = client.create(account1);
348 int statusCode = res.getStatus();
349 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
350 invalidStatusCodeMessage(testRequestType, statusCode));
351 Assert.assertEquals(statusCode, testExpectedStatusCode);
352 allResourceIdsCreated.add(extractId(res));
357 AccountsCommon account2 =
358 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
359 client.getTenantId(), true, false, true, true);
360 res = client.create(account2);
362 int statusCode = res.getStatus();
363 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
364 invalidStatusCodeMessage(testRequestType, statusCode));
365 Assert.assertEquals(statusCode, testExpectedStatusCode);
366 Assert.assertEquals(statusCode, testExpectedStatusCode);
367 allResourceIdsCreated.add(extractId(res));
372 AccountsCommon account3 =
373 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
374 client.getTenantId(), true, false, true, true);
375 res = client.create(account3);
377 int statusCode = res.getStatus();
378 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
379 invalidStatusCodeMessage(testRequestType, statusCode));
380 Assert.assertEquals(statusCode, testExpectedStatusCode);
381 Assert.assertEquals(statusCode, testExpectedStatusCode);
382 allResourceIdsCreated.add(extractId(res));
389 // Tests with expected failure outcomes
391 // Placeholders until the three tests below can be uncommented.
392 // See Issue CSPACE-401.
394 public void createWithEmptyEntityBody(String testName) throws Exception {
395 //FIXME: Should this test really be empty? If so, please comment accordingly.
399 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
402 public void createWithMalformedXml(String testName) throws Exception {
403 //FIXME: Should this test really be empty? If so, please comment accordingly.
407 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
410 public void createWithWrongXmlSchema(String testName) throws Exception {
411 //FIXME: Should this test really be empty? If so, please comment accordingly.
414 // ---------------------------------------------------------------
415 // CRUD tests : READ_LIST tests
416 // ---------------------------------------------------------------
420 * Search screen name.
422 * @param testName the test name
423 * @throws Exception the exception
425 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
426 public void searchScreenName(String testName) throws Exception {
430 // Submit the request to the service and store the response.
431 AccountClient client = new AccountClient();
433 client.readSearchList("tom", null, null);
435 assertStatusCode(res, testName);
436 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
437 Assert.assertEquals(1, list.getAccountListItem().size());
438 // Optionally output additional data about list members for debugging.
439 boolean iterateThroughList = true;
440 if (iterateThroughList && logger.isDebugEnabled()) {
441 printList(testName, list);
451 @Test(dataProvider = "testName")
452 public void searchWorkflowDeleted(String testName) throws Exception {
453 // Fixme: null test for now, overriding test in base class
459 * @param testName the test name
460 * @throws Exception the exception
462 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
463 public void searchUserId(String testName) throws Exception {
467 // Submit the request to the service and store the response.
468 AccountClient client = new AccountClient();
469 Response res = client.readSearchList(null, "tom", null);
471 assertStatusCode(res, testName);
472 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
473 Assert.assertEquals(1, list.getAccountListItem().size());
474 // Optionally output additional data about list members for debugging.
475 boolean iterateThroughList = true;
476 if (iterateThroughList && logger.isDebugEnabled()) {
477 printList(testName, list);
489 * @param testName the test name
490 * @throws Exception the exception
492 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
493 public void searchEmail(String testName) throws Exception {
497 // Submit the request to the service and store the response.
498 AccountClient client = new AccountClient();
499 Response res = client.readSearchList(null, null, "dinoland");
501 assertStatusCode(res, testName);
502 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
503 Assert.assertEquals(2, list.getAccountListItem().size());
504 // Optionally output additional data about list members for debugging.
505 boolean iterateThroughList = true;
506 if (iterateThroughList && logger.isDebugEnabled()) {
507 printList(testName, list);
517 * Search screen name email.
519 * @param testName the test name
520 * @throws Exception the exception
522 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
523 public void searchScreenNameEmail(String testName) throws Exception {
527 // Submit the request to the service and store the response.
528 AccountClient client = new AccountClient();
529 Response res = client.readSearchList("tom", null, "jerry");
531 assertStatusCode(res, testName);
532 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
533 Assert.assertEquals(1, list.getAccountListItem().size());
534 // Optionally output additional data about list members for debugging.
535 boolean iterateThroughList = true;
536 if (iterateThroughList && logger.isDebugEnabled()) {
537 printList(testName, list);
546 // ---------------------------------------------------------------
547 // CRUD tests : UPDATE tests
548 // ---------------------------------------------------------------
553 * @param testName the test name
554 * @throws Exception the exception
556 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
557 public void updatePassword(String testName) throws Exception {
561 AccountClient client = new AccountClient();
562 Response res = client.read(knownResourceId);
563 AccountsCommon accountFound = null;
565 if (logger.isDebugEnabled()) {
566 logger.debug(testName + ": read status = " + res.getStatus());
568 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
570 if (logger.isDebugEnabled()) {
571 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
573 accountFound = res.readEntity(AccountsCommon.class);
574 Assert.assertNotNull(accountFound);
579 //create a new account object to test partial updates
580 AccountsCommon accountToUpdate = new AccountsCommon();
581 accountToUpdate.setCsid(knownResourceId);
582 accountToUpdate.setUserId(accountFound.getUserId());
584 accountToUpdate.setPassword("imagination".getBytes());
585 if (logger.isDebugEnabled()) {
586 logger.debug(testName + ": updated object");
587 logger.debug(objectAsXmlString(accountToUpdate,
588 AccountsCommon.class));
591 // Submit the request to the service and store the response.
592 res = client.update(knownResourceId, accountToUpdate);
593 int statusCode = res.getStatus();
595 // Check the status code of the response: does it match the expected response(s)?
596 if (logger.isDebugEnabled()) {
597 logger.debug(testName + ": status = " + statusCode);
599 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
600 invalidStatusCodeMessage(testRequestType, statusCode));
601 Assert.assertEquals(statusCode, testExpectedStatusCode);
603 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
604 Assert.assertNotNull(accountUpdated);
606 // Assert.assertEquals(accountUpdated.getPassword(),
607 // accountFound.getPassword(),
608 // "Data in updated object did not match submitted data.");
615 * Update password without user.
617 * @param testName the test name
618 * @throws Exception the exception
620 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
621 public void updatePasswordWithoutUser(String testName) throws Exception {
625 AccountsCommon accountToUpdate = new AccountsCommon();
626 accountToUpdate.setCsid(knownResourceId);
627 accountToUpdate.setUserId(null);
629 accountToUpdate.setPassword("imagination".getBytes());
630 if (logger.isDebugEnabled()) {
631 logger.debug(testName + " : updated object");
632 logger.debug(objectAsXmlString(accountToUpdate,
633 AccountsCommon.class));
636 AccountClient client = new AccountClient();
637 // Submit the request to the service and store the response.
638 Response res = client.update(knownResourceId, accountToUpdate);
640 int statusCode = res.getStatus();
641 // Check the status code of the response: does it match the expected response(s)?
642 if (logger.isDebugEnabled()) {
643 logger.debug(testName + ": status = " + statusCode);
645 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(testRequestType, statusCode));
647 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
654 * Update invalid password.
656 * @param testName the test name
657 * @throws Exception the exception
659 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
660 public void updateInvalidPassword(String testName) throws Exception {
663 AccountClient client = new AccountClient();
664 Response res = client.read(knownResourceId);
665 AccountsCommon accountFound = null;
667 if (logger.isDebugEnabled()) {
668 logger.debug(testName + ": read status = " + res.getStatus());
670 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
672 if (logger.isDebugEnabled()) {
673 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
675 accountFound = res.readEntity(AccountsCommon.class);
680 AccountsCommon accountToUpdate = new AccountsCommon();
681 accountToUpdate.setCsid(knownResourceId);
682 accountToUpdate.setUserId(accountFound.getUserId());
683 Assert.assertNotNull(accountToUpdate);
686 accountToUpdate.setPassword("abc123".getBytes());
687 if (logger.isDebugEnabled()) {
688 logger.debug(testName + ": updated object");
689 logger.debug(objectAsXmlString(accountToUpdate,
690 AccountsCommon.class));
693 // Submit the request to the service and store the response.
694 res = client.update(knownResourceId, accountToUpdate);
696 int statusCode = res.getStatus();
697 // Check the status code of the response: does it match the expected response(s)?
698 if (logger.isDebugEnabled()) {
699 logger.debug(testName + ": status = " + statusCode);
701 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
702 invalidStatusCodeMessage(testRequestType, statusCode));
703 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
709 private void findPrebuiltAdminAccount() {
710 // Search for the prebuilt admin user and then hold its CSID
711 if (prebuiltAdminCSID == null) {
713 AccountClient client = new AccountClient();
714 Response res = client.readSearchList(null, this.prebuiltAdminUserId, null);
716 assertStatusCode(res, "findPrebuiltAdminAccount");
717 AccountsCommonList list = res.readEntity(AccountsCommonList.class);
718 List<AccountListItem> items = list.getAccountListItem();
719 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
720 AccountListItem item = items.get(0);
721 prebuiltAdminCSID = item.getCsid();
722 if (logger.isDebugEnabled()) {
723 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
733 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
734 public void verifyMetadataProtection(String testName) throws Exception {
735 findPrebuiltAdminAccount();
736 // Try to update the metadata - it should just get ignored
740 AccountClient client = new AccountClient();
741 Response res = client.read(prebuiltAdminCSID);
742 AccountsCommon accountFound = null;
744 if (logger.isDebugEnabled()) {
745 logger.debug(testName + ": read status = " + res.getStatus());
747 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
749 if (logger.isDebugEnabled()) {
750 logger.debug("Did get on Admin Account to update with ID: " + prebuiltAdminCSID);
752 accountFound = res.readEntity(AccountsCommon.class);
753 Assert.assertNotNull(accountFound);
758 //create a new account object to test partial updates
759 AccountsCommon accountToUpdate = new AccountsCommon();
760 accountToUpdate.setCsid(prebuiltAdminCSID);
761 accountToUpdate.setUserId(accountFound.getUserId());
762 // Update the content of this resource.
763 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
764 if (logger.isDebugEnabled()) {
765 logger.debug("updated object");
766 logger.debug(objectAsXmlString(accountFound,
767 AccountsCommon.class));
770 // Submit the request to the service and store the response.
771 res = client.update(prebuiltAdminCSID, accountToUpdate);
773 int statusCode = res.getStatus();
774 // Check the status code of the response: does it match the expected response(s)?
775 if (logger.isDebugEnabled()) {
776 logger.debug(testName + ": status = " + statusCode);
778 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
779 invalidStatusCodeMessage(testRequestType, statusCode));
780 // Note that the error is not returned, it is just ignored
781 Assert.assertEquals(statusCode, testExpectedStatusCode);
783 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
784 Assert.assertNotNull(accountUpdated);
786 Assert.assertFalse(accountUpdated.getEmail().equals(accountToUpdate.getEmail()),
787 "Admin Account (with metadata lock) allowed update to change the email!");
794 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
795 public void verifyProtectionReadOnly(String testName) throws Exception {
798 // Submit the request to the service and store the response.
799 AccountClient client = new AccountClient();
800 AccountsCommon account = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
801 client.getTenantId(), true, false, true, true);
802 account.setMetadataProtection(AccountClient.IMMUTABLE);
803 account.setRolesProtection(AccountClient.IMMUTABLE);
804 Response res = client.create(account);
805 String testResourceId = null;
807 assertStatusCode(res, testName);
808 // Store the ID returned from this create operation
809 // for additional tests below.
810 testResourceId = extractId(res);
811 allResourceIdsCreated.add(testResourceId);
812 if (logger.isDebugEnabled()) {
813 logger.debug(testName + ": testResourceId=" + testResourceId);
823 // Submit the request to the service and store the response.
824 Response accountRes = client.read(testResourceId);
826 assertStatusCode(accountRes, testName);
827 AccountsCommon accountRead = accountRes.readEntity(AccountsCommon.class);
828 Assert.assertNotNull(accountRead);
829 String mdProtection = accountRead.getMetadataProtection();
830 String rolesProtection = accountRead.getRolesProtection();
831 if (logger.isTraceEnabled()) {
832 logger.trace(testName + ": metadataProtection=" + mdProtection);
833 logger.trace(testName + ": rolesProtection=" + rolesProtection);
835 Assert.assertFalse(account.getMetadataProtection().equals(mdProtection),
836 "Account allowed create to set the metadata protection flag.");
837 Assert.assertFalse(account.getRolesProtection().equals(rolesProtection),
838 "Account allowed create to set the perms protection flag.");
840 if (accountRes != null) {
847 AccountsCommon accountToUpdate = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
848 client.getTenantId(), true, false, true, true);
849 accountToUpdate.setMetadataProtection(AccountClient.IMMUTABLE);
850 accountToUpdate.setRolesProtection(AccountClient.IMMUTABLE);
852 // Submit the request to the service and store the response.
853 accountRes = client.update(testResourceId, accountToUpdate);
855 assertStatusCode(accountRes, testName);
856 AccountsCommon accountUpdated = accountRes.readEntity(AccountsCommon.class);
857 Assert.assertNotNull(accountUpdated);
858 if (logger.isDebugEnabled()) {
859 logger.debug(testName + "Updated account: ");
860 logger.debug(objectAsXmlString(accountUpdated, AccountsCommon.class));
863 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()),
864 "Account allowed update of the metadata protection flag.");
866 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()),
867 "Account allowed update of the roles protection flag.");
869 if (accountRes != null) {
878 * @param testName the test name
879 * @throws Exception the exception
881 @Test(dataProvider = "testName", dependsOnMethods = {"updatePasswordWithoutUser"})
882 public void deactivate(String testName) throws Exception {
886 AccountClient client = new AccountClient();
887 Response res = client.read(knownResourceId);
888 AccountsCommon accountFound = null;
890 if (logger.isDebugEnabled()) {
891 logger.debug(testName + ": read status = " + res.getStatus());
893 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
895 if (logger.isDebugEnabled()) {
896 logger.debug("got object to update with ID: " + knownResourceId);
898 accountFound = res.readEntity(AccountsCommon.class);
903 //create a new account object to test partial updates
904 AccountsCommon accountToUpdate = new AccountsCommon();
905 accountToUpdate.setCsid(knownResourceId);
906 accountToUpdate.setUserId(accountFound.getUserId());
908 // Update the content of this resource.
909 accountToUpdate.setStatus(Status.INACTIVE);
910 if (logger.isDebugEnabled()) {
911 logger.debug("updated object");
912 logger.debug(objectAsXmlString(accountToUpdate,
913 AccountsCommon.class));
916 // Submit the request to the service and store the response.
917 res = client.update(knownResourceId, accountToUpdate);
919 int statusCode = res.getStatus();
920 // Check the status code of the response: does it match the expected response(s)?
921 if (logger.isDebugEnabled()) {
922 logger.debug(testName + ": status = " + statusCode);
924 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
925 invalidStatusCodeMessage(testRequestType, statusCode));
926 Assert.assertEquals(statusCode, testExpectedStatusCode);
928 AccountsCommon accountUpdated = res.readEntity(AccountsCommon.class);
929 Assert.assertNotNull(accountUpdated);
931 Assert.assertEquals(accountUpdated.getStatus(),
932 accountToUpdate.getStatus(),
933 "Data in updated object did not match submitted data.");
940 // Placeholders until the three tests below can be uncommented.
941 // See Issue CSPACE-401.
943 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
946 public void updateWithEmptyEntityBody(String testName) throws Exception {
947 //FIXME: Should this test really be empty? If so, please comment accordingly.
951 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
954 public void updateWithMalformedXml(String testName) throws Exception {
955 //FIXME: Should this test really be empty? If so, please comment accordingly.
959 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
962 public void updateWithWrongXmlSchema(String testName) throws Exception {
963 //FIXME: Should this test really be empty? If so, please comment accordingly.
967 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
968 public void updateNonExistent(String testName) throws Exception {
970 setupUpdateNonExistent();
972 // Submit the request to the service and store the response.
974 // Note: The ID used in this 'create' call may be arbitrary.
975 // The only relevant ID may be the one used in updateAccount(), below.
976 AccountClient client = new AccountClient();
977 AccountsCommon account = createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
978 client.getTenantId(), true, false, true, true);
979 Response res = client.update(NON_EXISTENT_ID, account);
981 int statusCode = res.getStatus();
983 // Check the status code of the response: does it match
984 // the expected response(s)?
985 if (logger.isDebugEnabled()) {
986 logger.debug(testName + ": status = " + statusCode);
988 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
989 invalidStatusCodeMessage(testRequestType, statusCode));
990 Assert.assertEquals(statusCode, testExpectedStatusCode);
999 * @param testName the test name
1000 * @throws Exception the exception
1002 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
1003 public void updateWrongUser(String testName) throws Exception {
1006 // Submit the request to the service and store the response.
1008 // Note: The ID used in this 'create' call may be arbitrary.
1009 // The only relevant ID may be the one used in updateAccount(), below.
1010 AccountClient client = new AccountClient();
1011 Response res = client.read(knownResourceId);
1012 AccountsCommon accountToUpdate = null;
1014 if (logger.isDebugEnabled()) {
1015 logger.debug(testName + ": read status = " + res.getStatus());
1017 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1019 if (logger.isDebugEnabled()) {
1020 logger.debug("got object to update with ID: " + knownResourceId);
1022 accountToUpdate = res.readEntity(AccountsCommon.class);
1023 Assert.assertNotNull(accountToUpdate);
1028 accountToUpdate.setUserId("barneyFake");
1029 if (logger.isDebugEnabled()) {
1030 logger.debug("updated object with wrongUser");
1031 logger.debug(objectAsXmlString(accountToUpdate,
1032 AccountsCommon.class));
1035 res = client.update(knownResourceId, accountToUpdate);
1037 int statusCode = res.getStatus();
1039 // Check the status code of the response: does it match
1040 // the expected response(s)?
1041 if (logger.isDebugEnabled()) {
1042 logger.debug(testName + ": status = " + statusCode);
1044 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1045 invalidStatusCodeMessage(testRequestType, statusCode));
1046 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1052 // ---------------------------------------------------------------
1053 // CRUD tests : DELETE tests
1054 // ---------------------------------------------------------------
1058 public void delete(String testName) throws Exception {
1059 // Do nothing because this test is not ready to delete the "knownResourceId".
1060 // Instead, the method localDelete() will get called later in the dependency chain. The
1061 // method localDelete() has a dependency on the test "updateWrongUser". Once the "updateWrongUser"
1062 // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn
1063 // calls the inherited delete() test/method.
1066 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "updateWrongUser"})
1067 public void localDelete(String testName) throws Exception {
1068 // Because of issues with TestNG not allowing @Test annotations on on override methods,
1069 // and because we want the "updateWrongUser" to run before the "delete" test, we need
1070 // this method. This method will call super.delete() after all the dependencies have been
1072 super.delete(testName);
1075 // ---------------------------------------------------------------
1076 // Utility methods used by tests above
1077 // ---------------------------------------------------------------
1079 * create account instance
1084 * @param useScreenName
1085 * @param invalidTenant
1087 * @param usePassword
1090 AccountsCommon createAccountInstance(String screenName,
1091 String userName, String passwd, String email, String tenantId,
1092 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1094 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1095 userName, passwd, email, tenantId, useScreenName,
1096 invalidTenant, useUser, usePassword);
1097 if (logger.isDebugEnabled()) {
1098 logger.debug("to be created, account common");
1099 logger.debug(objectAsXmlString(account,
1100 AccountsCommon.class));
1110 * @param testName the test name
1111 * @param list the list
1114 protected void printList(String testName, AccountsCommonList list) {
1115 AccountsCommonList acl = (AccountsCommonList)list;
1116 List<AccountListItem> items =
1117 acl.getAccountListItem();
1119 for (AccountListItem item : items) {
1120 logger.debug(testName + ": list-item[" + i + "] csid="
1122 logger.debug(testName + ": list-item[" + i + "] screenName="
1123 + item.getScreenName());
1124 logger.debug(testName + ": list-item[" + i + "] URI="
1131 protected AccountsCommon createInstance(String commonPartName,
1132 String identifier) {
1133 AccountClient client = new AccountClient();
1134 AccountsCommon account =
1135 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
1136 "barney@dinoland.com", client.getTenantId(),
1137 true, false, true, true);
1142 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
1143 * refer to this method in their @Test annotation declarations.
1146 @Test(dataProvider = "testName",
1147 dependsOnMethods = {
1148 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
1149 public void CRUDTests(String testName) {
1150 // Do nothing. Simply here to for a TestNG execution order for our tests
1154 protected AccountsCommon updateInstance(AccountsCommon accountsCommon) {
1155 AccountsCommon result = new AccountsCommon();
1157 result.setCsid(knownResourceId);
1158 result.setUserId(accountsCommon.getUserId());
1159 // Update the content of this resource.
1160 result.setEmail("updated-" + accountsCommon.getEmail());
1166 protected void compareUpdatedInstances(AccountsCommon original,
1167 AccountsCommon updated) throws Exception {
1168 Assert.assertEquals(original.getEmail(), updated.getEmail(),
1169 "Data in updated object did not match submitted data.");
1173 protected long getSizeOfList(AccountsCommonList list) {
1174 return list.getTotalItems();