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