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