]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
123230c00e55d3f94d5814303f629bd9973ed28a
[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 javax.ws.rs.core.Response;
28
29 import org.collectionspace.services.client.AccountClient;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.account.AccountsCommon;
32 import org.collectionspace.services.account.AccountsCommonList;
33 import org.collectionspace.services.account.Status;
34 import org.collectionspace.services.client.AccountFactory;
35 import org.collectionspace.services.client.test.AbstractServiceTestImpl;
36 import org.collectionspace.services.client.test.ServiceRequestType;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.jboss.resteasy.client.ClientResponse;
39
40 import org.testng.Assert;
41 import org.testng.annotations.Test;
42
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.testng.annotations.AfterClass;
46
47 /**
48  * AccountServiceTest, carries out tests against a
49  * deployed and running Account Service.
50  * 
51  * $LastChangedRevision: 917 $
52  * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
53  */
54 public class AccountServiceTest extends AbstractServiceTestImpl {
55
56     /** The Constant logger. */
57     static private final Logger logger =
58             LoggerFactory.getLogger(AccountServiceTest.class);
59     // Instance variables specific to this test.
60     /** The known resource id. */
61     private String knownResourceId = null;
62     
63     /** The add tenant. */
64     static boolean addTenant = true;
65
66     /*
67      * This method is called only by the parent class, AbstractServiceTestImpl
68      */
69     /* (non-Javadoc)
70      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
71      */
72     @Override
73     protected String getServicePathComponent() {
74         return new AccountClient().getServicePathComponent();
75     }
76
77     /* (non-Javadoc)
78      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79      */
80     @Override
81     protected CollectionSpaceClient getClientInstance() {
82         return new AccountClient();
83     }
84     
85     /* (non-Javadoc)
86      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
87      */
88     @Override
89         protected AbstractCommonList getAbstractCommonList(
90                         ClientResponse<AbstractCommonList> response) {
91         //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
92         throw new UnsupportedOperationException();
93     }
94     
95         /* (non-Javadoc)
96          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readPaginatedList(java.lang.String)
97          */
98         @Test(dataProvider = "testName")
99         @Override
100     public void readPaginatedList(String testName) throws Exception {
101                 //FIXME: http://issues.collectionspace.org/browse/CSPACE-1697
102         }    
103      
104     // ---------------------------------------------------------------
105     // CRUD tests : CREATE tests
106     // ---------------------------------------------------------------
107     // Success outcomes
108     /* (non-Javadoc)
109      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
110      */
111     @Override
112     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
113     public void create(String testName) throws Exception {
114
115         // Perform setup, such as initializing the type of service request
116         // (e.g. CREATE, DELETE), its valid and expected status codes, and
117         // its associated HTTP method name (e.g. POST, DELETE).
118         setupCreate(testName);
119
120         // Submit the request to the service and store the response.
121         AccountsCommon account =
122                 createAccountInstance("barney", "barney", "hithere08", "barney@dinoland.com",
123                 true, false, true, true);
124         AccountClient client = new AccountClient();
125         ClientResponse<Response> res = client.create(account);
126         int statusCode = res.getStatus();
127
128         // Check the status code of the response: does it match
129         // the expected response(s)?
130         //
131         // Specifically:
132         // Does it fall within the set of valid status codes?
133         // Does it exactly match the expected status code?
134         if (logger.isDebugEnabled()) {
135             logger.debug(testName + ": status = " + statusCode);
136         }
137         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
138                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
139         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
140
141         // Store the ID returned from this create operation
142         // for additional tests below.
143         knownResourceId = extractId(res);
144         if (logger.isDebugEnabled()) {
145             logger.debug(testName + ": knownResourceId=" + knownResourceId);
146         }
147     }
148
149     /**
150      * Creates the for unique user.
151      *
152      * @param testName the test name
153      * @throws Exception the exception
154      */
155     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
156     dependsOnMethods = {"create"})
157     public void createForUniqueUser(String testName) throws Exception {
158
159         setupCreate(testName);
160
161         // Submit the request to the service and store the response.
162         AccountsCommon account =
163                 createAccountInstance("barney1", "barney", "hithere08", "barney@dinoland.com",
164                 true, false, true, true);
165         AccountClient client = new AccountClient();
166         ClientResponse<Response> res = client.create(account);
167         int statusCode = res.getStatus();
168         if (logger.isDebugEnabled()) {
169             logger.debug(testName + ": status = " + statusCode);
170         }
171         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
172                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
173         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
174     }
175
176     /**
177      * Creates the with invalid tenant.
178      *
179      * @param testName the test name
180      * @throws Exception the exception
181      */
182     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
183     dependsOnMethods = {"create"})
184     public void createWithInvalidTenant(String testName) throws Exception {
185
186         setupCreate(testName);
187
188         // Submit the request to the service and store the response.
189         AccountsCommon account =
190                 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
191                 true, true, true, true);
192         AccountClient client = new AccountClient();
193         ClientResponse<Response> res = client.create(account);
194         int statusCode = res.getStatus();
195         // Does it exactly match the expected status code?
196         if (logger.isDebugEnabled()) {
197             logger.debug(testName + ": status = " + statusCode);
198         }
199         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
200                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
201         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
202
203     }
204
205     /**
206      * Creates the without user.
207      *
208      * @param testName the test name
209      * @throws Exception the exception
210      */
211     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
212     dependsOnMethods = {"create"})
213     public void createWithoutUser(String testName) throws Exception {
214
215         setupCreate(testName);
216
217         // Submit the request to the service and store the response.
218         AccountsCommon account =
219                 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
220                 true, false, false, true);
221         AccountClient client = new AccountClient();
222         ClientResponse<Response> res = client.create(account);
223         int statusCode = res.getStatus();
224         // Does it exactly match the expected status code?
225         if (logger.isDebugEnabled()) {
226             logger.debug(testName + ": status = " + statusCode);
227         }
228         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
229                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
230         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
231     }
232
233     /**
234      * Creates the with invalid email.
235      *
236      * @param testName the test name
237      * @throws Exception the exception
238      */
239     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
240     dependsOnMethods = {"create"})
241     public void createWithInvalidEmail(String testName) throws Exception {
242
243         setupCreate(testName);
244
245         // Submit the request to the service and store the response.
246         AccountsCommon account =
247                 createAccountInstance("babybop", "babybop", "hithere08", "babybop.dinoland.com",
248                 true, false, true, true);
249         AccountClient client = new AccountClient();
250         ClientResponse<Response> res = client.create(account);
251         int statusCode = res.getStatus();
252         // Does it exactly match the expected status code?
253         if (logger.isDebugEnabled()) {
254             logger.debug(testName + ": status = " + statusCode);
255         }
256         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
257                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
258         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
259     }
260
261     /**
262      * Creates the without screen name.
263      *
264      * @param testName the test name
265      * @throws Exception the exception
266      */
267     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
268     dependsOnMethods = {"create"})
269     public void createWithoutScreenName(String testName) throws Exception {
270
271         setupCreate(testName);
272
273         // Submit the request to the service and store the response.
274         AccountsCommon account =
275                 createAccountInstance("babybop", "babybop", "hithere08", "babybop@dinoland.com",
276                 false, false, true, true);
277         AccountClient client = new AccountClient();
278         ClientResponse<Response> res = client.create(account);
279         int statusCode = res.getStatus();
280         // Does it exactly match the expected status code?
281         if (logger.isDebugEnabled()) {
282             logger.debug(testName + ": status = " + statusCode);
283         }
284         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
285                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
286         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
287     }
288
289     /**
290      * Creates the with invalid password.
291      *
292      * @param testName the test name
293      * @throws Exception the exception
294      */
295     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
296     dependsOnMethods = {"create"})
297     public void createWithInvalidPassword(String testName) throws Exception {
298
299         setupCreate(testName);
300
301         // Submit the request to the service and store the response.
302         AccountsCommon account =
303                 createAccountInstance("babybop", "babybop", "shpswd", "babybop@dinoland.com",
304                 true, false, true, true);
305         AccountClient client = new AccountClient();
306         ClientResponse<Response> res = client.create(account);
307         int statusCode = res.getStatus();
308         // Does it exactly match the expected status code?
309         if (logger.isDebugEnabled()) {
310             logger.debug(testName + ": status = " + statusCode);
311         }
312         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
313                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
314         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
315     }
316
317         /**
318          * Creates the with most invalid.
319          *
320          * @param testName the test name
321          * @throws Exception the exception
322          */
323         @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
324     dependsOnMethods = {"create"})
325     public void createWithMostInvalid(String testName) throws Exception {
326
327         setupCreate(testName);
328
329         // Submit the request to the service and store the response.
330         AccountsCommon account =
331                 createAccountInstance("babybop", "babybop", "hithere08", "babybop/dinoland.com",
332                 false, true, false, false);
333         AccountClient client = new AccountClient();
334         ClientResponse<Response> res = client.create(account);
335         int statusCode = res.getStatus();
336         // Does it exactly match the expected status code?
337         if (logger.isDebugEnabled()) {
338             logger.debug(testName + ": status = " + statusCode);
339         }
340         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
343     }
344
345     //to not cause uniqueness violation for account, createList is removed
346     /* (non-Javadoc)
347      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
348      */
349     @Override
350     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351     dependsOnMethods = {"create"})
352     public void createList(String testName) throws Exception {
353
354         setupCreate(testName);
355         // Submit the request to the service and store the response.
356         AccountsCommon account1 =
357                 createAccountInstance("curious", "curious", "hithere08", "curious@george.com",
358                 true, false, true, true);
359         AccountClient client = new AccountClient();
360         ClientResponse<Response> res = client.create(account1);
361         int statusCode = res.getStatus();
362         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
365         allResourceIdsCreated.add(extractId(res));
366
367         AccountsCommon account2 =
368                 createAccountInstance("tom", "tom", "hithere09", "tom@jerry.com",
369                 true, false, true, true);
370         res = client.create(account2);
371         statusCode = res.getStatus();
372         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
373                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
374         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
375         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376         allResourceIdsCreated.add(extractId(res));
377
378         AccountsCommon account3 =
379                 createAccountInstance("mj", "mj", "hithere10", "mj@dinoland.com",
380                 true, false, true, true);
381         res = client.create(account3);
382         statusCode = res.getStatus();
383         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
384                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
385         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
386         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
387         allResourceIdsCreated.add(extractId(res));
388     }
389
390     // Failure outcomes
391     // Placeholders until the three tests below can be uncommented.
392     // See Issue CSPACE-401.
393     /* (non-Javadoc)
394      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
395      */
396     @Override
397     public void createWithEmptyEntityBody(String testName) throws Exception {
398         //FIXME: Should this test really be empty?  If so, please comment accordingly.
399     }
400
401     /* (non-Javadoc)
402      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
403      */
404     @Override
405     public void createWithMalformedXml(String testName) throws Exception {
406         //FIXME: Should this test really be empty?  If so, please comment accordingly.
407     }
408
409     /* (non-Javadoc)
410      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
411      */
412     @Override
413     public void createWithWrongXmlSchema(String testName) throws Exception {
414         //FIXME: Should this test really be empty?  If so, please comment accordingly.
415     }
416
417     // ---------------------------------------------------------------
418     // CRUD tests : READ tests
419     // ---------------------------------------------------------------
420     // Success outcomes
421     /* (non-Javadoc)
422      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
423      */
424     @Override
425     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
426     dependsOnMethods = {"create"})
427     public void read(String testName) throws Exception {
428
429         // Perform setup.
430         setupRead(testName);
431
432         // Submit the request to the service and store the response.
433         AccountClient client = new AccountClient();
434         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
435         int statusCode = res.getStatus();
436
437         // Check the status code of the response: does it match
438         // the expected response(s)?
439         if (logger.isDebugEnabled()) {
440             logger.debug(testName + ": status = " + statusCode);
441         }
442         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
443                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
444         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445
446         AccountsCommon output = (AccountsCommon) res.getEntity();
447         Assert.assertNotNull(output);
448     }
449
450     // Failure outcomes
451     /* (non-Javadoc)
452      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
453      */
454     @Override
455     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
456     dependsOnMethods = {"read"})
457     public void readNonExistent(String testName) throws Exception {
458
459         // Perform setup.
460         setupReadNonExistent(testName);
461
462         // Submit the request to the service and store the response.
463         AccountClient client = new AccountClient();
464         ClientResponse<AccountsCommon> res = client.read(NON_EXISTENT_ID);
465         int statusCode = res.getStatus();
466
467         // Check the status code of the response: does it match
468         // the expected response(s)?
469         if (logger.isDebugEnabled()) {
470             logger.debug(testName + ": status = " + statusCode);
471         }
472         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475     }
476
477     // ---------------------------------------------------------------
478     // CRUD tests : READ_LIST tests
479     // ---------------------------------------------------------------
480     // Success outcomes
481     /* (non-Javadoc)
482      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
483      */
484     @Override
485     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
486     dependsOnMethods = {"createList", "read"})
487     public void readList(String testName) throws Exception {
488
489         // Perform setup.
490         setupReadList(testName);
491
492         // Submit the request to the service and store the response.
493         AccountClient client = new AccountClient();
494         ClientResponse<AccountsCommonList> res = client.readList();
495         AccountsCommonList list = res.getEntity();
496         int statusCode = res.getStatus();
497
498         // Check the status code of the response: does it match
499         // the expected response(s)?
500         if (logger.isDebugEnabled()) {
501             logger.debug(testName + ": status = " + statusCode);
502         }
503         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
504                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
505         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
506
507         // Optionally output additional data about list members for debugging.
508         boolean iterateThroughList = true;
509         if (iterateThroughList && logger.isDebugEnabled()) {
510             printList(testName, list);
511         }
512     }
513
514     /**
515      * Search screen name.
516      *
517      * @param testName the test name
518      * @throws Exception the exception
519      */
520     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
521     dependsOnMethods = {"createList", "read"})
522     public void searchScreenName(String testName) throws Exception {
523
524         // Perform setup.
525         setupReadList(testName);
526
527         // Submit the request to the service and store the response.
528         AccountClient client = new AccountClient();
529         ClientResponse<AccountsCommonList> res =
530                 client.readSearchList("tom", null, null);
531         AccountsCommonList list = res.getEntity();
532         int statusCode = res.getStatus();
533
534         // Check the status code of the response: does it match
535         // the expected response(s)?
536         if (logger.isDebugEnabled()) {
537             logger.debug(testName + ": status = " + statusCode);
538         }
539         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
542         Assert.assertEquals(1, list.getAccountListItem().size());
543         // Optionally output additional data about list members for debugging.
544         boolean iterateThroughList = true;
545         if (iterateThroughList && logger.isDebugEnabled()) {
546             printList(testName, list);
547         }
548     }
549
550     /**
551      * Search user id.
552      *
553      * @param testName the test name
554      * @throws Exception the exception
555      */
556     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
557     dependsOnMethods = {"createList", "read"})
558     public void searchUserId(String testName) throws Exception {
559
560         // Perform setup.
561         setupReadList(testName);
562
563         // Submit the request to the service and store the response.
564         AccountClient client = new AccountClient();
565         ClientResponse<AccountsCommonList> res =
566                 client.readSearchList(null, "tom", null);
567         AccountsCommonList list = res.getEntity();
568         int statusCode = res.getStatus();
569
570         // Check the status code of the response: does it match
571         // the expected response(s)?
572         if (logger.isDebugEnabled()) {
573             logger.debug(testName + ": status = " + statusCode);
574         }
575         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
578         Assert.assertEquals(1, list.getAccountListItem().size());
579         // Optionally output additional data about list members for debugging.
580         boolean iterateThroughList = true;
581         if (iterateThroughList && logger.isDebugEnabled()) {
582             printList(testName, list);
583         }
584     }
585
586     /**
587      * Search email.
588      *
589      * @param testName the test name
590      * @throws Exception the exception
591      */
592     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
593     dependsOnMethods = {"createList", "read"})
594     public void searchEmail(String testName) throws Exception {
595
596         // Perform setup.
597         setupReadList(testName);
598
599         // Submit the request to the service and store the response.
600         AccountClient client = new AccountClient();
601         ClientResponse<AccountsCommonList> res =
602                 client.readSearchList(null, null, "dinoland");
603         AccountsCommonList list = res.getEntity();
604         int statusCode = res.getStatus();
605
606         // Check the status code of the response: does it match
607         // the expected response(s)?
608         if (logger.isDebugEnabled()) {
609             logger.debug(testName + ": status = " + statusCode);
610         }
611         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614         Assert.assertEquals(2, list.getAccountListItem().size());
615         // Optionally output additional data about list members for debugging.
616         boolean iterateThroughList = true;
617         if (iterateThroughList && logger.isDebugEnabled()) {
618             printList(testName, list);
619         }
620     }
621
622     /**
623      * Search screen name email.
624      *
625      * @param testName the test name
626      * @throws Exception the exception
627      */
628     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
629     dependsOnMethods = {"createList", "read"})
630     public void searchScreenNameEmail(String testName) throws Exception {
631
632         // Perform setup.
633         setupReadList(testName);
634
635         // Submit the request to the service and store the response.
636         AccountClient client = new AccountClient();
637         ClientResponse<AccountsCommonList> res =
638                 client.readSearchList("tom", null, "jerry");
639         AccountsCommonList list = res.getEntity();
640         int statusCode = res.getStatus();
641
642         // Check the status code of the response: does it match
643         // the expected response(s)?
644         if (logger.isDebugEnabled()) {
645             logger.debug(testName + ": status = " + statusCode);
646         }
647         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
648                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
649         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
650         Assert.assertEquals(1, list.getAccountListItem().size());
651         // Optionally output additional data about list members for debugging.
652         boolean iterateThroughList = true;
653         if (iterateThroughList && logger.isDebugEnabled()) {
654             printList(testName, list);
655         }
656     }
657
658     // Failure outcomes
659     // None at present.
660     // ---------------------------------------------------------------
661     // CRUD tests : UPDATE tests
662     // ---------------------------------------------------------------
663     // Success outcomes
664     /* (non-Javadoc)
665      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
666      */
667     @Override
668     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
669     dependsOnMethods = {"read", "readList", "readNonExistent"})
670     public void update(String testName) throws Exception {
671
672         // Perform setup.
673         setupUpdate(testName);
674
675         AccountClient client = new AccountClient();
676         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
677         if (logger.isDebugEnabled()) {
678             logger.debug(testName + ": read status = " + res.getStatus());
679         }
680         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
681
682         if (logger.isDebugEnabled()) {
683             logger.debug("got object to update with ID: " + knownResourceId);
684         }
685         AccountsCommon accountFound =
686                 (AccountsCommon) res.getEntity();
687         Assert.assertNotNull(accountFound);
688
689         //create a new account object to test partial updates
690         AccountsCommon accountToUpdate = new AccountsCommon();
691         accountToUpdate.setCsid(knownResourceId);
692         accountToUpdate.setUserId(accountFound.getUserId());
693         // Update the content of this resource.
694         accountToUpdate.setEmail("updated-" + accountFound.getEmail());
695         if (logger.isDebugEnabled()) {
696             logger.debug("updated object");
697             logger.debug(objectAsXmlString(accountFound,
698                     AccountsCommon.class));
699         }
700
701         // Submit the request to the service and store the response.
702         res = client.update(knownResourceId, accountToUpdate);
703         int statusCode = res.getStatus();
704         // Check the status code of the response: does it match the expected response(s)?
705         if (logger.isDebugEnabled()) {
706             logger.debug(testName + ": status = " + statusCode);
707         }
708         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
709                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
710         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
711
712         AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
713         Assert.assertNotNull(accountUpdated);
714
715         Assert.assertEquals(accountUpdated.getEmail(),
716                 accountToUpdate.getEmail(),
717                 "Data in updated object did not match submitted data.");
718     }
719
720     /**
721      * Update password.
722      *
723      * @param testName the test name
724      * @throws Exception the exception
725      */
726     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
727     dependsOnMethods = {"update"})
728     public void updatePassword(String testName) throws Exception {
729
730         // Perform setup.
731         setupUpdate(testName);
732
733         AccountClient client = new AccountClient();
734         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
735         if (logger.isDebugEnabled()) {
736             logger.debug(testName + ": read status = " + res.getStatus());
737         }
738         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
739
740         if (logger.isDebugEnabled()) {
741             logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
742         }
743         AccountsCommon accountFound =
744                 (AccountsCommon) res.getEntity();
745         Assert.assertNotNull(accountFound);
746
747         //create a new account object to test partial updates
748         AccountsCommon accountToUpdate = new AccountsCommon();
749         accountToUpdate.setCsid(knownResourceId);
750         accountToUpdate.setUserId(accountFound.getUserId());
751         //change password
752         accountToUpdate.setPassword("imagination".getBytes());
753         if (logger.isDebugEnabled()) {
754             logger.debug(testName + ": updated object");
755             logger.debug(objectAsXmlString(accountToUpdate,
756                     AccountsCommon.class));
757         }
758
759         // Submit the request to the service and store the response.
760         res = client.update(knownResourceId, accountToUpdate);
761         int statusCode = res.getStatus();
762         // Check the status code of the response: does it match the expected response(s)?
763         if (logger.isDebugEnabled()) {
764             logger.debug(testName + ": status = " + statusCode);
765         }
766         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
767                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
768         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
769
770
771         AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
772         Assert.assertNotNull(accountUpdated);
773
774 //        Assert.assertEquals(accountUpdated.getPassword(),
775 //                accountFound.getPassword(),
776 //                "Data in updated object did not match submitted data.");
777     }
778
779     /**
780      * Update password without user.
781      *
782      * @param testName the test name
783      * @throws Exception the exception
784      */
785     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
786     dependsOnMethods = {"update"})
787     public void updatePasswordWithoutUser(String testName) throws Exception {
788
789         // Perform setup.
790         setupUpdate(testName);
791
792         AccountsCommon accountToUpdate = new AccountsCommon();
793         accountToUpdate.setCsid(knownResourceId);
794         accountToUpdate.setUserId(null);
795         //change password
796         accountToUpdate.setPassword("imagination".getBytes());
797         if (logger.isDebugEnabled()) {
798             logger.debug(testName + " : updated object");
799             logger.debug(objectAsXmlString(accountToUpdate,
800                     AccountsCommon.class));
801         }
802
803         AccountClient client = new AccountClient();
804         // Submit the request to the service and store the response.
805         ClientResponse<AccountsCommon> res = client.update(knownResourceId, accountToUpdate);
806         int statusCode = res.getStatus();
807         // Check the status code of the response: does it match the expected response(s)?
808         if (logger.isDebugEnabled()) {
809             logger.debug(testName + ": status = " + statusCode);
810         }
811         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
812                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
813         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
814
815     }
816
817     /**
818      * Update invalid password.
819      *
820      * @param testName the test name
821      * @throws Exception the exception
822      */
823     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
824     dependsOnMethods = {"update"})
825     public void updateInvalidPassword(String testName) throws Exception {
826
827         // Perform setup.
828         setupUpdate(testName);
829         AccountClient client = new AccountClient();
830         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
831         if (logger.isDebugEnabled()) {
832             logger.debug(testName + ": read status = " + res.getStatus());
833         }
834         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
835
836         if (logger.isDebugEnabled()) {
837             logger.debug(testName + ": got object to update password with ID: " + knownResourceId);
838         }
839         AccountsCommon accountFound = (AccountsCommon) res.getEntity();
840
841         AccountsCommon accountToUpdate = new AccountsCommon();
842         accountToUpdate.setCsid(knownResourceId);
843         accountToUpdate.setUserId(accountFound.getUserId());
844         Assert.assertNotNull(accountToUpdate);
845
846         //change password
847         accountToUpdate.setPassword("abc123".getBytes());
848         if (logger.isDebugEnabled()) {
849             logger.debug(testName + ": updated object");
850             logger.debug(objectAsXmlString(accountToUpdate,
851                     AccountsCommon.class));
852         }
853
854         // Submit the request to the service and store the response.
855         res = client.update(knownResourceId, accountToUpdate);
856         int statusCode = res.getStatus();
857         // Check the status code of the response: does it match the expected response(s)?
858         if (logger.isDebugEnabled()) {
859             logger.debug(testName + ": status = " + statusCode);
860         }
861         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
862                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
863         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
864
865     }
866
867     /**
868      * Deactivate.
869      *
870      * @param testName the test name
871      * @throws Exception the exception
872      */
873     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
874     dependsOnMethods = {"updatePasswordWithoutUser"})
875     public void deactivate(String testName) throws Exception {
876
877         // Perform setup.
878         setupUpdate(testName);
879
880         AccountClient client = new AccountClient();
881         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
882         if (logger.isDebugEnabled()) {
883             logger.debug(testName + ": read status = " + res.getStatus());
884         }
885         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
886
887         if (logger.isDebugEnabled()) {
888             logger.debug("got object to update with ID: " + knownResourceId);
889         }
890         AccountsCommon accountFound = (AccountsCommon) res.getEntity();
891
892         //create a new account object to test partial updates
893         AccountsCommon accountToUpdate = new AccountsCommon();
894         accountToUpdate.setCsid(knownResourceId);
895         accountToUpdate.setUserId(accountFound.getUserId());
896
897         // Update the content of this resource.
898         accountToUpdate.setStatus(Status.INACTIVE);
899         if (logger.isDebugEnabled()) {
900             logger.debug("updated object");
901             logger.debug(objectAsXmlString(accountToUpdate,
902                     AccountsCommon.class));
903         }
904
905         // Submit the request to the service and store the response.
906         res = client.update(knownResourceId, accountToUpdate);
907         int statusCode = res.getStatus();
908         // Check the status code of the response: does it match the expected response(s)?
909         if (logger.isDebugEnabled()) {
910             logger.debug(testName + ": status = " + statusCode);
911         }
912         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
913                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
914         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
915
916         AccountsCommon accountUpdated = (AccountsCommon) res.getEntity();
917         Assert.assertNotNull(accountUpdated);
918
919         Assert.assertEquals(accountUpdated.getStatus(),
920                 accountToUpdate.getStatus(),
921                 "Data in updated object did not match submitted data.");
922
923     }
924
925     // Failure outcomes
926     // Placeholders until the three tests below can be uncommented.
927     // See Issue CSPACE-401.
928     /* (non-Javadoc)
929      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
930      */
931     @Override
932     public void updateWithEmptyEntityBody(String testName) throws Exception {
933         //FIXME: Should this test really be empty?  If so, please comment accordingly.
934     }
935
936     /* (non-Javadoc)
937      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
938      */
939     @Override
940     public void updateWithMalformedXml(String testName) throws Exception {
941         //FIXME: Should this test really be empty?  If so, please comment accordingly.
942     }
943
944     /* (non-Javadoc)
945      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
946      */
947     @Override
948     public void updateWithWrongXmlSchema(String testName) throws Exception {
949         //FIXME: Should this test really be empty?  If so, please comment accordingly.
950     }
951
952     /* (non-Javadoc)
953      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
954      */
955     @Override
956     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
957     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
958     public void updateNonExistent(String testName) throws Exception {
959
960         // Perform setup.
961         setupUpdateNonExistent(testName);
962
963         // Submit the request to the service and store the response.
964         //
965         // Note: The ID used in this 'create' call may be arbitrary.
966         // The only relevant ID may be the one used in updateAccount(), below.
967         AccountClient client = new AccountClient();
968         AccountsCommon account =
969                 createAccountInstance("simba", "simba", "tiger", "simba@lionking.com",
970                 true, false, true, true);
971         ClientResponse<AccountsCommon> res =
972                 client.update(NON_EXISTENT_ID, account);
973         int statusCode = res.getStatus();
974
975         // Check the status code of the response: does it match
976         // the expected response(s)?
977         if (logger.isDebugEnabled()) {
978             logger.debug(testName + ": status = " + statusCode);
979         }
980         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
981                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
982         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
983     }
984
985     /**
986      * Update wrong user.
987      *
988      * @param testName the test name
989      * @throws Exception the exception
990      */
991     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
992     dependsOnMethods = {"deactivate", "readNonExistent", "testSubmitRequest"})
993     public void updateWrongUser(String testName) throws Exception {
994
995         setupUpdate(testName);
996
997         // Submit the request to the service and store the response.
998         //
999         // Note: The ID used in this 'create' call may be arbitrary.
1000         // The only relevant ID may be the one used in updateAccount(), below.
1001         AccountClient client = new AccountClient();
1002         ClientResponse<AccountsCommon> res = client.read(knownResourceId);
1003         if (logger.isDebugEnabled()) {
1004             logger.debug(testName + ": read status = " + res.getStatus());
1005         }
1006         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1007
1008         if (logger.isDebugEnabled()) {
1009             logger.debug("got object to update with ID: " + knownResourceId);
1010         }
1011         AccountsCommon accountToUpdate =
1012                 (AccountsCommon) res.getEntity();
1013         Assert.assertNotNull(accountToUpdate);
1014
1015         accountToUpdate.setUserId("barneyFake");
1016         if (logger.isDebugEnabled()) {
1017             logger.debug("updated object with wrongUser");
1018             logger.debug(objectAsXmlString(accountToUpdate,
1019                     AccountsCommon.class));
1020         }
1021
1022         res = client.update(knownResourceId, accountToUpdate);
1023         int statusCode = res.getStatus();
1024
1025         // Check the status code of the response: does it match
1026         // the expected response(s)?
1027         if (logger.isDebugEnabled()) {
1028             logger.debug(testName + ": status = " + statusCode);
1029         }
1030         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032         Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
1033     }
1034
1035     // ---------------------------------------------------------------
1036     // CRUD tests : DELETE tests
1037     // ---------------------------------------------------------------
1038     // Success outcomes
1039     /* (non-Javadoc)
1040      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1041      */
1042     @Override
1043     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1044     dependsOnMethods = {"testSubmitRequest", "updateWrongUser"})
1045     public void delete(String testName) throws Exception {
1046
1047         // Perform setup.
1048         setupDelete(testName);
1049
1050         // Submit the request to the service and store the response.
1051         AccountClient client = new AccountClient();
1052         ClientResponse<Response> res = client.delete(knownResourceId);
1053         int statusCode = res.getStatus();
1054
1055         // Check the status code of the response: does it match
1056         // the expected response(s)?
1057         if (logger.isDebugEnabled()) {
1058             logger.debug(testName + ": status = " + statusCode);
1059         }
1060         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1061                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1062         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1063     }
1064
1065     // Failure outcomes
1066     /* (non-Javadoc)
1067      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1068      */
1069     @Override
1070     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1071     dependsOnMethods = {"delete"})
1072     public void deleteNonExistent(String testName) throws Exception {
1073
1074         // Perform setup.
1075         setupDeleteNonExistent(testName);
1076
1077         // Submit the request to the service and store the response.
1078         AccountClient client = new AccountClient();
1079         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1080         int statusCode = res.getStatus();
1081
1082         // Check the status code of the response: does it match
1083         // the expected response(s)?
1084         if (logger.isDebugEnabled()) {
1085             logger.debug(testName + ": status = " + statusCode);
1086         }
1087         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1088                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1089         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1090     }
1091
1092     // ---------------------------------------------------------------
1093     // Utility tests : tests of code used in tests above
1094     // ---------------------------------------------------------------
1095     /**
1096      * Tests the code for manually submitting data that is used by several
1097      * of the methods above.
1098      * @throws Exception 
1099      */
1100     @Test(dependsOnMethods = {"create", "read"})
1101     public void testSubmitRequest() throws Exception {
1102
1103         // Expected status code: 200 OK
1104         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1105
1106         // Submit the request to the service and store the response.
1107         String method = ServiceRequestType.READ.httpMethodName();
1108         String url = getResourceURL(knownResourceId);
1109         int statusCode = submitRequest(method, url);
1110
1111         // Check the status code of the response: does it match
1112         // the expected response(s)?
1113         if (logger.isDebugEnabled()) {
1114             logger.debug("testSubmitRequest: url=" + url
1115                     + " status=" + statusCode);
1116         }
1117         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1118
1119     }
1120
1121     // ---------------------------------------------------------------
1122     // Utility methods used by tests above
1123     // ---------------------------------------------------------------
1124     /**
1125      * create account instance
1126      * @param screenName
1127      * @param userName
1128      * @param passwd
1129      * @param email
1130      * @param useScreenName
1131      * @param invalidTenant
1132      * @param useUser
1133      * @param usePassword
1134      * @return
1135      */
1136     AccountsCommon createAccountInstance(String screenName,
1137             String userName, String passwd, String email,
1138             boolean useScreenName, boolean invalidTenant, boolean useUser, boolean usePassword) {
1139
1140         AccountsCommon account = AccountFactory.createAccountInstance(screenName,
1141                 userName, passwd, email, useScreenName,
1142                 addTenant, invalidTenant, useUser, usePassword);
1143
1144         if (logger.isDebugEnabled()) {
1145             logger.debug("to be created, account common");
1146             logger.debug(objectAsXmlString(account,
1147                     AccountsCommon.class));
1148         }
1149         return account;
1150
1151     }
1152
1153     /**
1154      * Prints the list.
1155      *
1156      * @param testName the test name
1157      * @param list the list
1158      */
1159     private void printList(String testName, AccountsCommonList list) {
1160         List<AccountsCommonList.AccountListItem> items =
1161                 list.getAccountListItem();
1162         int i = 0;
1163
1164         for (AccountsCommonList.AccountListItem item : items) {
1165             logger.debug(testName + ": list-item[" + i + "] csid="
1166                     + item.getCsid());
1167             logger.debug(testName + ": list-item[" + i + "] screenName="
1168                     + item.getScreenName());
1169             logger.debug(testName + ": list-item[" + i + "] URI="
1170                     + item.getUri());
1171             i++;
1172
1173         }
1174     }
1175 }