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 javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.AccountClient;
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.jboss.resteasy.client.ClientResponse;
38 import org.testng.Assert;
39 import org.testng.annotations.Test;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.testng.annotations.AfterClass;
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 static private final Logger logger =
55 LoggerFactory.getLogger(AccountServiceTest.class);
56 // Instance variables specific to this test.
57 private String knownResourceId = null;
58 private List<String> allResourceIdsCreated = new ArrayList();
59 static boolean addTenant = true;
61 * This method is called only by the parent class, AbstractServiceTestImpl
65 protected String getServicePathComponent() {
66 return new AccountClient().getServicePathComponent();
69 // ---------------------------------------------------------------
70 // CRUD tests : CREATE tests
71 // ---------------------------------------------------------------
74 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
75 public void create(String testName) throws Exception {
77 // Perform setup, such as initializing the type of service request
78 // (e.g. CREATE, DELETE), its valid and expected status codes, and
79 // its associated HTTP method name (e.g. POST, DELETE).
80 setupCreate(testName);
82 // Submit the request to the service and store the response.
83 AccountsCommon account =
84 createAccountInstance("barney", "barney", "hithere08", "barney@dinoland.com",
85 true, false, true, true);
86 AccountClient client = new AccountClient();
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 createForUniqueUser(String testName) throws Exception {
115 setupCreate(testName);
117 // Submit the request to the service and store the response.
118 AccountsCommon account =
119 createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
120 true, false, true, true);
121 AccountClient client = new AccountClient();
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.BAD_REQUEST.getStatusCode());
133 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
134 dependsOnMethods = {"create"})
135 public void createWithInvalidTenant(String testName) throws Exception {
137 setupCreate(testName);
139 // Submit the request to the service and store the response.
140 AccountsCommon account =
141 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
142 true, true, true, true);
143 AccountClient client = new AccountClient();
144 ClientResponse<Response> res = client.create(account);
145 int statusCode = res.getStatus();
146 // Does it exactly match the expected status code?
147 if (logger.isDebugEnabled()) {
148 logger.debug(testName + ": status = " + statusCode);
150 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
151 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
152 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
156 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
157 dependsOnMethods = {"create"})
158 public void createWithoutUser(String testName) throws Exception {
160 setupCreate(testName);
162 // Submit the request to the service and store the response.
163 AccountsCommon account =
164 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
165 true, false, false, true);
166 AccountClient client = new AccountClient();
167 ClientResponse<Response> res = client.create(account);
168 int statusCode = res.getStatus();
169 // Does it exactly match the expected status code?
170 if (logger.isDebugEnabled()) {
171 logger.debug(testName + ": status = " + statusCode);
173 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
174 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
175 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
178 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
179 dependsOnMethods = {"create"})
180 public void createWithInvalidEmail(String testName) throws Exception {
182 setupCreate(testName);
184 // Submit the request to the service and store the response.
185 AccountsCommon account =
186 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
187 true, false, true, true);
188 AccountClient client = new AccountClient();
189 ClientResponse<Response> res = client.create(account);
190 int statusCode = res.getStatus();
191 // Does it exactly match the expected status code?
192 if (logger.isDebugEnabled()) {
193 logger.debug(testName + ": status = " + statusCode);
195 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
196 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
197 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
200 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
201 dependsOnMethods = {"create"})
202 public void createWithoutScreenName(String testName) throws Exception {
204 setupCreate(testName);
206 // Submit the request to the service and store the response.
207 AccountsCommon account =
208 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
209 false, false, true, true);
210 AccountClient client = new AccountClient();
211 ClientResponse<Response> res = client.create(account);
212 int statusCode = res.getStatus();
213 // Does it exactly match the expected status code?
214 if (logger.isDebugEnabled()) {
215 logger.debug(testName + ": status = " + statusCode);
217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
219 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
222 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
223 dependsOnMethods = {"create"})
224 public void createWithInvalidPassword(String testName) throws Exception {
226 setupCreate(testName);
228 // Submit the request to the service and store the response.
229 AccountsCommon account =
230 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
231 true, false, true, true);
232 AccountClient client = new AccountClient();
233 ClientResponse<Response> res = client.create(account);
234 int statusCode = res.getStatus();
235 // Does it exactly match the expected status code?
236 if (logger.isDebugEnabled()) {
237 logger.debug(testName + ": status = " + statusCode);
239 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
240 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
241 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
244 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
245 dependsOnMethods = {"create"})
246 public void createWithMostInvalid(String testName) throws Exception {
248 setupCreate(testName);
250 // Submit the request to the service and store the response.
251 AccountsCommon account =
252 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
253 false, true, false, false);
254 AccountClient client = new AccountClient();
255 ClientResponse<Response> res = client.create(account);
256 int statusCode = res.getStatus();
257 // Does it exactly match the expected status code?
258 if (logger.isDebugEnabled()) {
259 logger.debug(testName + ": status = " + statusCode);
261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
263 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
266 //to not cause uniqueness violation for account, createList is removed
268 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
269 dependsOnMethods = {"create"})
270 public void createList(String testName) throws Exception {
272 setupCreate(testName);
273 // Submit the request to the service and store the response.
274 AccountsCommon account1 =
275 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
276 true, false, true, true);
277 AccountClient client = new AccountClient();
278 ClientResponse<Response> res = client.create(account1);
279 int statusCode = res.getStatus();
280 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
281 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
282 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
283 allResourceIdsCreated.add(extractId(res));
285 AccountsCommon account2 =
286 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
287 true, false, true, true);
288 res = client.create(account2);
289 statusCode = res.getStatus();
290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
293 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294 allResourceIdsCreated.add(extractId(res));
296 AccountsCommon account3 =
297 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
298 true, false, true, true);
299 res = client.create(account3);
300 statusCode = res.getStatus();
301 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
303 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
304 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
305 allResourceIdsCreated.add(extractId(res));
309 // Placeholders until the three tests below can be uncommented.
310 // See Issue CSPACE-401.
312 public void createWithEmptyEntityBody(String testName) throws Exception {
316 public void createWithMalformedXml(String testName) throws Exception {
320 public void createWithWrongXmlSchema(String testName) throws Exception {
323 // ---------------------------------------------------------------
324 // CRUD tests : READ tests
325 // ---------------------------------------------------------------
328 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
329 dependsOnMethods = {"create"})
330 public void read(String testName) throws Exception {
335 // Submit the request to the service and store the response.
336 AccountClient client = new AccountClient();
337 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
338 int statusCode = res.getStatus();
340 // Check the status code of the response: does it match
341 // the expected response(s)?
342 if (logger.isDebugEnabled()) {
343 logger.debug(testName + ": status = " + statusCode);
345 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
346 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
347 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
349 AccountsCommon output = (AccountsCommon) res.getEntity();
350 Assert.assertNotNull(output);
355 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
356 dependsOnMethods = {"read"})
357 public void readNonExistent(String testName) throws Exception {
360 setupReadNonExistent(testName);
362 // Submit the request to the service and store the response.
363 AccountClient client = new AccountClient();
364 ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
365 int statusCode = res.getStatus();
367 // Check the status code of the response: does it match
368 // the expected response(s)?
369 if (logger.isDebugEnabled()) {
370 logger.debug(testName + ": status = " + statusCode);
372 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
377 // ---------------------------------------------------------------
378 // CRUD tests : READ_LIST tests
379 // ---------------------------------------------------------------
382 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
383 dependsOnMethods = {"createList", "read"})
384 public void readList(String testName) throws Exception {
387 setupReadList(testName);
389 // Submit the request to the service and store the response.
390 AccountClient client = new AccountClient();
391 ClientResponse<AccountsCommonList> res = client.readList();
392 AccountsCommonList list = res.getEntity();
393 int statusCode = res.getStatus();
395 // Check the status code of the response: does it match
396 // the expected response(s)?
397 if (logger.isDebugEnabled()) {
398 logger.debug(testName + ": status = " + statusCode);
400 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
401 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
402 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
404 // Optionally output additional data about list members for debugging.
405 boolean iterateThroughList = true;
406 if (iterateThroughList && logger.isDebugEnabled()) {
407 printList(testName, list);
411 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
412 dependsOnMethods = {"createList", "read"})
413 public void searchScreenName(String testName) throws Exception {
416 setupReadList(testName);
418 // Submit the request to the service and store the response.
419 AccountClient client = new AccountClient();
420 ClientResponse<AccountsCommonList> res =
421 client.readSearchList("tom", null, null);
422 AccountsCommonList list = res.getEntity();
423 int statusCode = res.getStatus();
425 // Check the status code of the response: does it match
426 // the expected response(s)?
427 if (logger.isDebugEnabled()) {
428 logger.debug(testName + ": status = " + statusCode);
430 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
431 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
432 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
433 Assert.assertEquals(1, list.getAccountListItem().size());
434 // Optionally output additional data about list members for debugging.
435 boolean iterateThroughList = true;
436 if (iterateThroughList && logger.isDebugEnabled()) {
437 printList(testName, list);
441 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
442 dependsOnMethods = {"createList", "read"})
443 public void searchUserId(String testName) throws Exception {
446 setupReadList(testName);
448 // Submit the request to the service and store the response.
449 AccountClient client = new AccountClient();
450 ClientResponse<AccountsCommonList> res =
451 client.readSearchList(null, "tom", null);
452 AccountsCommonList list = res.getEntity();
453 int statusCode = res.getStatus();
455 // Check the status code of the response: does it match
456 // the expected response(s)?
457 if (logger.isDebugEnabled()) {
458 logger.debug(testName + ": status = " + statusCode);
460 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
461 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
462 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
463 Assert.assertEquals(1, list.getAccountListItem().size());
464 // Optionally output additional data about list members for debugging.
465 boolean iterateThroughList = true;
466 if (iterateThroughList && logger.isDebugEnabled()) {
467 printList(testName, list);
471 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
472 dependsOnMethods = {"createList", "read"})
473 public void searchEmail(String testName) throws Exception {
476 setupReadList(testName);
478 // Submit the request to the service and store the response.
479 AccountClient client = new AccountClient();
480 ClientResponse<AccountsCommonList> res =
481 client.readSearchList(null, null, "dinoland");
482 AccountsCommonList list = res.getEntity();
483 int statusCode = res.getStatus();
485 // Check the status code of the response: does it match
486 // the expected response(s)?
487 if (logger.isDebugEnabled()) {
488 logger.debug(testName + ": status = " + statusCode);
490 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
491 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
492 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
493 Assert.assertEquals(2, list.getAccountListItem().size());
494 // Optionally output additional data about list members for debugging.
495 boolean iterateThroughList = true;
496 if (iterateThroughList && logger.isDebugEnabled()) {
497 printList(testName, list);
501 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
502 dependsOnMethods = {"createList", "read"})
503 public void searchScreenNameEmail(String testName) throws Exception {
506 setupReadList(testName);
508 // Submit the request to the service and store the response.
509 AccountClient client = new AccountClient();
510 ClientResponse<AccountsCommonList> res =
511 client.readSearchList("tom", null, "jerry");
512 AccountsCommonList list = res.getEntity();
513 int statusCode = res.getStatus();
515 // Check the status code of the response: does it match
516 // the expected response(s)?
517 if (logger.isDebugEnabled()) {
518 logger.debug(testName + ": status = " + statusCode);
520 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
521 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
522 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
523 Assert.assertEquals(1, list.getAccountListItem().size());
524 // Optionally output additional data about list members for debugging.
525 boolean iterateThroughList = true;
526 if (iterateThroughList && logger.isDebugEnabled()) {
527 printList(testName, list);
533 // ---------------------------------------------------------------
534 // CRUD tests : UPDATE tests
535 // ---------------------------------------------------------------
538 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
539 dependsOnMethods = {"read", "readList", "readNonExistent"})
540 public void update(String testName) throws Exception {
543 setupUpdate(testName);
545 AccountClient client = new AccountClient();
546 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
547 if (logger.isDebugEnabled()) {
548 logger.debug(testName + ": read status = " + res.getStatus());
550 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
552 if (logger.isDebugEnabled()) {
553 logger.debug("got object to update with ID: " + knownResourceId);
555 AccountsCommon accountFound =
556 (AccountsCommon) res.getEntity();
557 Assert.assertNotNull(accountFound);
559 //create a new account object to test partial updates
560 AccountsCommon accountToUpdate = new AccountsCommon();
561 accountToUpdate.setCsid(knownResourceId);
562 accountToUpdate.setUserId(accountFound.getUserId());
563 // Update the content of this resource.
564 accountToUpdate.setEmail("updated-" + accountFound.getEmail());
565 if (logger.isDebugEnabled()) {
566 logger.debug("updated object");
567 logger.debug(objectAsXmlString(accountFound,
568 AccountsCommon.class));
571 // Submit the request to the service and store the response.
572 res = client.update(knownResourceId, accountToUpdate);
573 int statusCode = res.getStatus();
574 // Check the status code of the response: does it match the expected response(s)?
575 if (logger.isDebugEnabled()) {
576 logger.debug(testName + ": status = " + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
582 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
583 Assert.assertNotNull(accountUpdated);
585 Assert.assertEquals(accountUpdated.getEmail(),
586 accountToUpdate.getEmail(),
587 "Data in updated object did not match submitted data.");
590 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
591 dependsOnMethods = {"update"})
592 public void updatePassword(String testName) throws Exception {
595 setupUpdate(testName);
597 AccountClient client = new AccountClient();
598 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
599 if (logger.isDebugEnabled()) {
600 logger.debug(testName + ": read status = " + res.getStatus());
602 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
604 if (logger.isDebugEnabled()) {
605 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
607 AccountsCommon accountFound =
608 (AccountsCommon) res.getEntity();
609 Assert.assertNotNull(accountFound);
611 //create a new account object to test partial updates
612 AccountsCommon accountToUpdate = new AccountsCommon();
613 accountToUpdate.setCsid(knownResourceId);
614 accountToUpdate.setUserId(accountFound.getUserId());
616 accountToUpdate.setPassword("imagination".getBytes());
617 if (logger.isDebugEnabled()) {
618 logger.debug(testName + ": updated object");
619 logger.debug(objectAsXmlString(accountToUpdate,
620 AccountsCommon.class));
623 // Submit the request to the service and store the response.
624 res = client.update(knownResourceId, accountToUpdate);
625 int statusCode = res.getStatus();
626 // Check the status code of the response: does it match the expected response(s)?
627 if (logger.isDebugEnabled()) {
628 logger.debug(testName + ": status = " + statusCode);
630 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
631 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
632 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
635 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
636 Assert.assertNotNull(accountUpdated);
638 // Assert.assertEquals(accountUpdated.getPassword(),
639 // accountFound.getPassword(),
640 // "Data in updated object did not match submitted data.");
643 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
644 dependsOnMethods = {"update"})
645 public void updatePasswordWithoutUser(String testName) throws Exception {
648 setupUpdate(testName);
650 AccountsCommon accountToUpdate = new AccountsCommon();
651 accountToUpdate.setCsid(knownResourceId);
652 accountToUpdate.setUserId(null);
654 accountToUpdate.setPassword("imagination".getBytes());
655 if (logger.isDebugEnabled()) {
656 logger.debug(testName + " : updated object");
657 logger.debug(objectAsXmlString(accountToUpdate,
658 AccountsCommon.class));
661 AccountClient client = new AccountClient();
662 // Submit the request to the service and store the response.
663 ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
664 int statusCode = res.getStatus();
665 // Check the status code of the response: does it match the expected response(s)?
666 if (logger.isDebugEnabled()) {
667 logger.debug(testName + ": status = " + statusCode);
669 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
675 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
676 dependsOnMethods = {"update"})
677 public void updateInvalidPassword(String testName) throws Exception {
680 setupUpdate(testName);
681 AccountClient client = new AccountClient();
682 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
683 if (logger.isDebugEnabled()) {
684 logger.debug(testName + ": read status = " + res.getStatus());
686 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
688 if (logger.isDebugEnabled()) {
689 logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
691 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
693 AccountsCommon accountToUpdate = new AccountsCommon();
694 accountToUpdate.setCsid(knownResourceId);
695 accountToUpdate.setUserId(accountFound.getUserId());
696 Assert.assertNotNull(accountToUpdate);
699 accountToUpdate.setPassword("abc123".getBytes());
700 if (logger.isDebugEnabled()) {
701 logger.debug(testName + ": updated object");
702 logger.debug(objectAsXmlString(accountToUpdate,
703 AccountsCommon.class));
706 // Submit the request to the service and store the response.
707 res = client.update(knownResourceId, accountToUpdate);
708 int statusCode = res.getStatus();
709 // Check the status code of the response: does it match the expected response(s)?
710 if (logger.isDebugEnabled()) {
711 logger.debug(testName + ": status = " + statusCode);
713 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
714 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
715 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
719 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
720 dependsOnMethods = {"updatePasswordWithoutUser"})
721 public void deactivate(String testName) throws Exception {
724 setupUpdate(testName);
726 AccountClient client = new AccountClient();
727 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
728 if (logger.isDebugEnabled()) {
729 logger.debug(testName + ": read status = " + res.getStatus());
731 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
733 if (logger.isDebugEnabled()) {
734 logger.debug("got object to update with ID: " + knownResourceId);
736 AccountsCommon accountFound = (AccountsCommon) res.getEntity();
738 //create a new account object to test partial updates
739 AccountsCommon accountToUpdate = new AccountsCommon();
740 accountToUpdate.setCsid(knownResourceId);
741 accountToUpdate.setUserId(accountFound.getUserId());
743 // Update the content of this resource.
744 accountToUpdate.setStatus(Status.INACTIVE);
745 if (logger.isDebugEnabled()) {
746 logger.debug("updated object");
747 logger.debug(objectAsXmlString(accountToUpdate,
748 AccountsCommon.class));
751 // Submit the request to the service and store the response.
752 res = client.update(knownResourceId, accountToUpdate);
753 int statusCode = res.getStatus();
754 // Check the status code of the response: does it match the expected response(s)?
755 if (logger.isDebugEnabled()) {
756 logger.debug(testName + ": status = " + statusCode);
758 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
759 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
760 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
762 AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
763 Assert.assertNotNull(accountUpdated);
765 Assert.assertEquals(accountUpdated.getStatus(),
766 accountToUpdate.getStatus(),
767 "Data in updated object did not match submitted data.");
772 // Placeholders until the three tests below can be uncommented.
773 // See Issue CSPACE-401.
775 public void updateWithEmptyEntityBody(String testName) throws Exception {
779 public void updateWithMalformedXml(String testName) throws Exception {
783 public void updateWithWrongXmlSchema(String testName) throws Exception {
787 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
788 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
789 public void updateNonExistent(String testName) throws Exception {
792 setupUpdateNonExistent(testName);
794 // Submit the request to the service and store the response.
796 // Note: The ID used in this 'create' call may be arbitrary.
797 // The only relevant ID may be the one used in updateAccount(), below.
798 AccountClient client = new AccountClient();
799 AccountsCommon account =
800 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
801 true, false, true, true);
802 ClientResponse<AccountsCommon> res =
803 client.update(NON_EXISTENT_ID, account);
804 int statusCode = res.getStatus();
806 // Check the status code of the response: does it match
807 // the expected response(s)?
808 if (logger.isDebugEnabled()) {
809 logger.debug(testName + ": status = " + statusCode);
811 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
812 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
813 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
816 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
817 dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
818 public void updateWrongUser(String testName) throws Exception {
822 // Submit the request to the service and store the response.
824 // Note: The ID used in this 'create' call may be arbitrary.
825 // The only relevant ID may be the one used in updateAccount(), below.
826 AccountClient client = new AccountClient();
827 ClientResponse<AccountsCommon> res = client.read(knownResourceId);
828 if (logger.isDebugEnabled()) {
829 logger.debug(testName + ": read status = " + res.getStatus());
831 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
833 if (logger.isDebugEnabled()) {
834 logger.debug("got object to update with ID: " + knownResourceId);
836 AccountsCommon accountToUpdate =
837 (AccountsCommon) res.getEntity();
838 Assert.assertNotNull(accountToUpdate);
840 accountToUpdate.setUserId("barneyFake");
841 if (logger.isDebugEnabled()) {
842 logger.debug("updated object with wrongUser");
843 logger.debug(objectAsXmlString(accountToUpdate,
844 AccountsCommon.class));
847 res = client.update(knownResourceId, accountToUpdate);
848 int statusCode = res.getStatus();
850 // Check the status code of the response: does it match
851 // the expected response(s)?
852 if (logger.isDebugEnabled()) {
853 logger.debug(testName + ": status = " + statusCode);
855 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
856 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
857 Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
860 // ---------------------------------------------------------------
861 // CRUD tests : DELETE tests
862 // ---------------------------------------------------------------
865 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
866 dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
867 public void delete(String testName) throws Exception {
870 setupDelete(testName);
872 // Submit the request to the service and store the response.
873 AccountClient client = new AccountClient();
874 ClientResponse<Response> res = client.delete(knownResourceId);
875 int statusCode = res.getStatus();
877 // Check the status code of the response: does it match
878 // the expected response(s)?
879 if (logger.isDebugEnabled()) {
880 logger.debug(testName + ": status = " + statusCode);
882 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
883 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
884 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
889 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
890 dependsOnMethods = {"delete"})
891 public void deleteNonExistent(String testName) throws Exception {
894 setupDeleteNonExistent(testName);
896 // Submit the request to the service and store the response.
897 AccountClient client = new AccountClient();
898 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
899 int statusCode = res.getStatus();
901 // Check the status code of the response: does it match
902 // the expected response(s)?
903 if (logger.isDebugEnabled()) {
904 logger.debug(testName + ": status = " + statusCode);
906 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
907 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
908 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
911 // ---------------------------------------------------------------
912 // Utility tests : tests of code used in tests above
913 // ---------------------------------------------------------------
915 * Tests the code for manually submitting data that is used by several
916 * of the methods above.
918 @Test(dependsOnMethods = {"create", "read"})
919 public void testSubmitRequest() throws Exception {
921 // Expected status code: 200 OK
922 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
924 // Submit the request to the service and store the response.
925 String method = ServiceRequestType.READ.httpMethodName();
926 String url = getResourceURL(knownResourceId);
927 int statusCode = submitRequest(method, url);
929 // Check the status code of the response: does it match
930 // the expected response(s)?
931 if (logger.isDebugEnabled()) {
932 logger.debug("testSubmitRequest: url=" + url
933 + " status=" + statusCode);
935 Assert.assertEquals(statusCode, EXPECTED_STATUS);
939 // ---------------------------------------------------------------
940 // Utility methods used by tests above
941 // ---------------------------------------------------------------
943 * create account instance
948 * @param useScreenName
949 * @param invalidTenant
954 AccountsCommon createAccountInstance(String screenName,
955 String userName, String passwd, String email,
956 boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
958 AccountsCommon account = AccountFactory.createAccountInstance(screenName,
959 userName, passwd, email, useScreenName,
960 addTenant, invalidTenant, useUser, usePassword);
962 if (logger.isDebugEnabled()) {
963 logger.debug("to be created, account common");
964 logger.debug(objectAsXmlString(account,
965 AccountsCommon.class));
971 @AfterClass(alwaysRun = true)
972 public void cleanUp() {
973 setupDelete("delete");
974 String noTest = System.getProperty("noTestCleanup");
975 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
976 if (logger.isDebugEnabled()) {
977 logger.debug("Skipping Cleanup phase ...");
981 if (logger.isDebugEnabled()) {
982 logger.debug("Cleaning up temporary resources created for testing ...");
984 AccountClient client = new AccountClient();
985 for (String resourceId : allResourceIdsCreated) {
986 // Note: Any non-success responses are ignored and not reported.
987 ClientResponse<Response> res = client.delete(resourceId);
988 int statusCode = res.getStatus();
989 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
990 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
991 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
995 private void printList(String testName, AccountsCommonList list) {
996 List<AccountsCommonList.AccountListItem> items =
997 list.getAccountListItem();
1000 for (AccountsCommonList.AccountListItem item : items) {
1001 logger.debug(testName + ": list-item[" + i + "] csid="
1003 logger.debug(testName + ": list-item[" + i + "] screenName="
1004 + item.getScreenName());
1005 logger.debug(testName + ": list-item[" + i + "] URI="