]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
09bb984ada704a94f390ec9a070d11235b252de8
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.account.client.test;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.UUID;
28 import javax.ws.rs.core.Response;
29
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.AbstractServiceTest;
36 import org.collectionspace.services.client.test.ServiceRequestType;
37 import org.jboss.resteasy.client.ClientResponse;
38
39 import org.testng.Assert;
40 import org.testng.annotations.Test;
41
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * AccountServiceTest, carries out tests against a
47  * deployed and running Account Service.
48  * 
49  * $LastChangedRevision: 917 $
50  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
51  */
52 public class AccountServiceTest extends AbstractServiceTest {
53
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;
62     /*
63      * This method is called only by the parent class, AbstractServiceTest
64      */
65
66     @Override
67     protected String getServicePathComponent() {
68         return client.getServicePathComponent();
69     }
70
71     // ---------------------------------------------------------------
72     // CRUD tests : CREATE tests
73     // ---------------------------------------------------------------
74     // Success outcomes
75     @Override
76     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
77     public void create(String testName) throws Exception {
78
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);
83
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();
89
90         // Check the status code of the response: does it match
91         // the expected response(s)?
92         //
93         // Specifically:
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);
98         }
99         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
100                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
101         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
102
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);
108         }
109     }
110
111     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
112     dependsOnMethods = {"create"})
113     public void createWithoutTenant(String testName) throws Exception {
114
115         setupCreate(testName);
116
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);
125         }
126         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
127                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
128         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
129
130     }
131
132     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
133     dependsOnMethods = {"create"})
134     public void createWithoutUser(String testName) throws Exception {
135
136         setupCreate(testName);
137
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);
146         }
147         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
148                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
149         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
150     }
151
152     //to not cause uniqueness violation for account, createList is removed
153     @Override
154     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
155     dependsOnMethods = {"create"})
156     public void createList(String testName) throws Exception {
157
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);
168
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);
177
178         AccountsCommon account3 =
179                 createAccountInstance("dj", "hithere10", "dj@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);
186     }
187
188     // Failure outcomes
189     // Placeholders until the three tests below can be uncommented.
190     // See Issue CSPACE-401.
191     @Override
192     public void createWithEmptyEntityBody(String testName) throws Exception {
193     }
194
195     @Override
196     public void createWithMalformedXml(String testName) throws Exception {
197     }
198
199     @Override
200     public void createWithWrongXmlSchema(String testName) throws Exception {
201     }
202
203     // ---------------------------------------------------------------
204     // CRUD tests : READ tests
205     // ---------------------------------------------------------------
206     // Success outcomes
207     @Override
208     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
209     dependsOnMethods = {"create"})
210     public void read(String testName) throws Exception {
211
212         // Perform setup.
213         setupRead(testName);
214
215         // Submit the request to the service and store the response.
216         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
217         int statusCode = res.getStatus();
218
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);
223         }
224         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
225                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
226         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
227
228         AccountsCommon output = (AccountsCommon) res.getEntity();
229         Assert.assertNotNull(output);
230     }
231
232     // Failure outcomes
233     @Override
234     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
235     dependsOnMethods = {"read"})
236     public void readNonExistent(String testName) throws Exception {
237
238         // Perform setup.
239         setupReadNonExistent(testName);
240
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();
244
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);
249         }
250         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
251                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
252         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
253     }
254
255     // ---------------------------------------------------------------
256     // CRUD tests : READ_LIST tests
257     // ---------------------------------------------------------------
258     // Success outcomes
259     @Override
260     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
261     dependsOnMethods = {"createList", "read"})
262     public void readList(String testName) throws Exception {
263
264         // Perform setup.
265         setupReadList(testName);
266
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();
271
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);
276         }
277         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
278                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
279         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
280
281         // Optionally output additional data about list members for debugging.
282         boolean iterateThroughList = true;
283         if (iterateThroughList && logger.isDebugEnabled()) {
284             printList(testName, list);
285         }
286     }
287
288     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
289     dependsOnMethods = {"createList", "read"})
290     public void searchScreenName(String testName) throws Exception {
291
292         // Perform setup.
293         setupReadList(testName);
294
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();
299
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);
304         }
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);
313         }
314     }
315
316     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
317     dependsOnMethods = {"createList", "read"})
318     public void searchUserId(String testName) throws Exception {
319
320         // Perform setup.
321         setupReadList(testName);
322
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();
327
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);
332         }
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);
341         }
342     }
343
344     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
345     dependsOnMethods = {"createList", "read"})
346     public void searchEmail(String testName) throws Exception {
347
348         // Perform setup.
349         setupReadList(testName);
350
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();
355
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);
360         }
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);
369         }
370     }
371
372     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
373     dependsOnMethods = {"createList", "read"})
374     public void searchScreenNameEmail(String testName) throws Exception {
375
376         // Perform setup.
377         setupReadList(testName);
378
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();
383
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);
388         }
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);
397         }
398     }
399
400     // Failure outcomes
401     // None at present.
402     // ---------------------------------------------------------------
403     // CRUD tests : UPDATE tests
404     // ---------------------------------------------------------------
405     // Success outcomes
406     @Override
407     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
408     dependsOnMethods = {"read", "readList", "readNonExistent"})
409     public void update(String testName) throws Exception {
410
411         // Perform setup.
412         setupUpdate(testName);
413
414
415         ClientResponse<AccountsCommon> res =
416                 client.read(knownResourceId);
417         if (logger.isDebugEnabled()) {
418             logger.debug(testName + ": read status = " + res.getStatus());
419         }
420         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
421
422         if (logger.isDebugEnabled()) {
423             logger.debug("got object to update with ID: " + knownResourceId);
424         }
425         AccountsCommon toUpdateAccount =
426                 (AccountsCommon) res.getEntity();
427         Assert.assertNotNull(toUpdateAccount);
428
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));
435         }
436
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);
443         }
444         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
445                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
446         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447
448
449         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
450         Assert.assertNotNull(updatedAccount);
451
452         Assert.assertEquals(updatedAccount.getEmail(),
453                 toUpdateAccount.getEmail(),
454                 "Data in updated object did not match submitted data.");
455     }
456
457     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
458     dependsOnMethods = {"update"})
459     public void updatePassword(String testName) throws Exception {
460
461         // Perform setup.
462         setupUpdate(testName);
463
464         ClientResponse<AccountsCommon> res =
465                 client.read(knownResourceId);
466         if (logger.isDebugEnabled()) {
467             logger.debug(testName + ": read status = " + res.getStatus());
468         }
469         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
470
471         if (logger.isDebugEnabled()) {
472             logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
473         }
474         AccountsCommon toUpdateAccount =
475                 (AccountsCommon) res.getEntity();
476         Assert.assertNotNull(toUpdateAccount);
477
478         //change password
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));
484         }
485
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);
492         }
493         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
494                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
495         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
496
497
498         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
499         Assert.assertNotNull(updatedAccount);
500
501 //        Assert.assertEquals(updatedAccount.getPassword(),
502 //                toUpdateAccount.getPassword(),
503 //                "Data in updated object did not match submitted data.");
504     }
505
506     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
507     dependsOnMethods = {"update"})
508     public void updatePasswordWithoutUser(String testName) throws Exception {
509
510         // Perform setup.
511         setupUpdate(testName);
512
513         ClientResponse<AccountsCommon> res =
514                 client.read(knownResourceId);
515         if (logger.isDebugEnabled()) {
516             logger.debug(testName + ": read status = " + res.getStatus());
517         }
518         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
519
520         if (logger.isDebugEnabled()) {
521             logger.debug(testName + " : got object to update with ID: " + knownResourceId);
522         }
523         AccountsCommon toUpdateAccount =
524                 (AccountsCommon) res.getEntity();
525         Assert.assertNotNull(toUpdateAccount);
526
527         toUpdateAccount.setUserId(null);
528         //change password
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));
534         }
535
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);
542         }
543         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
546
547     }
548
549     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
550     dependsOnMethods = {"updatePasswordWithoutUser"})
551     public void deactivate(String testName) throws Exception {
552
553         // Perform setup.
554         setupUpdate(testName);
555
556         ClientResponse<AccountsCommon> res =
557                 client.read(knownResourceId);
558         if (logger.isDebugEnabled()) {
559             logger.debug(testName + ": read status = " + res.getStatus());
560         }
561         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
562
563         if (logger.isDebugEnabled()) {
564             logger.debug("got object to update with ID: " + knownResourceId);
565         }
566         AccountsCommon toUpdateAccount =
567                 (AccountsCommon) res.getEntity();
568         Assert.assertNotNull(toUpdateAccount);
569
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));
576         }
577
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);
584         }
585         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588
589
590         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
591         Assert.assertNotNull(updatedAccount);
592
593         Assert.assertEquals(updatedAccount.getStatus(),
594                 toUpdateAccount.getStatus(),
595                 "Data in updated object did not match submitted data.");
596
597     }
598
599     // Failure outcomes
600     // Placeholders until the three tests below can be uncommented.
601     // See Issue CSPACE-401.
602     @Override
603     public void updateWithEmptyEntityBody(String testName) throws Exception {
604     }
605
606     @Override
607     public void updateWithMalformedXml(String testName) throws Exception {
608     }
609
610     @Override
611     public void updateWithWrongXmlSchema(String testName) throws Exception {
612     }
613
614     @Override
615     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
616     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
617     public void updateNonExistent(String testName) throws Exception {
618
619         // Perform setup.
620         setupUpdateNonExistent(testName);
621
622         // Submit the request to the service and store the response.
623         //
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();
631
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);
636         }
637         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
638                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
639         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640     }
641
642     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
643     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
644     public void updateWrongUser(String testName) throws Exception {
645
646         setupUpdate();
647         // Submit the request to the service and store the response.
648         //
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());
655         }
656         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
657
658         if (logger.isDebugEnabled()) {
659             logger.debug("got object to update with ID: " + knownResourceId);
660         }
661         AccountsCommon toUpdateAccount =
662                 (AccountsCommon) res.getEntity();
663         Assert.assertNotNull(toUpdateAccount);
664
665         toUpdateAccount.setUserId("barneyFake");
666         if (logger.isDebugEnabled()) {
667             logger.debug("updated object with wrongUser");
668             logger.debug(objectAsXmlString(toUpdateAccount,
669                     AccountsCommon.class));
670         }
671
672         res = client.update(knownResourceId, toUpdateAccount);
673         int statusCode = res.getStatus();
674
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);
679         }
680         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
681                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
682         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
683     }
684
685     // ---------------------------------------------------------------
686     // CRUD tests : DELETE tests
687     // ---------------------------------------------------------------
688     // Success outcomes
689     @Override
690     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
691     dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
692     public void delete(String testName) throws Exception {
693
694         // Perform setup.
695         setupDelete(testName);
696
697         // Submit the request to the service and store the response.
698         ClientResponse<Response> res = client.delete(knownResourceId);
699         int statusCode = res.getStatus();
700
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);
705         }
706         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
707                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
708         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
709     }
710
711     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
712     dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
713     public void deleteList(String testName) throws Exception {
714
715         // Perform setup.
716         setupDelete(testName);
717
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);
723
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);
729
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);
735     }
736
737     // Failure outcomes
738     @Override
739     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
740     dependsOnMethods = {"delete"})
741     public void deleteNonExistent(String testName) throws Exception {
742
743         // Perform setup.
744         setupDeleteNonExistent(testName);
745
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();
749
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);
754         }
755         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
756                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
757         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
758     }
759
760     // ---------------------------------------------------------------
761     // Utility tests : tests of code used in tests above
762     // ---------------------------------------------------------------
763     /**
764      * Tests the code for manually submitting data that is used by several
765      * of the methods above.
766      */
767     @Test(dependsOnMethods = {"create", "read"})
768     public void testSubmitRequest() throws Exception {
769
770         // Expected status code: 200 OK
771         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
772
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);
777
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);
783         }
784         Assert.assertEquals(statusCode, EXPECTED_STATUS);
785
786     }
787
788     // ---------------------------------------------------------------
789     // Utility methods used by tests above
790     // ---------------------------------------------------------------
791     /*
792      * createAccountInstance
793      * @param tenant fillup tenant
794      * @param user to fill up user
795      * @param password to fill up password
796      */
797     private AccountsCommon createAccountInstance(String screenName,
798             String passwd, String email, boolean tenant, boolean user, boolean password) {
799
800         AccountsCommon account = new AccountsCommon();
801         account.setScreenName(screenName);
802         if (user) {
803             account.setUserId(screenName);
804         }
805         if (password) {
806             account.setPassword(Base64.encodeBase64(passwd.getBytes()));
807         }
808         account.setEmail(email);
809         account.setPhone("1234567890");
810         if (tenant) {
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");
815             atl.add(at);
816
817             AccountsCommon.Tenant at2 = new AccountsCommon.Tenant();
818             at2.setId(UUID.randomUUID().toString());
819             at2.setName("collectionspace.org");
820             atl.add(at2);
821             account.setTenant(atl);
822         }
823         if (logger.isDebugEnabled()) {
824             logger.debug("to be created, account common");
825             logger.debug(objectAsXmlString(account,
826                     AccountsCommon.class));
827         }
828         return account;
829
830     }
831
832     private void printList(String testName, AccountsCommonList list) {
833         List<AccountsCommonList.AccountListItem> items =
834                 list.getAccountListItem();
835         int i = 0;
836
837         for (AccountsCommonList.AccountListItem item : items) {
838             logger.debug(testName + ": list-item[" + i + "] csid="
839                     + item.getCsid());
840             logger.debug(testName + ": list-item[" + i + "] screenName="
841                     + item.getScreenName());
842             logger.debug(testName + ": list-item[" + i + "] URI="
843                     + item.getUri());
844             i++;
845
846         }
847     }
848 }