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