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