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;
28 import org.collectionspace.services.client.AccountClient;
29 import org.collectionspace.services.client.CollectionSpaceClient;
30 import org.collectionspace.services.account.AccountsCommon;
31 import org.collectionspace.services.account.AccountsCommonList;
32 import org.collectionspace.services.account.Status;
33 import org.collectionspace.services.client.AccountFactory;
34 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
35 import org.collectionspace.services.client.test.ServiceRequestType;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
37 import org.jboss.resteasy.client.ClientResponse;
39 import org.testng.Assert;
40 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 {
54 /** The Constant logger. */
55 private final String CLASS_NAME = AccountServiceTest.class.getName();
56 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
57 // Instance variables specific to this test.
58 /** The known resource id. */
59 private String knownResourceId = null;
60 private String knownUserId = "barney";
61 private String knownUserPassword = "hithere08";
62 /** The add tenant. */
63 static boolean addTenant = true;
66 public String getServiceName() {
67 return AccountClient.SERVICE_NAME;
71 * This method is called only by the parent class, AbstractServiceTestImpl
74 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
77 protected String getServicePathComponent() {
78 return new AccountClient().getServicePathComponent();
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
85 protected CollectionSpaceClient getClientInstance() {
86 return new AccountClient();
90 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
93 protected AbstractCommonList getAbstractCommonList(
94 ClientResponse<AbstractCommonList> response) {
95 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
96 throw new UnsupportedOperationException();
100 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
102 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
103 dependsOnMethods = {"readList"})
105 public void readPaginatedList(String testName) throws Exception {
106 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
109 // ---------------------------------------------------------------
110 // CRUD tests : CREATE tests
111 // ---------------------------------------------------------------
114 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
117 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
118 public void create(String testName) throws Exception {
120 if (logger.isDebugEnabled()) {
121 logger.debug(testBanner(testName, CLASS_NAME));
123 // Perform setup, such as initializing the type of service request
124 // (e.g. CREATE, DELETE), its valid and expected status codes, and
125 // its associated HTTP method name (e.g. POST, DELETE).
128 AccountClient client = new AccountClient();
129 // Submit the request to the service and store the response.
130 AccountsCommon account =
131 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
132 "barney@dinoland.com", client.getTenantId(),
133 true, false, true, true);
134 ClientResponse<Response> res = client.create(account);
135 int statusCode = res.getStatus();
137 // Check the status code of the response: does it match
138 // the expected response(s)?
141 // Does it fall within the set of valid status codes?
142 // Does it exactly match the expected status code?
143 if (logger.isDebugEnabled()) {
144 logger.debug(testName + ": status = " + statusCode);
146 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
147 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
148 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
150 // Store the ID returned from this create operation
151 // for additional tests below.
152 knownResourceId = extractId(res);
153 if (logger.isDebugEnabled()) {
154 logger.debug(testName + ": knownResourceId=" + knownResourceId);
159 * Creates the for unique user.
161 * @param testName the test name
162 * @throws Exception the exception
164 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
165 dependsOnMethods = {"create"})
166 public void createForUniqueUser(String testName) throws Exception {
168 if (logger.isDebugEnabled()) {
169 logger.debug(testBanner(testName, CLASS_NAME));
173 // Submit the request to the service and store the response.
174 AccountClient client = new AccountClient();
175 AccountsCommon account =
176 createAccountInstance("barney1", knownUserId, knownUserPassword,
177 "barney@dinoland.com",
178 client.getTenantId(), true, false, true, true);
180 ClientResponse<Response> res = client.create(account);
181 int statusCode = res.getStatus();
182 if (logger.isDebugEnabled()) {
183 logger.debug(testName + ": status = " + statusCode);
185 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
186 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
187 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
191 * Creates the with invalid tenant.
193 * @param testName the test name
194 * @throws Exception the exception
196 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
197 dependsOnMethods = {"create"})
198 public void createWithInvalidTenant(String testName) throws Exception {
200 if (logger.isDebugEnabled()) {
201 logger.debug(testBanner(testName, CLASS_NAME));
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, true, 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(REQUEST_TYPE.isValidStatusCode(statusCode),
217 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
218 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
223 * Creates the without user.
225 * @param testName the test name
226 * @throws Exception the exception
228 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
229 dependsOnMethods = {"create"})
230 public void createWithoutUser(String testName) throws Exception {
232 if (logger.isDebugEnabled()) {
233 logger.debug(testBanner(testName, CLASS_NAME));
237 // Submit the request to the service and store the response.
238 AccountClient client = new AccountClient();
239 AccountsCommon account =
240 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
241 client.getTenantId(), true, false, false, true);
242 ClientResponse<Response> res = client.create(account);
243 int statusCode = res.getStatus();
244 // Does it exactly match the expected status code?
245 if (logger.isDebugEnabled()) {
246 logger.debug(testName + ": status = " + statusCode);
248 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
249 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
250 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
254 * Creates the with invalid email.
256 * @param testName the test name
257 * @throws Exception the exception
259 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
260 dependsOnMethods = {"create"})
261 public void createWithInvalidEmail(String testName) throws Exception {
263 if (logger.isDebugEnabled()) {
264 logger.debug(testBanner(testName, CLASS_NAME));
268 // Submit the request to the service and store the response.
269 AccountClient client = new AccountClient();
270 AccountsCommon account =
271 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
272 client.getTenantId(), true, false, true, true);
273 ClientResponse<Response> res = client.create(account);
274 int statusCode = res.getStatus();
275 // Does it exactly match the expected status code?
276 if (logger.isDebugEnabled()) {
277 logger.debug(testName + ": status = " + statusCode);
279 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
280 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
281 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
285 * Creates the without screen name.
287 * @param testName the test name
288 * @throws Exception the exception
290 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
291 dependsOnMethods = {"create"})
292 public void createWithoutScreenName(String testName) throws Exception {
294 if (logger.isDebugEnabled()) {
295 logger.debug(testBanner(testName, CLASS_NAME));
299 // Submit the request to the service and store the response.
300 AccountClient client = new AccountClient();
301 AccountsCommon account =
302 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
303 client.getTenantId(), false, false, true, true);
304 ClientResponse<Response> res = client.create(account);
305 int statusCode = res.getStatus();
306 // Does it exactly match the expected status code?
307 if (logger.isDebugEnabled()) {
308 logger.debug(testName + ": status = " + statusCode);
310 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
311 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
312 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
316 * Creates the with invalid password.
318 * @param testName the test name
319 * @throws Exception the exception
321 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
322 dependsOnMethods = {"create"})
323 public void createWithInvalidPassword(String testName) throws Exception {
325 if (logger.isDebugEnabled()) {
326 logger.debug(testBanner(testName, CLASS_NAME));
330 // Submit the request to the service and store the response.
331 AccountClient client = new AccountClient();
332 AccountsCommon account =
333 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
334 client.getTenantId(), true, false, true, true);
335 ClientResponse<Response> res = client.create(account);
336 int statusCode = res.getStatus();
337 // Does it exactly match the expected status code?
338 if (logger.isDebugEnabled()) {
339 logger.debug(testName + ": status = " + statusCode);
341 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
342 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
343 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
347 * Creates the with most invalid.
349 * @param testName the test name
350 * @throws Exception the exception
352 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
353 dependsOnMethods = {"create"})
354 public void createWithMostInvalid(String testName) throws Exception {
356 if (logger.isDebugEnabled()) {
357 logger.debug(testBanner(testName, CLASS_NAME));
361 // Submit the request to the service and store the response.
362 AccountClient client = new AccountClient();
363 AccountsCommon account =
364 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
365 client.getTenantId(), false, true, false, false);
366 ClientResponse<Response> res = client.create(account);
367 int statusCode = res.getStatus();
368 // Does it exactly match the expected status code?
369 if (logger.isDebugEnabled()) {
370 logger.debug(testName + ": status = " + statusCode);
372 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
377 //to not cause uniqueness violation for account, createList is removed
379 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
382 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
383 dependsOnMethods = {"create"})
384 public void createList(String testName) throws Exception {
386 if (logger.isDebugEnabled()) {
387 logger.debug(testBanner(testName, CLASS_NAME));
390 // Submit the request to the service and store the response.
391 AccountClient client = new AccountClient();
392 AccountsCommon account1 =
393 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
394 client.getTenantId(), true, false, true, true);
395 ClientResponse<Response> res = client.create(account1);
396 int statusCode = res.getStatus();
397 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
398 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
399 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
400 allResourceIdsCreated.add(extractId(res));
402 AccountsCommon account2 =
403 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
404 client.getTenantId(), true, false, true, true);
405 res = client.create(account2);
406 statusCode = res.getStatus();
407 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
408 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
409 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
410 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
411 allResourceIdsCreated.add(extractId(res));
413 AccountsCommon account3 =
414 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
415 client.getTenantId(), true, false, true, true);
416 res = client.create(account3);
417 statusCode = res.getStatus();
418 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
419 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
420 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
421 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
422 allResourceIdsCreated.add(extractId(res));
426 // Placeholders until the three tests below can be uncommented.
427 // See Issue CSPACE-401.
429 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
432 public void createWithEmptyEntityBody(String testName) throws Exception {
433 //FIXME: Should this test really be empty? If so, please comment accordingly.
437 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
440 public void createWithMalformedXml(String testName) throws Exception {
441 //FIXME: Should this test really be empty? If so, please comment accordingly.
445 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
448 public void createWithWrongXmlSchema(String testName) throws Exception {
449 //FIXME: Should this test really be empty? If so, please comment accordingly.
452 // ---------------------------------------------------------------
453 // CRUD tests : READ tests
454 // ---------------------------------------------------------------
457 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
460 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
461 dependsOnMethods = {"create"})
462 public void read(String testName) throws Exception {
464 if (logger.isDebugEnabled()) {
465 logger.debug(testBanner(testName, CLASS_NAME));
470 // Submit the request to the service and store the response.
471 AccountClient client = new AccountClient();
472 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
473 int statusCode = res.getStatus();
475 // Check the status code of the response: does it match
476 // the expected response(s)?
477 if (logger.isDebugEnabled()) {
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 AccountsCommon output = (AccountsCommon) res.getEntity();
485 Assert.assertNotNull(output);
490 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
493 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
494 dependsOnMethods = {"read"})
495 public void readNonExistent(String testName) throws Exception {
497 if (logger.isDebugEnabled()) {
498 logger.debug(testBanner(testName, CLASS_NAME));
501 setupReadNonExistent();
503 // Submit the request to the service and store the response.
504 AccountClient client = new AccountClient();
505 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
506 int statusCode = res.getStatus();
508 // Check the status code of the response: does it match
509 // the expected response(s)?
510 if (logger.isDebugEnabled()) {
511 logger.debug(testName + ": status = " + statusCode);
513 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
514 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
515 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
518 // ---------------------------------------------------------------
519 // CRUD tests : READ_LIST tests
520 // ---------------------------------------------------------------
523 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
526 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
527 dependsOnMethods = {"createList", "read"})
528 public void readList(String testName) throws Exception {
530 if (logger.isDebugEnabled()) {
531 logger.debug(testBanner(testName, CLASS_NAME));
536 // Submit the request to the service and store the response.
537 AccountClient client = new AccountClient();
538 ClientResponse<AccountsCommonList> res = client.readList();
539 AccountsCommonList list = res.getEntity();
540 int statusCode = res.getStatus();
542 // Check the status code of the response: does it match
543 // the expected response(s)?
544 if (logger.isDebugEnabled()) {
545 logger.debug(testName + ": status = " + statusCode);
547 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
548 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
549 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
551 // Optionally output additional data about list members for debugging.
552 boolean iterateThroughList = true;
553 if (iterateThroughList && logger.isDebugEnabled()) {
554 printList(testName, list);
559 * Search screen name.
561 * @param testName the test name
562 * @throws Exception the exception
564 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
565 dependsOnMethods = {"createList", "read"})
566 public void searchScreenName(String testName) throws Exception {
568 if (logger.isDebugEnabled()) {
569 logger.debug(testBanner(testName, CLASS_NAME));
574 // Submit the request to the service and store the response.
575 AccountClient client = new AccountClient();
576 ClientResponse<AccountsCommonList> res =
577 client.readSearchList("tom", null, null);
578 AccountsCommonList list = res.getEntity();
579 int statusCode = res.getStatus();
581 // Check the status code of the response: does it match
582 // the expected response(s)?
583 if (logger.isDebugEnabled()) {
584 logger.debug(testName + ": status = " + statusCode);
586 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
587 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
588 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
589 Assert.assertEquals(1, list.getAccountListItem().size());
590 // Optionally output additional data about list members for debugging.
591 boolean iterateThroughList = true;
592 if (iterateThroughList && logger.isDebugEnabled()) {
593 printList(testName, list);
600 * @param testName the test name
601 * @throws Exception the exception
603 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
604 dependsOnMethods = {"createList", "read"})
605 public void searchUserId(String testName) throws Exception {
607 if (logger.isDebugEnabled()) {
608 logger.debug(testBanner(testName, CLASS_NAME));
613 // Submit the request to the service and store the response.
614 AccountClient client = new AccountClient();
615 ClientResponse<AccountsCommonList> res =
616 client.readSearchList(null, "tom", null);
617 AccountsCommonList list = res.getEntity();
618 int statusCode = res.getStatus();
620 // Check the status code of the response: does it match
621 // the expected response(s)?
622 if (logger.isDebugEnabled()) {
623 logger.debug(testName + ": status = " + statusCode);
625 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
626 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
627 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628 Assert.assertEquals(1, list.getAccountListItem().size());
629 // Optionally output additional data about list members for debugging.
630 boolean iterateThroughList = true;
631 if (iterateThroughList && logger.isDebugEnabled()) {
632 printList(testName, list);
639 * @param testName the test name
640 * @throws Exception the exception
642 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
643 dependsOnMethods = {"createList", "read"})
644 public void searchEmail(String testName) throws Exception {
646 if (logger.isDebugEnabled()) {
647 logger.debug(testBanner(testName, CLASS_NAME));
652 // Submit the request to the service and store the response.
653 AccountClient client = new AccountClient();
654 ClientResponse<AccountsCommonList> res =
655 client.readSearchList(null, null, "dinoland");
656 AccountsCommonList list = res.getEntity();
657 int statusCode = res.getStatus();
659 // Check the status code of the response: does it match
660 // the expected response(s)?
661 if (logger.isDebugEnabled()) {
662 logger.debug(testName + ": status = " + statusCode);
664 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667 Assert.assertEquals(2, list.getAccountListItem().size());
668 // Optionally output additional data about list members for debugging.
669 boolean iterateThroughList = true;
670 if (iterateThroughList && logger.isDebugEnabled()) {
671 printList(testName, list);
676 * Search screen name email.
678 * @param testName the test name
679 * @throws Exception the exception
681 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
682 dependsOnMethods = {"createList", "read"})
683 public void searchScreenNameEmail(String testName) throws Exception {
685 if (logger.isDebugEnabled()) {
686 logger.debug(testBanner(testName, CLASS_NAME));
691 // Submit the request to the service and store the response.
692 AccountClient client = new AccountClient();
693 ClientResponse<AccountsCommonList> res =
694 client.readSearchList("tom", null, "jerry");
695 AccountsCommonList list = res.getEntity();
696 int statusCode = res.getStatus();
698 // Check the status code of the response: does it match
699 // the expected response(s)?
700 if (logger.isDebugEnabled()) {
701 logger.debug(testName + ": status = " + statusCode);
703 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
704 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
705 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
706 Assert.assertEquals(1, list.getAccountListItem().size());
707 // Optionally output additional data about list members for debugging.
708 boolean iterateThroughList = true;
709 if (iterateThroughList && logger.isDebugEnabled()) {
710 printList(testName, list);
716 // ---------------------------------------------------------------
717 // CRUD tests : UPDATE tests
718 // ---------------------------------------------------------------
721 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
724 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
725 dependsOnMethods = {"read", "readList", "readNonExistent"})
726 public void update(String testName) throws Exception {
728 if (logger.isDebugEnabled()) {
729 logger.debug(testBanner(testName, CLASS_NAME));
734 AccountClient client = new AccountClient();
735 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
736 if (logger.isDebugEnabled()) {
737 logger.debug(testName + ": read status = " + res.getStatus());
739 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
741 if (logger.isDebugEnabled()) {
742 logger.debug("got object to update with ID: " + knownResourceId);
744 AccountsCommon accountFound =
745 (AccountsCommon) res.getEntity();
746 Assert.assertNotNull(accountFound);
748 //create a new account object to test partial updates
749 AccountsCommon accountToUpdate = new AccountsCommon();
750 accountToUpdate.setCsid(knownResourceId);
751 accountToUpdate.setUserId(accountFound.getUserId());
752 // Update the content of this resource.
753 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
754 if (logger.isDebugEnabled()) {
755 logger.debug("updated object");
756 logger.debug(objectAsXmlString(accountFound,
757 AccountsCommon.class));
760 // Submit the request to the service and store the response.
761 res = client.update(knownResourceId, accountToUpdate);
762 int statusCode = res.getStatus();
763 // Check the status code of the response: does it match the expected response(s)?
764 if (logger.isDebugEnabled()) {
765 logger.debug(testName + ": status = " + statusCode);
767 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
768 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
769 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
771 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
772 Assert.assertNotNull(accountUpdated);
774 Assert.assertEquals(accountUpdated.getEmail(),
775 accountToUpdate.getEmail(),
776 "Data in updated object did not match submitted data.");
782 * @param testName the test name
783 * @throws Exception the exception
785 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
786 dependsOnMethods = {"update"})
787 public void updatePassword(String testName) throws Exception {
789 if (logger.isDebugEnabled()) {
790 logger.debug(testBanner(testName, CLASS_NAME));
795 AccountClient client = new AccountClient();
796 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
797 if (logger.isDebugEnabled()) {
798 logger.debug(testName + ": read status = " + res.getStatus());
800 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
802 if (logger.isDebugEnabled()) {
803 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
805 AccountsCommon accountFound =
806 (AccountsCommon) res.getEntity();
807 Assert.assertNotNull(accountFound);
809 //create a new account object to test partial updates
810 AccountsCommon accountToUpdate = new AccountsCommon();
811 accountToUpdate.setCsid(knownResourceId);
812 accountToUpdate.setUserId(accountFound.getUserId());
814 accountToUpdate.setPassword("imagination".getBytes());
815 if (logger.isDebugEnabled()) {
816 logger.debug(testName + ": updated object");
817 logger.debug(objectAsXmlString(accountToUpdate,
818 AccountsCommon.class));
821 // Submit the request to the service and store the response.
822 res = client.update(knownResourceId, accountToUpdate);
823 int statusCode = res.getStatus();
824 // Check the status code of the response: does it match the expected response(s)?
825 if (logger.isDebugEnabled()) {
826 logger.debug(testName + ": status = " + statusCode);
828 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
829 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
830 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
833 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
834 Assert.assertNotNull(accountUpdated);
836 // Assert.assertEquals(accountUpdated.getPassword(),
837 // accountFound.getPassword(),
838 // "Data in updated object did not match submitted data.");
842 * Update password without user.
844 * @param testName the test name
845 * @throws Exception the exception
847 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
848 dependsOnMethods = {"update"})
849 public void updatePasswordWithoutUser(String testName) throws Exception {
851 if (logger.isDebugEnabled()) {
852 logger.debug(testBanner(testName, CLASS_NAME));
857 AccountsCommon accountToUpdate = new AccountsCommon();
858 accountToUpdate.setCsid(knownResourceId);
859 accountToUpdate.setUserId(null);
861 accountToUpdate.setPassword("imagination".getBytes());
862 if (logger.isDebugEnabled()) {
863 logger.debug(testName + " : updated object");
864 logger.debug(objectAsXmlString(accountToUpdate,
865 AccountsCommon.class));
868 AccountClient client = new AccountClient();
869 // Submit the request to the service and store the response.
870 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
871 int statusCode = res.getStatus();
872 // Check the status code of the response: does it match the expected response(s)?
873 if (logger.isDebugEnabled()) {
874 logger.debug(testName + ": status = " + statusCode);
876 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
877 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
878 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
883 * Update invalid password.
885 * @param testName the test name
886 * @throws Exception the exception
888 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
889 dependsOnMethods = {"update"})
890 public void updateInvalidPassword(String testName) throws Exception {
892 if (logger.isDebugEnabled()) {
893 logger.debug(testBanner(testName, CLASS_NAME));
897 AccountClient client = new AccountClient();
898 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
899 if (logger.isDebugEnabled()) {
900 logger.debug(testName + ": read status = " + res.getStatus());
902 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
904 if (logger.isDebugEnabled()) {
905 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
907 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
909 AccountsCommon accountToUpdate = new AccountsCommon();
910 accountToUpdate.setCsid(knownResourceId);
911 accountToUpdate.setUserId(accountFound.getUserId());
912 Assert.assertNotNull(accountToUpdate);
915 accountToUpdate.setPassword("abc123".getBytes());
916 if (logger.isDebugEnabled()) {
917 logger.debug(testName + ": updated object");
918 logger.debug(objectAsXmlString(accountToUpdate,
919 AccountsCommon.class));
922 // Submit the request to the service and store the response.
923 res = client.update(knownResourceId, accountToUpdate);
924 int statusCode = res.getStatus();
925 // Check the status code of the response: does it match the expected response(s)?
926 if (logger.isDebugEnabled()) {
927 logger.debug(testName + ": status = " + statusCode);
929 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
930 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
931 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
938 * @param testName the test name
939 * @throws Exception the exception
941 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
942 dependsOnMethods = {"updatePasswordWithoutUser"})
943 public void deactivate(String testName) throws Exception {
945 if (logger.isDebugEnabled()) {
946 logger.debug(testBanner(testName, CLASS_NAME));
951 AccountClient client = new AccountClient();
952 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
953 if (logger.isDebugEnabled()) {
954 logger.debug(testName + ": read status = " + res.getStatus());
956 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
958 if (logger.isDebugEnabled()) {
959 logger.debug("got object to update with ID: " + knownResourceId);
961 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
963 //create a new account object to test partial updates
964 AccountsCommon accountToUpdate = new AccountsCommon();
965 accountToUpdate.setCsid(knownResourceId);
966 accountToUpdate.setUserId(accountFound.getUserId());
968 // Update the content of this resource.
969 accountToUpdate.setStatus(Status.INACTIVE);
970 if (logger.isDebugEnabled()) {
971 logger.debug("updated object");
972 logger.debug(objectAsXmlString(accountToUpdate,
973 AccountsCommon.class));
976 // Submit the request to the service and store the response.
977 res = client.update(knownResourceId, accountToUpdate);
978 int statusCode = res.getStatus();
979 // Check the status code of the response: does it match the expected response(s)?
980 if (logger.isDebugEnabled()) {
981 logger.debug(testName + ": status = " + statusCode);
983 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
984 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
985 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
987 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
988 Assert.assertNotNull(accountUpdated);
990 Assert.assertEquals(accountUpdated.getStatus(),
991 accountToUpdate.getStatus(),
992 "Data in updated object did not match submitted data.");
997 // Placeholders until the three tests below can be uncommented.
998 // See Issue CSPACE-401.
1000 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1003 public void updateWithEmptyEntityBody(String testName) throws Exception {
1004 //FIXME: Should this test really be empty? If so, please comment accordingly.
1008 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1011 public void updateWithMalformedXml(String testName) throws Exception {
1012 //FIXME: Should this test really be empty? If so, please comment accordingly.
1016 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1019 public void updateWithWrongXmlSchema(String testName) throws Exception {
1020 //FIXME: Should this test really be empty? If so, please comment accordingly.
1024 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1027 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1028 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1029 public void updateNonExistent(String testName) throws Exception {
1031 if (logger.isDebugEnabled()) {
1032 logger.debug(testBanner(testName, CLASS_NAME));
1035 setupUpdateNonExistent();
1037 // Submit the request to the service and store the response.
1039 // Note: The ID used in this 'create' call may be arbitrary.
1040 // The only relevant ID may be the one used in updateAccount(), below.
1041 AccountClient client = new AccountClient();
1042 AccountsCommon account =
1043 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
1044 client.getTenantId(), true, false, true, true);
1045 ClientResponse<AccountsCommon> res =
1046 client.update(NON_EXISTENT_ID, account);
1047 int statusCode = res.getStatus();
1049 // Check the status code of the response: does it match
1050 // the expected response(s)?
1051 if (logger.isDebugEnabled()) {
1052 logger.debug(testName + ": status = " + statusCode);
1054 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1055 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1056 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1060 * Update wrong user.
1062 * @param testName the test name
1063 * @throws Exception the exception
1065 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1066 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1067 public void updateWrongUser(String testName) throws Exception {
1069 if (logger.isDebugEnabled()) {
1070 logger.debug(testBanner(testName, CLASS_NAME));
1074 // Submit the request to the service and store the response.
1076 // Note: The ID used in this 'create' call may be arbitrary.
1077 // The only relevant ID may be the one used in updateAccount(), below.
1078 AccountClient client = new AccountClient();
1079 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
1080 if (logger.isDebugEnabled()) {
1081 logger.debug(testName + ": read status = " + res.getStatus());
1083 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1085 if (logger.isDebugEnabled()) {
1086 logger.debug("got object to update with ID: " + knownResourceId);
1088 AccountsCommon accountToUpdate =
1089 (AccountsCommon) res.getEntity();
1090 Assert.assertNotNull(accountToUpdate);
1092 accountToUpdate.setUserId("barneyFake");
1093 if (logger.isDebugEnabled()) {
1094 logger.debug("updated object with wrongUser");
1095 logger.debug(objectAsXmlString(accountToUpdate,
1096 AccountsCommon.class));
1099 res = client.update(knownResourceId, accountToUpdate);
1100 int statusCode = res.getStatus();
1102 // Check the status code of the response: does it match
1103 // the expected response(s)?
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testName + ": status = " + statusCode);
1107 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1108 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1109 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1112 // ---------------------------------------------------------------
1113 // CRUD tests : DELETE tests
1114 // ---------------------------------------------------------------
1117 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1120 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1121 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
1122 public void delete(String testName) throws Exception {
1124 if (logger.isDebugEnabled()) {
1125 logger.debug(testBanner(testName, CLASS_NAME));
1130 // Submit the request to the service and store the response.
1131 AccountClient client = new AccountClient();
1132 ClientResponse<Response> res = client.delete(knownResourceId);
1133 int statusCode = res.getStatus();
1135 // Check the status code of the response: does it match
1136 // the expected response(s)?
1137 if (logger.isDebugEnabled()) {
1138 logger.debug(testName + ": status = " + statusCode);
1140 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1141 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1142 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1147 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1150 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1151 dependsOnMethods = {"delete"})
1152 public void deleteNonExistent(String testName) throws Exception {
1154 if (logger.isDebugEnabled()) {
1155 logger.debug(testBanner(testName, CLASS_NAME));
1158 setupDeleteNonExistent();
1160 // Submit the request to the service and store the response.
1161 AccountClient client = new AccountClient();
1162 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1163 int statusCode = res.getStatus();
1165 // Check the status code of the response: does it match
1166 // the expected response(s)?
1167 if (logger.isDebugEnabled()) {
1168 logger.debug(testName + ": status = " + statusCode);
1170 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1171 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1172 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1175 // ---------------------------------------------------------------
1177 // ---------------------------------------------------------------
1180 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
1181 public void searchWorkflowDeleted(String testName) throws Exception {
1182 // Fixme: null test for now, overriding test in base class
1185 // ---------------------------------------------------------------
1186 // Utility tests : tests of code used in tests above
1187 // ---------------------------------------------------------------
1189 * Tests the code for manually submitting data that is used by several
1190 * of the methods above.
1193 @Test(dependsOnMethods = {"create", "read"})
1194 public void testSubmitRequest() throws Exception {
1198 // Submit the request to the service and store the response.
1199 String method = ServiceRequestType.READ.httpMethodName();
1200 String url = getResourceURL(knownResourceId);
1201 int statusCode = submitRequest(method, url);
1203 // Check the status code of the response: does it match
1204 // the expected response(s)?
1205 if (logger.isDebugEnabled()) {
1206 logger.debug("testSubmitRequest: url=" + url
1207 + " status=" + statusCode);
1209 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1213 // ---------------------------------------------------------------
1214 // Utility methods used by tests above
1215 // ---------------------------------------------------------------
1217 * create account instance
1222 * @param useScreenName
1223 * @param invalidTenant
1225 * @param usePassword
1228 AccountsCommon createAccountInstance(String screenName,
1229 String userName, String passwd, String email, String tenantId,
1230 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1232 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1233 userName, passwd, email, tenantId, useScreenName,
1234 invalidTenant, useUser, usePassword);
1235 if (logger.isDebugEnabled()) {
1236 logger.debug("to be created, account common");
1237 logger.debug(objectAsXmlString(account,
1238 AccountsCommon.class));
1248 * @param testName the test name
1249 * @param list the list
1251 private void printList(String testName, AccountsCommonList list) {
1252 List<AccountsCommonList.AccountListItem> items =
1253 list.getAccountListItem();
1256 for (AccountsCommonList.AccountListItem item : items) {
1257 logger.debug(testName + ": list-item[" + i + "] csid="
1259 logger.debug(testName + ": list-item[" + i + "] screenName="
1260 + item.getScreenName());
1261 logger.debug(testName + ": list-item[" + i + "] URI="