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.ArrayList;
26 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.Status;
34 import org.collectionspace.services.client.AccountFactory;
35 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
36 import org.collectionspace.services.client.test.ServiceRequestType;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.jboss.resteasy.client.ClientResponse;
40 import org.testng.Assert;
41 import org.testng.annotations.Test;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.testng.annotations.AfterClass;
48 * AccountServiceTest, carries out tests against a
49 * deployed and running Account Service.
51 * $LastChangedRevision: 917 $
52 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
54 public class AccountServiceTest extends AbstractServiceTestImpl {
56 /** The Constant logger. */
57 static private final Logger logger =
58 LoggerFactory.getLogger(AccountServiceTest.class);
59 // Instance variables specific to this test.
60 /** The known resource id. */
61 private String knownResourceId = null;
63 /** The add tenant. */
64 static boolean addTenant = true;
67 * This method is called only by the parent class, AbstractServiceTestImpl
70 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
73 protected String getServicePathComponent() {
74 return new AccountClient().getServicePathComponent();
78 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
81 protected CollectionSpaceClient getClientInstance() {
82 return new AccountClient();
86 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
89 protected AbstractCommonList getAbstractCommonList(
90 ClientResponse<AbstractCommonList> response) {
91 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
92 throw new UnsupportedOperationException();
96 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
98 @Test(dataProvider = "testName")
100 public void readPaginatedList(String testName) throws Exception {
101 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
104 // ---------------------------------------------------------------
105 // CRUD tests : CREATE tests
106 // ---------------------------------------------------------------
109 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
112 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
113 public void create(String testName) throws Exception {
115 // Perform setup, such as initializing the type of service request
116 // (e.g. CREATE, DELETE), its valid and expected status codes, and
117 // its associated HTTP method name (e.g. POST, DELETE).
118 setupCreate(testName);
120 // Submit the request to the service and store the response.
121 AccountsCommon account =
122 createAccountInstance("barney", "barney", "hithere08", "barney@dinoland.com",
123 true, false, true, true);
124 AccountClient client = new AccountClient();
125 ClientResponse<Response> res = client.create(account);
126 int statusCode = res.getStatus();
128 // Check the status code of the response: does it match
129 // the expected response(s)?
132 // Does it fall within the set of valid status codes?
133 // Does it exactly match the expected status code?
134 if (logger.isDebugEnabled()) {
135 logger.debug(testName + ": status = " + statusCode);
137 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
138 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
139 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
141 // Store the ID returned from this create operation
142 // for additional tests below.
143 knownResourceId = extractId(res);
144 if (logger.isDebugEnabled()) {
145 logger.debug(testName + ": knownResourceId=" + knownResourceId);
150 * Creates the for unique user.
152 * @param testName the test name
153 * @throws Exception the exception
155 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
156 dependsOnMethods = {"create"})
157 public void createForUniqueUser(String testName) throws Exception {
159 setupCreate(testName);
161 // Submit the request to the service and store the response.
162 AccountsCommon account =
163 createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
164 true, false, true, true);
165 AccountClient client = new AccountClient();
166 ClientResponse<Response> res = client.create(account);
167 int statusCode = res.getStatus();
168 if (logger.isDebugEnabled()) {
169 logger.debug(testName + ": status = " + statusCode);
171 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
172 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
173 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
177 * Creates the with invalid tenant.
179 * @param testName the test name
180 * @throws Exception the exception
182 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
183 dependsOnMethods = {"create"})
184 public void createWithInvalidTenant(String testName) throws Exception {
186 setupCreate(testName);
188 // Submit the request to the service and store the response.
189 AccountsCommon account =
190 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
191 true, true, true, true);
192 AccountClient client = new AccountClient();
193 ClientResponse<Response> res = client.create(account);
194 int statusCode = res.getStatus();
195 // Does it exactly match the expected status code?
196 if (logger.isDebugEnabled()) {
197 logger.debug(testName + ": status = " + statusCode);
199 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
200 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
201 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
206 * Creates the without user.
208 * @param testName the test name
209 * @throws Exception the exception
211 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
212 dependsOnMethods = {"create"})
213 public void createWithoutUser(String testName) throws Exception {
215 setupCreate(testName);
217 // Submit the request to the service and store the response.
218 AccountsCommon account =
219 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
220 true, false, false, true);
221 AccountClient client = new AccountClient();
222 ClientResponse<Response> res = client.create(account);
223 int statusCode = res.getStatus();
224 // Does it exactly match the expected status code?
225 if (logger.isDebugEnabled()) {
226 logger.debug(testName + ": status = " + statusCode);
228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
230 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
234 * Creates the with invalid email.
236 * @param testName the test name
237 * @throws Exception the exception
239 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
240 dependsOnMethods = {"create"})
241 public void createWithInvalidEmail(String testName) throws Exception {
243 setupCreate(testName);
245 // Submit the request to the service and store the response.
246 AccountsCommon account =
247 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
248 true, false, true, true);
249 AccountClient client = new AccountClient();
250 ClientResponse<Response> res = client.create(account);
251 int statusCode = res.getStatus();
252 // Does it exactly match the expected status code?
253 if (logger.isDebugEnabled()) {
254 logger.debug(testName + ": status = " + statusCode);
256 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
257 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
258 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
262 * Creates the without screen name.
264 * @param testName the test name
265 * @throws Exception the exception
267 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268 dependsOnMethods = {"create"})
269 public void createWithoutScreenName(String testName) throws Exception {
271 setupCreate(testName);
273 // Submit the request to the service and store the response.
274 AccountsCommon account =
275 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
276 false, false, true, true);
277 AccountClient client = new AccountClient();
278 ClientResponse<Response> res = client.create(account);
279 int statusCode = res.getStatus();
280 // Does it exactly match the expected status code?
281 if (logger.isDebugEnabled()) {
282 logger.debug(testName + ": status = " + statusCode);
284 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
285 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
286 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
290 * Creates the with invalid password.
292 * @param testName the test name
293 * @throws Exception the exception
295 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
296 dependsOnMethods = {"create"})
297 public void createWithInvalidPassword(String testName) throws Exception {
299 setupCreate(testName);
301 // Submit the request to the service and store the response.
302 AccountsCommon account =
303 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
304 true, false, true, true);
305 AccountClient client = new AccountClient();
306 ClientResponse<Response> res = client.create(account);
307 int statusCode = res.getStatus();
308 // Does it exactly match the expected status code?
309 if (logger.isDebugEnabled()) {
310 logger.debug(testName + ": status = " + statusCode);
312 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
313 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
314 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
318 * Creates the with most invalid.
320 * @param testName the test name
321 * @throws Exception the exception
323 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
324 dependsOnMethods = {"create"})
325 public void createWithMostInvalid(String testName) throws Exception {
327 setupCreate(testName);
329 // Submit the request to the service and store the response.
330 AccountsCommon account =
331 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
332 false, true, false, false);
333 AccountClient client = new AccountClient();
334 ClientResponse<Response> res = client.create(account);
335 int statusCode = res.getStatus();
336 // Does it exactly match the expected status code?
337 if (logger.isDebugEnabled()) {
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
345 //to not cause uniqueness violation for account, createList is removed
347 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
350 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351 dependsOnMethods = {"create"})
352 public void createList(String testName) throws Exception {
354 setupCreate(testName);
355 // Submit the request to the service and store the response.
356 AccountsCommon account1 =
357 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
358 true, false, true, true);
359 AccountClient client = new AccountClient();
360 ClientResponse<Response> res = client.create(account1);
361 int statusCode = res.getStatus();
362 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
365 allResourceIdsCreated.add(extractId(res));
367 AccountsCommon account2 =
368 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
369 true, false, true, true);
370 res = client.create(account2);
371 statusCode = res.getStatus();
372 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
375 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376 allResourceIdsCreated.add(extractId(res));
378 AccountsCommon account3 =
379 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
380 true, false, true, true);
381 res = client.create(account3);
382 statusCode = res.getStatus();
383 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
384 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
385 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
386 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387 allResourceIdsCreated.add(extractId(res));
391 // Placeholders until the three tests below can be uncommented.
392 // See Issue CSPACE-401.
394 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
397 public void createWithEmptyEntityBody(String testName) throws Exception {
398 //FIXME: Should this test really be empty? If so, please comment accordingly.
402 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
405 public void createWithMalformedXml(String testName) throws Exception {
406 //FIXME: Should this test really be empty? If so, please comment accordingly.
410 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
413 public void createWithWrongXmlSchema(String testName) throws Exception {
414 //FIXME: Should this test really be empty? If so, please comment accordingly.
417 // ---------------------------------------------------------------
418 // CRUD tests : READ tests
419 // ---------------------------------------------------------------
422 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
425 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
426 dependsOnMethods = {"create"})
427 public void read(String testName) throws Exception {
432 // Submit the request to the service and store the response.
433 AccountClient client = new AccountClient();
434 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
435 int statusCode = res.getStatus();
437 // Check the status code of the response: does it match
438 // the expected response(s)?
439 if (logger.isDebugEnabled()) {
440 logger.debug(testName + ": status = " + statusCode);
442 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
446 AccountsCommon output = (AccountsCommon) res.getEntity();
447 Assert.assertNotNull(output);
452 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
455 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456 dependsOnMethods = {"read"})
457 public void readNonExistent(String testName) throws Exception {
460 setupReadNonExistent(testName);
462 // Submit the request to the service and store the response.
463 AccountClient client = new AccountClient();
464 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match
468 // the expected response(s)?
469 if (logger.isDebugEnabled()) {
470 logger.debug(testName + ": status = " + statusCode);
472 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
477 // ---------------------------------------------------------------
478 // CRUD tests : READ_LIST tests
479 // ---------------------------------------------------------------
482 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
485 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
486 dependsOnMethods = {"createList", "read"})
487 public void readList(String testName) throws Exception {
490 setupReadList(testName);
492 // Submit the request to the service and store the response.
493 AccountClient client = new AccountClient();
494 ClientResponse<AccountsCommonList> res = client.readList();
495 AccountsCommonList list = res.getEntity();
496 int statusCode = res.getStatus();
498 // Check the status code of the response: does it match
499 // the expected response(s)?
500 if (logger.isDebugEnabled()) {
501 logger.debug(testName + ": status = " + statusCode);
503 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
504 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
505 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
507 // Optionally output additional data about list members for debugging.
508 boolean iterateThroughList = true;
509 if (iterateThroughList && logger.isDebugEnabled()) {
510 printList(testName, list);
515 * Search screen name.
517 * @param testName the test name
518 * @throws Exception the exception
520 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
521 dependsOnMethods = {"createList", "read"})
522 public void searchScreenName(String testName) throws Exception {
525 setupReadList(testName);
527 // Submit the request to the service and store the response.
528 AccountClient client = new AccountClient();
529 ClientResponse<AccountsCommonList> res =
530 client.readSearchList("tom", null, null);
531 AccountsCommonList list = res.getEntity();
532 int statusCode = res.getStatus();
534 // Check the status code of the response: does it match
535 // the expected response(s)?
536 if (logger.isDebugEnabled()) {
537 logger.debug(testName + ": status = " + statusCode);
539 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
542 Assert.assertEquals(1, list.getAccountListItem().size());
543 // Optionally output additional data about list members for debugging.
544 boolean iterateThroughList = true;
545 if (iterateThroughList && logger.isDebugEnabled()) {
546 printList(testName, list);
553 * @param testName the test name
554 * @throws Exception the exception
556 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
557 dependsOnMethods = {"createList", "read"})
558 public void searchUserId(String testName) throws Exception {
561 setupReadList(testName);
563 // Submit the request to the service and store the response.
564 AccountClient client = new AccountClient();
565 ClientResponse<AccountsCommonList> res =
566 client.readSearchList(null, "tom", null);
567 AccountsCommonList list = res.getEntity();
568 int statusCode = res.getStatus();
570 // Check the status code of the response: does it match
571 // the expected response(s)?
572 if (logger.isDebugEnabled()) {
573 logger.debug(testName + ": status = " + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578 Assert.assertEquals(1, list.getAccountListItem().size());
579 // Optionally output additional data about list members for debugging.
580 boolean iterateThroughList = true;
581 if (iterateThroughList && logger.isDebugEnabled()) {
582 printList(testName, list);
589 * @param testName the test name
590 * @throws Exception the exception
592 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
593 dependsOnMethods = {"createList", "read"})
594 public void searchEmail(String testName) throws Exception {
597 setupReadList(testName);
599 // Submit the request to the service and store the response.
600 AccountClient client = new AccountClient();
601 ClientResponse<AccountsCommonList> res =
602 client.readSearchList(null, null, "dinoland");
603 AccountsCommonList list = res.getEntity();
604 int statusCode = res.getStatus();
606 // Check the status code of the response: does it match
607 // the expected response(s)?
608 if (logger.isDebugEnabled()) {
609 logger.debug(testName + ": status = " + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614 Assert.assertEquals(2, list.getAccountListItem().size());
615 // Optionally output additional data about list members for debugging.
616 boolean iterateThroughList = true;
617 if (iterateThroughList && logger.isDebugEnabled()) {
618 printList(testName, list);
623 * Search screen name email.
625 * @param testName the test name
626 * @throws Exception the exception
628 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
629 dependsOnMethods = {"createList", "read"})
630 public void searchScreenNameEmail(String testName) throws Exception {
633 setupReadList(testName);
635 // Submit the request to the service and store the response.
636 AccountClient client = new AccountClient();
637 ClientResponse<AccountsCommonList> res =
638 client.readSearchList("tom", null, "jerry");
639 AccountsCommonList list = res.getEntity();
640 int statusCode = res.getStatus();
642 // Check the status code of the response: does it match
643 // the expected response(s)?
644 if (logger.isDebugEnabled()) {
645 logger.debug(testName + ": status = " + statusCode);
647 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
648 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
649 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650 Assert.assertEquals(1, list.getAccountListItem().size());
651 // Optionally output additional data about list members for debugging.
652 boolean iterateThroughList = true;
653 if (iterateThroughList && logger.isDebugEnabled()) {
654 printList(testName, list);
660 // ---------------------------------------------------------------
661 // CRUD tests : UPDATE tests
662 // ---------------------------------------------------------------
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
668 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
669 dependsOnMethods = {"read", "readList", "readNonExistent"})
670 public void update(String testName) throws Exception {
673 setupUpdate(testName);
675 AccountClient client = new AccountClient();
676 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
677 if (logger.isDebugEnabled()) {
678 logger.debug(testName + ": read status = " + res.getStatus());
680 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
682 if (logger.isDebugEnabled()) {
683 logger.debug("got object to update with ID: " + knownResourceId);
685 AccountsCommon accountFound =
686 (AccountsCommon) res.getEntity();
687 Assert.assertNotNull(accountFound);
689 //create a new account object to test partial updates
690 AccountsCommon accountToUpdate = new AccountsCommon();
691 accountToUpdate.setCsid(knownResourceId);
692 accountToUpdate.setUserId(accountFound.getUserId());
693 // Update the content of this resource.
694 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
695 if (logger.isDebugEnabled()) {
696 logger.debug("updated object");
697 logger.debug(objectAsXmlString(accountFound,
698 AccountsCommon.class));
701 // Submit the request to the service and store the response.
702 res = client.update(knownResourceId, accountToUpdate);
703 int statusCode = res.getStatus();
704 // Check the status code of the response: does it match the expected response(s)?
705 if (logger.isDebugEnabled()) {
706 logger.debug(testName + ": status = " + statusCode);
708 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
709 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
710 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
713 Assert.assertNotNull(accountUpdated);
715 Assert.assertEquals(accountUpdated.getEmail(),
716 accountToUpdate.getEmail(),
717 "Data in updated object did not match submitted data.");
723 * @param testName the test name
724 * @throws Exception the exception
726 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
727 dependsOnMethods = {"update"})
728 public void updatePassword(String testName) throws Exception {
731 setupUpdate(testName);
733 AccountClient client = new AccountClient();
734 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
735 if (logger.isDebugEnabled()) {
736 logger.debug(testName + ": read status = " + res.getStatus());
738 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
740 if (logger.isDebugEnabled()) {
741 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
743 AccountsCommon accountFound =
744 (AccountsCommon) res.getEntity();
745 Assert.assertNotNull(accountFound);
747 //create a new account object to test partial updates
748 AccountsCommon accountToUpdate = new AccountsCommon();
749 accountToUpdate.setCsid(knownResourceId);
750 accountToUpdate.setUserId(accountFound.getUserId());
752 accountToUpdate.setPassword("imagination".getBytes());
753 if (logger.isDebugEnabled()) {
754 logger.debug(testName + ": updated object");
755 logger.debug(objectAsXmlString(accountToUpdate,
756 AccountsCommon.class));
759 // Submit the request to the service and store the response.
760 res = client.update(knownResourceId, accountToUpdate);
761 int statusCode = res.getStatus();
762 // Check the status code of the response: does it match the expected response(s)?
763 if (logger.isDebugEnabled()) {
764 logger.debug(testName + ": status = " + statusCode);
766 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
767 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
768 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
771 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
772 Assert.assertNotNull(accountUpdated);
774 // Assert.assertEquals(accountUpdated.getPassword(),
775 // accountFound.getPassword(),
776 // "Data in updated object did not match submitted data.");
780 * Update password without user.
782 * @param testName the test name
783 * @throws Exception the exception
785 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
786 dependsOnMethods = {"update"})
787 public void updatePasswordWithoutUser(String testName) throws Exception {
790 setupUpdate(testName);
792 AccountsCommon accountToUpdate = new AccountsCommon();
793 accountToUpdate.setCsid(knownResourceId);
794 accountToUpdate.setUserId(null);
796 accountToUpdate.setPassword("imagination".getBytes());
797 if (logger.isDebugEnabled()) {
798 logger.debug(testName + " : updated object");
799 logger.debug(objectAsXmlString(accountToUpdate,
800 AccountsCommon.class));
803 AccountClient client = new AccountClient();
804 // Submit the request to the service and store the response.
805 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
806 int statusCode = res.getStatus();
807 // Check the status code of the response: does it match the expected response(s)?
808 if (logger.isDebugEnabled()) {
809 logger.debug(testName + ": status = " + statusCode);
811 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
812 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
813 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
818 * Update invalid password.
820 * @param testName the test name
821 * @throws Exception the exception
823 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
824 dependsOnMethods = {"update"})
825 public void updateInvalidPassword(String testName) throws Exception {
828 setupUpdate(testName);
829 AccountClient client = new AccountClient();
830 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
831 if (logger.isDebugEnabled()) {
832 logger.debug(testName + ": read status = " + res.getStatus());
834 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
836 if (logger.isDebugEnabled()) {
837 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
839 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
841 AccountsCommon accountToUpdate = new AccountsCommon();
842 accountToUpdate.setCsid(knownResourceId);
843 accountToUpdate.setUserId(accountFound.getUserId());
844 Assert.assertNotNull(accountToUpdate);
847 accountToUpdate.setPassword("abc123".getBytes());
848 if (logger.isDebugEnabled()) {
849 logger.debug(testName + ": updated object");
850 logger.debug(objectAsXmlString(accountToUpdate,
851 AccountsCommon.class));
854 // Submit the request to the service and store the response.
855 res = client.update(knownResourceId, accountToUpdate);
856 int statusCode = res.getStatus();
857 // Check the status code of the response: does it match the expected response(s)?
858 if (logger.isDebugEnabled()) {
859 logger.debug(testName + ": status = " + statusCode);
861 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
862 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
863 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
870 * @param testName the test name
871 * @throws Exception the exception
873 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
874 dependsOnMethods = {"updatePasswordWithoutUser"})
875 public void deactivate(String testName) throws Exception {
878 setupUpdate(testName);
880 AccountClient client = new AccountClient();
881 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
882 if (logger.isDebugEnabled()) {
883 logger.debug(testName + ": read status = " + res.getStatus());
885 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
887 if (logger.isDebugEnabled()) {
888 logger.debug("got object to update with ID: " + knownResourceId);
890 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
892 //create a new account object to test partial updates
893 AccountsCommon accountToUpdate = new AccountsCommon();
894 accountToUpdate.setCsid(knownResourceId);
895 accountToUpdate.setUserId(accountFound.getUserId());
897 // Update the content of this resource.
898 accountToUpdate.setStatus(Status.INACTIVE);
899 if (logger.isDebugEnabled()) {
900 logger.debug("updated object");
901 logger.debug(objectAsXmlString(accountToUpdate,
902 AccountsCommon.class));
905 // Submit the request to the service and store the response.
906 res = client.update(knownResourceId, accountToUpdate);
907 int statusCode = res.getStatus();
908 // Check the status code of the response: does it match the expected response(s)?
909 if (logger.isDebugEnabled()) {
910 logger.debug(testName + ": status = " + statusCode);
912 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
913 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
914 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
916 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
917 Assert.assertNotNull(accountUpdated);
919 Assert.assertEquals(accountUpdated.getStatus(),
920 accountToUpdate.getStatus(),
921 "Data in updated object did not match submitted data.");
926 // Placeholders until the three tests below can be uncommented.
927 // See Issue CSPACE-401.
929 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
932 public void updateWithEmptyEntityBody(String testName) throws Exception {
933 //FIXME: Should this test really be empty? If so, please comment accordingly.
937 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
940 public void updateWithMalformedXml(String testName) throws Exception {
941 //FIXME: Should this test really be empty? If so, please comment accordingly.
945 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
948 public void updateWithWrongXmlSchema(String testName) throws Exception {
949 //FIXME: Should this test really be empty? If so, please comment accordingly.
953 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
956 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
957 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
958 public void updateNonExistent(String testName) throws Exception {
961 setupUpdateNonExistent(testName);
963 // Submit the request to the service and store the response.
965 // Note: The ID used in this 'create' call may be arbitrary.
966 // The only relevant ID may be the one used in updateAccount(), below.
967 AccountClient client = new AccountClient();
968 AccountsCommon account =
969 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
970 true, false, true, true);
971 ClientResponse<AccountsCommon> res =
972 client.update(NON_EXISTENT_ID, account);
973 int statusCode = res.getStatus();
975 // Check the status code of the response: does it match
976 // the expected response(s)?
977 if (logger.isDebugEnabled()) {
978 logger.debug(testName + ": status = " + statusCode);
980 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
981 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
982 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
988 * @param testName the test name
989 * @throws Exception the exception
991 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
992 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
993 public void updateWrongUser(String testName) throws Exception {
995 setupUpdate(testName);
997 // Submit the request to the service and store the response.
999 // Note: The ID used in this 'create' call may be arbitrary.
1000 // The only relevant ID may be the one used in updateAccount(), below.
1001 AccountClient client = new AccountClient();
1002 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
1003 if (logger.isDebugEnabled()) {
1004 logger.debug(testName + ": read status = " + res.getStatus());
1006 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1008 if (logger.isDebugEnabled()) {
1009 logger.debug("got object to update with ID: " + knownResourceId);
1011 AccountsCommon accountToUpdate =
1012 (AccountsCommon) res.getEntity();
1013 Assert.assertNotNull(accountToUpdate);
1015 accountToUpdate.setUserId("barneyFake");
1016 if (logger.isDebugEnabled()) {
1017 logger.debug("updated object with wrongUser");
1018 logger.debug(objectAsXmlString(accountToUpdate,
1019 AccountsCommon.class));
1022 res = client.update(knownResourceId, accountToUpdate);
1023 int statusCode = res.getStatus();
1025 // Check the status code of the response: does it match
1026 // the expected response(s)?
1027 if (logger.isDebugEnabled()) {
1028 logger.debug(testName + ": status = " + statusCode);
1030 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1035 // ---------------------------------------------------------------
1036 // CRUD tests : DELETE tests
1037 // ---------------------------------------------------------------
1040 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1043 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1044 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
1045 public void delete(String testName) throws Exception {
1048 setupDelete(testName);
1050 // Submit the request to the service and store the response.
1051 AccountClient client = new AccountClient();
1052 ClientResponse<Response> res = client.delete(knownResourceId);
1053 int statusCode = res.getStatus();
1055 // Check the status code of the response: does it match
1056 // the expected response(s)?
1057 if (logger.isDebugEnabled()) {
1058 logger.debug(testName + ": status = " + statusCode);
1060 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1061 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1062 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1067 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1070 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1071 dependsOnMethods = {"delete"})
1072 public void deleteNonExistent(String testName) throws Exception {
1075 setupDeleteNonExistent(testName);
1077 // Submit the request to the service and store the response.
1078 AccountClient client = new AccountClient();
1079 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1080 int statusCode = res.getStatus();
1082 // Check the status code of the response: does it match
1083 // the expected response(s)?
1084 if (logger.isDebugEnabled()) {
1085 logger.debug(testName + ": status = " + statusCode);
1087 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1088 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1089 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1092 // ---------------------------------------------------------------
1093 // Utility tests : tests of code used in tests above
1094 // ---------------------------------------------------------------
1096 * Tests the code for manually submitting data that is used by several
1097 * of the methods above.
1100 @Test(dependsOnMethods = {"create", "read"})
1101 public void testSubmitRequest() throws Exception {
1103 // Expected status code: 200 OK
1104 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1106 // Submit the request to the service and store the response.
1107 String method = ServiceRequestType.READ.httpMethodName();
1108 String url = getResourceURL(knownResourceId);
1109 int statusCode = submitRequest(method, url);
1111 // Check the status code of the response: does it match
1112 // the expected response(s)?
1113 if (logger.isDebugEnabled()) {
1114 logger.debug("testSubmitRequest: url=" + url
1115 + " status=" + statusCode);
1117 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1121 // ---------------------------------------------------------------
1122 // Utility methods used by tests above
1123 // ---------------------------------------------------------------
1125 * create account instance
1130 * @param useScreenName
1131 * @param invalidTenant
1133 * @param usePassword
1136 AccountsCommon createAccountInstance(String screenName,
1137 String userName, String passwd, String email,
1138 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1140 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1141 userName, passwd, email, useScreenName,
1142 addTenant, invalidTenant, useUser, usePassword);
1144 if (logger.isDebugEnabled()) {
1145 logger.debug("to be created, account common");
1146 logger.debug(objectAsXmlString(account,
1147 AccountsCommon.class));
1156 * @param testName the test name
1157 * @param list the list
1159 private void printList(String testName, AccountsCommonList list) {
1160 List<AccountsCommonList.AccountListItem> items =
1161 list.getAccountListItem();
1164 for (AccountsCommonList.AccountListItem item : items) {
1165 logger.debug(testName + ": list-item[" + i + "] csid="
1167 logger.debug(testName + ": list-item[" + i + "] screenName="
1168 + item.getScreenName());
1169 logger.debug(testName + ": list-item[" + i + "] URI="