]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
810a99b606fad287de4c6b33094f9c37132d1e36
[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
62     /*
63      * This method is called only by the parent class, AbstractServiceTest
64      */
65     @Override
66     protected String getServicePathComponent() {
67         return client.getServicePathComponent();
68     }
69
70     // ---------------------------------------------------------------
71     // CRUD tests : CREATE tests
72     // ---------------------------------------------------------------
73     // Success outcomes
74     @Override
75     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class)
76     public void create(String testName) throws Exception {
77
78         // Perform setup, such as initializing the type of service request
79         // (e.g. CREATE, DELETE), its valid and expected status codes, and
80         // its associated HTTP method name (e.g. POST, DELETE).
81         setupCreate(testName);
82
83         // Submit the request to the service and store the response.
84         AccountsCommon account =
85                 createAccountInstance("barney", "hithere08", "barney@dinoland.com", true, true, true);
86         ClientResponse<Response> res = client.create(account);
87         int statusCode = res.getStatus();
88
89         // Check the status code of the response: does it match
90         // the expected response(s)?
91         //
92         // Specifically:
93         // Does it fall within the set of valid status codes?
94         // Does it exactly match the expected status code?
95         if (logger.isDebugEnabled()) {
96             logger.debug(testName + ": status = " + statusCode);
97         }
98         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
99                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
100         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
101
102         // Store the ID returned from this create operation
103         // for additional tests below.
104         knownResourceId = extractId(res);
105         if (logger.isDebugEnabled()) {
106             logger.debug(testName + ": knownResourceId=" + knownResourceId);
107         }
108     }
109
110     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
111     dependsOnMethods = {"create"})
112     public void createWithoutTenant(String testName) throws Exception {
113
114         setupCreate(testName);
115
116         // Submit the request to the service and store the response.
117         AccountsCommon account =
118                 createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", false, true, true);
119         ClientResponse<Response> res = client.create(account);
120         int statusCode = res.getStatus();
121         // Does it exactly match the expected status code?
122         if (logger.isDebugEnabled()) {
123             logger.debug(testName + ": status = " + statusCode);
124         }
125         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
126                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
127         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
128
129     }
130
131     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
132     dependsOnMethods = {"create"})
133     public void createWithoutUser(String testName) throws Exception {
134
135         setupCreate(testName);
136
137         // Submit the request to the service and store the response.
138         AccountsCommon account =
139                 createAccountInstance("babybop", "hithere08", "babybop@dinoland.com", true, false, true);
140         ClientResponse<Response> res = client.create(account);
141         int statusCode = res.getStatus();
142         // Does it exactly match the expected status code?
143         if (logger.isDebugEnabled()) {
144             logger.debug(testName + ": status = " + statusCode);
145         }
146         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
147                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
148         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
149     }
150
151     //to not cause uniqueness violation for account, createList is removed
152     @Override
153     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
154     dependsOnMethods = {"create"})
155     public void createList(String testName) throws Exception {
156
157         setupCreate(testName);
158         // Submit the request to the service and store the response.
159         AccountsCommon account1 =
160                 createAccountInstance("curious", "hithere08", "curious@george.com", true, true, true);
161         ClientResponse<Response> res = client.create(account1);
162         int statusCode = res.getStatus();
163         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
164                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
165         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
166         resource1Id = extractId(res);
167
168         AccountsCommon account2 =
169                 createAccountInstance("tom", "hithere09", "tom@jerry.com", true, true, true);
170         res = client.create(account2);
171         statusCode = res.getStatus();
172         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
173                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
174         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
175         resource2Id = extractId(res);
176     }
177
178     // Failure outcomes
179     // Placeholders until the three tests below can be uncommented.
180     // See Issue CSPACE-401.
181     @Override
182     public void createWithEmptyEntityBody(String testName) throws Exception {
183     }
184
185     @Override
186     public void createWithMalformedXml(String testName) throws Exception {
187     }
188
189     @Override
190     public void createWithWrongXmlSchema(String testName) throws Exception {
191     }
192
193     // ---------------------------------------------------------------
194     // CRUD tests : READ tests
195     // ---------------------------------------------------------------
196     // Success outcomes
197     @Override
198     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
199     dependsOnMethods = {"create"})
200     public void read(String testName) throws Exception {
201
202         // Perform setup.
203         setupRead(testName);
204
205         // Submit the request to the service and store the response.
206         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
207         int statusCode = res.getStatus();
208
209         // Check the status code of the response: does it match
210         // the expected response(s)?
211         if (logger.isDebugEnabled()) {
212             logger.debug(testName + ": status = " + statusCode);
213         }
214         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
215                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
216         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
217
218         AccountsCommon output = (AccountsCommon) res.getEntity();
219         Assert.assertNotNull(output);
220     }
221
222     // Failure outcomes
223     @Override
224     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
225     dependsOnMethods = {"read"})
226     public void readNonExistent(String testName) throws Exception {
227
228         // Perform setup.
229         setupReadNonExistent(testName);
230
231         // Submit the request to the service and store the response.
232         ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
233         int statusCode = res.getStatus();
234
235         // Check the status code of the response: does it match
236         // the expected response(s)?
237         if (logger.isDebugEnabled()) {
238             logger.debug(testName + ": status = " + statusCode);
239         }
240         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
241                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
242         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
243     }
244
245     // ---------------------------------------------------------------
246     // CRUD tests : READ_LIST tests
247     // ---------------------------------------------------------------
248     // Success outcomes
249     @Override
250     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
251     dependsOnMethods = {"createList", "read"})
252     public void readList(String testName) throws Exception {
253
254         // Perform setup.
255         setupReadList(testName);
256
257         // Submit the request to the service and store the response.
258         ClientResponse<AccountsCommonList> res = client.readList();
259         AccountsCommonList list = res.getEntity();
260         int statusCode = res.getStatus();
261
262         // Check the status code of the response: does it match
263         // the expected response(s)?
264         if (logger.isDebugEnabled()) {
265             logger.debug(testName + ": status = " + statusCode);
266         }
267         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
268                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
269         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
270
271         // Optionally output additional data about list members for debugging.
272         boolean iterateThroughList = true;
273         if (iterateThroughList && logger.isDebugEnabled()) {
274             printList(testName, list);
275         }
276     }
277
278     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
279     dependsOnMethods = {"createList", "read"})
280     public void readSearchList(String testName) throws Exception {
281
282         // Perform setup.
283         setupReadList(testName);
284
285         // Submit the request to the service and store the response.
286         ClientResponse<AccountsCommonList> res = client.readSearchList("tom");
287         AccountsCommonList list = res.getEntity();
288         int statusCode = res.getStatus();
289
290         // Check the status code of the response: does it match
291         // the expected response(s)?
292         if (logger.isDebugEnabled()) {
293             logger.debug(testName + ": status = " + statusCode);
294         }
295         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
296                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
297         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
298
299         // Optionally output additional data about list members for debugging.
300         boolean iterateThroughList = true;
301         if (iterateThroughList && logger.isDebugEnabled()) {
302             printList(testName, list);
303         }
304     }
305
306     // Failure outcomes
307     // None at present.
308     // ---------------------------------------------------------------
309     // CRUD tests : UPDATE tests
310     // ---------------------------------------------------------------
311     // Success outcomes
312     @Override
313     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
314     dependsOnMethods = {"read", "readList", "readNonExistent"})
315     public void update(String testName) throws Exception {
316
317         // Perform setup.
318         setupUpdate(testName);
319
320
321         ClientResponse<AccountsCommon> res =
322                 client.read(knownResourceId);
323         if (logger.isDebugEnabled()) {
324             logger.debug(testName + ": read status = " + res.getStatus());
325         }
326         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
327
328         if (logger.isDebugEnabled()) {
329             logger.debug("got object to update with ID: " + knownResourceId);
330         }
331         AccountsCommon toUpdateAccount =
332                 (AccountsCommon) res.getEntity();
333         Assert.assertNotNull(toUpdateAccount);
334
335         // Update the content of this resource.
336         toUpdateAccount.setEmail("updated-" + toUpdateAccount.getEmail());
337         if (logger.isDebugEnabled()) {
338             logger.debug("updated object");
339             logger.debug(objectAsXmlString(toUpdateAccount,
340                     AccountsCommon.class));
341         }
342
343         // Submit the request to the service and store the response.
344         res = client.update(knownResourceId, toUpdateAccount);
345         int statusCode = res.getStatus();
346         // Check the status code of the response: does it match the expected response(s)?
347         if (logger.isDebugEnabled()) {
348             logger.debug(testName + ": status = " + statusCode);
349         }
350         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
351                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
352         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
353
354
355         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
356         Assert.assertNotNull(updatedAccount);
357
358         Assert.assertEquals(updatedAccount.getEmail(),
359                 toUpdateAccount.getEmail(),
360                 "Data in updated object did not match submitted data.");
361     }
362
363     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
364     dependsOnMethods = {"update"})
365     public void updatePassword(String testName) throws Exception {
366
367         // Perform setup.
368         setupUpdate(testName);
369
370         ClientResponse<AccountsCommon> res =
371                 client.read(knownResourceId);
372         if (logger.isDebugEnabled()) {
373             logger.debug(testName + ": read status = " + res.getStatus());
374         }
375         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
376
377         if (logger.isDebugEnabled()) {
378             logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
379         }
380         AccountsCommon toUpdateAccount =
381                 (AccountsCommon) res.getEntity();
382         Assert.assertNotNull(toUpdateAccount);
383
384         //change password
385         toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
386         if (logger.isDebugEnabled()) {
387             logger.debug(testName + ": updated object");
388             logger.debug(objectAsXmlString(toUpdateAccount,
389                     AccountsCommon.class));
390         }
391
392         // Submit the request to the service and store the response.
393         res = client.update(knownResourceId, toUpdateAccount);
394         int statusCode = res.getStatus();
395         // Check the status code of the response: does it match the expected response(s)?
396         if (logger.isDebugEnabled()) {
397             logger.debug(testName + ": status = " + statusCode);
398         }
399         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
400                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
401         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
402
403
404         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
405         Assert.assertNotNull(updatedAccount);
406
407 //        Assert.assertEquals(updatedAccount.getPassword(),
408 //                toUpdateAccount.getPassword(),
409 //                "Data in updated object did not match submitted data.");
410     }
411
412     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
413     dependsOnMethods = {"update"})
414     public void updatePasswordWithoutUser(String testName) throws Exception {
415
416         // Perform setup.
417         setupUpdate(testName);
418
419         ClientResponse<AccountsCommon> res =
420                 client.read(knownResourceId);
421         if (logger.isDebugEnabled()) {
422             logger.debug(testName + ": read status = " + res.getStatus());
423         }
424         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
425
426         if (logger.isDebugEnabled()) {
427             logger.debug(testName + " : got object to update with ID: " + knownResourceId);
428         }
429         AccountsCommon toUpdateAccount =
430                 (AccountsCommon) res.getEntity();
431         Assert.assertNotNull(toUpdateAccount);
432
433         toUpdateAccount.setUserId(null);
434         //change password
435         toUpdateAccount.setPassword(Base64.encodeBase64("imagination".getBytes()));
436         if (logger.isDebugEnabled()) {
437             logger.debug(testName + " : updated object");
438             logger.debug(objectAsXmlString(toUpdateAccount,
439                     AccountsCommon.class));
440         }
441
442         // Submit the request to the service and store the response.
443         res = client.update(knownResourceId, toUpdateAccount);
444         int statusCode = res.getStatus();
445         // Check the status code of the response: does it match the expected response(s)?
446         if (logger.isDebugEnabled()) {
447             logger.debug(testName + ": status = " + statusCode);
448         }
449         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
450                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
451         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
452
453     }
454
455     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
456     dependsOnMethods = {"updatePasswordWithoutUser"})
457     public void deactivate(String testName) throws Exception {
458
459         // Perform setup.
460         setupUpdate(testName);
461
462         ClientResponse<AccountsCommon> res =
463                 client.read(knownResourceId);
464         if (logger.isDebugEnabled()) {
465             logger.debug(testName + ": read status = " + res.getStatus());
466         }
467         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
468
469         if (logger.isDebugEnabled()) {
470             logger.debug("got object to update with ID: " + knownResourceId);
471         }
472         AccountsCommon toUpdateAccount =
473                 (AccountsCommon) res.getEntity();
474         Assert.assertNotNull(toUpdateAccount);
475
476         // Update the content of this resource.
477         toUpdateAccount.setStatus(Status.INACTIVE);
478         if (logger.isDebugEnabled()) {
479             logger.debug("updated object");
480             logger.debug(objectAsXmlString(toUpdateAccount,
481                     AccountsCommon.class));
482         }
483
484         // Submit the request to the service and store the response.
485         res = client.update(knownResourceId, toUpdateAccount);
486         int statusCode = res.getStatus();
487         // Check the status code of the response: does it match the expected response(s)?
488         if (logger.isDebugEnabled()) {
489             logger.debug(testName + ": status = " + statusCode);
490         }
491         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
492                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
493         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
494
495
496         AccountsCommon updatedAccount = (AccountsCommon) res.getEntity();
497         Assert.assertNotNull(updatedAccount);
498
499         Assert.assertEquals(updatedAccount.getStatus(),
500                 toUpdateAccount.getStatus(),
501                 "Data in updated object did not match submitted data.");
502
503     }
504
505     // Failure outcomes
506     // Placeholders until the three tests below can be uncommented.
507     // See Issue CSPACE-401.
508     @Override
509     public void updateWithEmptyEntityBody(String testName) throws Exception {
510     }
511
512     @Override
513     public void updateWithMalformedXml(String testName) throws Exception {
514     }
515
516     @Override
517     public void updateWithWrongXmlSchema(String testName) throws Exception {
518     }
519
520     @Override
521     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
522     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
523     public void updateNonExistent(String testName) throws Exception {
524
525         // Perform setup.
526         setupUpdateNonExistent(testName);
527
528         // Submit the request to the service and store the response.
529         //
530         // Note: The ID used in this 'create' call may be arbitrary.
531         // The only relevant ID may be the one used in updateAccount(), below.
532         AccountsCommon account =
533                 createAccountInstance("simba", "tiger", "simba@lionking.com", true, true, true);
534         ClientResponse<AccountsCommon> res =
535                 client.update(NON_EXISTENT_ID, account);
536         int statusCode = res.getStatus();
537
538         // Check the status code of the response: does it match
539         // 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, EXPECTED_STATUS_CODE);
546     }
547
548     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
549     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
550     public void updateWrongUser(String testName) throws Exception {
551
552         setupUpdate();
553         // Submit the request to the service and store the response.
554         //
555         // Note: The ID used in this 'create' call may be arbitrary.
556         // The only relevant ID may be the one used in updateAccount(), below.
557         ClientResponse<AccountsCommon> res =
558                 client.read(knownResourceId);
559         if (logger.isDebugEnabled()) {
560             logger.debug(testName + ": read status = " + res.getStatus());
561         }
562         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
563
564         if (logger.isDebugEnabled()) {
565             logger.debug("got object to update with ID: " + knownResourceId);
566         }
567         AccountsCommon toUpdateAccount =
568                 (AccountsCommon) res.getEntity();
569         Assert.assertNotNull(toUpdateAccount);
570
571         toUpdateAccount.setUserId("barneyFake");
572         if (logger.isDebugEnabled()) {
573             logger.debug("updated object with wrongUser");
574             logger.debug(objectAsXmlString(toUpdateAccount,
575                     AccountsCommon.class));
576         }
577
578         res = client.update(knownResourceId, toUpdateAccount);
579         int statusCode = res.getStatus();
580
581         // Check the status code of the response: does it match
582         // the expected response(s)?
583         if (logger.isDebugEnabled()) {
584             logger.debug(testName + ": status = " + statusCode);
585         }
586         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
587                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
588         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
589     }
590
591     // ---------------------------------------------------------------
592     // CRUD tests : DELETE tests
593     // ---------------------------------------------------------------
594     // Success outcomes
595     @Override
596     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
597     dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
598     public void delete(String testName) throws Exception {
599
600         // Perform setup.
601         setupDelete(testName);
602
603         // Submit the request to the service and store the response.
604         ClientResponse<Response> res = client.delete(knownResourceId);
605         int statusCode = res.getStatus();
606
607         // Check the status code of the response: does it match
608         // the expected response(s)?
609         if (logger.isDebugEnabled()) {
610             logger.debug(testName + ": status = " + statusCode);
611         }
612         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
613                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
614         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
615     }
616
617     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
618     dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
619     public void deleteList(String testName) throws Exception {
620
621         // Perform setup.
622         setupDelete(testName);
623
624         ClientResponse<Response> res = client.delete(resource1Id);
625         int statusCode = res.getStatus();
626         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
627                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
628         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
629
630         res = client.delete(resource2Id);
631         statusCode = res.getStatus();
632         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
633                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
634         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
635     }
636
637     // Failure outcomes
638     @Override
639     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTest.class,
640     dependsOnMethods = {"delete"})
641     public void deleteNonExistent(String testName) throws Exception {
642
643         // Perform setup.
644         setupDeleteNonExistent(testName);
645
646         // Submit the request to the service and store the response.
647         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
648         int statusCode = res.getStatus();
649
650         // Check the status code of the response: does it match
651         // the expected response(s)?
652         if (logger.isDebugEnabled()) {
653             logger.debug(testName + ": status = " + statusCode);
654         }
655         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
658     }
659
660     // ---------------------------------------------------------------
661     // Utility tests : tests of code used in tests above
662     // ---------------------------------------------------------------
663     /**
664      * Tests the code for manually submitting data that is used by several
665      * of the methods above.
666      */
667     @Test(dependsOnMethods = {"create", "read"})
668     public void testSubmitRequest() throws Exception {
669
670         // Expected status code: 200 OK
671         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
672
673         // Submit the request to the service and store the response.
674         String method = ServiceRequestType.READ.httpMethodName();
675         String url = getResourceURL(knownResourceId);
676         int statusCode = submitRequest(method, url);
677
678         // Check the status code of the response: does it match
679         // the expected response(s)?
680         if (logger.isDebugEnabled()) {
681             logger.debug("testSubmitRequest: url=" + url
682                     + " status=" + statusCode);
683         }
684         Assert.assertEquals(statusCode, EXPECTED_STATUS);
685
686     }
687
688     // ---------------------------------------------------------------
689     // Utility methods used by tests above
690     // ---------------------------------------------------------------
691     /*
692      * createAccountInstance
693      * @param tenant fillup tenant
694      * @param user to fill up user
695      * @param password to fill up password
696      */
697     private AccountsCommon createAccountInstance(String screenName,
698             String passwd, String email, boolean tenant, boolean user, boolean password) {
699
700         AccountsCommon account = new AccountsCommon();
701         account.setScreenName(screenName);
702         if (user) {
703             account.setUserId(screenName);
704         }
705         if (password) {
706             account.setPassword(Base64.encodeBase64(passwd.getBytes()));
707         }
708         account.setEmail(email);
709         account.setPhone("1234567890");
710         if (tenant) {
711             List<AccountsCommon.Tenant> atl = new ArrayList<AccountsCommon.Tenant>();
712             AccountsCommon.Tenant at = new AccountsCommon.Tenant();
713             at.setId(UUID.randomUUID().toString());
714             at.setName("movingimages.us");
715             atl.add(at);
716
717             AccountsCommon.Tenant at2 = new AccountsCommon.Tenant();
718             at2.setId(UUID.randomUUID().toString());
719             at2.setName("collectionspace.org");
720             atl.add(at2);
721             account.setTenant(atl);
722         }
723         if (logger.isDebugEnabled()) {
724             logger.debug("to be created, account common");
725             logger.debug(objectAsXmlString(account,
726                     AccountsCommon.class));
727         }
728         return account;
729
730     }
731
732     private void printList(String testName, AccountsCommonList list) {
733         List<AccountsCommonList.AccountListItem> items =
734                 list.getAccountListItem();
735         int i = 0;
736
737         for (AccountsCommonList.AccountListItem item : items) {
738             logger.debug(testName + ": list-item[" + i + "] csid="
739                     + item.getCsid());
740             logger.debug(testName + ": list-item[" + i + "] screenName="
741                     + item.getScreenName());
742             logger.debug(testName + ": list-item[" + i + "] URI="
743                     + item.getUri());
744             i++;
745
746         }
747     }
748 }