2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.account.client.test;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.UUID;
28 import javax.ws.rs.core.Response;
30 import org.apache.commons.codec.binary.Base64;
31 import org.collectionspace.services.client.AccountClient;
32 import org.collectionspace.services.account.AccountsCommon;
33 import org.collectionspace.services.account.AccountsCommonList;
34 import org.collectionspace.services.account.Status;
35 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
36 import org.collectionspace.services.client.test.ServiceRequestType;
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 private final Logger logger =
55 LoggerFactory.getLogger(AccountServiceTest.class);
56 // Instance variables specific to this test.
57 private AccountClient client = new AccountClient();
58 private String knownResourceId = null;
59 private String resource1Id = null;
60 private String resource2Id = null;
61 private String resource3Id = null;
63 * This method is called only by the parent class, AbstractServiceTestImpl
67 protected String getServicePathComponent() {
68 return client.getServicePathComponent();
71 // ---------------------------------------------------------------
72 // CRUD tests : CREATE tests
73 // ---------------------------------------------------------------
76 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
77 public void create(String testName) throws Exception {
79 // Perform setup, such as initializing the type of service request
80 // (e.g. CREATE, DELETE), its valid and expected status codes, and
81 // its associated HTTP method name (e.g. POST, DELETE).
82 setupCreate(testName);
84 // Submit the request to the service and store the response.
85 AccountsCommon account =
86 createAccountInstance("barney", "hithere08", "barney@dinoland.com", true, true, true);
87 ClientResponse<Response> res = client.create(account);
88 int statusCode = res.getStatus();
90 // Check the status code of the response: does it match
91 // the expected response(s)?
94 // Does it fall within the set of valid status codes?
95 // Does it exactly match the expected status code?
96 if (logger.isDebugEnabled()) {
97 logger.debug(testName + ": status = " + statusCode);
99 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
100 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
101 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
103 // Store the ID returned from this create operation
104 // for additional tests below.
105 knownResourceId = extractId(res);
106 if (logger.isDebugEnabled()) {
107 logger.debug(testName + ": knownResourceId=" + knownResourceId);
111 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
112 dependsOnMethods = {"create"})
113 public void createWithoutTenant(String testName) throws Exception {
115 setupCreate(testName);
117 // Submit the request to the service and store the response.
118 AccountsCommon account =
119 createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", false, true, true);
120 ClientResponse<Response> res = client.create(account);
121 int statusCode = res.getStatus();
122 // Does it exactly match the expected status code?
123 if (logger.isDebugEnabled()) {
124 logger.debug(testName + ": status = " + statusCode);
126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
132 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
133 dependsOnMethods = {"create"})
134 public void createWithoutUser(String testName) throws Exception {
136 setupCreate(testName);
138 // Submit the request to the service and store the response.
139 AccountsCommon account =
140 createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", true, false, true);
141 ClientResponse<Response> res = client.create(account);
142 int statusCode = res.getStatus();
143 // Does it exactly match the expected status code?
144 if (logger.isDebugEnabled()) {
145 logger.debug(testName + ": status = " + statusCode);
147 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
148 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
149 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
152 //to not cause uniqueness violation for account, createList is removed
154 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
155 dependsOnMethods = {"create"})
156 public void createList(String testName) throws Exception {
158 setupCreate(testName);
159 // Submit the request to the service and store the response.
160 AccountsCommon account1 =
161 createAccountInstance("curious", "hithere08", "curious@george.com", true, true, true);
162 ClientResponse<Response> res = client.create(account1);
163 int statusCode = res.getStatus();
164 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
165 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
166 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
167 resource1Id = extractId(res);
169 AccountsCommon account2 =
170 createAccountInstance("tom", "hithere09", "tom@jerry.com", true, true, true);
171 res = client.create(account2);
172 statusCode = res.getStatus();
173 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
174 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
175 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
176 resource2Id = extractId(res);
178 AccountsCommon account3 =
179 createAccountInstance("mj", "hithere10", "mj@dinoland.com", true, true, true);
180 res = client.create(account3);
181 statusCode = res.getStatus();
182 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
183 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
184 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
185 resource3Id = extractId(res);
189 // Placeholders until the three tests below can be uncommented.
190 // See Issue CSPACE-401.
192 public void createWithEmptyEntityBody(String testName) throws Exception {
196 public void createWithMalformedXml(String testName) throws Exception {
200 public void createWithWrongXmlSchema(String testName) throws Exception {
203 // ---------------------------------------------------------------
204 // CRUD tests : READ tests
205 // ---------------------------------------------------------------
208 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
209 dependsOnMethods = {"create"})
210 public void read(String testName) throws Exception {
215 // Submit the request to the service and store the response.
216 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
217 int statusCode = res.getStatus();
219 // Check the status code of the response: does it match
220 // the expected response(s)?
221 if (logger.isDebugEnabled()) {
222 logger.debug(testName + ": status = " + statusCode);
224 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
225 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
226 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
228 AccountsCommon output = (AccountsCommon) res.getEntity();
229 Assert.assertNotNull(output);
234 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
235 dependsOnMethods = {"read"})
236 public void readNonExistent(String testName) throws Exception {
239 setupReadNonExistent(testName);
241 // Submit the request to the service and store the response.
242 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
243 int statusCode = res.getStatus();
245 // Check the status code of the response: does it match
246 // the expected response(s)?
247 if (logger.isDebugEnabled()) {
248 logger.debug(testName + ": status = " + statusCode);
250 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
251 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
252 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
255 // ---------------------------------------------------------------
256 // CRUD tests : READ_LIST tests
257 // ---------------------------------------------------------------
260 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
261 dependsOnMethods = {"createList", "read"})
262 public void readList(String testName) throws Exception {
265 setupReadList(testName);
267 // Submit the request to the service and store the response.
268 ClientResponse<AccountsCommonList> res = client.readList();
269 AccountsCommonList list = res.getEntity();
270 int statusCode = res.getStatus();
272 // Check the status code of the response: does it match
273 // the expected response(s)?
274 if (logger.isDebugEnabled()) {
275 logger.debug(testName + ": status = " + statusCode);
277 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
278 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
279 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
281 // Optionally output additional data about list members for debugging.
282 boolean iterateThroughList = true;
283 if (iterateThroughList && logger.isDebugEnabled()) {
284 printList(testName, list);
288 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
289 dependsOnMethods = {"createList", "read"})
290 public void searchScreenName(String testName) throws Exception {
293 setupReadList(testName);
295 // Submit the request to the service and store the response.
296 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, null);
297 AccountsCommonList list = res.getEntity();
298 int statusCode = res.getStatus();
300 // Check the status code of the response: does it match
301 // the expected response(s)?
302 if (logger.isDebugEnabled()) {
303 logger.debug(testName + ": status = " + statusCode);
305 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
306 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
307 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
308 Assert.assertEquals(1, list.getAccountListItem().size());
309 // Optionally output additional data about list members for debugging.
310 boolean iterateThroughList = true;
311 if (iterateThroughList && logger.isDebugEnabled()) {
312 printList(testName, list);
316 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
317 dependsOnMethods = {"createList", "read"})
318 public void searchUserId(String testName) throws Exception {
321 setupReadList(testName);
323 // Submit the request to the service and store the response.
324 ClientResponse<AccountsCommonList> res = client.readSearchList(null, "tom", null);
325 AccountsCommonList list = res.getEntity();
326 int statusCode = res.getStatus();
328 // Check the status code of the response: does it match
329 // the expected response(s)?
330 if (logger.isDebugEnabled()) {
331 logger.debug(testName + ": status = " + statusCode);
333 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
334 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
335 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
336 Assert.assertEquals(1, list.getAccountListItem().size());
337 // Optionally output additional data about list members for debugging.
338 boolean iterateThroughList = true;
339 if (iterateThroughList && logger.isDebugEnabled()) {
340 printList(testName, list);
344 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
345 dependsOnMethods = {"createList", "read"})
346 public void searchEmail(String testName) throws Exception {
349 setupReadList(testName);
351 // Submit the request to the service and store the response.
352 ClientResponse<AccountsCommonList> res = client.readSearchList(null, null, "dinoland");
353 AccountsCommonList list = res.getEntity();
354 int statusCode = res.getStatus();
356 // Check the status code of the response: does it match
357 // the expected response(s)?
358 if (logger.isDebugEnabled()) {
359 logger.debug(testName + ": status = " + statusCode);
361 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
362 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
363 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
364 Assert.assertEquals(2, list.getAccountListItem().size());
365 // Optionally output additional data about list members for debugging.
366 boolean iterateThroughList = true;
367 if (iterateThroughList && logger.isDebugEnabled()) {
368 printList(testName, list);
372 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
373 dependsOnMethods = {"createList", "read"})
374 public void searchScreenNameEmail(String testName) throws Exception {
377 setupReadList(testName);
379 // Submit the request to the service and store the response.
380 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, "jerry");
381 AccountsCommonList list = res.getEntity();
382 int statusCode = res.getStatus();
384 // Check the status code of the response: does it match
385 // the expected response(s)?
386 if (logger.isDebugEnabled()) {
387 logger.debug(testName + ": status = " + statusCode);
389 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
390 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
391 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
392 Assert.assertEquals(1, list.getAccountListItem().size());
393 // Optionally output additional data about list members for debugging.
394 boolean iterateThroughList = true;
395 if (iterateThroughList && logger.isDebugEnabled()) {
396 printList(testName, list);
402 // ---------------------------------------------------------------
403 // CRUD tests : UPDATE tests
404 // ---------------------------------------------------------------
407 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
408 dependsOnMethods = {"read", "readList", "readNonExistent"})
409 public void update(String testName) throws Exception {
412 setupUpdate(testName);
415 ClientResponse<AccountsCommon> res =
416 client.read(knownResourceId);
417 if (logger.isDebugEnabled()) {
418 logger.debug(testName + ": read status = " + res.getStatus());
420 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
422 if (logger.isDebugEnabled()) {
423 logger.debug("got object to update with ID: " + knownResourceId);
425 AccountsCommon toUpdateAccount =
426 (AccountsCommon) res.getEntity();
427 Assert.assertNotNull(toUpdateAccount);
429 // Update the content of this resource.
430 toUpdateAccount.setEmail("updated-" + toUpdateAccount.getEmail());
431 if (logger.isDebugEnabled()) {
432 logger.debug("updated object");
433 logger.debug(objectAsXmlString(toUpdateAccount,
434 AccountsCommon.class));
437 // Submit the request to the service and store the response.
438 res = client.update(knownResourceId, toUpdateAccount);
439 int statusCode = res.getStatus();
440 // Check the status code of the response: does it match the expected response(s)?
441 if (logger.isDebugEnabled()) {
442 logger.debug(testName + ": status = " + statusCode);
444 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
445 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
446 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
449 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
450 Assert.assertNotNull(updatedAccount);
452 Assert.assertEquals(updatedAccount.getEmail(),
453 toUpdateAccount.getEmail(),
454 "Data in updated object did not match submitted data.");
457 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
458 dependsOnMethods = {"update"})
459 public void updatePassword(String testName) throws Exception {
462 setupUpdate(testName);
464 ClientResponse<AccountsCommon> res =
465 client.read(knownResourceId);
466 if (logger.isDebugEnabled()) {
467 logger.debug(testName + ": read status = " + res.getStatus());
469 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
471 if (logger.isDebugEnabled()) {
472 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
474 AccountsCommon toUpdateAccount =
475 (AccountsCommon) res.getEntity();
476 Assert.assertNotNull(toUpdateAccount);
479 toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
480 if (logger.isDebugEnabled()) {
481 logger.debug(testName + ": updated object");
482 logger.debug(objectAsXmlString(toUpdateAccount,
483 AccountsCommon.class));
486 // Submit the request to the service and store the response.
487 res = client.update(knownResourceId, toUpdateAccount);
488 int statusCode = res.getStatus();
489 // Check the status code of the response: does it match the expected response(s)?
490 if (logger.isDebugEnabled()) {
491 logger.debug(testName + ": status = " + statusCode);
493 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
494 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
495 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
498 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
499 Assert.assertNotNull(updatedAccount);
501 // Assert.assertEquals(updatedAccount.getPassword(),
502 // toUpdateAccount.getPassword(),
503 // "Data in updated object did not match submitted data.");
506 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
507 dependsOnMethods = {"update"})
508 public void updatePasswordWithoutUser(String testName) throws Exception {
511 setupUpdate(testName);
513 ClientResponse<AccountsCommon> res =
514 client.read(knownResourceId);
515 if (logger.isDebugEnabled()) {
516 logger.debug(testName + ": read status = " + res.getStatus());
518 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
520 if (logger.isDebugEnabled()) {
521 logger.debug(testName + " : got object to update with ID: " + knownResourceId);
523 AccountsCommon toUpdateAccount =
524 (AccountsCommon) res.getEntity();
525 Assert.assertNotNull(toUpdateAccount);
527 toUpdateAccount.setUserId(null);
529 toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
530 if (logger.isDebugEnabled()) {
531 logger.debug(testName + " : updated object");
532 logger.debug(objectAsXmlString(toUpdateAccount,
533 AccountsCommon.class));
536 // Submit the request to the service and store the response.
537 res = client.update(knownResourceId, toUpdateAccount);
538 int statusCode = res.getStatus();
539 // Check the status code of the response: does it match the expected response(s)?
540 if (logger.isDebugEnabled()) {
541 logger.debug(testName + ": status = " + statusCode);
543 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
549 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
550 dependsOnMethods = {"updatePasswordWithoutUser"})
551 public void deactivate(String testName) throws Exception {
554 setupUpdate(testName);
556 ClientResponse<AccountsCommon> res =
557 client.read(knownResourceId);
558 if (logger.isDebugEnabled()) {
559 logger.debug(testName + ": read status = " + res.getStatus());
561 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
563 if (logger.isDebugEnabled()) {
564 logger.debug("got object to update with ID: " + knownResourceId);
566 AccountsCommon toUpdateAccount =
567 (AccountsCommon) res.getEntity();
568 Assert.assertNotNull(toUpdateAccount);
570 // Update the content of this resource.
571 toUpdateAccount.setStatus(Status.INACTIVE);
572 if (logger.isDebugEnabled()) {
573 logger.debug("updated object");
574 logger.debug(objectAsXmlString(toUpdateAccount,
575 AccountsCommon.class));
578 // Submit the request to the service and store the response.
579 res = client.update(knownResourceId, toUpdateAccount);
580 int statusCode = res.getStatus();
581 // Check the status code of the response: does it match 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);
590 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
591 Assert.assertNotNull(updatedAccount);
593 Assert.assertEquals(updatedAccount.getStatus(),
594 toUpdateAccount.getStatus(),
595 "Data in updated object did not match submitted data.");
600 // Placeholders until the three tests below can be uncommented.
601 // See Issue CSPACE-401.
603 public void updateWithEmptyEntityBody(String testName) throws Exception {
607 public void updateWithMalformedXml(String testName) throws Exception {
611 public void updateWithWrongXmlSchema(String testName) throws Exception {
615 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
616 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
617 public void updateNonExistent(String testName) throws Exception {
620 setupUpdateNonExistent(testName);
622 // Submit the request to the service and store the response.
624 // Note: The ID used in this 'create' call may be arbitrary.
625 // The only relevant ID may be the one used in updateAccount(), below.
626 AccountsCommon account =
627 createAccountInstance("simba", "tiger", "simba@lionking.com", true, true, true);
628 ClientResponse<AccountsCommon> res =
629 client.update(NON_EXISTENT_ID, account);
630 int statusCode = res.getStatus();
632 // Check the status code of the response: does it match
633 // the expected response(s)?
634 if (logger.isDebugEnabled()) {
635 logger.debug(testName + ": status = " + statusCode);
637 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
638 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
639 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
642 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
643 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
644 public void updateWrongUser(String testName) throws Exception {
647 // Submit the request to the service and store the response.
649 // Note: The ID used in this 'create' call may be arbitrary.
650 // The only relevant ID may be the one used in updateAccount(), below.
651 ClientResponse<AccountsCommon> res =
652 client.read(knownResourceId);
653 if (logger.isDebugEnabled()) {
654 logger.debug(testName + ": read status = " + res.getStatus());
656 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
658 if (logger.isDebugEnabled()) {
659 logger.debug("got object to update with ID: " + knownResourceId);
661 AccountsCommon toUpdateAccount =
662 (AccountsCommon) res.getEntity();
663 Assert.assertNotNull(toUpdateAccount);
665 toUpdateAccount.setUserId("barneyFake");
666 if (logger.isDebugEnabled()) {
667 logger.debug("updated object with wrongUser");
668 logger.debug(objectAsXmlString(toUpdateAccount,
669 AccountsCommon.class));
672 res = client.update(knownResourceId, toUpdateAccount);
673 int statusCode = res.getStatus();
675 // Check the status code of the response: does it match
676 // the expected response(s)?
677 if (logger.isDebugEnabled()) {
678 logger.debug(testName + ": status = " + statusCode);
680 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
685 // ---------------------------------------------------------------
686 // CRUD tests : DELETE tests
687 // ---------------------------------------------------------------
690 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
691 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
692 public void delete(String testName) throws Exception {
695 setupDelete(testName);
697 // Submit the request to the service and store the response.
698 ClientResponse<Response> res = client.delete(knownResourceId);
699 int statusCode = res.getStatus();
701 // Check the status code of the response: does it match
702 // the expected response(s)?
703 if (logger.isDebugEnabled()) {
704 logger.debug(testName + ": status = " + statusCode);
706 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
707 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
708 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
711 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
712 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
713 public void deleteList(String testName) throws Exception {
716 setupDelete(testName);
718 ClientResponse<Response> res = client.delete(resource1Id);
719 int statusCode = res.getStatus();
720 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
721 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
722 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
724 res = client.delete(resource2Id);
725 statusCode = res.getStatus();
726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
730 res = client.delete(resource3Id);
731 statusCode = res.getStatus();
732 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
733 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
734 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
739 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
740 dependsOnMethods = {"delete"})
741 public void deleteNonExistent(String testName) throws Exception {
744 setupDeleteNonExistent(testName);
746 // Submit the request to the service and store the response.
747 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
748 int statusCode = res.getStatus();
750 // Check the status code of the response: does it match
751 // the expected response(s)?
752 if (logger.isDebugEnabled()) {
753 logger.debug(testName + ": status = " + statusCode);
755 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
756 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
757 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
760 // ---------------------------------------------------------------
761 // Utility tests : tests of code used in tests above
762 // ---------------------------------------------------------------
764 * Tests the code for manually submitting data that is used by several
765 * of the methods above.
767 @Test(dependsOnMethods = {"create", "read"})
768 public void testSubmitRequest() throws Exception {
770 // Expected status code: 200 OK
771 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
773 // Submit the request to the service and store the response.
774 String method = ServiceRequestType.READ.httpMethodName();
775 String url = getResourceURL(knownResourceId);
776 int statusCode = submitRequest(method, url);
778 // Check the status code of the response: does it match
779 // the expected response(s)?
780 if (logger.isDebugEnabled()) {
781 logger.debug("testSubmitRequest: url=" + url
782 + " status=" + statusCode);
784 Assert.assertEquals(statusCode, EXPECTED_STATUS);
788 // ---------------------------------------------------------------
789 // Utility methods used by tests above
790 // ---------------------------------------------------------------
792 * createAccountInstance
793 * @param tenant fillup tenant
794 * @param user to fill up user
795 * @param password to fill up password
797 private AccountsCommon createAccountInstance(String screenName,
798 String passwd, String email, boolean tenant, boolean user, boolean password) {
800 AccountsCommon account = new AccountsCommon();
801 account.setScreenName(screenName);
803 account.setUserId(screenName);
806 account.setPassword(Base64.encodeBase64(passwd.getBytes()));
808 account.setEmail(email);
809 account.setPhone("1234567890");
811 List<AccountsCommon.Tenant> atl = new ArrayList<AccountsCommon.Tenant>();
812 AccountsCommon.Tenant at = new AccountsCommon.Tenant();
813 at.setId(UUID.randomUUID().toString());
814 at.setName("movingimages.us");
817 AccountsCommon.Tenant at2 = new AccountsCommon.Tenant();
818 at2.setId(UUID.randomUUID().toString());
819 at2.setName("collectionspace.org");
821 account.setTenant(atl);
823 if (logger.isDebugEnabled()) {
824 logger.debug("to be created, account common");
825 logger.debug(objectAsXmlString(account,
826 AccountsCommon.class));
832 private void printList(String testName, AccountsCommonList list) {
833 List<AccountsCommonList.AccountListItem> items =
834 list.getAccountListItem();
837 for (AccountsCommonList.AccountListItem item : items) {
838 logger.debug(testName + ": list-item[" + i + "] csid="
840 logger.debug(testName + ": list-item[" + i + "] screenName="
841 + item.getScreenName());
842 logger.debug(testName + ": list-item[" + i + "] URI="