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.jboss.resteasy.client.ClientResponse;
30 import org.collectionspace.services.client.AccountClient;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.account.AccountsCommon;
33 import org.collectionspace.services.account.AccountsCommonList;
34 import org.collectionspace.services.account.AccountListItem;
35 import org.collectionspace.services.account.Status;
36 import org.collectionspace.services.authorization.AccountRole;
37 import org.collectionspace.services.client.AccountFactory;
38 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
39 import org.collectionspace.services.client.test.ServiceRequestType;
40 import org.testng.Assert;
41 import org.testng.annotations.Test;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * AccountServiceTest, carries out tests against a
47 * deployed and running Account Service.
49 * $LastChangedRevision: 917 $
50 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
52 public class AccountServiceTest extends AbstractServiceTestImpl<AccountsCommonList, AccountsCommon, AccountsCommon, AccountsCommon> {
54 /** The Constant logger. */
55 private final String CLASS_NAME = AccountServiceTest.class.getName();
56 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
58 // Instance variables specific to this test.
59 private String prebuiltAdminCSID = null;
60 private String prebuiltAdminUserId = "admin@core.collectionspace.org";
61 private String knownUserId = "barney";
62 private String knownUserPassword = "hithere08";
63 /** The add tenant. */
64 static boolean addTenant = true;
67 public String getServiceName() {
68 return AccountClient.SERVICE_NAME;
72 * The entity type expected from the JAX-RS Response object
74 public Class<AccountsCommon> getEntityResponseType() {
75 return AccountsCommon.class;
79 * This method is called only by the parent class, AbstractServiceTestImpl
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
85 protected String getServicePathComponent() {
86 return new AccountClient().getServicePathComponent();
90 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
93 protected CollectionSpaceClient getClientInstance() {
94 return new AccountClient();
98 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
101 protected AccountsCommonList getCommonList(Response response) {
102 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
103 throw new UnsupportedOperationException();
106 protected Class<AccountsCommonList> getCommonListType() {
107 return (Class<AccountsCommonList>) AccountsCommonList.class;
111 public void readPaginatedList(String testName) throws Exception {
112 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
115 // ---------------------------------------------------------------
116 // CRUD tests : CREATE tests
117 // ---------------------------------------------------------------
121 * Creates the for unique user.
123 * @param testName the test name
124 * @throws Exception the exception
126 @Test(dataProvider = "testName",
127 dependsOnMethods = {"CRUDTests"})
128 public void createForUniqueUser(String testName) throws Exception {
131 // Submit the request to the service and store the response.
132 AccountClient client = new AccountClient();
133 AccountsCommon account =
134 createAccountInstance("barney1", knownUserId, knownUserPassword,
135 "barney@dinoland.com",
136 client.getTenantId(), true, false, true, true);
138 ClientResponse<Response> res = client.create(account);
139 int statusCode = res.getStatus();
140 if (logger.isDebugEnabled()) {
141 logger.debug(testName + ": status = " + statusCode);
143 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
144 invalidStatusCodeMessage(testRequestType, statusCode));
145 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
149 * Creates the with invalid tenant.
151 * @param testName the test name
152 * @throws Exception the exception
154 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
155 public void createWithInvalidTenant(String testName) throws Exception {
158 // Submit the request to the service and store the response.
159 AccountClient client = new AccountClient();
160 AccountsCommon account =
161 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
162 client.getTenantId(), true, true, true, true);
163 ClientResponse<Response> res = client.create(account);
164 int statusCode = res.getStatus();
165 // Does it exactly match the expected status code?
166 if (logger.isDebugEnabled()) {
167 logger.debug(testName + ": status = " + statusCode);
169 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
170 invalidStatusCodeMessage(testRequestType, statusCode));
171 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
175 * Creates the without user.
177 * @param testName the test name
178 * @throws Exception the exception
180 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
181 public void createWithoutUser(String testName) throws Exception {
184 // Submit the request to the service and store the response.
185 AccountClient client = new AccountClient();
186 AccountsCommon account =
187 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
188 client.getTenantId(), true, false, false, true);
189 ClientResponse<Response> res = client.create(account);
190 int statusCode = res.getStatus();
191 // Does it exactly match the expected status code?
192 if (logger.isDebugEnabled()) {
193 logger.debug(testName + ": status = " + statusCode);
195 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
196 invalidStatusCodeMessage(testRequestType, statusCode));
197 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
201 * Creates the with invalid email.
203 * @param testName the test name
204 * @throws Exception the exception
206 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
207 public void createWithInvalidEmail(String testName) throws Exception {
210 // Submit the request to the service and store the response.
211 AccountClient client = new AccountClient();
212 AccountsCommon account =
213 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
214 client.getTenantId(), true, false, true, true);
215 ClientResponse<Response> res = client.create(account);
216 int statusCode = res.getStatus();
217 // Does it exactly match the expected status code?
218 if (logger.isDebugEnabled()) {
219 logger.debug(testName + ": status = " + statusCode);
221 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
222 invalidStatusCodeMessage(testRequestType, statusCode));
223 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
227 * Creates the without screen name.
229 * @param testName the test name
230 * @throws Exception the exception
232 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
233 public void createWithoutScreenName(String testName) throws Exception {
236 // Submit the request to the service and store the response.
237 AccountClient client = new AccountClient();
238 AccountsCommon account =
239 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
240 client.getTenantId(), false, false, true, true);
241 ClientResponse<Response> res = client.create(account);
242 int statusCode = res.getStatus();
243 // Does it exactly match the expected status code?
244 if (logger.isDebugEnabled()) {
245 logger.debug(testName + ": status = " + statusCode);
247 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
248 invalidStatusCodeMessage(testRequestType, statusCode));
249 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
253 * Creates the with invalid password.
255 * @param testName the test name
256 * @throws Exception the exception
258 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
259 public void createWithInvalidPassword(String testName) throws Exception {
262 // Submit the request to the service and store the response.
263 AccountClient client = new AccountClient();
264 AccountsCommon account =
265 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
266 client.getTenantId(), true, false, true, true);
267 ClientResponse<Response> res = client.create(account);
268 int statusCode = res.getStatus();
269 // Does it exactly match the expected status code?
270 if (logger.isDebugEnabled()) {
271 logger.debug(testName + ": status = " + statusCode);
273 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
274 invalidStatusCodeMessage(testRequestType, statusCode));
275 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
279 * Creates the with most invalid.
281 * @param testName the test name
282 * @throws Exception the exception
284 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
285 public void createWithMostInvalid(String testName) throws Exception {
288 // Submit the request to the service and store the response.
289 AccountClient client = new AccountClient();
290 AccountsCommon account =
291 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
292 client.getTenantId(), false, true, false, false);
293 ClientResponse<Response> res = client.create(account);
294 int statusCode = res.getStatus();
295 // Does it exactly match the expected status code?
296 if (logger.isDebugEnabled()) {
297 logger.debug(testName + ": status = " + statusCode);
299 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
300 invalidStatusCodeMessage(testRequestType, statusCode));
301 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
305 // To avoid uniqueness violations for accounts, createList is removed
308 public void createList(String testName) throws Exception {
310 // Submit the request to the service and store the response.
311 AccountClient client = new AccountClient();
312 AccountsCommon account1 =
313 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
314 client.getTenantId(), true, false, true, true);
315 ClientResponse<Response> res = client.create(account1);
316 int statusCode = res.getStatus();
317 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
318 invalidStatusCodeMessage(testRequestType, statusCode));
319 Assert.assertEquals(statusCode, testExpectedStatusCode);
320 allResourceIdsCreated.add(extractId(res));
322 AccountsCommon account2 =
323 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
324 client.getTenantId(), true, false, true, true);
325 res = client.create(account2);
326 statusCode = res.getStatus();
327 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
328 invalidStatusCodeMessage(testRequestType, statusCode));
329 Assert.assertEquals(statusCode, testExpectedStatusCode);
330 Assert.assertEquals(statusCode, testExpectedStatusCode);
331 allResourceIdsCreated.add(extractId(res));
333 AccountsCommon account3 =
334 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
335 client.getTenantId(), true, false, true, true);
336 res = client.create(account3);
337 statusCode = res.getStatus();
338 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
339 invalidStatusCodeMessage(testRequestType, statusCode));
340 Assert.assertEquals(statusCode, testExpectedStatusCode);
341 Assert.assertEquals(statusCode, testExpectedStatusCode);
342 allResourceIdsCreated.add(extractId(res));
346 // Tests with expected failure outcomes
348 // Placeholders until the three tests below can be uncommented.
349 // See Issue CSPACE-401.
351 public void createWithEmptyEntityBody(String testName) throws Exception {
352 //FIXME: Should this test really be empty? If so, please comment accordingly.
356 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
359 public void createWithMalformedXml(String testName) throws Exception {
360 //FIXME: Should this test really be empty? If so, please comment accordingly.
364 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
367 public void createWithWrongXmlSchema(String testName) throws Exception {
368 //FIXME: Should this test really be empty? If so, please comment accordingly.
371 // ---------------------------------------------------------------
372 // CRUD tests : READ_LIST tests
373 // ---------------------------------------------------------------
377 * Search screen name.
379 * @param testName the test name
380 * @throws Exception the exception
382 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
383 public void searchScreenName(String testName) throws Exception {
387 // Submit the request to the service and store the response.
388 AccountClient client = new AccountClient();
389 ClientResponse<AccountsCommonList> res =
390 client.readSearchList("tom", null, null);
392 assertStatusCode(res, testName);
393 AccountsCommonList list = res.getEntity();
394 Assert.assertEquals(1, list.getAccountListItem().size());
395 // Optionally output additional data about list members for debugging.
396 boolean iterateThroughList = true;
397 if (iterateThroughList && logger.isDebugEnabled()) {
398 printList(testName, list);
402 res.releaseConnection();
408 @Test(dataProvider = "testName")
409 public void searchWorkflowDeleted(String testName) throws Exception {
410 // Fixme: null test for now, overriding test in base class
416 * @param testName the test name
417 * @throws Exception the exception
419 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
420 public void searchUserId(String testName) throws Exception {
424 // Submit the request to the service and store the response.
425 AccountClient client = new AccountClient();
426 ClientResponse<AccountsCommonList> res = client.readSearchList(null, "tom", null);
428 assertStatusCode(res, testName);
429 AccountsCommonList list = res.getEntity();
430 Assert.assertEquals(1, list.getAccountListItem().size());
431 // Optionally output additional data about list members for debugging.
432 boolean iterateThroughList = true;
433 if (iterateThroughList && logger.isDebugEnabled()) {
434 printList(testName, list);
438 res.releaseConnection();
446 * @param testName the test name
447 * @throws Exception the exception
449 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
450 public void searchEmail(String testName) throws Exception {
454 // Submit the request to the service and store the response.
455 AccountClient client = new AccountClient();
456 ClientResponse<AccountsCommonList> res = client.readSearchList(null, null, "dinoland");
458 assertStatusCode(res, testName);
459 AccountsCommonList list = res.getEntity();
460 Assert.assertEquals(2, list.getAccountListItem().size());
461 // Optionally output additional data about list members for debugging.
462 boolean iterateThroughList = true;
463 if (iterateThroughList && logger.isDebugEnabled()) {
464 printList(testName, list);
468 res.releaseConnection();
474 * Search screen name email.
476 * @param testName the test name
477 * @throws Exception the exception
479 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
480 public void searchScreenNameEmail(String testName) throws Exception {
484 // Submit the request to the service and store the response.
485 AccountClient client = new AccountClient();
486 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, "jerry");
488 assertStatusCode(res, testName);
489 AccountsCommonList list = res.getEntity();
490 Assert.assertEquals(1, list.getAccountListItem().size());
491 // Optionally output additional data about list members for debugging.
492 boolean iterateThroughList = true;
493 if (iterateThroughList && logger.isDebugEnabled()) {
494 printList(testName, list);
498 res.releaseConnection();
503 // ---------------------------------------------------------------
504 // CRUD tests : UPDATE tests
505 // ---------------------------------------------------------------
510 * @param testName the test name
511 * @throws Exception the exception
513 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
514 public void updatePassword(String testName) throws Exception {
518 AccountClient client = new AccountClient();
519 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
520 if (logger.isDebugEnabled()) {
521 logger.debug(testName + ": read status = " + res.getStatus());
523 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
525 if (logger.isDebugEnabled()) {
526 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
528 AccountsCommon accountFound =
529 (AccountsCommon) res.getEntity();
530 Assert.assertNotNull(accountFound);
532 //create a new account object to test partial updates
533 AccountsCommon accountToUpdate = new AccountsCommon();
534 accountToUpdate.setCsid(knownResourceId);
535 accountToUpdate.setUserId(accountFound.getUserId());
537 accountToUpdate.setPassword("imagination".getBytes());
538 if (logger.isDebugEnabled()) {
539 logger.debug(testName + ": updated object");
540 logger.debug(objectAsXmlString(accountToUpdate,
541 AccountsCommon.class));
544 // Submit the request to the service and store the response.
545 res = client.update(knownResourceId, accountToUpdate);
546 int statusCode = res.getStatus();
547 // Check the status code of the response: does it match the expected response(s)?
548 if (logger.isDebugEnabled()) {
549 logger.debug(testName + ": status = " + statusCode);
551 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
552 invalidStatusCodeMessage(testRequestType, statusCode));
553 Assert.assertEquals(statusCode, testExpectedStatusCode);
555 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
556 Assert.assertNotNull(accountUpdated);
558 // Assert.assertEquals(accountUpdated.getPassword(),
559 // accountFound.getPassword(),
560 // "Data in updated object did not match submitted data.");
564 * Update password without user.
566 * @param testName the test name
567 * @throws Exception the exception
569 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
570 public void updatePasswordWithoutUser(String testName) throws Exception {
574 AccountsCommon accountToUpdate = new AccountsCommon();
575 accountToUpdate.setCsid(knownResourceId);
576 accountToUpdate.setUserId(null);
578 accountToUpdate.setPassword("imagination".getBytes());
579 if (logger.isDebugEnabled()) {
580 logger.debug(testName + " : updated object");
581 logger.debug(objectAsXmlString(accountToUpdate,
582 AccountsCommon.class));
585 AccountClient client = new AccountClient();
586 // Submit the request to the service and store the response.
587 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
588 int statusCode = res.getStatus();
589 // Check the status code of the response: does it match the expected response(s)?
590 if (logger.isDebugEnabled()) {
591 logger.debug(testName + ": status = " + statusCode);
593 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
594 invalidStatusCodeMessage(testRequestType, statusCode));
595 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
600 * Update invalid password.
602 * @param testName the test name
603 * @throws Exception the exception
605 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
606 public void updateInvalidPassword(String testName) throws Exception {
609 AccountClient client = new AccountClient();
610 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
611 if (logger.isDebugEnabled()) {
612 logger.debug(testName + ": read status = " + res.getStatus());
614 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
616 if (logger.isDebugEnabled()) {
617 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
619 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
621 AccountsCommon accountToUpdate = new AccountsCommon();
622 accountToUpdate.setCsid(knownResourceId);
623 accountToUpdate.setUserId(accountFound.getUserId());
624 Assert.assertNotNull(accountToUpdate);
627 accountToUpdate.setPassword("abc123".getBytes());
628 if (logger.isDebugEnabled()) {
629 logger.debug(testName + ": updated object");
630 logger.debug(objectAsXmlString(accountToUpdate,
631 AccountsCommon.class));
634 // Submit the request to the service and store the response.
635 res = client.update(knownResourceId, accountToUpdate);
636 int statusCode = res.getStatus();
637 // Check the status code of the response: does it match the expected response(s)?
638 if (logger.isDebugEnabled()) {
639 logger.debug(testName + ": status = " + statusCode);
641 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
642 invalidStatusCodeMessage(testRequestType, statusCode));
643 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
646 private void findPrebuiltAdminAccount() {
647 // Search for the prebuilt admin user and then hold its CSID
648 if (prebuiltAdminCSID == null) {
650 AccountClient client = new AccountClient();
651 ClientResponse<AccountsCommonList> res =
652 client.readSearchList(null, this.prebuiltAdminUserId, null);
654 assertStatusCode(res, "findPrebuiltAdminAccount");
655 AccountsCommonList list = res.getEntity();
656 List<AccountListItem> items = list.getAccountListItem();
657 Assert.assertEquals(1, items.size(), "Found more than one Admin account!");
658 AccountListItem item = items.get(0);
659 prebuiltAdminCSID = item.getCsid();
660 if (logger.isDebugEnabled()) {
661 logger.debug("Found Admin Account with ID: " + prebuiltAdminCSID);
665 res.releaseConnection();
671 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
672 public void verifyMetadataProtection(String testName) throws Exception {
673 findPrebuiltAdminAccount();
674 // Try to update the metadata - it should just get ignored
678 AccountClient client = new AccountClient();
679 ClientResponse<AccountsCommon> res = client.read(prebuiltAdminCSID);
680 if (logger.isDebugEnabled()) {
681 logger.debug(testName + ": read status = " + res.getStatus());
683 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
685 if (logger.isDebugEnabled()) {
686 logger.debug("Did get on Admin Account to update with ID: " + prebuiltAdminCSID);
688 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
689 Assert.assertNotNull(accountFound);
691 //create a new account object to test partial updates
692 AccountsCommon accountToUpdate = new AccountsCommon();
693 accountToUpdate.setCsid(prebuiltAdminCSID);
694 accountToUpdate.setUserId(accountFound.getUserId());
695 // Update the content of this resource.
696 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
697 if (logger.isDebugEnabled()) {
698 logger.debug("updated object");
699 logger.debug(objectAsXmlString(accountFound,
700 AccountsCommon.class));
703 // Submit the request to the service and store the response.
704 res = client.update(prebuiltAdminCSID, accountToUpdate);
705 int statusCode = res.getStatus();
706 // Check the status code of the response: does it match the expected response(s)?
707 if (logger.isDebugEnabled()) {
708 logger.debug(testName + ": status = " + statusCode);
710 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
711 invalidStatusCodeMessage(testRequestType, statusCode));
712 // Note that the error is not returned, it is just ignored
713 Assert.assertEquals(statusCode, testExpectedStatusCode);
715 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
716 Assert.assertNotNull(accountUpdated);
718 Assert.assertFalse(accountUpdated.getEmail().equals(accountToUpdate.getEmail()),
719 "Admin Account (with metadata lock) allowed update to change the email!");
723 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
724 public void verifyProtectionReadOnly(String testName) throws Exception {
727 // Submit the request to the service and store the response.
728 AccountClient client = new AccountClient();
729 AccountsCommon account = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
730 client.getTenantId(), true, false, true, true);
731 account.setMetadataProtection(AccountClient.IMMUTABLE);
732 account.setRolesProtection(AccountClient.IMMUTABLE);
733 ClientResponse<Response> res = client.create(account);
734 String testResourceId = null;
736 assertStatusCode(res, testName);
737 // Store the ID returned from this create operation
738 // for additional tests below.
739 testResourceId = extractId(res);
740 allResourceIdsCreated.add(testResourceId);
741 if (logger.isDebugEnabled()) {
742 logger.debug(testName + ": testResourceId=" + testResourceId);
746 res.releaseConnection();
752 // Submit the request to the service and store the response.
753 ClientResponse<AccountsCommon> accountRes = client.read(testResourceId);
755 assertStatusCode(accountRes, testName);
756 AccountsCommon accountRead = (AccountsCommon) accountRes.getEntity();
757 Assert.assertNotNull(accountRead);
758 String mdProtection = accountRead.getMetadataProtection();
759 String rolesProtection = accountRead.getRolesProtection();
760 if (logger.isTraceEnabled()) {
761 logger.trace(testName + ": metadataProtection=" + mdProtection);
762 logger.trace(testName + ": rolesProtection=" + rolesProtection);
764 Assert.assertFalse(account.getMetadataProtection().equals(mdProtection),
765 "Account allowed create to set the metadata protection flag.");
766 Assert.assertFalse(account.getRolesProtection().equals(rolesProtection),
767 "Account allowed create to set the perms protection flag.");
769 if (accountRes != null) {
770 accountRes.releaseConnection();
776 AccountsCommon accountToUpdate = createAccountInstance("mdTest", "mdTest", "mdTestPW", "md@test.com",
777 client.getTenantId(), true, false, true, true);
778 accountToUpdate.setMetadataProtection(AccountClient.IMMUTABLE);
779 accountToUpdate.setRolesProtection(AccountClient.IMMUTABLE);
781 // Submit the request to the service and store the response.
782 accountRes = client.update(testResourceId, accountToUpdate);
784 assertStatusCode(accountRes, testName);
785 AccountsCommon accountUpdated = (AccountsCommon) accountRes.getEntity();
786 Assert.assertNotNull(accountUpdated);
787 if (logger.isDebugEnabled()) {
788 logger.debug(testName + "Updated account: ");
789 logger.debug(objectAsXmlString(accountUpdated,AccountsCommon.class));
792 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getMetadataProtection()),
793 "Account allowed update of the metadata protection flag.");
795 AccountClient.IMMUTABLE.equalsIgnoreCase(accountUpdated.getRolesProtection()),
796 "Account allowed update of the roles protection flag.");
798 if (accountRes != null) {
799 accountRes.releaseConnection();
807 * @param testName the test name
808 * @throws Exception the exception
810 @Test(dataProvider = "testName", dependsOnMethods = {"updatePasswordWithoutUser"})
811 public void deactivate(String testName) throws Exception {
815 AccountClient client = new AccountClient();
816 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
817 if (logger.isDebugEnabled()) {
818 logger.debug(testName + ": read status = " + res.getStatus());
820 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
822 if (logger.isDebugEnabled()) {
823 logger.debug("got object to update with ID: " + knownResourceId);
825 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
827 //create a new account object to test partial updates
828 AccountsCommon accountToUpdate = new AccountsCommon();
829 accountToUpdate.setCsid(knownResourceId);
830 accountToUpdate.setUserId(accountFound.getUserId());
832 // Update the content of this resource.
833 accountToUpdate.setStatus(Status.INACTIVE);
834 if (logger.isDebugEnabled()) {
835 logger.debug("updated object");
836 logger.debug(objectAsXmlString(accountToUpdate,
837 AccountsCommon.class));
840 // Submit the request to the service and store the response.
841 res = client.update(knownResourceId, accountToUpdate);
842 int statusCode = res.getStatus();
843 // Check the status code of the response: does it match the expected response(s)?
844 if (logger.isDebugEnabled()) {
845 logger.debug(testName + ": status = " + statusCode);
847 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
848 invalidStatusCodeMessage(testRequestType, statusCode));
849 Assert.assertEquals(statusCode, testExpectedStatusCode);
851 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
852 Assert.assertNotNull(accountUpdated);
854 Assert.assertEquals(accountUpdated.getStatus(),
855 accountToUpdate.getStatus(),
856 "Data in updated object did not match submitted data.");
860 // Placeholders until the three tests below can be uncommented.
861 // See Issue CSPACE-401.
863 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
866 public void updateWithEmptyEntityBody(String testName) throws Exception {
867 //FIXME: Should this test really be empty? If so, please comment accordingly.
871 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
874 public void updateWithMalformedXml(String testName) throws Exception {
875 //FIXME: Should this test really be empty? If so, please comment accordingly.
879 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
882 public void updateWithWrongXmlSchema(String testName) throws Exception {
883 //FIXME: Should this test really be empty? If so, please comment accordingly.
887 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
888 public void updateNonExistent(String testName) throws Exception {
890 setupUpdateNonExistent();
892 // Submit the request to the service and store the response.
894 // Note: The ID used in this 'create' call may be arbitrary.
895 // The only relevant ID may be the one used in updateAccount(), below.
896 AccountClient client = new AccountClient();
897 AccountsCommon account =
898 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
899 client.getTenantId(), true, false, true, true);
900 ClientResponse<AccountsCommon> res =
901 client.update(NON_EXISTENT_ID, account);
902 int statusCode = res.getStatus();
904 // Check the status code of the response: does it match
905 // the expected response(s)?
906 if (logger.isDebugEnabled()) {
907 logger.debug(testName + ": status = " + statusCode);
909 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
910 invalidStatusCodeMessage(testRequestType, statusCode));
911 Assert.assertEquals(statusCode, testExpectedStatusCode);
917 * @param testName the test name
918 * @throws Exception the exception
920 @Test(dataProvider = "testName", dependsOnMethods = {"deactivate", "CRUDTests"})
921 public void updateWrongUser(String testName) throws Exception {
924 // Submit the request to the service and store the response.
926 // Note: The ID used in this 'create' call may be arbitrary.
927 // The only relevant ID may be the one used in updateAccount(), below.
928 AccountClient client = new AccountClient();
929 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
930 if (logger.isDebugEnabled()) {
931 logger.debug(testName + ": read status = " + res.getStatus());
933 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
935 if (logger.isDebugEnabled()) {
936 logger.debug("got object to update with ID: " + knownResourceId);
938 AccountsCommon accountToUpdate =
939 (AccountsCommon) res.getEntity();
940 Assert.assertNotNull(accountToUpdate);
942 accountToUpdate.setUserId("barneyFake");
943 if (logger.isDebugEnabled()) {
944 logger.debug("updated object with wrongUser");
945 logger.debug(objectAsXmlString(accountToUpdate,
946 AccountsCommon.class));
949 res = client.update(knownResourceId, accountToUpdate);
950 int statusCode = res.getStatus();
952 // Check the status code of the response: does it match
953 // the expected response(s)?
954 if (logger.isDebugEnabled()) {
955 logger.debug(testName + ": status = " + statusCode);
957 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
958 invalidStatusCodeMessage(testRequestType, statusCode));
959 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
962 // ---------------------------------------------------------------
963 // CRUD tests : DELETE tests
964 // ---------------------------------------------------------------
968 public void delete(String testName) throws Exception {
969 // Do nothing because this test is not ready to delete the "knownResourceId".
970 // Instead, the method localDelete() will get called later in the dependency chain. The
971 // method localDelete() has a dependency on the test "updateWrongUser". Once the "updateWrongUser"
972 // test is run, the localDelete() test/method will get run. The localDelete() test/method in turn
973 // calls the inherited delete() test/method.
976 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests", "updateWrongUser"})
977 public void localDelete(String testName) throws Exception {
978 // Because of issues with TestNG not allowing @Test annotations on on override methods,
979 // and because we want the "updateWrongUser" to run before the "delete" test, we need
980 // this method. This method will call super.delete() after all the dependencies have been
982 super.delete(testName);
985 // ---------------------------------------------------------------
986 // Utility methods used by tests above
987 // ---------------------------------------------------------------
989 * create account instance
994 * @param useScreenName
995 * @param invalidTenant
1000 AccountsCommon createAccountInstance(String screenName,
1001 String userName, String passwd, String email, String tenantId,
1002 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1004 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1005 userName, passwd, email, tenantId, useScreenName,
1006 invalidTenant, useUser, usePassword);
1007 if (logger.isDebugEnabled()) {
1008 logger.debug("to be created, account common");
1009 logger.debug(objectAsXmlString(account,
1010 AccountsCommon.class));
1020 * @param testName the test name
1021 * @param list the list
1024 protected void printList(String testName, AccountsCommonList list) {
1025 AccountsCommonList acl = (AccountsCommonList)list;
1026 List<AccountListItem> items =
1027 acl.getAccountListItem();
1029 for (AccountListItem item : items) {
1030 logger.debug(testName + ": list-item[" + i + "] csid="
1032 logger.debug(testName + ": list-item[" + i + "] screenName="
1033 + item.getScreenName());
1034 logger.debug(testName + ": list-item[" + i + "] URI="
1041 protected AccountsCommon createInstance(String commonPartName,
1042 String identifier) {
1043 AccountClient client = new AccountClient();
1044 AccountsCommon account =
1045 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
1046 "barney@dinoland.com", client.getTenantId(),
1047 true, false, true, true);
1052 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
1053 * refer to this method in their @Test annotation declarations.
1056 @Test(dataProvider = "testName",
1057 dependsOnMethods = {
1058 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
1059 public void CRUDTests(String testName) {
1060 // Do nothing. Simply here to for a TestNG execution order for our tests
1064 protected AccountsCommon updateInstance(AccountsCommon accountsCommon) {
1065 AccountsCommon result = new AccountsCommon();
1067 result.setCsid(knownResourceId);
1068 result.setUserId(accountsCommon.getUserId());
1069 // Update the content of this resource.
1070 result.setEmail("updated-" + accountsCommon.getEmail());
1076 protected void compareUpdatedInstances(AccountsCommon original,
1077 AccountsCommon updated) throws Exception {
1078 Assert.assertEquals(original.getEmail(), updated.getEmail(),
1079 "Data in updated object did not match submitted data.");
1083 protected long getSizeOfList(AccountsCommonList list) {
1084 return list.getTotalItems();