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 * This method is called only by the parent class, AbstractServiceTestImpl
69 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
72 protected String getServicePathComponent() {
73 return new AccountClient().getServicePathComponent();
77 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
80 protected CollectionSpaceClient getClientInstance() {
81 return new AccountClient();
85 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
88 protected AbstractCommonList getAbstractCommonList(
89 ClientResponse<AbstractCommonList> response) {
90 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
91 throw new UnsupportedOperationException();
95 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
97 @Test(dataProvider = "testName")
99 public void readPaginatedList(String testName) throws Exception {
100 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
103 // ---------------------------------------------------------------
104 // CRUD tests : CREATE tests
105 // ---------------------------------------------------------------
108 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
111 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
112 public void create(String testName) throws Exception {
114 if (logger.isDebugEnabled()) {
115 logger.debug(testBanner(testName, CLASS_NAME));
117 // Perform setup, such as initializing the type of service request
118 // (e.g. CREATE, DELETE), its valid and expected status codes, and
119 // its associated HTTP method name (e.g. POST, DELETE).
122 AccountClient client = new AccountClient();
123 // Submit the request to the service and store the response.
124 AccountsCommon account =
125 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
126 "barney@dinoland.com", client.getTenantId(),
127 true, false, true, true);
128 ClientResponse<Response> res = client.create(account);
129 int statusCode = res.getStatus();
131 // Check the status code of the response: does it match
132 // the expected response(s)?
135 // Does it fall within the set of valid status codes?
136 // Does it exactly match the expected status code?
137 if (logger.isDebugEnabled()) {
138 logger.debug(testName + ": status = " + statusCode);
140 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
141 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
142 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
144 // Store the ID returned from this create operation
145 // for additional tests below.
146 knownResourceId = extractId(res);
147 if (logger.isDebugEnabled()) {
148 logger.debug(testName + ": knownResourceId=" + knownResourceId);
153 * Creates the for unique user.
155 * @param testName the test name
156 * @throws Exception the exception
158 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
159 dependsOnMethods = {"create"})
160 public void createForUniqueUser(String testName) throws Exception {
162 if (logger.isDebugEnabled()) {
163 logger.debug(testBanner(testName, CLASS_NAME));
167 // Submit the request to the service and store the response.
168 AccountClient client = new AccountClient();
169 AccountsCommon account =
170 createAccountInstance("barney1", knownUserId, knownUserPassword,
171 "barney@dinoland.com",
172 client.getTenantId(), true, false, true, true);
174 ClientResponse<Response> res = client.create(account);
175 int statusCode = res.getStatus();
176 if (logger.isDebugEnabled()) {
177 logger.debug(testName + ": status = " + statusCode);
179 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
180 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
181 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
185 * Creates the with invalid tenant.
187 * @param testName the test name
188 * @throws Exception the exception
190 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
191 dependsOnMethods = {"create"})
192 public void createWithInvalidTenant(String testName) throws Exception {
194 if (logger.isDebugEnabled()) {
195 logger.debug(testBanner(testName, CLASS_NAME));
199 // Submit the request to the service and store the response.
200 AccountClient client = new AccountClient();
201 AccountsCommon account =
202 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
203 client.getTenantId(), true, true, true, true);
204 ClientResponse<Response> res = client.create(account);
205 int statusCode = res.getStatus();
206 // Does it exactly match the expected status code?
207 if (logger.isDebugEnabled()) {
208 logger.debug(testName + ": status = " + statusCode);
210 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
211 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
212 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
217 * Creates the without user.
219 * @param testName the test name
220 * @throws Exception the exception
222 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
223 dependsOnMethods = {"create"})
224 public void createWithoutUser(String testName) throws Exception {
226 if (logger.isDebugEnabled()) {
227 logger.debug(testBanner(testName, CLASS_NAME));
231 // Submit the request to the service and store the response.
232 AccountClient client = new AccountClient();
233 AccountsCommon account =
234 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
235 client.getTenantId(), true, false, false, true);
236 ClientResponse<Response> res = client.create(account);
237 int statusCode = res.getStatus();
238 // Does it exactly match the expected status code?
239 if (logger.isDebugEnabled()) {
240 logger.debug(testName + ": status = " + statusCode);
242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
244 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
248 * Creates the with invalid email.
250 * @param testName the test name
251 * @throws Exception the exception
253 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
254 dependsOnMethods = {"create"})
255 public void createWithInvalidEmail(String testName) throws Exception {
257 if (logger.isDebugEnabled()) {
258 logger.debug(testBanner(testName, CLASS_NAME));
262 // Submit the request to the service and store the response.
263 AccountClient client = new AccountClient();
264 AccountsCommon account =
265 createAccountInstance("babybop", "babybop", "hithere08", "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(REQUEST_TYPE.isValidStatusCode(statusCode),
274 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
275 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
279 * Creates the without screen name.
281 * @param testName the test name
282 * @throws Exception the exception
284 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
285 dependsOnMethods = {"create"})
286 public void createWithoutScreenName(String testName) throws Exception {
288 if (logger.isDebugEnabled()) {
289 logger.debug(testBanner(testName, CLASS_NAME));
293 // Submit the request to the service and store the response.
294 AccountClient client = new AccountClient();
295 AccountsCommon account =
296 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
297 client.getTenantId(), false, false, true, true);
298 ClientResponse<Response> res = client.create(account);
299 int statusCode = res.getStatus();
300 // Does it exactly match the expected status code?
301 if (logger.isDebugEnabled()) {
302 logger.debug(testName + ": status = " + statusCode);
304 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
305 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
306 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
310 * Creates the with invalid password.
312 * @param testName the test name
313 * @throws Exception the exception
315 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
316 dependsOnMethods = {"create"})
317 public void createWithInvalidPassword(String testName) throws Exception {
319 if (logger.isDebugEnabled()) {
320 logger.debug(testBanner(testName, CLASS_NAME));
324 // Submit the request to the service and store the response.
325 AccountClient client = new AccountClient();
326 AccountsCommon account =
327 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
328 client.getTenantId(), true, false, true, true);
329 ClientResponse<Response> res = client.create(account);
330 int statusCode = res.getStatus();
331 // Does it exactly match the expected status code?
332 if (logger.isDebugEnabled()) {
333 logger.debug(testName + ": status = " + statusCode);
335 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
336 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
337 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
341 * Creates the with most invalid.
343 * @param testName the test name
344 * @throws Exception the exception
346 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
347 dependsOnMethods = {"create"})
348 public void createWithMostInvalid(String testName) throws Exception {
350 if (logger.isDebugEnabled()) {
351 logger.debug(testBanner(testName, CLASS_NAME));
355 // Submit the request to the service and store the response.
356 AccountClient client = new AccountClient();
357 AccountsCommon account =
358 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
359 client.getTenantId(), false, true, false, false);
360 ClientResponse<Response> res = client.create(account);
361 int statusCode = res.getStatus();
362 // Does it exactly match the expected status code?
363 if (logger.isDebugEnabled()) {
364 logger.debug(testName + ": status = " + statusCode);
366 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
367 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
368 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
371 //to not cause uniqueness violation for account, createList is removed
373 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
376 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
377 dependsOnMethods = {"create"})
378 public void createList(String testName) throws Exception {
380 if (logger.isDebugEnabled()) {
381 logger.debug(testBanner(testName, CLASS_NAME));
384 // Submit the request to the service and store the response.
385 AccountClient client = new AccountClient();
386 AccountsCommon account1 =
387 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
388 client.getTenantId(), true, false, true, true);
389 ClientResponse<Response> res = client.create(account1);
390 int statusCode = res.getStatus();
391 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
392 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
393 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
394 allResourceIdsCreated.add(extractId(res));
396 AccountsCommon account2 =
397 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
398 client.getTenantId(), true, false, true, true);
399 res = client.create(account2);
400 statusCode = res.getStatus();
401 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
402 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
403 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
404 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
405 allResourceIdsCreated.add(extractId(res));
407 AccountsCommon account3 =
408 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
409 client.getTenantId(), true, false, true, true);
410 res = client.create(account3);
411 statusCode = res.getStatus();
412 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
415 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416 allResourceIdsCreated.add(extractId(res));
420 // Placeholders until the three tests below can be uncommented.
421 // See Issue CSPACE-401.
423 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
426 public void createWithEmptyEntityBody(String testName) throws Exception {
427 //FIXME: Should this test really be empty? If so, please comment accordingly.
431 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
434 public void createWithMalformedXml(String testName) throws Exception {
435 //FIXME: Should this test really be empty? If so, please comment accordingly.
439 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
442 public void createWithWrongXmlSchema(String testName) throws Exception {
443 //FIXME: Should this test really be empty? If so, please comment accordingly.
446 // ---------------------------------------------------------------
447 // CRUD tests : READ tests
448 // ---------------------------------------------------------------
451 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
454 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
455 dependsOnMethods = {"create"})
456 public void read(String testName) throws Exception {
458 if (logger.isDebugEnabled()) {
459 logger.debug(testBanner(testName, CLASS_NAME));
464 // Submit the request to the service and store the response.
465 AccountClient client = new AccountClient();
466 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
467 int statusCode = res.getStatus();
469 // Check the status code of the response: does it match
470 // the expected response(s)?
471 if (logger.isDebugEnabled()) {
472 logger.debug(testName + ": status = " + statusCode);
474 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
475 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
476 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
478 AccountsCommon output = (AccountsCommon) res.getEntity();
479 Assert.assertNotNull(output);
484 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
487 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
488 dependsOnMethods = {"read"})
489 public void readNonExistent(String testName) throws Exception {
491 if (logger.isDebugEnabled()) {
492 logger.debug(testBanner(testName, CLASS_NAME));
495 setupReadNonExistent();
497 // Submit the request to the service and store the response.
498 AccountClient client = new AccountClient();
499 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
500 int statusCode = res.getStatus();
502 // Check the status code of the response: does it match
503 // the expected response(s)?
504 if (logger.isDebugEnabled()) {
505 logger.debug(testName + ": status = " + statusCode);
507 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
508 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
509 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
512 // ---------------------------------------------------------------
513 // CRUD tests : READ_LIST tests
514 // ---------------------------------------------------------------
517 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
520 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
521 dependsOnMethods = {"createList", "read"})
522 public void readList(String testName) throws Exception {
524 if (logger.isDebugEnabled()) {
525 logger.debug(testBanner(testName, CLASS_NAME));
530 // Submit the request to the service and store the response.
531 AccountClient client = new AccountClient();
532 ClientResponse<AccountsCommonList> res = client.readList();
533 AccountsCommonList list = res.getEntity();
534 int statusCode = res.getStatus();
536 // Check the status code of the response: does it match
537 // the expected response(s)?
538 if (logger.isDebugEnabled()) {
539 logger.debug(testName + ": status = " + statusCode);
541 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
542 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
543 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
545 // Optionally output additional data about list members for debugging.
546 boolean iterateThroughList = true;
547 if (iterateThroughList && logger.isDebugEnabled()) {
548 printList(testName, list);
553 * Search screen name.
555 * @param testName the test name
556 * @throws Exception the exception
558 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
559 dependsOnMethods = {"createList", "read"})
560 public void searchScreenName(String testName) throws Exception {
562 if (logger.isDebugEnabled()) {
563 logger.debug(testBanner(testName, CLASS_NAME));
568 // Submit the request to the service and store the response.
569 AccountClient client = new AccountClient();
570 ClientResponse<AccountsCommonList> res =
571 client.readSearchList("tom", null, null);
572 AccountsCommonList list = res.getEntity();
573 int statusCode = res.getStatus();
575 // Check the status code of the response: does it match
576 // the expected response(s)?
577 if (logger.isDebugEnabled()) {
578 logger.debug(testName + ": status = " + statusCode);
580 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
581 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
582 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
583 Assert.assertEquals(1, list.getAccountListItem().size());
584 // Optionally output additional data about list members for debugging.
585 boolean iterateThroughList = true;
586 if (iterateThroughList && logger.isDebugEnabled()) {
587 printList(testName, list);
594 * @param testName the test name
595 * @throws Exception the exception
597 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
598 dependsOnMethods = {"createList", "read"})
599 public void searchUserId(String testName) throws Exception {
601 if (logger.isDebugEnabled()) {
602 logger.debug(testBanner(testName, CLASS_NAME));
607 // Submit the request to the service and store the response.
608 AccountClient client = new AccountClient();
609 ClientResponse<AccountsCommonList> res =
610 client.readSearchList(null, "tom", null);
611 AccountsCommonList list = res.getEntity();
612 int statusCode = res.getStatus();
614 // Check the status code of the response: does it match
615 // the expected response(s)?
616 if (logger.isDebugEnabled()) {
617 logger.debug(testName + ": status = " + statusCode);
619 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
620 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
621 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
622 Assert.assertEquals(1, list.getAccountListItem().size());
623 // Optionally output additional data about list members for debugging.
624 boolean iterateThroughList = true;
625 if (iterateThroughList && logger.isDebugEnabled()) {
626 printList(testName, list);
633 * @param testName the test name
634 * @throws Exception the exception
636 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
637 dependsOnMethods = {"createList", "read"})
638 public void searchEmail(String testName) throws Exception {
640 if (logger.isDebugEnabled()) {
641 logger.debug(testBanner(testName, CLASS_NAME));
646 // Submit the request to the service and store the response.
647 AccountClient client = new AccountClient();
648 ClientResponse<AccountsCommonList> res =
649 client.readSearchList(null, null, "dinoland");
650 AccountsCommonList list = res.getEntity();
651 int statusCode = res.getStatus();
653 // Check the status code of the response: does it match
654 // the expected response(s)?
655 if (logger.isDebugEnabled()) {
656 logger.debug(testName + ": status = " + statusCode);
658 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
659 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
660 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
661 Assert.assertEquals(2, list.getAccountListItem().size());
662 // Optionally output additional data about list members for debugging.
663 boolean iterateThroughList = true;
664 if (iterateThroughList && logger.isDebugEnabled()) {
665 printList(testName, list);
670 * Search screen name email.
672 * @param testName the test name
673 * @throws Exception the exception
675 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
676 dependsOnMethods = {"createList", "read"})
677 public void searchScreenNameEmail(String testName) throws Exception {
679 if (logger.isDebugEnabled()) {
680 logger.debug(testBanner(testName, CLASS_NAME));
685 // Submit the request to the service and store the response.
686 AccountClient client = new AccountClient();
687 ClientResponse<AccountsCommonList> res =
688 client.readSearchList("tom", null, "jerry");
689 AccountsCommonList list = res.getEntity();
690 int statusCode = res.getStatus();
692 // Check the status code of the response: does it match
693 // the expected response(s)?
694 if (logger.isDebugEnabled()) {
695 logger.debug(testName + ": status = " + statusCode);
697 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
698 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
699 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
700 Assert.assertEquals(1, list.getAccountListItem().size());
701 // Optionally output additional data about list members for debugging.
702 boolean iterateThroughList = true;
703 if (iterateThroughList && logger.isDebugEnabled()) {
704 printList(testName, list);
710 // ---------------------------------------------------------------
711 // CRUD tests : UPDATE tests
712 // ---------------------------------------------------------------
715 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
718 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
719 dependsOnMethods = {"read", "readList", "readNonExistent"})
720 public void update(String testName) throws Exception {
722 if (logger.isDebugEnabled()) {
723 logger.debug(testBanner(testName, CLASS_NAME));
728 AccountClient client = new AccountClient();
729 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
730 if (logger.isDebugEnabled()) {
731 logger.debug(testName + ": read status = " + res.getStatus());
733 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
735 if (logger.isDebugEnabled()) {
736 logger.debug("got object to update with ID: " + knownResourceId);
738 AccountsCommon accountFound =
739 (AccountsCommon) res.getEntity();
740 Assert.assertNotNull(accountFound);
742 //create a new account object to test partial updates
743 AccountsCommon accountToUpdate = new AccountsCommon();
744 accountToUpdate.setCsid(knownResourceId);
745 accountToUpdate.setUserId(accountFound.getUserId());
746 // Update the content of this resource.
747 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
748 if (logger.isDebugEnabled()) {
749 logger.debug("updated object");
750 logger.debug(objectAsXmlString(accountFound,
751 AccountsCommon.class));
754 // Submit the request to the service and store the response.
755 res = client.update(knownResourceId, accountToUpdate);
756 int statusCode = res.getStatus();
757 // Check the status code of the response: does it match the expected response(s)?
758 if (logger.isDebugEnabled()) {
759 logger.debug(testName + ": status = " + statusCode);
761 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
762 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
763 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
765 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
766 Assert.assertNotNull(accountUpdated);
768 Assert.assertEquals(accountUpdated.getEmail(),
769 accountToUpdate.getEmail(),
770 "Data in updated object did not match submitted data.");
776 * @param testName the test name
777 * @throws Exception the exception
779 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
780 dependsOnMethods = {"update"})
781 public void updatePassword(String testName) throws Exception {
783 if (logger.isDebugEnabled()) {
784 logger.debug(testBanner(testName, CLASS_NAME));
789 AccountClient client = new AccountClient();
790 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
791 if (logger.isDebugEnabled()) {
792 logger.debug(testName + ": read status = " + res.getStatus());
794 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
796 if (logger.isDebugEnabled()) {
797 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
799 AccountsCommon accountFound =
800 (AccountsCommon) res.getEntity();
801 Assert.assertNotNull(accountFound);
803 //create a new account object to test partial updates
804 AccountsCommon accountToUpdate = new AccountsCommon();
805 accountToUpdate.setCsid(knownResourceId);
806 accountToUpdate.setUserId(accountFound.getUserId());
808 accountToUpdate.setPassword("imagination".getBytes());
809 if (logger.isDebugEnabled()) {
810 logger.debug(testName + ": updated object");
811 logger.debug(objectAsXmlString(accountToUpdate,
812 AccountsCommon.class));
815 // Submit the request to the service and store the response.
816 res = client.update(knownResourceId, accountToUpdate);
817 int statusCode = res.getStatus();
818 // Check the status code of the response: does it match the expected response(s)?
819 if (logger.isDebugEnabled()) {
820 logger.debug(testName + ": status = " + statusCode);
822 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
823 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
824 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
827 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
828 Assert.assertNotNull(accountUpdated);
830 // Assert.assertEquals(accountUpdated.getPassword(),
831 // accountFound.getPassword(),
832 // "Data in updated object did not match submitted data.");
836 * Update password without user.
838 * @param testName the test name
839 * @throws Exception the exception
841 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
842 dependsOnMethods = {"update"})
843 public void updatePasswordWithoutUser(String testName) throws Exception {
845 if (logger.isDebugEnabled()) {
846 logger.debug(testBanner(testName, CLASS_NAME));
851 AccountsCommon accountToUpdate = new AccountsCommon();
852 accountToUpdate.setCsid(knownResourceId);
853 accountToUpdate.setUserId(null);
855 accountToUpdate.setPassword("imagination".getBytes());
856 if (logger.isDebugEnabled()) {
857 logger.debug(testName + " : updated object");
858 logger.debug(objectAsXmlString(accountToUpdate,
859 AccountsCommon.class));
862 AccountClient client = new AccountClient();
863 // Submit the request to the service and store the response.
864 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
865 int statusCode = res.getStatus();
866 // Check the status code of the response: does it match the expected response(s)?
867 if (logger.isDebugEnabled()) {
868 logger.debug(testName + ": status = " + statusCode);
870 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
871 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
872 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
877 * Update invalid password.
879 * @param testName the test name
880 * @throws Exception the exception
882 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
883 dependsOnMethods = {"update"})
884 public void updateInvalidPassword(String testName) throws Exception {
886 if (logger.isDebugEnabled()) {
887 logger.debug(testBanner(testName, CLASS_NAME));
891 AccountClient client = new AccountClient();
892 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
893 if (logger.isDebugEnabled()) {
894 logger.debug(testName + ": read status = " + res.getStatus());
896 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
898 if (logger.isDebugEnabled()) {
899 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
901 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
903 AccountsCommon accountToUpdate = new AccountsCommon();
904 accountToUpdate.setCsid(knownResourceId);
905 accountToUpdate.setUserId(accountFound.getUserId());
906 Assert.assertNotNull(accountToUpdate);
909 accountToUpdate.setPassword("abc123".getBytes());
910 if (logger.isDebugEnabled()) {
911 logger.debug(testName + ": updated object");
912 logger.debug(objectAsXmlString(accountToUpdate,
913 AccountsCommon.class));
916 // Submit the request to the service and store the response.
917 res = client.update(knownResourceId, accountToUpdate);
918 int statusCode = res.getStatus();
919 // Check the status code of the response: does it match the expected response(s)?
920 if (logger.isDebugEnabled()) {
921 logger.debug(testName + ": status = " + statusCode);
923 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
924 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
925 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
932 * @param testName the test name
933 * @throws Exception the exception
935 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
936 dependsOnMethods = {"updatePasswordWithoutUser"})
937 public void deactivate(String testName) throws Exception {
939 if (logger.isDebugEnabled()) {
940 logger.debug(testBanner(testName, CLASS_NAME));
945 AccountClient client = new AccountClient();
946 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
947 if (logger.isDebugEnabled()) {
948 logger.debug(testName + ": read status = " + res.getStatus());
950 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
952 if (logger.isDebugEnabled()) {
953 logger.debug("got object to update with ID: " + knownResourceId);
955 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
957 //create a new account object to test partial updates
958 AccountsCommon accountToUpdate = new AccountsCommon();
959 accountToUpdate.setCsid(knownResourceId);
960 accountToUpdate.setUserId(accountFound.getUserId());
962 // Update the content of this resource.
963 accountToUpdate.setStatus(Status.INACTIVE);
964 if (logger.isDebugEnabled()) {
965 logger.debug("updated object");
966 logger.debug(objectAsXmlString(accountToUpdate,
967 AccountsCommon.class));
970 // Submit the request to the service and store the response.
971 res = client.update(knownResourceId, accountToUpdate);
972 int statusCode = res.getStatus();
973 // Check the status code of the response: does it match the expected response(s)?
974 if (logger.isDebugEnabled()) {
975 logger.debug(testName + ": status = " + statusCode);
977 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
978 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
979 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
981 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
982 Assert.assertNotNull(accountUpdated);
984 Assert.assertEquals(accountUpdated.getStatus(),
985 accountToUpdate.getStatus(),
986 "Data in updated object did not match submitted data.");
991 // Placeholders until the three tests below can be uncommented.
992 // See Issue CSPACE-401.
994 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
997 public void updateWithEmptyEntityBody(String testName) throws Exception {
998 //FIXME: Should this test really be empty? If so, please comment accordingly.
1002 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1005 public void updateWithMalformedXml(String testName) throws Exception {
1006 //FIXME: Should this test really be empty? If so, please comment accordingly.
1010 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1013 public void updateWithWrongXmlSchema(String testName) throws Exception {
1014 //FIXME: Should this test really be empty? If so, please comment accordingly.
1018 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1021 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1022 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1023 public void updateNonExistent(String testName) throws Exception {
1025 if (logger.isDebugEnabled()) {
1026 logger.debug(testBanner(testName, CLASS_NAME));
1029 setupUpdateNonExistent();
1031 // Submit the request to the service and store the response.
1033 // Note: The ID used in this 'create' call may be arbitrary.
1034 // The only relevant ID may be the one used in updateAccount(), below.
1035 AccountClient client = new AccountClient();
1036 AccountsCommon account =
1037 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
1038 client.getTenantId(), true, false, true, true);
1039 ClientResponse<AccountsCommon> res =
1040 client.update(NON_EXISTENT_ID, account);
1041 int statusCode = res.getStatus();
1043 // Check the status code of the response: does it match
1044 // the expected response(s)?
1045 if (logger.isDebugEnabled()) {
1046 logger.debug(testName + ": status = " + statusCode);
1048 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1049 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1050 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1054 * Update wrong user.
1056 * @param testName the test name
1057 * @throws Exception the exception
1059 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1060 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1061 public void updateWrongUser(String testName) throws Exception {
1063 if (logger.isDebugEnabled()) {
1064 logger.debug(testBanner(testName, CLASS_NAME));
1068 // Submit the request to the service and store the response.
1070 // Note: The ID used in this 'create' call may be arbitrary.
1071 // The only relevant ID may be the one used in updateAccount(), below.
1072 AccountClient client = new AccountClient();
1073 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
1074 if (logger.isDebugEnabled()) {
1075 logger.debug(testName + ": read status = " + res.getStatus());
1077 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1079 if (logger.isDebugEnabled()) {
1080 logger.debug("got object to update with ID: " + knownResourceId);
1082 AccountsCommon accountToUpdate =
1083 (AccountsCommon) res.getEntity();
1084 Assert.assertNotNull(accountToUpdate);
1086 accountToUpdate.setUserId("barneyFake");
1087 if (logger.isDebugEnabled()) {
1088 logger.debug("updated object with wrongUser");
1089 logger.debug(objectAsXmlString(accountToUpdate,
1090 AccountsCommon.class));
1093 res = client.update(knownResourceId, accountToUpdate);
1094 int statusCode = res.getStatus();
1096 // Check the status code of the response: does it match
1097 // the expected response(s)?
1098 if (logger.isDebugEnabled()) {
1099 logger.debug(testName + ": status = " + statusCode);
1101 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1102 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1103 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1106 // ---------------------------------------------------------------
1107 // CRUD tests : DELETE tests
1108 // ---------------------------------------------------------------
1111 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1114 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1115 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
1116 public void delete(String testName) throws Exception {
1118 if (logger.isDebugEnabled()) {
1119 logger.debug(testBanner(testName, CLASS_NAME));
1124 // Submit the request to the service and store the response.
1125 AccountClient client = new AccountClient();
1126 ClientResponse<Response> res = client.delete(knownResourceId);
1127 int statusCode = res.getStatus();
1129 // Check the status code of the response: does it match
1130 // the expected response(s)?
1131 if (logger.isDebugEnabled()) {
1132 logger.debug(testName + ": status = " + statusCode);
1134 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1135 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1136 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1141 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1144 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1145 dependsOnMethods = {"delete"})
1146 public void deleteNonExistent(String testName) throws Exception {
1148 if (logger.isDebugEnabled()) {
1149 logger.debug(testBanner(testName, CLASS_NAME));
1152 setupDeleteNonExistent();
1154 // Submit the request to the service and store the response.
1155 AccountClient client = new AccountClient();
1156 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1157 int statusCode = res.getStatus();
1159 // Check the status code of the response: does it match
1160 // the expected response(s)?
1161 if (logger.isDebugEnabled()) {
1162 logger.debug(testName + ": status = " + statusCode);
1164 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1165 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1166 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1169 // ---------------------------------------------------------------
1170 // Utility tests : tests of code used in tests above
1171 // ---------------------------------------------------------------
1173 * Tests the code for manually submitting data that is used by several
1174 * of the methods above.
1177 @Test(dependsOnMethods = {"create", "read"})
1178 public void testSubmitRequest() throws Exception {
1182 // Submit the request to the service and store the response.
1183 String method = ServiceRequestType.READ.httpMethodName();
1184 String url = getResourceURL(knownResourceId);
1185 int statusCode = submitRequest(method, url);
1187 // Check the status code of the response: does it match
1188 // the expected response(s)?
1189 if (logger.isDebugEnabled()) {
1190 logger.debug("testSubmitRequest: url=" + url
1191 + " status=" + statusCode);
1193 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1197 // ---------------------------------------------------------------
1198 // Utility methods used by tests above
1199 // ---------------------------------------------------------------
1201 * create account instance
1206 * @param useScreenName
1207 * @param invalidTenant
1209 * @param usePassword
1212 AccountsCommon createAccountInstance(String screenName,
1213 String userName, String passwd, String email, String tenantId,
1214 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1216 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1217 userName, passwd, email, tenantId, useScreenName,
1218 invalidTenant, useUser, usePassword);
1219 if (logger.isDebugEnabled()) {
1220 logger.debug("to be created, account common");
1221 logger.debug(objectAsXmlString(account,
1222 AccountsCommon.class));
1232 * @param testName the test name
1233 * @param list the list
1235 private void printList(String testName, AccountsCommonList list) {
1236 List<AccountsCommonList.AccountListItem> items =
1237 list.getAccountListItem();
1240 for (AccountsCommonList.AccountListItem item : items) {
1241 logger.debug(testName + ": list-item[" + i + "] csid="
1243 logger.debug(testName + ": list-item[" + i + "] screenName="
1244 + item.getScreenName());
1245 logger.debug(testName + ": list-item[" + i + "] URI="