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")
104 public void readPaginatedList(String testName) throws Exception {
105 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
108 // ---------------------------------------------------------------
109 // CRUD tests : CREATE tests
110 // ---------------------------------------------------------------
113 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
116 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
117 public void create(String testName) throws Exception {
119 if (logger.isDebugEnabled()) {
120 logger.debug(testBanner(testName, CLASS_NAME));
122 // Perform setup, such as initializing the type of service request
123 // (e.g. CREATE, DELETE), its valid and expected status codes, and
124 // its associated HTTP method name (e.g. POST, DELETE).
127 AccountClient client = new AccountClient();
128 // Submit the request to the service and store the response.
129 AccountsCommon account =
130 createAccountInstance(knownUserId, knownUserId, knownUserPassword,
131 "barney@dinoland.com", client.getTenantId(),
132 true, false, true, true);
133 ClientResponse<Response> res = client.create(account);
134 int statusCode = res.getStatus();
136 // Check the status code of the response: does it match
137 // the expected response(s)?
140 // Does it fall within the set of valid status codes?
141 // Does it exactly match the expected status code?
142 if (logger.isDebugEnabled()) {
143 logger.debug(testName + ": status = " + statusCode);
145 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
146 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
147 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
149 // Store the ID returned from this create operation
150 // for additional tests below.
151 knownResourceId = extractId(res);
152 if (logger.isDebugEnabled()) {
153 logger.debug(testName + ": knownResourceId=" + knownResourceId);
158 * Creates the for unique user.
160 * @param testName the test name
161 * @throws Exception the exception
163 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
164 dependsOnMethods = {"create"})
165 public void createForUniqueUser(String testName) throws Exception {
167 if (logger.isDebugEnabled()) {
168 logger.debug(testBanner(testName, CLASS_NAME));
172 // Submit the request to the service and store the response.
173 AccountClient client = new AccountClient();
174 AccountsCommon account =
175 createAccountInstance("barney1", knownUserId, knownUserPassword,
176 "barney@dinoland.com",
177 client.getTenantId(), true, false, true, true);
179 ClientResponse<Response> res = client.create(account);
180 int statusCode = res.getStatus();
181 if (logger.isDebugEnabled()) {
182 logger.debug(testName + ": status = " + statusCode);
184 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
185 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
186 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
190 * Creates the with invalid tenant.
192 * @param testName the test name
193 * @throws Exception the exception
195 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
196 dependsOnMethods = {"create"})
197 public void createWithInvalidTenant(String testName) throws Exception {
199 if (logger.isDebugEnabled()) {
200 logger.debug(testBanner(testName, CLASS_NAME));
204 // Submit the request to the service and store the response.
205 AccountClient client = new AccountClient();
206 AccountsCommon account =
207 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
208 client.getTenantId(), true, true, true, true);
209 ClientResponse<Response> res = client.create(account);
210 int statusCode = res.getStatus();
211 // Does it exactly match the expected status code?
212 if (logger.isDebugEnabled()) {
213 logger.debug(testName + ": status = " + statusCode);
215 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
216 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
217 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
222 * Creates the without user.
224 * @param testName the test name
225 * @throws Exception the exception
227 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
228 dependsOnMethods = {"create"})
229 public void createWithoutUser(String testName) throws Exception {
231 if (logger.isDebugEnabled()) {
232 logger.debug(testBanner(testName, CLASS_NAME));
236 // Submit the request to the service and store the response.
237 AccountClient client = new AccountClient();
238 AccountsCommon account =
239 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
240 client.getTenantId(), true, false, false, true);
241 ClientResponse<Response> res = client.create(account);
242 int statusCode = res.getStatus();
243 // Does it exactly match the expected status code?
244 if (logger.isDebugEnabled()) {
245 logger.debug(testName + ": status = " + statusCode);
247 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
248 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
249 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
253 * Creates the with invalid email.
255 * @param testName the test name
256 * @throws Exception the exception
258 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
259 dependsOnMethods = {"create"})
260 public void createWithInvalidEmail(String testName) throws Exception {
262 if (logger.isDebugEnabled()) {
263 logger.debug(testBanner(testName, CLASS_NAME));
267 // Submit the request to the service and store the response.
268 AccountClient client = new AccountClient();
269 AccountsCommon account =
270 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
271 client.getTenantId(), true, false, true, true);
272 ClientResponse<Response> res = client.create(account);
273 int statusCode = res.getStatus();
274 // Does it exactly match the expected status code?
275 if (logger.isDebugEnabled()) {
276 logger.debug(testName + ": status = " + statusCode);
278 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
279 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
280 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
284 * Creates the without screen name.
286 * @param testName the test name
287 * @throws Exception the exception
289 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
290 dependsOnMethods = {"create"})
291 public void createWithoutScreenName(String testName) throws Exception {
293 if (logger.isDebugEnabled()) {
294 logger.debug(testBanner(testName, CLASS_NAME));
298 // Submit the request to the service and store the response.
299 AccountClient client = new AccountClient();
300 AccountsCommon account =
301 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
302 client.getTenantId(), false, false, true, true);
303 ClientResponse<Response> res = client.create(account);
304 int statusCode = res.getStatus();
305 // Does it exactly match the expected status code?
306 if (logger.isDebugEnabled()) {
307 logger.debug(testName + ": status = " + statusCode);
309 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
310 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
311 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
315 * Creates the with invalid password.
317 * @param testName the test name
318 * @throws Exception the exception
320 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
321 dependsOnMethods = {"create"})
322 public void createWithInvalidPassword(String testName) throws Exception {
324 if (logger.isDebugEnabled()) {
325 logger.debug(testBanner(testName, CLASS_NAME));
329 // Submit the request to the service and store the response.
330 AccountClient client = new AccountClient();
331 AccountsCommon account =
332 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
333 client.getTenantId(), true, false, true, true);
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());
346 * Creates the with most invalid.
348 * @param testName the test name
349 * @throws Exception the exception
351 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
352 dependsOnMethods = {"create"})
353 public void createWithMostInvalid(String testName) throws Exception {
355 if (logger.isDebugEnabled()) {
356 logger.debug(testBanner(testName, CLASS_NAME));
360 // Submit the request to the service and store the response.
361 AccountClient client = new AccountClient();
362 AccountsCommon account =
363 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
364 client.getTenantId(), false, true, false, false);
365 ClientResponse<Response> res = client.create(account);
366 int statusCode = res.getStatus();
367 // Does it exactly match the expected status code?
368 if (logger.isDebugEnabled()) {
369 logger.debug(testName + ": status = " + statusCode);
371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
376 //to not cause uniqueness violation for account, createList is removed
378 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
381 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
382 dependsOnMethods = {"create"})
383 public void createList(String testName) throws Exception {
385 if (logger.isDebugEnabled()) {
386 logger.debug(testBanner(testName, CLASS_NAME));
389 // Submit the request to the service and store the response.
390 AccountClient client = new AccountClient();
391 AccountsCommon account1 =
392 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
393 client.getTenantId(), true, false, true, true);
394 ClientResponse<Response> res = client.create(account1);
395 int statusCode = res.getStatus();
396 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
397 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
398 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
399 allResourceIdsCreated.add(extractId(res));
401 AccountsCommon account2 =
402 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
403 client.getTenantId(), true, false, true, true);
404 res = client.create(account2);
405 statusCode = res.getStatus();
406 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
407 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
408 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
409 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
410 allResourceIdsCreated.add(extractId(res));
412 AccountsCommon account3 =
413 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
414 client.getTenantId(), true, false, true, true);
415 res = client.create(account3);
416 statusCode = res.getStatus();
417 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
418 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
419 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
420 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
421 allResourceIdsCreated.add(extractId(res));
425 // Placeholders until the three tests below can be uncommented.
426 // See Issue CSPACE-401.
428 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
431 public void createWithEmptyEntityBody(String testName) throws Exception {
432 //FIXME: Should this test really be empty? If so, please comment accordingly.
436 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
439 public void createWithMalformedXml(String testName) throws Exception {
440 //FIXME: Should this test really be empty? If so, please comment accordingly.
444 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
447 public void createWithWrongXmlSchema(String testName) throws Exception {
448 //FIXME: Should this test really be empty? If so, please comment accordingly.
451 // ---------------------------------------------------------------
452 // CRUD tests : READ tests
453 // ---------------------------------------------------------------
456 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
459 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
460 dependsOnMethods = {"create"})
461 public void read(String testName) throws Exception {
463 if (logger.isDebugEnabled()) {
464 logger.debug(testBanner(testName, CLASS_NAME));
469 // Submit the request to the service and store the response.
470 AccountClient client = new AccountClient();
471 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
472 int statusCode = res.getStatus();
474 // Check the status code of the response: does it match
475 // the expected response(s)?
476 if (logger.isDebugEnabled()) {
477 logger.debug(testName + ": status = " + statusCode);
479 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
480 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
481 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
483 AccountsCommon output = (AccountsCommon) res.getEntity();
484 Assert.assertNotNull(output);
489 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
492 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
493 dependsOnMethods = {"read"})
494 public void readNonExistent(String testName) throws Exception {
496 if (logger.isDebugEnabled()) {
497 logger.debug(testBanner(testName, CLASS_NAME));
500 setupReadNonExistent();
502 // Submit the request to the service and store the response.
503 AccountClient client = new AccountClient();
504 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
505 int statusCode = res.getStatus();
507 // Check the status code of the response: does it match
508 // the expected response(s)?
509 if (logger.isDebugEnabled()) {
510 logger.debug(testName + ": status = " + statusCode);
512 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
513 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
514 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
517 // ---------------------------------------------------------------
518 // CRUD tests : READ_LIST tests
519 // ---------------------------------------------------------------
522 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
525 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
526 dependsOnMethods = {"createList", "read"})
527 public void readList(String testName) throws Exception {
529 if (logger.isDebugEnabled()) {
530 logger.debug(testBanner(testName, CLASS_NAME));
535 // Submit the request to the service and store the response.
536 AccountClient client = new AccountClient();
537 ClientResponse<AccountsCommonList> res = client.readList();
538 AccountsCommonList list = res.getEntity();
539 int statusCode = res.getStatus();
541 // Check the status code of the response: does it match
542 // the expected response(s)?
543 if (logger.isDebugEnabled()) {
544 logger.debug(testName + ": status = " + statusCode);
546 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
550 // Optionally output additional data about list members for debugging.
551 boolean iterateThroughList = true;
552 if (iterateThroughList && logger.isDebugEnabled()) {
553 printList(testName, list);
558 * Search screen name.
560 * @param testName the test name
561 * @throws Exception the exception
563 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
564 dependsOnMethods = {"createList", "read"})
565 public void searchScreenName(String testName) throws Exception {
567 if (logger.isDebugEnabled()) {
568 logger.debug(testBanner(testName, CLASS_NAME));
573 // Submit the request to the service and store the response.
574 AccountClient client = new AccountClient();
575 ClientResponse<AccountsCommonList> res =
576 client.readSearchList("tom", null, null);
577 AccountsCommonList list = res.getEntity();
578 int statusCode = res.getStatus();
580 // Check the status code of the response: does it match
581 // the expected response(s)?
582 if (logger.isDebugEnabled()) {
583 logger.debug(testName + ": status = " + statusCode);
585 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 Assert.assertEquals(1, list.getAccountListItem().size());
589 // Optionally output additional data about list members for debugging.
590 boolean iterateThroughList = true;
591 if (iterateThroughList && logger.isDebugEnabled()) {
592 printList(testName, list);
599 * @param testName the test name
600 * @throws Exception the exception
602 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
603 dependsOnMethods = {"createList", "read"})
604 public void searchUserId(String testName) throws Exception {
606 if (logger.isDebugEnabled()) {
607 logger.debug(testBanner(testName, CLASS_NAME));
612 // Submit the request to the service and store the response.
613 AccountClient client = new AccountClient();
614 ClientResponse<AccountsCommonList> res =
615 client.readSearchList(null, "tom", null);
616 AccountsCommonList list = res.getEntity();
617 int statusCode = res.getStatus();
619 // Check the status code of the response: does it match
620 // the expected response(s)?
621 if (logger.isDebugEnabled()) {
622 logger.debug(testName + ": status = " + statusCode);
624 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
625 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
626 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
627 Assert.assertEquals(1, list.getAccountListItem().size());
628 // Optionally output additional data about list members for debugging.
629 boolean iterateThroughList = true;
630 if (iterateThroughList && logger.isDebugEnabled()) {
631 printList(testName, list);
638 * @param testName the test name
639 * @throws Exception the exception
641 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
642 dependsOnMethods = {"createList", "read"})
643 public void searchEmail(String testName) throws Exception {
645 if (logger.isDebugEnabled()) {
646 logger.debug(testBanner(testName, CLASS_NAME));
651 // Submit the request to the service and store the response.
652 AccountClient client = new AccountClient();
653 ClientResponse<AccountsCommonList> res =
654 client.readSearchList(null, null, "dinoland");
655 AccountsCommonList list = res.getEntity();
656 int statusCode = res.getStatus();
658 // Check the status code of the response: does it match
659 // the expected response(s)?
660 if (logger.isDebugEnabled()) {
661 logger.debug(testName + ": status = " + statusCode);
663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
666 Assert.assertEquals(2, list.getAccountListItem().size());
667 // Optionally output additional data about list members for debugging.
668 boolean iterateThroughList = true;
669 if (iterateThroughList && logger.isDebugEnabled()) {
670 printList(testName, list);
675 * Search screen name email.
677 * @param testName the test name
678 * @throws Exception the exception
680 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
681 dependsOnMethods = {"createList", "read"})
682 public void searchScreenNameEmail(String testName) throws Exception {
684 if (logger.isDebugEnabled()) {
685 logger.debug(testBanner(testName, CLASS_NAME));
690 // Submit the request to the service and store the response.
691 AccountClient client = new AccountClient();
692 ClientResponse<AccountsCommonList> res =
693 client.readSearchList("tom", null, "jerry");
694 AccountsCommonList list = res.getEntity();
695 int statusCode = res.getStatus();
697 // Check the status code of the response: does it match
698 // the expected response(s)?
699 if (logger.isDebugEnabled()) {
700 logger.debug(testName + ": status = " + statusCode);
702 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
703 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
704 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
705 Assert.assertEquals(1, list.getAccountListItem().size());
706 // Optionally output additional data about list members for debugging.
707 boolean iterateThroughList = true;
708 if (iterateThroughList && logger.isDebugEnabled()) {
709 printList(testName, list);
715 // ---------------------------------------------------------------
716 // CRUD tests : UPDATE tests
717 // ---------------------------------------------------------------
720 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
723 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
724 dependsOnMethods = {"read", "readList", "readNonExistent"})
725 public void update(String testName) throws Exception {
727 if (logger.isDebugEnabled()) {
728 logger.debug(testBanner(testName, CLASS_NAME));
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("got object to update 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());
751 // Update the content of this resource.
752 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
753 if (logger.isDebugEnabled()) {
754 logger.debug("updated object");
755 logger.debug(objectAsXmlString(accountFound,
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);
770 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
771 Assert.assertNotNull(accountUpdated);
773 Assert.assertEquals(accountUpdated.getEmail(),
774 accountToUpdate.getEmail(),
775 "Data in updated object did not match submitted data.");
781 * @param testName the test name
782 * @throws Exception the exception
784 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
785 dependsOnMethods = {"update"})
786 public void updatePassword(String testName) throws Exception {
788 if (logger.isDebugEnabled()) {
789 logger.debug(testBanner(testName, CLASS_NAME));
794 AccountClient client = new AccountClient();
795 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
796 if (logger.isDebugEnabled()) {
797 logger.debug(testName + ": read status = " + res.getStatus());
799 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
801 if (logger.isDebugEnabled()) {
802 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
804 AccountsCommon accountFound =
805 (AccountsCommon) res.getEntity();
806 Assert.assertNotNull(accountFound);
808 //create a new account object to test partial updates
809 AccountsCommon accountToUpdate = new AccountsCommon();
810 accountToUpdate.setCsid(knownResourceId);
811 accountToUpdate.setUserId(accountFound.getUserId());
813 accountToUpdate.setPassword("imagination".getBytes());
814 if (logger.isDebugEnabled()) {
815 logger.debug(testName + ": updated object");
816 logger.debug(objectAsXmlString(accountToUpdate,
817 AccountsCommon.class));
820 // Submit the request to the service and store the response.
821 res = client.update(knownResourceId, accountToUpdate);
822 int statusCode = res.getStatus();
823 // Check the status code of the response: does it match the expected response(s)?
824 if (logger.isDebugEnabled()) {
825 logger.debug(testName + ": status = " + statusCode);
827 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
828 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
829 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
832 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
833 Assert.assertNotNull(accountUpdated);
835 // Assert.assertEquals(accountUpdated.getPassword(),
836 // accountFound.getPassword(),
837 // "Data in updated object did not match submitted data.");
841 * Update password without user.
843 * @param testName the test name
844 * @throws Exception the exception
846 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
847 dependsOnMethods = {"update"})
848 public void updatePasswordWithoutUser(String testName) throws Exception {
850 if (logger.isDebugEnabled()) {
851 logger.debug(testBanner(testName, CLASS_NAME));
856 AccountsCommon accountToUpdate = new AccountsCommon();
857 accountToUpdate.setCsid(knownResourceId);
858 accountToUpdate.setUserId(null);
860 accountToUpdate.setPassword("imagination".getBytes());
861 if (logger.isDebugEnabled()) {
862 logger.debug(testName + " : updated object");
863 logger.debug(objectAsXmlString(accountToUpdate,
864 AccountsCommon.class));
867 AccountClient client = new AccountClient();
868 // Submit the request to the service and store the response.
869 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
870 int statusCode = res.getStatus();
871 // Check the status code of the response: does it match the expected response(s)?
872 if (logger.isDebugEnabled()) {
873 logger.debug(testName + ": status = " + statusCode);
875 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
876 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
877 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
882 * Update invalid password.
884 * @param testName the test name
885 * @throws Exception the exception
887 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
888 dependsOnMethods = {"update"})
889 public void updateInvalidPassword(String testName) throws Exception {
891 if (logger.isDebugEnabled()) {
892 logger.debug(testBanner(testName, CLASS_NAME));
896 AccountClient client = new AccountClient();
897 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
898 if (logger.isDebugEnabled()) {
899 logger.debug(testName + ": read status = " + res.getStatus());
901 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
903 if (logger.isDebugEnabled()) {
904 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
906 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
908 AccountsCommon accountToUpdate = new AccountsCommon();
909 accountToUpdate.setCsid(knownResourceId);
910 accountToUpdate.setUserId(accountFound.getUserId());
911 Assert.assertNotNull(accountToUpdate);
914 accountToUpdate.setPassword("abc123".getBytes());
915 if (logger.isDebugEnabled()) {
916 logger.debug(testName + ": updated object");
917 logger.debug(objectAsXmlString(accountToUpdate,
918 AccountsCommon.class));
921 // Submit the request to the service and store the response.
922 res = client.update(knownResourceId, accountToUpdate);
923 int statusCode = res.getStatus();
924 // Check the status code of the response: does it match the expected response(s)?
925 if (logger.isDebugEnabled()) {
926 logger.debug(testName + ": status = " + statusCode);
928 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
929 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
930 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
937 * @param testName the test name
938 * @throws Exception the exception
940 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
941 dependsOnMethods = {"updatePasswordWithoutUser"})
942 public void deactivate(String testName) throws Exception {
944 if (logger.isDebugEnabled()) {
945 logger.debug(testBanner(testName, CLASS_NAME));
950 AccountClient client = new AccountClient();
951 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
952 if (logger.isDebugEnabled()) {
953 logger.debug(testName + ": read status = " + res.getStatus());
955 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
957 if (logger.isDebugEnabled()) {
958 logger.debug("got object to update with ID: " + knownResourceId);
960 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
962 //create a new account object to test partial updates
963 AccountsCommon accountToUpdate = new AccountsCommon();
964 accountToUpdate.setCsid(knownResourceId);
965 accountToUpdate.setUserId(accountFound.getUserId());
967 // Update the content of this resource.
968 accountToUpdate.setStatus(Status.INACTIVE);
969 if (logger.isDebugEnabled()) {
970 logger.debug("updated object");
971 logger.debug(objectAsXmlString(accountToUpdate,
972 AccountsCommon.class));
975 // Submit the request to the service and store the response.
976 res = client.update(knownResourceId, accountToUpdate);
977 int statusCode = res.getStatus();
978 // Check the status code of the response: does it match the expected response(s)?
979 if (logger.isDebugEnabled()) {
980 logger.debug(testName + ": status = " + statusCode);
982 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
983 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
984 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
986 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
987 Assert.assertNotNull(accountUpdated);
989 Assert.assertEquals(accountUpdated.getStatus(),
990 accountToUpdate.getStatus(),
991 "Data in updated object did not match submitted data.");
996 // Placeholders until the three tests below can be uncommented.
997 // See Issue CSPACE-401.
999 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1002 public void updateWithEmptyEntityBody(String testName) throws Exception {
1003 //FIXME: Should this test really be empty? If so, please comment accordingly.
1007 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1010 public void updateWithMalformedXml(String testName) throws Exception {
1011 //FIXME: Should this test really be empty? If so, please comment accordingly.
1015 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1018 public void updateWithWrongXmlSchema(String testName) throws Exception {
1019 //FIXME: Should this test really be empty? If so, please comment accordingly.
1023 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1026 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1027 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1028 public void updateNonExistent(String testName) throws Exception {
1030 if (logger.isDebugEnabled()) {
1031 logger.debug(testBanner(testName, CLASS_NAME));
1034 setupUpdateNonExistent();
1036 // Submit the request to the service and store the response.
1038 // Note: The ID used in this 'create' call may be arbitrary.
1039 // The only relevant ID may be the one used in updateAccount(), below.
1040 AccountClient client = new AccountClient();
1041 AccountsCommon account =
1042 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
1043 client.getTenantId(), true, false, true, true);
1044 ClientResponse<AccountsCommon> res =
1045 client.update(NON_EXISTENT_ID, account);
1046 int statusCode = res.getStatus();
1048 // Check the status code of the response: does it match
1049 // the expected response(s)?
1050 if (logger.isDebugEnabled()) {
1051 logger.debug(testName + ": status = " + statusCode);
1053 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1054 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1055 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1059 * Update wrong user.
1061 * @param testName the test name
1062 * @throws Exception the exception
1064 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1065 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
1066 public void updateWrongUser(String testName) throws Exception {
1068 if (logger.isDebugEnabled()) {
1069 logger.debug(testBanner(testName, CLASS_NAME));
1073 // Submit the request to the service and store the response.
1075 // Note: The ID used in this 'create' call may be arbitrary.
1076 // The only relevant ID may be the one used in updateAccount(), below.
1077 AccountClient client = new AccountClient();
1078 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
1079 if (logger.isDebugEnabled()) {
1080 logger.debug(testName + ": read status = " + res.getStatus());
1082 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1084 if (logger.isDebugEnabled()) {
1085 logger.debug("got object to update with ID: " + knownResourceId);
1087 AccountsCommon accountToUpdate =
1088 (AccountsCommon) res.getEntity();
1089 Assert.assertNotNull(accountToUpdate);
1091 accountToUpdate.setUserId("barneyFake");
1092 if (logger.isDebugEnabled()) {
1093 logger.debug("updated object with wrongUser");
1094 logger.debug(objectAsXmlString(accountToUpdate,
1095 AccountsCommon.class));
1098 res = client.update(knownResourceId, accountToUpdate);
1099 int statusCode = res.getStatus();
1101 // Check the status code of the response: does it match
1102 // the expected response(s)?
1103 if (logger.isDebugEnabled()) {
1104 logger.debug(testName + ": status = " + statusCode);
1106 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1107 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1108 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1111 // ---------------------------------------------------------------
1112 // CRUD tests : DELETE tests
1113 // ---------------------------------------------------------------
1116 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1119 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1120 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
1121 public void delete(String testName) throws Exception {
1123 if (logger.isDebugEnabled()) {
1124 logger.debug(testBanner(testName, CLASS_NAME));
1129 // Submit the request to the service and store the response.
1130 AccountClient client = new AccountClient();
1131 ClientResponse<Response> res = client.delete(knownResourceId);
1132 int statusCode = res.getStatus();
1134 // Check the status code of the response: does it match
1135 // the expected response(s)?
1136 if (logger.isDebugEnabled()) {
1137 logger.debug(testName + ": status = " + statusCode);
1139 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1140 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1141 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1146 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1149 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1150 dependsOnMethods = {"delete"})
1151 public void deleteNonExistent(String testName) throws Exception {
1153 if (logger.isDebugEnabled()) {
1154 logger.debug(testBanner(testName, CLASS_NAME));
1157 setupDeleteNonExistent();
1159 // Submit the request to the service and store the response.
1160 AccountClient client = new AccountClient();
1161 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1162 int statusCode = res.getStatus();
1164 // Check the status code of the response: does it match
1165 // the expected response(s)?
1166 if (logger.isDebugEnabled()) {
1167 logger.debug(testName + ": status = " + statusCode);
1169 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1170 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1171 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1174 // ---------------------------------------------------------------
1175 // Utility tests : tests of code used in tests above
1176 // ---------------------------------------------------------------
1178 * Tests the code for manually submitting data that is used by several
1179 * of the methods above.
1182 @Test(dependsOnMethods = {"create", "read"})
1183 public void testSubmitRequest() throws Exception {
1187 // Submit the request to the service and store the response.
1188 String method = ServiceRequestType.READ.httpMethodName();
1189 String url = getResourceURL(knownResourceId);
1190 int statusCode = submitRequest(method, url);
1192 // Check the status code of the response: does it match
1193 // the expected response(s)?
1194 if (logger.isDebugEnabled()) {
1195 logger.debug("testSubmitRequest: url=" + url
1196 + " status=" + statusCode);
1198 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1202 // ---------------------------------------------------------------
1203 // Utility methods used by tests above
1204 // ---------------------------------------------------------------
1206 * create account instance
1211 * @param useScreenName
1212 * @param invalidTenant
1214 * @param usePassword
1217 AccountsCommon createAccountInstance(String screenName,
1218 String userName, String passwd, String email, String tenantId,
1219 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1221 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1222 userName, passwd, email, tenantId, useScreenName,
1223 invalidTenant, useUser, usePassword);
1224 if (logger.isDebugEnabled()) {
1225 logger.debug("to be created, account common");
1226 logger.debug(objectAsXmlString(account,
1227 AccountsCommon.class));
1237 * @param testName the test name
1238 * @param list the list
1240 private void printList(String testName, AccountsCommonList list) {
1241 List<AccountsCommonList.AccountListItem> items =
1242 list.getAccountListItem();
1245 for (AccountsCommonList.AccountListItem item : items) {
1246 logger.debug(testName + ": list-item[" + i + "] csid="
1248 logger.debug(testName + ": list-item[" + i + "] screenName="
1249 + item.getScreenName());
1250 logger.debug(testName + ": list-item[" + i + "] URI="