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;
26 import javax.ws.rs.core.Response;
27 import org.jboss.resteasy.client.ClientResponse;
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;
35 import org.collectionspace.services.account.Status;
36 import org.collectionspace.services.client.AccountFactory;
37 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
38 import org.collectionspace.services.client.test.ServiceRequestType;
40 import org.testng.Assert;
41 import org.testng.annotations.Test;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * AccountServiceTest, carries out tests against a
48 * deployed and running Account Service.
50 * $LastChangedRevision: 917 $
51 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
53 public class AccountServiceTest extends AbstractServiceTestImpl<AccountsCommonList, AccountsCommon, AccountsCommon, AccountsCommon> {
55 /** The Constant logger. */
56 private final String CLASS_NAME = AccountServiceTest.class.getName();
57 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
59 // Instance variables specific to this test.
60 private String prebuiltAdminCSID = null;
61 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
62 private String knownUserId = "barney";
63 private String knownUserPassword = "hithere08";
64 /** The add tenant. */
65 static boolean addTenant = true;
68 public String getServiceName() {
69 return AccountClient.SERVICE_NAME;
73 * This method is called only by the parent class, AbstractServiceTestImpl
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
79 protected String getServicePathComponent() {
80 return new AccountClient().getServicePathComponent();
84 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
87 protected CollectionSpaceClient getClientInstance() {
88 return new AccountClient();
92 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
95 protected AccountsCommonList getCommonList(
96 ClientResponse<AccountsCommonList> response) {
97 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
98 throw new UnsupportedOperationException();
101 protected Class<AccountsCommonList> getCommonListType() {
102 return (Class<AccountsCommonList>) AccountsCommonList.class;
106 public void readPaginatedList(String testName) throws Exception {
107 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
110 // ---------------------------------------------------------------
111 // CRUD tests : CREATE tests
112 // ---------------------------------------------------------------
116 * Creates the for unique user.
118 * @param testName the test name
119 * @throws Exception the exception
121 @Test(dataProvider = "testName",
122 dependsOnMethods = {"CRUDTests"})
123 public void createForUniqueUser(String testName) throws Exception {
126 // Submit the request to the service and store the response.
127 AccountClient client = new AccountClient();
128 AccountsCommon account =
129 createAccountInstance("barney1", knownUserId, knownUserPassword,
130 "barney@dinoland.com",
131 client.getTenantId(), true, false, true, true);
133 ClientResponse<Response> res = client.create(account);
134 int statusCode = res.getStatus();
135 if (logger.isDebugEnabled()) {
136 logger.debug(testName + ": status = " + statusCode);
138 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
139 invalidStatusCodeMessage(testRequestType, statusCode));
140 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
144 * Creates the with invalid tenant.
146 * @param testName the test name
147 * @throws Exception the exception
149 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
150 public void createWithInvalidTenant(String testName) throws Exception {
153 // Submit the request to the service and store the response.
154 AccountClient client = new AccountClient();
155 AccountsCommon account =
156 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
157 client.getTenantId(), true, true, true, true);
158 ClientResponse<Response> res = client.create(account);
159 int statusCode = res.getStatus();
160 // Does it exactly match the expected status code?
161 if (logger.isDebugEnabled()) {
162 logger.debug(testName + ": status = " + statusCode);
164 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
165 invalidStatusCodeMessage(testRequestType, statusCode));
166 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
170 * Creates the without user.
172 * @param testName the test name
173 * @throws Exception the exception
175 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
176 public void createWithoutUser(String testName) throws Exception {
179 // Submit the request to the service and store the response.
180 AccountClient client = new AccountClient();
181 AccountsCommon account =
182 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
183 client.getTenantId(), true, false, false, true);
184 ClientResponse<Response> res = client.create(account);
185 int statusCode = res.getStatus();
186 // Does it exactly match the expected status code?
187 if (logger.isDebugEnabled()) {
188 logger.debug(testName + ": status = " + statusCode);
190 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
191 invalidStatusCodeMessage(testRequestType, statusCode));
192 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
196 * Creates the with invalid email.
198 * @param testName the test name
199 * @throws Exception the exception
201 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
202 public void createWithInvalidEmail(String testName) throws Exception {
205 // Submit the request to the service and store the response.
206 AccountClient client = new AccountClient();
207 AccountsCommon account =
208 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
209 client.getTenantId(), true, false, true, true);
210 ClientResponse<Response> res = client.create(account);
211 int statusCode = res.getStatus();
212 // Does it exactly match the expected status code?
213 if (logger.isDebugEnabled()) {
214 logger.debug(testName + ": status = " + statusCode);
216 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
217 invalidStatusCodeMessage(testRequestType, statusCode));
218 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
222 * Creates the without screen name.
224 * @param testName the test name
225 * @throws Exception the exception
227 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
228 public void createWithoutScreenName(String testName) throws Exception {
231 // Submit the request to the service and store the response.
232 AccountClient client = new AccountClient();
233 AccountsCommon account =
234 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
235 client.getTenantId(), false, false, true, true);
236 ClientResponse<Response> res = client.create(account);
237 int statusCode = res.getStatus();
238 // Does it exactly match the expected status code?
239 if (logger.isDebugEnabled()) {
240 logger.debug(testName + ": status = " + statusCode);
242 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
243 invalidStatusCodeMessage(testRequestType, statusCode));
244 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
248 * Creates the with invalid password.
250 * @param testName the test name
251 * @throws Exception the exception
253 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
254 public void createWithInvalidPassword(String testName) throws Exception {
257 // Submit the request to the service and store the response.
258 AccountClient client = new AccountClient();
259 AccountsCommon account =
260 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
261 client.getTenantId(), true, false, true, true);
262 ClientResponse<Response> res = client.create(account);
263 int statusCode = res.getStatus();
264 // Does it exactly match the expected status code?
265 if (logger.isDebugEnabled()) {
266 logger.debug(testName + ": status = " + statusCode);
268 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
269 invalidStatusCodeMessage(testRequestType, statusCode));
270 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
274 * Creates the with most invalid.
276 * @param testName the test name
277 * @throws Exception the exception
279 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
280 public void createWithMostInvalid(String testName) throws Exception {
283 // Submit the request to the service and store the response.
284 AccountClient client = new AccountClient();
285 AccountsCommon account =
286 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
287 client.getTenantId(), false, true, false, false);
288 ClientResponse<Response> res = client.create(account);
289 int statusCode = res.getStatus();
290 // Does it exactly match the expected status code?
291 if (logger.isDebugEnabled()) {
292 logger.debug(testName + ": status = " + statusCode);
294 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
295 invalidStatusCodeMessage(testRequestType, statusCode));
296 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
300 // To avoid uniqueness violations for accounts, createList is removed
303 public void createList(String testName) throws Exception {
305 // Submit the request to the service and store the response.
306 AccountClient client = new AccountClient();
307 AccountsCommon account1 =
308 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
309 client.getTenantId(), true, false, true, true);
310 ClientResponse<Response> res = client.create(account1);
311 int statusCode = res.getStatus();
312 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
313 invalidStatusCodeMessage(testRequestType, statusCode));
314 Assert.assertEquals(statusCode, testExpectedStatusCode);
315 allResourceIdsCreated.add(extractId(res));
317 AccountsCommon account2 =
318 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
319 client.getTenantId(), true, false, true, true);
320 res = client.create(account2);
321 statusCode = res.getStatus();
322 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
323 invalidStatusCodeMessage(testRequestType, statusCode));
324 Assert.assertEquals(statusCode, testExpectedStatusCode);
325 Assert.assertEquals(statusCode, testExpectedStatusCode);
326 allResourceIdsCreated.add(extractId(res));
328 AccountsCommon account3 =
329 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
330 client.getTenantId(), true, false, true, true);
331 res = client.create(account3);
332 statusCode = res.getStatus();
333 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
334 invalidStatusCodeMessage(testRequestType, statusCode));
335 Assert.assertEquals(statusCode, testExpectedStatusCode);
336 Assert.assertEquals(statusCode, testExpectedStatusCode);
337 allResourceIdsCreated.add(extractId(res));
341 // Tests with expected failure outcomes
343 // Placeholders until the three tests below can be uncommented.
344 // See Issue CSPACE-401.
346 public void createWithEmptyEntityBody(String testName) throws Exception {
347 //FIXME: Should this test really be empty? If so, please comment accordingly.
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
354 public void createWithMalformedXml(String testName) throws Exception {
355 //FIXME: Should this test really be empty? If so, please comment accordingly.
359 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
362 public void createWithWrongXmlSchema(String testName) throws Exception {
363 //FIXME: Should this test really be empty? If so, please comment accordingly.
366 // ---------------------------------------------------------------
367 // CRUD tests : READ_LIST tests
368 // ---------------------------------------------------------------
372 * Search screen name.
374 * @param testName the test name
375 * @throws Exception the exception
377 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
378 public void searchScreenName(String testName) throws Exception {
382 // Submit the request to the service and store the response.
383 AccountClient client = new AccountClient();
384 ClientResponse<AccountsCommonList> res =
385 client.readSearchList("tom", null, null);
387 assertStatusCode(res, testName);
388 AccountsCommonList list = res.getEntity();
389 Assert.assertEquals(1, list.getAccountListItem().size());
390 // Optionally output additional data about list members for debugging.
391 boolean iterateThroughList = true;
392 if (iterateThroughList && logger.isDebugEnabled()) {
393 printList(testName, list);
397 res.releaseConnection();
403 @Test(dataProvider = "testName")
404 public void searchWorkflowDeleted(String testName) throws Exception {
405 // Fixme: null test for now, overriding test in base class
411 * @param testName the test name
412 * @throws Exception the exception
414 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
415 public void searchUserId(String testName) throws Exception {
419 // Submit the request to the service and store the response.
420 AccountClient client = new AccountClient();
421 ClientResponse<AccountsCommonList> res = client.readSearchList(null, "tom", null);
423 assertStatusCode(res, testName);
424 AccountsCommonList list = res.getEntity();
425 Assert.assertEquals(1, list.getAccountListItem().size());
426 // Optionally output additional data about list members for debugging.
427 boolean iterateThroughList = true;
428 if (iterateThroughList && logger.isDebugEnabled()) {
429 printList(testName, list);
433 res.releaseConnection();
441 * @param testName the test name
442 * @throws Exception the exception
444 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
445 public void searchEmail(String testName) throws Exception {
449 // Submit the request to the service and store the response.
450 AccountClient client = new AccountClient();
451 ClientResponse<AccountsCommonList> res = client.readSearchList(null, null, "dinoland");
453 assertStatusCode(res, testName);
454 AccountsCommonList list = res.getEntity();
455 Assert.assertEquals(2, list.getAccountListItem().size());
456 // Optionally output additional data about list members for debugging.
457 boolean iterateThroughList = true;
458 if (iterateThroughList && logger.isDebugEnabled()) {
459 printList(testName, list);
463 res.releaseConnection();
469 * Search screen name email.
471 * @param testName the test name
472 * @throws Exception the exception
474 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
475 public void searchScreenNameEmail(String testName) throws Exception {
479 // Submit the request to the service and store the response.
480 AccountClient client = new AccountClient();
481 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, "jerry");
483 assertStatusCode(res, testName);
484 AccountsCommonList list = res.getEntity();
485 Assert.assertEquals(1, list.getAccountListItem().size());
486 // Optionally output additional data about list members for debugging.
487 boolean iterateThroughList = true;
488 if (iterateThroughList && logger.isDebugEnabled()) {
489 printList(testName, list);
493 res.releaseConnection();
498 // ---------------------------------------------------------------
499 // CRUD tests : UPDATE tests
500 // ---------------------------------------------------------------
505 * @param testName the test name
506 * @throws Exception the exception
508 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
509 public void updatePassword(String testName) throws Exception {
513 AccountClient client = new AccountClient();
514 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
515 if (logger.isDebugEnabled()) {
516 logger.debug(testName + ": read status = " + res.getStatus());
518 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
520 if (logger.isDebugEnabled()) {
521 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
523 AccountsCommon accountFound =
524 (AccountsCommon) res.getEntity();
525 Assert.assertNotNull(accountFound);
527 //create a new account object to test partial updates
528 AccountsCommon accountToUpdate = new AccountsCommon();
529 accountToUpdate.setCsid(knownResourceId);
530 accountToUpdate.setUserId(accountFound.getUserId());
532 accountToUpdate.setPassword("imagination".getBytes());
533 if (logger.isDebugEnabled()) {
534 logger.debug(testName + ": updated object");
535 logger.debug(objectAsXmlString(accountToUpdate,
536 AccountsCommon.class));
539 // Submit the request to the service and store the response.
540 res = client.update(knownResourceId, accountToUpdate);
541 int statusCode = res.getStatus();
542 // Check the status code of the response: does it match the expected response(s)?
543 if (logger.isDebugEnabled()) {
544 logger.debug(testName + ": status = " + statusCode);
546 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(testRequestType, statusCode));
548 Assert.assertEquals(statusCode, testExpectedStatusCode);
550 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
551 Assert.assertNotNull(accountUpdated);
553 // Assert.assertEquals(accountUpdated.getPassword(),
554 // accountFound.getPassword(),
555 // "Data in updated object did not match submitted data.");
559 * Update password without user.
561 * @param testName the test name
562 * @throws Exception the exception
564 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
565 public void updatePasswordWithoutUser(String testName) throws Exception {
569 AccountsCommon accountToUpdate = new AccountsCommon();
570 accountToUpdate.setCsid(knownResourceId);
571 accountToUpdate.setUserId(null);
573 accountToUpdate.setPassword("imagination".getBytes());
574 if (logger.isDebugEnabled()) {
575 logger.debug(testName + " : updated object");
576 logger.debug(objectAsXmlString(accountToUpdate,
577 AccountsCommon.class));
580 AccountClient client = new AccountClient();
581 // Submit the request to the service and store the response.
582 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
583 int statusCode = res.getStatus();
584 // Check the status code of the response: does it match the expected response(s)?
585 if (logger.isDebugEnabled()) {
586 logger.debug(testName + ": status = " + statusCode);
588 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
589 invalidStatusCodeMessage(testRequestType, statusCode));
590 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
595 * Update invalid password.
597 * @param testName the test name
598 * @throws Exception the exception
600 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
601 public void updateInvalidPassword(String testName) throws Exception {
604 AccountClient client = new AccountClient();
605 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
606 if (logger.isDebugEnabled()) {
607 logger.debug(testName + ": read status = " + res.getStatus());
609 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
611 if (logger.isDebugEnabled()) {
612 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
614 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
616 AccountsCommon accountToUpdate = new AccountsCommon();
617 accountToUpdate.setCsid(knownResourceId);
618 accountToUpdate.setUserId(accountFound.getUserId());
619 Assert.assertNotNull(accountToUpdate);
622 accountToUpdate.setPassword("abc123".getBytes());
623 if (logger.isDebugEnabled()) {
624 logger.debug(testName + ": updated object");
625 logger.debug(objectAsXmlString(accountToUpdate,
626 AccountsCommon.class));
629 // Submit the request to the service and store the response.
630 res = client.update(knownResourceId, accountToUpdate);
631 int statusCode = res.getStatus();
632 // Check the status code of the response: does it match the expected response(s)?
633 if (logger.isDebugEnabled()) {
634 logger.debug(testName + ": status = " + statusCode);
636 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(testRequestType, statusCode));
638 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
641 private void findPrebuiltAdminAccount() {
642 // Search for the prebuilt admin user and then hold its CSID
643 if (prebuiltAdminCSID == null) {
645 AccountClient client = new AccountClient();
646 ClientResponse<AccountsCommonList> res =
647 client.readSearchList(null, this.prebuiltAdminUserId, null);
649 assertStatusCode(res, "findPrebuiltAdminAccount");
650 AccountsCommonList list = res.getEntity();
651 List<AccountListItem> items = list.getAccountListItem();
652 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
653 AccountListItem item = items.get(0);
654 prebuiltAdminCSID = item.getCsid();
655 if (logger.isDebugEnabled()) {
656 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
660 res.releaseConnection();
666 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
667 public void verifyMetadataProtection(String testName) throws Exception {
668 findPrebuiltAdminAccount();
669 // Try to update the metadata - it should just get ignored
673 AccountClient client = new AccountClient();
674 ClientResponse<AccountsCommon> res = client.read(prebuiltAdminCSID);
675 if (logger.isDebugEnabled()) {
676 logger.debug(testName + ": read status = " + res.getStatus());
678 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
680 if (logger.isDebugEnabled()) {
681 logger.debug("Did get on Admin Account to update with ID: " + prebuiltAdminCSID);
683 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
684 Assert.assertNotNull(accountFound);
686 //create a new account object to test partial updates
687 AccountsCommon accountToUpdate = new AccountsCommon();
688 accountToUpdate.setCsid(prebuiltAdminCSID);
689 accountToUpdate.setUserId(accountFound.getUserId());
690 // Update the content of this resource.
691 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
692 if (logger.isDebugEnabled()) {
693 logger.debug("updated object");
694 logger.debug(objectAsXmlString(accountFound,
695 AccountsCommon.class));
698 // Submit the request to the service and store the response.
699 res = client.update(prebuiltAdminCSID, accountToUpdate);
700 int statusCode = res.getStatus();
701 // Check the status code of the response: does it match the expected response(s)?
702 if (logger.isDebugEnabled()) {
703 logger.debug(testName + ": status = " + statusCode);
705 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
706 invalidStatusCodeMessage(testRequestType, statusCode));
707 // Note that the error is not returned, it is just ignored
708 Assert.assertEquals(statusCode, testExpectedStatusCode);
710 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
711 Assert.assertNotNull(accountUpdated);
713 Assert.assertFalse(accountUpdated.getEmail().equals(accountToUpdate.getEmail()),
714 "Admin Account (with metadata lock) allowed update to change the email!");
718 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
719 public void verifyProtectionReadOnly(String testName) throws Exception {
722 // Submit the request to the service and store the response.
723 AccountClient client = new AccountClient();
724 AccountsCommon account = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
725 client.getTenantId(), true, false, true, true);
726 account.setMetadataProtection(AccountClient.IMMUTABLE);
727 account.setRolesProtection(AccountClient.IMMUTABLE);
728 ClientResponse<Response> res = client.create(account);
729 String testResourceId = null;
731 assertStatusCode(res, testName);
732 // Store the ID returned from this create operation
733 // for additional tests below.
734 testResourceId = extractId(res);
735 allResourceIdsCreated.add(testResourceId);
736 if (logger.isDebugEnabled()) {
737 logger.debug(testName + ": testResourceId=" + testResourceId);
741 res.releaseConnection();
747 // Submit the request to the service and store the response.
748 ClientResponse<AccountsCommon> accountRes = client.read(testResourceId);
750 assertStatusCode(accountRes, testName);
751 AccountsCommon accountRead = (AccountsCommon) accountRes.getEntity();
752 Assert.assertNotNull(accountRead);
753 String mdProtection = accountRead.getMetadataProtection();
754 String rolesProtection = accountRead.getRolesProtection();
755 if (logger.isTraceEnabled()) {
756 logger.trace(testName + ": metadataProtection=" + mdProtection);
757 logger.trace(testName + ": rolesProtection=" + rolesProtection);
759 Assert.assertFalse(account.getMetadataProtection().equals(mdProtection),
760 "Account allowed create to set the metadata protection flag.");
761 Assert.assertFalse(account.getRolesProtection().equals(rolesProtection),
762 "Account allowed create to set the perms protection flag.");
764 if (accountRes != null) {
765 accountRes.releaseConnection();
771 AccountsCommon accountToUpdate = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
772 client.getTenantId(), true, false, true, true);
773 accountToUpdate.setMetadataProtection(AccountClient.IMMUTABLE);
774 accountToUpdate.setRolesProtection(AccountClient.IMMUTABLE);
776 // Submit the request to the service and store the response.
777 accountRes = client.update(testResourceId, accountToUpdate);
779 assertStatusCode(accountRes, testName);
780 AccountsCommon accountUpdated = (AccountsCommon) accountRes.getEntity();
781 Assert.assertNotNull(accountUpdated);
782 if (logger.isDebugEnabled()) {
783 logger.debug(testName + "Updated account: ");
784 logger.debug(objectAsXmlString(accountUpdated,AccountsCommon.class));
787 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()),
788 "Account allowed update of the metadata protection flag.");
790 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()),
791 "Account allowed update of the roles protection flag.");
793 if (accountRes != null) {
794 accountRes.releaseConnection();
802 * @param testName the test name
803 * @throws Exception the exception
805 @Test(dataProvider = "testName", dependsOnMethods = {"updatePasswordWithoutUser"})
806 public void deactivate(String testName) throws Exception {
810 AccountClient client = new AccountClient();
811 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
812 if (logger.isDebugEnabled()) {
813 logger.debug(testName + ": read status = " + res.getStatus());
815 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
817 if (logger.isDebugEnabled()) {
818 logger.debug("got object to update with ID: " + knownResourceId);
820 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
822 //create a new account object to test partial updates
823 AccountsCommon accountToUpdate = new AccountsCommon();
824 accountToUpdate.setCsid(knownResourceId);
825 accountToUpdate.setUserId(accountFound.getUserId());
827 // Update the content of this resource.
828 accountToUpdate.setStatus(Status.INACTIVE);
829 if (logger.isDebugEnabled()) {
830 logger.debug("updated object");
831 logger.debug(objectAsXmlString(accountToUpdate,
832 AccountsCommon.class));
835 // Submit the request to the service and store the response.
836 res = client.update(knownResourceId, accountToUpdate);
837 int statusCode = res.getStatus();
838 // Check the status code of the response: does it match the expected response(s)?
839 if (logger.isDebugEnabled()) {
840 logger.debug(testName + ": status = " + statusCode);
842 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
843 invalidStatusCodeMessage(testRequestType, statusCode));
844 Assert.assertEquals(statusCode, testExpectedStatusCode);
846 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
847 Assert.assertNotNull(accountUpdated);
849 Assert.assertEquals(accountUpdated.getStatus(),
850 accountToUpdate.getStatus(),
851 "Data in updated object did not match submitted data.");
855 // Placeholders until the three tests below can be uncommented.
856 // See Issue CSPACE-401.
858 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
861 public void updateWithEmptyEntityBody(String testName) throws Exception {
862 //FIXME: Should this test really be empty? If so, please comment accordingly.
866 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
869 public void updateWithMalformedXml(String testName) throws Exception {
870 //FIXME: Should this test really be empty? If so, please comment accordingly.
874 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
877 public void updateWithWrongXmlSchema(String testName) throws Exception {
878 //FIXME: Should this test really be empty? If so, please comment accordingly.
882 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
883 public void updateNonExistent(String testName) throws Exception {
885 setupUpdateNonExistent();
887 // Submit the request to the service and store the response.
889 // Note: The ID used in this 'create' call may be arbitrary.
890 // The only relevant ID may be the one used in updateAccount(), below.
891 AccountClient client = new AccountClient();
892 AccountsCommon account =
893 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
894 client.getTenantId(), true, false, true, true);
895 ClientResponse<AccountsCommon> res =
896 client.update(NON_EXISTENT_ID, account);
897 int statusCode = res.getStatus();
899 // Check the status code of the response: does it match
900 // the expected response(s)?
901 if (logger.isDebugEnabled()) {
902 logger.debug(testName + ": status = " + statusCode);
904 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
905 invalidStatusCodeMessage(testRequestType, statusCode));
906 Assert.assertEquals(statusCode, testExpectedStatusCode);
912 * @param testName the test name
913 * @throws Exception the exception
915 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
916 public void updateWrongUser(String testName) throws Exception {
919 // Submit the request to the service and store the response.
921 // Note: The ID used in this 'create' call may be arbitrary.
922 // The only relevant ID may be the one used in updateAccount(), below.
923 AccountClient client = new AccountClient();
924 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
925 if (logger.isDebugEnabled()) {
926 logger.debug(testName + ": read status = " + res.getStatus());
928 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
930 if (logger.isDebugEnabled()) {
931 logger.debug("got object to update with ID: " + knownResourceId);
933 AccountsCommon accountToUpdate =
934 (AccountsCommon) res.getEntity();
935 Assert.assertNotNull(accountToUpdate);
937 accountToUpdate.setUserId("barneyFake");
938 if (logger.isDebugEnabled()) {
939 logger.debug("updated object with wrongUser");
940 logger.debug(objectAsXmlString(accountToUpdate,
941 AccountsCommon.class));
944 res = client.update(knownResourceId, accountToUpdate);
945 int statusCode = res.getStatus();
947 // Check the status code of the response: does it match
948 // the expected response(s)?
949 if (logger.isDebugEnabled()) {
950 logger.debug(testName + ": status = " + statusCode);
952 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
953 invalidStatusCodeMessage(testRequestType, statusCode));
954 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
957 // ---------------------------------------------------------------
958 // CRUD tests : DELETE tests
959 // ---------------------------------------------------------------
963 public void delete(String testName) throws Exception {
964 // Do nothing because this test is not ready to delete the "knownResourceId".
965 // Instead, the method localDelete() will get called later in the dependency chain. The
966 // method localDelete() has a dependency on the test "updateWrongUser". Once the "updateWrongUser"
967 // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn
968 // calls the inherited delete() test/method.
971 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "updateWrongUser"})
972 public void localDelete(String testName) throws Exception {
973 // Because of issues with TestNG not allowing @Test annotations on on override methods,
974 // and because we want the "updateWrongUser" to run before the "delete" test, we need
975 // this method. This method will call super.delete() after all the dependencies have been
977 super.delete(testName);
980 // ---------------------------------------------------------------
981 // Utility methods used by tests above
982 // ---------------------------------------------------------------
984 * create account instance
989 * @param useScreenName
990 * @param invalidTenant
995 AccountsCommon createAccountInstance(String screenName,
996 String userName, String passwd, String email, String tenantId,
997 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
999 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1000 userName, passwd, email, tenantId, useScreenName,
1001 invalidTenant, useUser, usePassword);
1002 if (logger.isDebugEnabled()) {
1003 logger.debug("to be created, account common");
1004 logger.debug(objectAsXmlString(account,
1005 AccountsCommon.class));
1015 * @param testName the test name
1016 * @param list the list
1019 protected void printList(String testName, AccountsCommonList list) {
1020 AccountsCommonList acl = (AccountsCommonList)list;
1021 List<AccountListItem> items =
1022 acl.getAccountListItem();
1024 for (AccountListItem item : items) {
1025 logger.debug(testName + ": list-item[" + i + "] csid="
1027 logger.debug(testName + ": list-item[" + i + "] screenName="
1028 + item.getScreenName());
1029 logger.debug(testName + ": list-item[" + i + "] URI="
1036 protected AccountsCommon createInstance(String commonPartName,
1037 String identifier) {
1038 AccountClient client = new AccountClient();
1039 AccountsCommon account =
1040 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
1041 "barney@dinoland.com", client.getTenantId(),
1042 true, false, true, true);
1047 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
1048 * refer to this method in their @Test annotation declarations.
1051 @Test(dataProvider = "testName",
1052 dependsOnMethods = {
1053 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
1054 public void CRUDTests(String testName) {
1055 // Do nothing. Simply here to for a TestNG execution order for our tests
1059 protected AccountsCommon updateInstance(AccountsCommon accountsCommon) {
1060 AccountsCommon result = new AccountsCommon();
1062 result.setCsid(knownResourceId);
1063 result.setUserId(accountsCommon.getUserId());
1064 // Update the content of this resource.
1065 result.setEmail("updated-" + accountsCommon.getEmail());
1071 protected void compareUpdatedInstances(AccountsCommon original,
1072 AccountsCommon updated) throws Exception {
1073 Assert.assertEquals(original.getEmail(), updated.getEmail(),
1074 "Data in updated object did not match submitted data.");