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", "barney", "hithere08", "barney@dinoland.com",
87 true, true, true, true);
88 ClientResponse<Response> res = client.create(account);
89 int statusCode = res.getStatus();
91 // Check the status code of the response: does it match
92 // the expected response(s)?
95 // Does it fall within the set of valid status codes?
96 // Does it exactly match the expected status code?
97 if (logger.isDebugEnabled()) {
98 logger.debug(testName + ": status = " + statusCode);
100 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
101 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
102 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
104 // Store the ID returned from this create operation
105 // for additional tests below.
106 knownResourceId = extractId(res);
107 if (logger.isDebugEnabled()) {
108 logger.debug(testName + ": knownResourceId=" + knownResourceId);
112 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
113 dependsOnMethods = {"create"})
114 public void createForUniqueUser(String testName) throws Exception {
116 setupCreate(testName);
118 // Submit the request to the service and store the response.
119 AccountsCommon account =
120 createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
121 true, true, true, true);
122 ClientResponse<Response> res = client.create(account);
123 int statusCode = res.getStatus();
125 if (logger.isDebugEnabled()) {
126 logger.debug(testName + ": status = " + statusCode);
128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
130 Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
133 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
134 dependsOnMethods = {"create"})
135 public void createForUniqueScreenName(String testName) throws Exception {
137 setupCreate(testName);
139 // Submit the request to the service and store the response.
140 AccountsCommon account =
141 createAccountInstance("barney", "otherUser", "hithere08", "barney@dinoland.com",
142 true, true, true, true);
143 ClientResponse<Response> res = client.create(account);
144 int statusCode = res.getStatus();
146 if (logger.isDebugEnabled()) {
147 logger.debug(testName + ": status = " + statusCode);
149 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
150 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
151 Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
154 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
155 dependsOnMethods = {"create"})
156 public void createWithoutTenant(String testName) throws Exception {
158 setupCreate(testName);
160 // Submit the request to the service and store the response.
161 AccountsCommon account =
162 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
163 true, false, true, true);
164 ClientResponse<Response> res = client.create(account);
165 int statusCode = res.getStatus();
166 // Does it exactly match the expected status code?
167 if (logger.isDebugEnabled()) {
168 logger.debug(testName + ": status = " + statusCode);
170 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
171 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
172 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
176 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
177 dependsOnMethods = {"create"})
178 public void createWithoutUser(String testName) throws Exception {
180 setupCreate(testName);
182 // Submit the request to the service and store the response.
183 AccountsCommon account =
184 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
185 true, true, false, true);
186 ClientResponse<Response> res = client.create(account);
187 int statusCode = res.getStatus();
188 // Does it exactly match the expected status code?
189 if (logger.isDebugEnabled()) {
190 logger.debug(testName + ": status = " + statusCode);
192 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
193 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
194 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
197 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
198 dependsOnMethods = {"create"})
199 public void createWithInvalidEmail(String testName) throws Exception {
201 setupCreate(testName);
203 // Submit the request to the service and store the response.
204 AccountsCommon account =
205 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
206 true, true, true, true);
207 ClientResponse<Response> res = client.create(account);
208 int statusCode = res.getStatus();
209 // Does it exactly match the expected status code?
210 if (logger.isDebugEnabled()) {
211 logger.debug(testName + ": status = " + statusCode);
213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
218 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
219 dependsOnMethods = {"create"})
220 public void createWithoutScreenName(String testName) throws Exception {
222 setupCreate(testName);
224 // Submit the request to the service and store the response.
225 AccountsCommon account =
226 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
227 false, true, true, true);
228 ClientResponse<Response> res = client.create(account);
229 int statusCode = res.getStatus();
230 // Does it exactly match the expected status code?
231 if (logger.isDebugEnabled()) {
232 logger.debug(testName + ": status = " + statusCode);
234 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
235 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
236 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
239 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
240 dependsOnMethods = {"create"})
241 public void createWithMostInvalid(String testName) throws Exception {
243 setupCreate(testName);
245 // Submit the request to the service and store the response.
246 AccountsCommon account =
247 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
248 false, false, false, false);
249 ClientResponse<Response> res = client.create(account);
250 int statusCode = res.getStatus();
251 // Does it exactly match the expected status code?
252 if (logger.isDebugEnabled()) {
253 logger.debug(testName + ": status = " + statusCode);
255 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
256 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
257 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
260 //to not cause uniqueness violation for account, createList is removed
262 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
263 dependsOnMethods = {"create"})
264 public void createList(String testName) throws Exception {
266 setupCreate(testName);
267 // Submit the request to the service and store the response.
268 AccountsCommon account1 =
269 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
270 true, true, true, true);
271 ClientResponse<Response> res = client.create(account1);
272 int statusCode = res.getStatus();
273 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
274 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
275 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276 resource1Id = extractId(res);
278 AccountsCommon account2 =
279 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
280 true, true, true, true);
281 res = client.create(account2);
282 statusCode = res.getStatus();
283 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
284 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
285 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
286 resource2Id = extractId(res);
288 AccountsCommon account3 =
289 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
290 true, true, true, true);
291 res = client.create(account3);
292 statusCode = res.getStatus();
293 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
294 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
295 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
296 resource3Id = extractId(res);
300 // Placeholders until the three tests below can be uncommented.
301 // See Issue CSPACE-401.
303 public void createWithEmptyEntityBody(String testName) throws Exception {
307 public void createWithMalformedXml(String testName) throws Exception {
311 public void createWithWrongXmlSchema(String testName) throws Exception {
314 // ---------------------------------------------------------------
315 // CRUD tests : READ tests
316 // ---------------------------------------------------------------
319 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
320 dependsOnMethods = {"create"})
321 public void read(String testName) throws Exception {
326 // Submit the request to the service and store the response.
327 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
328 int statusCode = res.getStatus();
330 // Check the status code of the response: does it match
331 // the expected response(s)?
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, EXPECTED_STATUS_CODE);
339 AccountsCommon output = (AccountsCommon) res.getEntity();
340 Assert.assertNotNull(output);
345 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
346 dependsOnMethods = {"read"})
347 public void readNonExistent(String testName) throws Exception {
350 setupReadNonExistent(testName);
352 // Submit the request to the service and store the response.
353 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
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);
366 // ---------------------------------------------------------------
367 // CRUD tests : READ_LIST tests
368 // ---------------------------------------------------------------
371 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
372 dependsOnMethods = {"createList", "read"})
373 public void readList(String testName) throws Exception {
376 setupReadList(testName);
378 // Submit the request to the service and store the response.
379 ClientResponse<AccountsCommonList> res = client.readList();
380 AccountsCommonList list = res.getEntity();
381 int statusCode = res.getStatus();
383 // Check the status code of the response: does it match
384 // the expected response(s)?
385 if (logger.isDebugEnabled()) {
386 logger.debug(testName + ": status = " + statusCode);
388 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
389 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
390 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
392 // Optionally output additional data about list members for debugging.
393 boolean iterateThroughList = true;
394 if (iterateThroughList && logger.isDebugEnabled()) {
395 printList(testName, list);
399 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
400 dependsOnMethods = {"createList", "read"})
401 public void searchScreenName(String testName) throws Exception {
404 setupReadList(testName);
406 // Submit the request to the service and store the response.
407 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, null);
408 AccountsCommonList list = res.getEntity();
409 int statusCode = res.getStatus();
411 // Check the status code of the response: does it match
412 // the expected response(s)?
413 if (logger.isDebugEnabled()) {
414 logger.debug(testName + ": status = " + statusCode);
416 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
417 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
418 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
419 Assert.assertEquals(1, list.getAccountListItem().size());
420 // Optionally output additional data about list members for debugging.
421 boolean iterateThroughList = true;
422 if (iterateThroughList && logger.isDebugEnabled()) {
423 printList(testName, list);
427 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
428 dependsOnMethods = {"createList", "read"})
429 public void searchUserId(String testName) throws Exception {
432 setupReadList(testName);
434 // Submit the request to the service and store the response.
435 ClientResponse<AccountsCommonList> res = client.readSearchList(null, "tom", null);
436 AccountsCommonList list = res.getEntity();
437 int statusCode = res.getStatus();
439 // Check the status code of the response: does it match
440 // 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);
447 Assert.assertEquals(1, list.getAccountListItem().size());
448 // Optionally output additional data about list members for debugging.
449 boolean iterateThroughList = true;
450 if (iterateThroughList && logger.isDebugEnabled()) {
451 printList(testName, list);
455 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456 dependsOnMethods = {"createList", "read"})
457 public void searchEmail(String testName) throws Exception {
460 setupReadList(testName);
462 // Submit the request to the service and store the response.
463 ClientResponse<AccountsCommonList> res = client.readSearchList(null, null, "dinoland");
464 AccountsCommonList list = res.getEntity();
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match
468 // the expected response(s)?
469 if (logger.isDebugEnabled()) {
470 logger.debug(testName + ": status = " + statusCode);
472 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475 Assert.assertEquals(2, list.getAccountListItem().size());
476 // Optionally output additional data about list members for debugging.
477 boolean iterateThroughList = true;
478 if (iterateThroughList && logger.isDebugEnabled()) {
479 printList(testName, list);
483 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
484 dependsOnMethods = {"createList", "read"})
485 public void searchScreenNameEmail(String testName) throws Exception {
488 setupReadList(testName);
490 // Submit the request to the service and store the response.
491 ClientResponse<AccountsCommonList> res = client.readSearchList("tom", null, "jerry");
492 AccountsCommonList list = res.getEntity();
493 int statusCode = res.getStatus();
495 // Check the status code of the response: does it match
496 // the expected response(s)?
497 if (logger.isDebugEnabled()) {
498 logger.debug(testName + ": status = " + statusCode);
500 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
501 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
502 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 Assert.assertEquals(1, list.getAccountListItem().size());
504 // Optionally output additional data about list members for debugging.
505 boolean iterateThroughList = true;
506 if (iterateThroughList && logger.isDebugEnabled()) {
507 printList(testName, list);
513 // ---------------------------------------------------------------
514 // CRUD tests : UPDATE tests
515 // ---------------------------------------------------------------
518 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
519 dependsOnMethods = {"read", "readList", "readNonExistent"})
520 public void update(String testName) throws Exception {
523 setupUpdate(testName);
526 ClientResponse<AccountsCommon> res =
527 client.read(knownResourceId);
528 if (logger.isDebugEnabled()) {
529 logger.debug(testName + ": read status = " + res.getStatus());
531 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
533 if (logger.isDebugEnabled()) {
534 logger.debug("got object to update with ID: " + knownResourceId);
536 AccountsCommon toUpdateAccount =
537 (AccountsCommon) res.getEntity();
538 Assert.assertNotNull(toUpdateAccount);
540 // Update the content of this resource.
541 toUpdateAccount.setEmail("updated-" + toUpdateAccount.getEmail());
542 if (logger.isDebugEnabled()) {
543 logger.debug("updated object");
544 logger.debug(objectAsXmlString(toUpdateAccount,
545 AccountsCommon.class));
548 // Submit the request to the service and store the response.
549 res = client.update(knownResourceId, toUpdateAccount);
550 int statusCode = res.getStatus();
551 // Check the status code of the response: does it match the expected response(s)?
552 if (logger.isDebugEnabled()) {
553 logger.debug(testName + ": status = " + statusCode);
555 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
556 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
557 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
560 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
561 Assert.assertNotNull(updatedAccount);
563 Assert.assertEquals(updatedAccount.getEmail(),
564 toUpdateAccount.getEmail(),
565 "Data in updated object did not match submitted data.");
568 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
569 dependsOnMethods = {"update"})
570 public void updatePassword(String testName) throws Exception {
573 setupUpdate(testName);
575 ClientResponse<AccountsCommon> res =
576 client.read(knownResourceId);
577 if (logger.isDebugEnabled()) {
578 logger.debug(testName + ": read status = " + res.getStatus());
580 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
582 if (logger.isDebugEnabled()) {
583 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
585 AccountsCommon toUpdateAccount =
586 (AccountsCommon) res.getEntity();
587 Assert.assertNotNull(toUpdateAccount);
590 toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
591 if (logger.isDebugEnabled()) {
592 logger.debug(testName + ": updated object");
593 logger.debug(objectAsXmlString(toUpdateAccount,
594 AccountsCommon.class));
597 // Submit the request to the service and store the response.
598 res = client.update(knownResourceId, toUpdateAccount);
599 int statusCode = res.getStatus();
600 // Check the status code of the response: does it match the expected response(s)?
601 if (logger.isDebugEnabled()) {
602 logger.debug(testName + ": status = " + statusCode);
604 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
609 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
610 Assert.assertNotNull(updatedAccount);
612 // Assert.assertEquals(updatedAccount.getPassword(),
613 // toUpdateAccount.getPassword(),
614 // "Data in updated object did not match submitted data.");
617 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
618 dependsOnMethods = {"update"})
619 public void updatePasswordWithoutUser(String testName) throws Exception {
622 setupUpdate(testName);
624 ClientResponse<AccountsCommon> res =
625 client.read(knownResourceId);
626 if (logger.isDebugEnabled()) {
627 logger.debug(testName + ": read status = " + res.getStatus());
629 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
631 if (logger.isDebugEnabled()) {
632 logger.debug(testName + " : got object to update with ID: " + knownResourceId);
634 AccountsCommon toUpdateAccount =
635 (AccountsCommon) res.getEntity();
636 Assert.assertNotNull(toUpdateAccount);
638 toUpdateAccount.setUserId(null);
640 toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
641 if (logger.isDebugEnabled()) {
642 logger.debug(testName + " : updated object");
643 logger.debug(objectAsXmlString(toUpdateAccount,
644 AccountsCommon.class));
647 // Submit the request to the service and store the response.
648 res = client.update(knownResourceId, toUpdateAccount);
649 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match the expected response(s)?
651 if (logger.isDebugEnabled()) {
652 logger.debug(testName + ": status = " + statusCode);
654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
660 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
661 dependsOnMethods = {"updatePasswordWithoutUser"})
662 public void deactivate(String testName) throws Exception {
665 setupUpdate(testName);
667 ClientResponse<AccountsCommon> res =
668 client.read(knownResourceId);
669 if (logger.isDebugEnabled()) {
670 logger.debug(testName + ": read status = " + res.getStatus());
672 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
674 if (logger.isDebugEnabled()) {
675 logger.debug("got object to update with ID: " + knownResourceId);
677 AccountsCommon toUpdateAccount =
678 (AccountsCommon) res.getEntity();
679 Assert.assertNotNull(toUpdateAccount);
681 // Update the content of this resource.
682 toUpdateAccount.setStatus(Status.INACTIVE);
683 if (logger.isDebugEnabled()) {
684 logger.debug("updated object");
685 logger.debug(objectAsXmlString(toUpdateAccount,
686 AccountsCommon.class));
689 // Submit the request to the service and store the response.
690 res = client.update(knownResourceId, toUpdateAccount);
691 int statusCode = res.getStatus();
692 // Check the status code of the response: does it match the expected response(s)?
693 if (logger.isDebugEnabled()) {
694 logger.debug(testName + ": status = " + statusCode);
696 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701 AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
702 Assert.assertNotNull(updatedAccount);
704 Assert.assertEquals(updatedAccount.getStatus(),
705 toUpdateAccount.getStatus(),
706 "Data in updated object did not match submitted data.");
711 // Placeholders until the three tests below can be uncommented.
712 // See Issue CSPACE-401.
714 public void updateWithEmptyEntityBody(String testName) throws Exception {
718 public void updateWithMalformedXml(String testName) throws Exception {
722 public void updateWithWrongXmlSchema(String testName) throws Exception {
726 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
727 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
728 public void updateNonExistent(String testName) throws Exception {
731 setupUpdateNonExistent(testName);
733 // Submit the request to the service and store the response.
735 // Note: The ID used in this 'create' call may be arbitrary.
736 // The only relevant ID may be the one used in updateAccount(), below.
737 AccountsCommon account =
738 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
739 true, true, true, true);
740 ClientResponse<AccountsCommon> res =
741 client.update(NON_EXISTENT_ID, account);
742 int statusCode = res.getStatus();
744 // Check the status code of the response: does it match
745 // the expected response(s)?
746 if (logger.isDebugEnabled()) {
747 logger.debug(testName + ": status = " + statusCode);
749 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
750 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
751 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
755 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
756 public void updateWrongUser(String testName) throws Exception {
759 // Submit the request to the service and store the response.
761 // Note: The ID used in this 'create' call may be arbitrary.
762 // The only relevant ID may be the one used in updateAccount(), below.
763 ClientResponse<AccountsCommon> res =
764 client.read(knownResourceId);
765 if (logger.isDebugEnabled()) {
766 logger.debug(testName + ": read status = " + res.getStatus());
768 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
770 if (logger.isDebugEnabled()) {
771 logger.debug("got object to update with ID: " + knownResourceId);
773 AccountsCommon toUpdateAccount =
774 (AccountsCommon) res.getEntity();
775 Assert.assertNotNull(toUpdateAccount);
777 toUpdateAccount.setUserId("barneyFake");
778 if (logger.isDebugEnabled()) {
779 logger.debug("updated object with wrongUser");
780 logger.debug(objectAsXmlString(toUpdateAccount,
781 AccountsCommon.class));
784 res = client.update(knownResourceId, toUpdateAccount);
785 int statusCode = res.getStatus();
787 // Check the status code of the response: does it match
788 // the expected response(s)?
789 if (logger.isDebugEnabled()) {
790 logger.debug(testName + ": status = " + statusCode);
792 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
793 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
794 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
797 // ---------------------------------------------------------------
798 // CRUD tests : DELETE tests
799 // ---------------------------------------------------------------
802 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
803 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
804 public void delete(String testName) throws Exception {
807 setupDelete(testName);
809 // Submit the request to the service and store the response.
810 ClientResponse<Response> res = client.delete(knownResourceId);
811 int statusCode = res.getStatus();
813 // Check the status code of the response: does it match
814 // the expected response(s)?
815 if (logger.isDebugEnabled()) {
816 logger.debug(testName + ": status = " + statusCode);
818 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
819 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
820 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
823 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
824 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
825 public void deleteList(String testName) throws Exception {
828 setupDelete(testName);
830 ClientResponse<Response> res = client.delete(resource1Id);
831 int statusCode = res.getStatus();
832 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
833 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
834 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
836 res = client.delete(resource2Id);
837 statusCode = res.getStatus();
838 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
839 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
840 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
842 res = client.delete(resource3Id);
843 statusCode = res.getStatus();
844 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
845 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
846 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
851 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
852 dependsOnMethods = {"delete"})
853 public void deleteNonExistent(String testName) throws Exception {
856 setupDeleteNonExistent(testName);
858 // Submit the request to the service and store the response.
859 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
860 int statusCode = res.getStatus();
862 // Check the status code of the response: does it match
863 // the expected response(s)?
864 if (logger.isDebugEnabled()) {
865 logger.debug(testName + ": status = " + statusCode);
867 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
868 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
869 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
872 // ---------------------------------------------------------------
873 // Utility tests : tests of code used in tests above
874 // ---------------------------------------------------------------
876 * Tests the code for manually submitting data that is used by several
877 * of the methods above.
879 @Test(dependsOnMethods = {"create", "read"})
880 public void testSubmitRequest() throws Exception {
882 // Expected status code: 200 OK
883 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
885 // Submit the request to the service and store the response.
886 String method = ServiceRequestType.READ.httpMethodName();
887 String url = getResourceURL(knownResourceId);
888 int statusCode = submitRequest(method, url);
890 // Check the status code of the response: does it match
891 // the expected response(s)?
892 if (logger.isDebugEnabled()) {
893 logger.debug("testSubmitRequest: url=" + url
894 + " status=" + statusCode);
896 Assert.assertEquals(statusCode, EXPECTED_STATUS);
900 // ---------------------------------------------------------------
901 // Utility methods used by tests above
902 // ---------------------------------------------------------------
904 * create account instance
909 * @param useScreenName
915 private AccountsCommon createAccountInstance(String screenName,
916 String userName, String passwd, String email,
917 boolean useScreenName, boolean useTenant, boolean useUser, boolean usePassword) {
919 AccountsCommon account = new AccountsCommon();
921 account.setScreenName(screenName);
924 account.setUserId(userName);
927 account.setPassword(Base64.encodeBase64(passwd.getBytes()));
929 account.setPersonRefName(screenName);
930 account.setEmail(email);
931 account.setPhone("1234567890");
933 List<AccountsCommon.Tenant> atl = new ArrayList<AccountsCommon.Tenant>();
934 AccountsCommon.Tenant at = new AccountsCommon.Tenant();
935 at.setId(UUID.randomUUID().toString());
936 at.setName("movingimages.us");
939 AccountsCommon.Tenant at2 = new AccountsCommon.Tenant();
940 at2.setId(UUID.randomUUID().toString());
941 at2.setName("collectionspace.org");
943 account.setTenant(atl);
945 if (logger.isDebugEnabled()) {
946 logger.debug("to be created, account common");
947 logger.debug(objectAsXmlString(account,
948 AccountsCommon.class));
954 private void printList(String testName, AccountsCommonList list) {
955 List<AccountsCommonList.AccountListItem> items =
956 list.getAccountListItem();
959 for (AccountsCommonList.AccountListItem item : items) {
960 logger.debug(testName + ": list-item[" + i + "] csid="
962 logger.debug(testName + ": list-item[" + i + "] screenName="
963 + item.getScreenName());
964 logger.debug(testName + ": list-item[" + i + "] URI="