]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
30fb54f8cf4bfc6fefea6294d0168ff9fc7b8f2b
[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 (c)) 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.client.test;
24
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.PersonJAXBSchema;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonauthoritiesCommon;
41 import org.collectionspace.services.person.PersonauthoritiesCommonList;
42 import org.collectionspace.services.person.PersonsCommon;
43 import org.collectionspace.services.person.PersonsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
53
54 /**
55  * PersonAuthorityServiceTest, carries out tests against a
56  * deployed and running PersonAuthority Service.
57  *
58  * $LastChangedRevision: 753 $
59  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
60  */
61 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
62
63     /** The logger. */
64     private final Logger logger =
65         LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
66
67     // Instance variables specific to this test.
68     /** The service path component. */
69     final String SERVICE_PATH_COMPONENT = "personauthorities";
70     
71     /** The item service path component. */
72     final String ITEM_SERVICE_PATH_COMPONENT = "items";
73     
74     /** The contact service path component. */
75     final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
76     
77     /** The test forename. */
78     final String TEST_FORE_NAME = "John";
79     
80     /** The test middle name. */
81     final String TEST_MIDDLE_NAME = null;
82     
83     /** The test surname. */
84     final String TEST_SUR_NAME = "Wayne";
85     
86     /** The test birthdate. */
87     final String TEST_BIRTH_DATE = "May 26, 1907";
88     
89     /** The test death date. */
90     final String TEST_DEATH_DATE = "June 11, 1979";
91
92     // Test name for partial term matching: Lech Walesa
93     final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
94     // Contains two non-USASCII range Unicode UTF-8 characters
95     final String TEST_PARTIAL_TERM_SUR_NAME = "Wa" + "\u0142" + "\u0119" + "sa";
96     final String TEST_PARTIAL_TERM_DISPLAY_NAME =
97             TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME;
98  
99     /** The known resource id. */
100     private String knownResourceId = null;
101     
102     /** The known resource display name. */
103     private String knownResourceDisplayName = null;
104     
105     /** The known resource ref name. */
106     private String knownResourceRefName = null;
107     
108     /** The known item resource id. */
109     private String knownItemResourceId = null;
110
111     // The resource ID of an item resource used for partial term matching tests.
112     private String knownItemPartialTermResourceId = null;
113     
114     /** The known contact resource id. */
115     private String knownContactResourceId = null;
116     
117     /** The n items to create in list. */
118     private int nItemsToCreateInList = 3;
119     
120     /** The all item resource ids created. */
121     private Map<String, String> allItemResourceIdsCreated =
122         new HashMap<String, String>();
123     
124     /** The all contact resource ids created. */
125     private Map<String, String> allContactResourceIdsCreated =
126         new HashMap<String, String>();
127
128     /* (non-Javadoc)
129      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
130      */
131     @Override
132     protected CollectionSpaceClient getClientInstance() {
133         return new PersonAuthorityClient();
134     }
135     
136     /* (non-Javadoc)
137      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
138      */
139     @Override
140         protected AbstractCommonList getAbstractCommonList(
141                         ClientResponse<AbstractCommonList> response) {
142         return response.getEntity(PersonsCommonList.class);
143     }
144  
145     // ---------------------------------------------------------------
146     // CRUD tests : CREATE tests
147     // ---------------------------------------------------------------
148     // Success outcomes
149     /* (non-Javadoc)
150      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
151      */
152     @Override
153     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
154         groups = {"create"})
155     public void create(String testName) throws Exception {
156
157         // Perform setup, such as initializing the type of service request
158         // (e.g. CREATE, DELETE), its valid and expected status codes, and
159         // its associated HTTP method name (e.g. POST, DELETE).
160         setupCreate(testName);
161
162         // Submit the request to the service and store the response.
163         PersonAuthorityClient client = new PersonAuthorityClient();
164         String identifier = createIdentifier();
165         String displayName = "displayName-" + identifier;
166         String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
167         String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
168         MultipartOutput multipart = 
169             PersonAuthorityClientUtils.createPersonAuthorityInstance(
170             displayName, fullRefName, client.getCommonPartName());
171         
172         String newID = null;
173         ClientResponse<Response> res = client.create(multipart);
174         try {
175                 int statusCode = res.getStatus();
176         
177                 // Check the status code of the response: does it match
178                 // the expected response(s)?
179                 //
180                 // Specifically:
181                 // Does it fall within the set of valid status codes?
182                 // Does it exactly match the expected status code?
183                 if(logger.isDebugEnabled()){
184                     logger.debug(testName + ": status = " + statusCode);
185                 }
186                 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
187                         invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
188                 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
189         
190                 newID = PersonAuthorityClientUtils.extractId(res);
191         } finally {
192                 res.releaseConnection();
193         }
194         // Store the refname from the first resource created
195         // for additional tests below.
196         knownResourceRefName = baseRefName;
197         // Store the ID returned from the first resource created
198         // for additional tests below.
199         if (knownResourceId == null){
200             knownResourceId = newID;
201             knownResourceDisplayName = displayName;
202             if (logger.isDebugEnabled()) {
203                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
204             }
205         }
206         // Store the IDs from every resource created by tests,
207         // so they can be deleted after tests have been run.
208         allResourceIdsCreated.add(newID);
209     }
210
211     /**
212      * Creates the item.
213      *
214      * @param testName the test name
215      */
216     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
217         groups = {"create"}, dependsOnMethods = {"create"})
218     public void createItem(String testName) {
219         setupCreate(testName);
220         String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
221     }
222
223     /**
224      * Creates the item in authority.
225      *
226      * @param vcsid the vcsid
227      * @param authRefName the auth ref name
228      * @return the string
229      */
230     private String createItemInAuthority(String vcsid, String authRefName) {
231
232         final String testName = "createItemInAuthority";
233         if(logger.isDebugEnabled()){
234             logger.debug(testName + ":...");
235         }
236
237         // Submit the request to the service and store the response.
238         PersonAuthorityClient client = new PersonAuthorityClient();
239         String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
240         Map<String, String> johnWayneMap = new HashMap<String,String>();
241         //
242         // Fill the property map
243         //
244         johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
245         johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
246         
247         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
248         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
249         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
250         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
251         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
252         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
253         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
254             "known by his stage name John Wayne, was an American film actor, director " +
255             "and producer. He epitomized rugged masculinity and has become an enduring " +
256             "American icon. He is famous for his distinctive voice, walk and height. " +
257             "He was also known for his conservative political views and his support in " +
258             "the 1950s for anti-communist positions.");
259         MultipartOutput multipart = 
260             PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
261                 client.getItemCommonPartName() );
262
263         String newID = null;
264         ClientResponse<Response> res = client.createItem(vcsid, multipart);
265         try {
266                 int statusCode = res.getStatus();
267                 // Check the status code of the response: does it match
268                 // the expected response(s)?
269                 if(logger.isDebugEnabled()){
270                     logger.debug(testName + ": status = " + statusCode);
271                 }
272                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
275
276                 newID = PersonAuthorityClientUtils.extractId(res);
277         } finally {
278                 res.releaseConnection();
279         }
280
281         // Store the ID returned from the first item resource created
282         // for additional tests below.
283         if (knownItemResourceId == null){
284             knownItemResourceId = newID;
285             if (logger.isDebugEnabled()) {
286                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);                
287             }
288         }
289
290         // Store the IDs from any item resources created
291         // by tests, along with the IDs of their parents, so these items
292         // can be deleted after all tests have been run.
293         allItemResourceIdsCreated.put(newID, vcsid);
294
295         return newID;
296     }
297     
298     /**
299      * Creates an item in the authority, used for partial term matching tests.
300      *
301      * @param vcsid the vcsid
302      * @param authRefName the auth ref name
303      * @return the string
304      */
305     private String createItemInAuthorityForPartialTermMatch(String vcsid, String authRefName) {
306         
307         final String testName = "createItemInAuthorityForPartialTermMatch";
308         if(logger.isDebugEnabled()){
309             logger.debug(testName + ":...");
310         }
311
312         setupCreate(testName);
313
314         // Submit the request to the service and store the response.
315         PersonAuthorityClient client = new PersonAuthorityClient();
316         String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName,
317                 TEST_PARTIAL_TERM_DISPLAY_NAME, true);
318         Map<String, String> partialTermPersonMap = new HashMap<String,String>();
319         //
320         // Fill the property map
321         //
322         partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
323         partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
324         partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
325         partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
326         partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
327         MultipartOutput multipart = 
328             PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, partialTermPersonMap,
329                 client.getItemCommonPartName() );
330
331         String newID = null;
332         ClientResponse<Response> res = client.createItem(vcsid, multipart);
333         try {
334                 int statusCode = res.getStatus();
335                 // Check the status code of the response: does it match
336                 // the expected response(s)?
337                 if(logger.isDebugEnabled()){
338                     logger.debug(testName + ": status = " + statusCode);
339                 }
340                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
343
344                 newID = PersonAuthorityClientUtils.extractId(res);
345         } finally {
346                 res.releaseConnection();
347         }
348
349         // Store the ID returned from the first item resource created
350         // for additional tests below.
351         if (knownItemResourceId == null){
352             knownItemResourceId = newID;
353             if (logger.isDebugEnabled()) {
354                 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
355             }
356         }
357
358         // Store the IDs from any item resources created
359         // by tests, along with the IDs of their parents, so these items
360         // can be deleted after all tests have been run.
361         allItemResourceIdsCreated.put(newID, vcsid);
362
363         return newID;
364     }
365
366     /**
367      * Creates the contact.
368      *
369      * @param testName the test name
370      */
371     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
372         groups = {"create"}, dependsOnMethods = {"createItem"})
373     public void createContact(String testName) {
374         setupCreate(testName);
375         String newID = createContactInItem(knownResourceId, knownItemResourceId);
376     }
377
378    /**
379     * Creates the contact in item.
380     *
381     * @param parentcsid the parentcsid
382     * @param itemcsid the itemcsid
383     * @return the string
384     */
385    private String createContactInItem(String parentcsid, String itemcsid) {
386
387         final String testName = "createContactInItem";
388         setupCreate(testName);
389         if(logger.isDebugEnabled()){
390             logger.debug(testName + ":...");
391         }
392
393         // Submit the request to the service and store the response.
394         PersonAuthorityClient client = new PersonAuthorityClient();
395         String identifier = createIdentifier();
396         MultipartOutput multipart =
397             ContactClientUtils.createContactInstance(parentcsid,
398             itemcsid, identifier, new ContactClient().getCommonPartName());
399         
400         String newID = null;
401         ClientResponse<Response> res =
402              client.createContact(parentcsid, itemcsid, multipart);
403         try {
404                 int statusCode = res.getStatus();
405                 // Check the status code of the response: does it match
406                 // the expected response(s)?
407                 if(logger.isDebugEnabled()){
408                     logger.debug(testName + ": status = " + statusCode);
409                 }
410                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413
414                 newID = PersonAuthorityClientUtils.extractId(res);
415         } finally {
416                 res.releaseConnection();
417         }
418
419         // Store the ID returned from the first contact resource created
420         // for additional tests below.
421         if (knownContactResourceId == null){
422             knownContactResourceId = newID;
423             if (logger.isDebugEnabled()) {
424                 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
425             }
426         }
427
428         // Store the IDs from any contact resources created
429         // by tests, along with the IDs of their parent items,
430         // so these items can be deleted after all tests have been run.
431         allContactResourceIdsCreated.put(newID, itemcsid);
432
433         return newID;
434     }
435
436     // Failure outcomes
437
438     // Placeholders until the three tests below can be uncommented.
439     // See Issue CSPACE-401.
440     /* (non-Javadoc)
441      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
442      */
443     @Override
444     public void createWithEmptyEntityBody(String testName) throws Exception {
445         //Should this really be empty?
446     }
447
448     /* (non-Javadoc)
449      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
450      */
451     @Override
452     public void createWithMalformedXml(String testName) throws Exception {
453         //Should this really be empty?
454     }
455
456     /* (non-Javadoc)
457      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
458      */
459     @Override
460     public void createWithWrongXmlSchema(String testName) throws Exception {
461         //Should this really be empty?
462     }
463
464 /*
465     @Override
466     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
467         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
468     public void createWithEmptyEntityBody(String testName) throws Exception {
469
470     // Perform setup.
471     setupCreateWithEmptyEntityBody(testName);
472
473     // Submit the request to the service and store the response.
474     String method = REQUEST_TYPE.httpMethodName();
475     String url = getServiceRootURL();
476     String mediaType = MediaType.APPLICATION_XML;
477     final String entity = "";
478     int statusCode = submitRequest(method, url, mediaType, entity);
479
480     // Check the status code of the response: does it match
481     // the expected response(s)?
482     if(logger.isDebugEnabled()) {
483         logger.debug(testName + ": url=" + url +
484             " status=" + statusCode);
485      }
486     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
487     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
488     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
489     }
490
491     @Override
492     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
493         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
494     public void createWithMalformedXml(String testName) throws Exception {
495
496     // Perform setup.
497     setupCreateWithMalformedXml(testName);
498
499     // Submit the request to the service and store the response.
500     String method = REQUEST_TYPE.httpMethodName();
501     String url = getServiceRootURL();
502     String mediaType = MediaType.APPLICATION_XML;
503     final String entity = MALFORMED_XML_DATA; // Constant from base class.
504     int statusCode = submitRequest(method, url, mediaType, entity);
505
506     // Check the status code of the response: does it match
507     // the expected response(s)?
508     if(logger.isDebugEnabled()){
509         logger.debug(testName + ": url=" + url +
510             " status=" + statusCode);
511      }
512     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
513     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
514     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
515     }
516
517     @Override
518     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
519         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
520     public void createWithWrongXmlSchema(String testName) throws Exception {
521
522     // Perform setup.
523     setupCreateWithWrongXmlSchema(testName);
524
525     // Submit the request to the service and store the response.
526     String method = REQUEST_TYPE.httpMethodName();
527     String url = getServiceRootURL();
528     String mediaType = MediaType.APPLICATION_XML;
529     final String entity = WRONG_XML_SCHEMA_DATA;
530     int statusCode = submitRequest(method, url, mediaType, entity);
531
532     // Check the status code of the response: does it match
533     // the expected response(s)?
534     if(logger.isDebugEnabled()){
535         logger.debug(testName + ": url=" + url +
536             " status=" + statusCode);
537      }
538     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
539     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
540     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
541     }
542 */
543
544     // ---------------------------------------------------------------
545     // CRUD tests : CREATE LIST tests
546     // ---------------------------------------------------------------
547     // Success outcomes
548     /* (non-Javadoc)
549  * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
550  */
551     @Override
552     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
553         groups = {"createList"}, dependsOnGroups = {"create"})
554     public void createList(String testName) throws Exception {
555         for (int i = 0; i < nItemsToCreateInList; i++) {
556             create(testName);
557         }
558     }
559
560     /**
561      * Creates the item list.
562      *
563      * @param testName the test name
564      * @throws Exception the exception
565      */
566     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
567         groups = {"createList"}, dependsOnMethods = {"createList"})
568     public void createItemList(String testName) throws Exception {
569         // Add items to the initially-created, known parent record.
570         for (int j = 0; j < nItemsToCreateInList; j++) {
571             createItem(testName);
572         }
573     }
574
575     /**
576      * Creates the contact list.
577      *
578      * @param testName the test name
579      * @throws Exception the exception
580      */
581     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
582         groups = {"createList"}, dependsOnMethods = {"createItemList"})
583     public void createContactList(String testName) throws Exception {
584         // Add contacts to the initially-created, known item record.
585         for (int j = 0; j < nItemsToCreateInList; j++) {
586             createContact(testName);
587         }
588     }
589
590     // ---------------------------------------------------------------
591     // CRUD tests : READ tests
592     // ---------------------------------------------------------------
593     // Success outcomes
594     /* (non-Javadoc)
595      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
596      */
597     @Override
598     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
599         groups = {"read"}, dependsOnGroups = {"create"})
600     public void read(String testName) throws Exception {
601
602         // Perform setup.
603         setupRead();
604         
605         // Submit the request to the service and store the response.
606         PersonAuthorityClient client = new PersonAuthorityClient();
607         ClientResponse<MultipartInput> res = client.read(knownResourceId);
608         try {
609                 int statusCode = res.getStatus();
610                 // Check the status code of the response: does it match
611                 // the expected response(s)?
612                 if(logger.isDebugEnabled()){
613                     logger.debug(testName + ": status = " + statusCode);
614                 }
615                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
618                 //FIXME: remove the following try catch once Aron fixes signatures
619                 try {
620                     MultipartInput input = (MultipartInput) res.getEntity();
621                     PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
622                             client.getCommonPartName(), PersonauthoritiesCommon.class);
623                     Assert.assertNotNull(personAuthority);
624                 } catch (Exception e) {
625                     throw new RuntimeException(e);
626                 }
627         } finally {
628                 res.releaseConnection();
629         }
630     }
631
632     /**
633      * Read by name.
634      *
635      * @param testName the test name
636      * @throws Exception the exception
637      */
638     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
639             groups = {"read"}, dependsOnGroups = {"create"})
640         public void readByName(String testName) throws Exception {
641
642         // Perform setup.
643         setupRead();
644
645         // Submit the request to the service and store the response.
646         PersonAuthorityClient client = new PersonAuthorityClient();
647         ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
648         try {
649                 int statusCode = res.getStatus();
650                 // Check the status code of the response: does it match
651                 // the expected response(s)?
652                 if(logger.isDebugEnabled()){
653                     logger.debug(testName + ": status = " + statusCode);
654                 }
655                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
658                 //FIXME: remove the following try catch once Aron fixes signatures
659                 try {
660                     MultipartInput input = (MultipartInput) res.getEntity();
661                     PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
662                             client.getCommonPartName(), PersonauthoritiesCommon.class);
663                     Assert.assertNotNull(personAuthority);
664                 } catch (Exception e) {
665                     throw new RuntimeException(e);
666                 }
667         } finally {
668                 res.releaseConnection();
669         }
670     }
671
672 /*
673     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
674         groups = {"read"}, dependsOnMethods = {"read"})
675     public void readByName(String testName) throws Exception {
676
677         // Perform setup.
678         setupRead();
679
680         // Submit the request to the service and store the response.
681         ClientResponse<MultipartInput> res = client.read(knownResourceId);
682         int statusCode = res.getStatus();
683
684         // Check the status code of the response: does it match
685         // the expected response(s)?
686         if(logger.isDebugEnabled()){
687             logger.debug(testName + ": status = " + statusCode);
688         }
689         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
690                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
691         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692         //FIXME: remove the following try catch once Aron fixes signatures
693         try {
694             MultipartInput input = (MultipartInput) res.getEntity();
695             PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
696                     client.getCommonPartName(), PersonauthoritiesCommon.class);
697             Assert.assertNotNull(personAuthority);
698         } catch (Exception e) {
699             throw new RuntimeException(e);
700         }
701     }
702 */
703
704     /**
705  * Read item.
706  *
707  * @param testName the test name
708  * @throws Exception the exception
709  */
710 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
711         groups = {"read"}, dependsOnMethods = {"read"})
712     public void readItem(String testName) throws Exception {
713         // Perform setup.
714         setupRead(testName);
715
716         // Submit the request to the service and store the response.
717         PersonAuthorityClient client = new PersonAuthorityClient();
718         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
719         try {
720                 int statusCode = res.getStatus();
721         
722                 // Check the status code of the response: does it match
723                 // the expected response(s)?
724                 if(logger.isDebugEnabled()){
725                     logger.debug(testName + ": status = " + statusCode);
726                 }
727                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
728                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
729                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
730         
731                 // Check whether we've received a person.
732                 MultipartInput input = (MultipartInput) res.getEntity();
733                 PersonsCommon person = (PersonsCommon) extractPart(input,
734                         client.getItemCommonPartName(), PersonsCommon.class);
735                 Assert.assertNotNull(person);
736                 boolean showFull = true;
737                 if(showFull && logger.isDebugEnabled()){
738                     logger.debug(testName + ": returned payload:");
739                     logger.debug(objectAsXmlString(person, PersonsCommon.class));
740                 }
741                 Assert.assertEquals(person.getInAuthority(), knownResourceId);
742         } finally {
743                 res.releaseConnection();
744         }
745     }
746
747     /**
748      * Verify item display name.
749      *
750      * @param testName the test name
751      * @throws Exception the exception
752      */
753     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754         dependsOnMethods = {"readItem", "updateItem"})
755     public void verifyItemDisplayName(String testName) throws Exception {
756         // Perform setup.
757         setupUpdate(testName);
758
759         // Submit the request to the service and store the response.
760         PersonAuthorityClient client = new PersonAuthorityClient();
761         MultipartInput input =null;
762         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
763         try {
764                 int statusCode = res.getStatus();
765         
766                 // Check the status code of the response: does it match
767                 // the expected response(s)?
768                 if(logger.isDebugEnabled()){
769                     logger.debug(testName + ": status = " + statusCode);
770                 }
771                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
772                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
773                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
774         
775                 // Check whether person has expected displayName.
776                 input = (MultipartInput) res.getEntity();
777         } finally {
778                 res.releaseConnection();
779         }
780                 
781         PersonsCommon person = (PersonsCommon) extractPart(input,
782                 client.getItemCommonPartName(), PersonsCommon.class);
783         Assert.assertNotNull(person);
784         String displayName = person.getDisplayName();
785         // Make sure displayName matches computed form
786         String expectedDisplayName = 
787             PersonAuthorityClientUtils.prepareDefaultDisplayName(
788                 TEST_FORE_NAME, null, TEST_SUR_NAME,
789                 TEST_BIRTH_DATE, TEST_DEATH_DATE);
790         Assert.assertNotNull(displayName, expectedDisplayName);
791     
792         // Update the shortName and verify the computed name is updated.
793         person.setCsid(null);
794         person.setDisplayNameComputed(true);
795         person.setForeName("updated-" + TEST_FORE_NAME);
796         expectedDisplayName = 
797             PersonAuthorityClientUtils.prepareDefaultDisplayName(
798                 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, 
799                 TEST_BIRTH_DATE, TEST_DEATH_DATE);
800
801         // Submit the updated resource to the service and store the response.
802         MultipartOutput output = new MultipartOutput();
803         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
804         commonPart.getHeaders().add("label", client.getItemCommonPartName());
805         res = client.updateItem(knownResourceId, knownItemResourceId, output);
806         try {
807                 int statusCode = res.getStatus();
808         
809                 // Check the status code of the response: does it match the expected response(s)?
810                 if(logger.isDebugEnabled()){
811                     logger.debug("updateItem: status = " + statusCode);
812                 }
813                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
814                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
815                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
816         
817                 // Retrieve the updated resource and verify that its contents exist.
818                 input = (MultipartInput) res.getEntity();
819         } finally {
820                 res.releaseConnection();
821         }
822         
823         PersonsCommon updatedPerson =
824                 (PersonsCommon) extractPart(input,
825                         client.getItemCommonPartName(), PersonsCommon.class);
826         Assert.assertNotNull(updatedPerson);
827
828         // Verify that the updated resource received the correct data.
829         Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
830             "Updated ForeName in Person did not match submitted data.");
831         // Verify that the updated resource computes the right displayName.
832         Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
833             "Updated ForeName in Person not reflected in computed DisplayName.");
834
835         // Now Update the displayName, not computed and verify the computed name is overriden.
836         person.setDisplayNameComputed(false);
837         expectedDisplayName = "TestName";
838         person.setDisplayName(expectedDisplayName);
839
840         // Submit the updated resource to the service and store the response.
841         output = new MultipartOutput();
842         commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
843         commonPart.getHeaders().add("label", client.getItemCommonPartName());
844         res = client.updateItem(knownResourceId, knownItemResourceId, output);
845         try {
846                 int statusCode = res.getStatus();
847         
848                 // Check the status code of the response: does it match the expected response(s)?
849                 if(logger.isDebugEnabled()){
850                     logger.debug("updateItem: status = " + statusCode);
851                 }
852                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
855         
856                 // Retrieve the updated resource and verify that its contents exist.
857                 input = (MultipartInput) res.getEntity();
858         } finally {
859                 res.releaseConnection();
860         }
861         
862         updatedPerson =
863                 (PersonsCommon) extractPart(input,
864                         client.getItemCommonPartName(), PersonsCommon.class);
865         Assert.assertNotNull(updatedPerson);
866
867         // Verify that the updated resource received the correct data.
868         Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
869                 "Updated displayNameComputed in Person did not match submitted data.");
870         // Verify that the updated resource computes the right displayName.
871         Assert.assertEquals(updatedPerson.getDisplayName(),
872                         expectedDisplayName,
873                 "Updated DisplayName (not computed) in Person not stored.");
874     }
875
876     /**
877      * Verify illegal item display name.
878      *
879      * @param testName the test name
880      * @throws Exception the exception
881      */
882     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
883             dependsOnMethods = {"verifyItemDisplayName"})
884     public void verifyIllegalItemDisplayName(String testName) throws Exception {
885
886         // Perform setup.
887         setupUpdateWithWrongXmlSchema(testName);
888
889         // Submit the request to the service and store the response.
890         PersonAuthorityClient client = new PersonAuthorityClient();
891         MultipartInput input = null;
892         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
893         try {
894                 int statusCode = res.getStatus();
895         
896                 // Check the status code of the response: does it match
897                 // the expected response(s)?
898                 if(logger.isDebugEnabled()){
899                     logger.debug(testName + ": status = " + statusCode);
900                 }
901                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
902                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
903                 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
904         
905                 // Check whether Person has expected displayName.
906                 input = (MultipartInput) res.getEntity();
907         } finally {
908                 res.releaseConnection();
909         }
910         
911         PersonsCommon person = (PersonsCommon) extractPart(input,
912                 client.getItemCommonPartName(), PersonsCommon.class);
913         Assert.assertNotNull(person);
914         // Try to Update with computed false and no displayName
915         person.setDisplayNameComputed(false);
916         person.setDisplayName(null);
917
918         // Submit the updated resource to the service and store the response.
919         MultipartOutput output = new MultipartOutput();
920         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
921         commonPart.getHeaders().add("label", client.getItemCommonPartName());
922         res = client.updateItem(knownResourceId, knownItemResourceId, output);
923         try {
924                 int statusCode = res.getStatus();
925         
926                 // Check the status code of the response: does it match the expected response(s)?
927                 if(logger.isDebugEnabled()){
928                     logger.debug("updateItem: status = " + statusCode);
929                 }
930                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
931                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
932                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
933         } finally {
934                 res.releaseConnection();
935         }
936     }
937     
938     /**
939      * Read contact.
940      *
941      * @param testName the test name
942      * @throws Exception the exception
943      */
944     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
945         groups = {"read"}, dependsOnMethods = {"readItem"})
946     public void readContact(String testName) throws Exception {
947         // Perform setup.
948         setupRead(testName);
949
950         // Submit the request to the service and store the response.
951         PersonAuthorityClient client = new PersonAuthorityClient();
952         MultipartInput input = null;
953         ClientResponse<MultipartInput> res =
954             client.readContact(knownResourceId, knownItemResourceId,
955             knownContactResourceId);
956         try {
957                 int statusCode = res.getStatus();
958         
959                 // Check the status code of the response: does it match
960                 // the expected response(s)?
961                 if(logger.isDebugEnabled()){
962                     logger.debug(testName + ": status = " + statusCode);
963                 }
964                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
965                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
966                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
967         
968                 // Check whether we've received a contact.
969                 input = (MultipartInput) res.getEntity();
970         } finally {
971                 res.releaseConnection();
972         }
973         
974         ContactsCommon contact = (ContactsCommon) extractPart(input,
975                 new ContactClient().getCommonPartName(), ContactsCommon.class);
976         Assert.assertNotNull(contact);
977         boolean showFull = true;
978         if(showFull && logger.isDebugEnabled()){
979             logger.debug(testName + ": returned payload:");
980             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
981         }
982         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
983         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
984
985     }
986
987     // Failure outcomes
988     /* (non-Javadoc)
989      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
990      */
991     @Override
992     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
993         groups = {"read"}, dependsOnMethods = {"read"})
994     public void readNonExistent(String testName) {
995
996         // Perform setup.
997         setupReadNonExistent(testName);
998
999         // Submit the request to the service and store the response.
1000         PersonAuthorityClient client = new PersonAuthorityClient();
1001         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
1002         try {
1003                 int statusCode = res.getStatus();
1004                 // Check the status code of the response: does it match
1005                 // the expected response(s)?
1006                 if(logger.isDebugEnabled()){
1007                     logger.debug(testName + ": status = " + statusCode);
1008                 }
1009                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1010                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1011                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1012         } finally {
1013                 res.releaseConnection();
1014         }
1015     }
1016
1017     /**
1018      * Read item non existent.
1019      *
1020      * @param testName the test name
1021      */
1022     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1023         groups = {"read"}, dependsOnMethods = {"readItem"})
1024     public void readItemNonExistent(String testName) {
1025
1026         // Perform setup.
1027         setupReadNonExistent(testName);
1028
1029         // Submit the request to the service and store the response.
1030         PersonAuthorityClient client = new PersonAuthorityClient();
1031         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1032         try {
1033                 int statusCode = res.getStatus();
1034         
1035                 // Check the status code of the response: does it match
1036                 // the expected response(s)?
1037                 if(logger.isDebugEnabled()){
1038                     logger.debug(testName + ": status = " + statusCode);
1039                 }
1040                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1041                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1042                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1043         } finally {
1044                 res.releaseConnection();
1045         }
1046     }
1047
1048     /**
1049      * Read contact non existent.
1050      *
1051      * @param testName the test name
1052      */
1053     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1054         groups = {"read"}, dependsOnMethods = {"readContact"})
1055     public void readContactNonExistent(String testName) {
1056
1057         // Perform setup.
1058         setupReadNonExistent(testName);
1059
1060         // Submit the request to the service and store the response.
1061         PersonAuthorityClient client = new PersonAuthorityClient();
1062         ClientResponse<MultipartInput> res =
1063             client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1064         try {
1065                 int statusCode = res.getStatus();
1066         
1067                 // Check the status code of the response: does it match
1068                 // the expected response(s)?
1069                 if(logger.isDebugEnabled()){
1070                     logger.debug(testName + ": status = " + statusCode);
1071                 }
1072                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1073                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1074                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1075         } finally {
1076                 res.releaseConnection();
1077         }
1078     }
1079
1080     // ---------------------------------------------------------------
1081     // CRUD tests : READ_LIST tests
1082     // ---------------------------------------------------------------
1083     // Success outcomes
1084
1085     /* (non-Javadoc)
1086      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1087      */
1088     @Override
1089     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1090         groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1091     public void readList(String testName) throws Exception {
1092
1093         // Perform setup.
1094         setupReadList(testName);
1095
1096         // Submit the request to the service and store the response.
1097         PersonAuthorityClient client = new PersonAuthorityClient();
1098         PersonauthoritiesCommonList list = null;
1099         ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1100         try {
1101                 int statusCode = res.getStatus();
1102         
1103                 // Check the status code of the response: does it match
1104                 // the expected response(s)?
1105                 if(logger.isDebugEnabled()){
1106                     logger.debug(testName + ": status = " + statusCode);
1107                 }
1108                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1109                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1110                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1111         
1112                 list = res.getEntity();
1113         } finally {
1114                 res.releaseConnection();
1115         }
1116
1117         // Optionally output additional data about list members for debugging.
1118         boolean iterateThroughList = false;
1119         if (iterateThroughList && logger.isDebugEnabled()) {
1120             List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1121                     list.getPersonauthorityListItem();
1122             int i = 0;
1123             for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1124                 String csid = item.getCsid();
1125                 logger.debug(testName + ": list-item[" + i + "] csid=" +
1126                         csid);
1127                 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1128                         item.getDisplayName());
1129                 logger.debug(testName + ": list-item[" + i + "] URI=" +
1130                         item.getUri());
1131                 readItemList(csid, null);
1132                 i++;
1133             }
1134         }
1135     }
1136
1137     /**
1138      * Read item list.
1139      */
1140     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1141     public void readItemList() {
1142         readItemList(knownResourceId, null);
1143     }
1144
1145     /**
1146      * Read item list by authority name.
1147      */
1148     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1149     public void readItemListByAuthorityName() {
1150         readItemList(null, knownResourceDisplayName);
1151     }
1152     
1153     /**
1154      * Read item list.
1155      *
1156      * @param vcsid the vcsid
1157      * @param name the name
1158      */
1159     private void readItemList(String vcsid, String name) {
1160
1161         final String testName = "readItemList";
1162
1163         // Perform setup.
1164         setupReadList(testName);
1165         
1166         // Submit the request to the service and store the response.
1167         PersonAuthorityClient client = new PersonAuthorityClient();
1168         ClientResponse<PersonsCommonList> res = null;
1169         if (vcsid!= null) {
1170                 res = client.readItemList(vcsid);
1171         } else if (name!= null) {
1172                 res = client.readItemListForNamedAuthority(name);
1173         } else {
1174                 Assert.fail("readItemList passed null csid and name!");
1175         }
1176         PersonsCommonList list = null;
1177         try {
1178                 int statusCode = res.getStatus();
1179         
1180                 // Check the status code of the response: does it match
1181                 // the expected response(s)?
1182                 if(logger.isDebugEnabled()){
1183                     logger.debug(testName + ": status = " + statusCode);
1184                 }
1185                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1186                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1187                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1188
1189                 list = res.getEntity();
1190         } finally {
1191                 res.releaseConnection();
1192         }
1193
1194         List<PersonsCommonList.PersonListItem> items =
1195             list.getPersonListItem();
1196         int nItemsReturned = items.size();
1197         // There will be one item created, associated with a
1198         // known parent resource, by the createItem test.
1199         //
1200         // In addition, there will be 'nItemsToCreateInList'
1201         // additional items created by the createItemList test,
1202         // all associated with the same parent resource.
1203         int nExpectedItems = nItemsToCreateInList + 1;
1204         if(logger.isDebugEnabled()){
1205             logger.debug(testName + ": Expected "
1206                         + nExpectedItems +" items; got: "+nItemsReturned);
1207         }
1208         Assert.assertEquals(nItemsReturned, nExpectedItems);
1209
1210         int i = 0;
1211         for (PersonsCommonList.PersonListItem item : items) {
1212                 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1213                 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1214                 // Optionally output additional data about list members for debugging.
1215                 boolean showDetails = true;
1216                 if (showDetails && logger.isDebugEnabled()) {
1217                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
1218                         item.getCsid());
1219                 logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
1220                         item.getRefName());
1221                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
1222                         item.getDisplayName());
1223                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
1224                         item.getUri());
1225             }
1226             i++;
1227         }
1228     }
1229
1230     /**
1231      * Read contact list.
1232      */
1233     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1234     public void readContactList() {
1235         readContactList(knownResourceId, knownItemResourceId);
1236     }
1237
1238     /**
1239      * Read contact list.
1240      *
1241      * @param parentcsid the parentcsid
1242      * @param itemcsid the itemcsid
1243      */
1244     private void readContactList(String parentcsid, String itemcsid) {
1245         final String testName = "readContactList";
1246
1247         // Perform setup.
1248         setupReadList(testName);
1249
1250         // Submit the request to the service and store the response.
1251         PersonAuthorityClient client = new PersonAuthorityClient();
1252         ContactsCommonList list = null;
1253         ClientResponse<ContactsCommonList> res =
1254                 client.readContactList(parentcsid, itemcsid);
1255         try {
1256                 int statusCode = res.getStatus();
1257         
1258                 // Check the status code of the response: does it match
1259                 // the expected response(s)?
1260                 if(logger.isDebugEnabled()){
1261                     logger.debug(testName + ": status = " + statusCode);
1262                 }
1263                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1264                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1265                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1266         
1267                 list = res.getEntity();
1268         } finally {
1269                 res.releaseConnection();
1270         }
1271         
1272         List<ContactsCommonList.ContactListItem> listitems =
1273             list.getContactListItem();
1274         int nItemsReturned = listitems.size();
1275         // There will be one item created, associated with a
1276         // known parent resource, by the createItem test.
1277         //
1278         // In addition, there will be 'nItemsToCreateInList'
1279         // additional items created by the createItemList test,
1280         // all associated with the same parent resource.
1281         int nExpectedItems = nItemsToCreateInList + 1;
1282         if(logger.isDebugEnabled()){
1283             logger.debug(testName + ": Expected "
1284                         + nExpectedItems +" items; got: "+nItemsReturned);
1285         }
1286         Assert.assertEquals(nItemsReturned, nExpectedItems);
1287
1288         int i = 0;
1289         for (ContactsCommonList.ContactListItem listitem : listitems) {
1290                 // Optionally output additional data about list members for debugging.
1291                 boolean showDetails = false;
1292                 if (showDetails && logger.isDebugEnabled()) {
1293                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
1294                         listitem.getCsid());
1295                 logger.debug("  " + testName + ": list-item[" + i + "] addressPlace=" +
1296                         listitem.getAddressPlace());
1297                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
1298                         listitem.getUri());
1299             }
1300             i++;
1301         }
1302     }
1303
1304     // Failure outcomes
1305
1306     // There are no failure outcome tests at present.
1307
1308     // ---------------------------------------------------------------
1309     // CRUD tests : READ_LIST tests by partial term match.
1310     // ---------------------------------------------------------------
1311
1312     // Success outcomes
1313
1314     /**
1315      * Read item list by partial term.
1316      */
1317     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1318         groups = {"readListByPartialTerm"}, dependsOnGroups = {"readList"})
1319     public void readItemListByPartialTerm(String testName) {
1320         int numMatchesFound = 0;
1321         final String PARTIAL_TERM = TEST_PARTIAL_TERM_FORE_NAME;
1322         // setupCreate(testName);
1323         String newID = createItemInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
1324         numMatchesFound =
1325             readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM);
1326         final int NUM_MATCHES_EXPECTED = 1;
1327         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1328     }
1329
1330     /**
1331      * Read item list by partial term, where the case of at
1332      * least one character of the partial term doesn't match that
1333      * of the full term expected to be matched.
1334      */
1335     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1336         groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1337     public void readItemListByPartialTermNonMatchingCase(String testName) {
1338
1339         setupReadList(testName);
1340         int numMatchesFound = 0;
1341         final int NUM_MATCHES_EXPECTED = 1;
1342
1343         final String PARTIAL_TERM_LOWERCASE = TEST_PARTIAL_TERM_FORE_NAME.toLowerCase();
1344         numMatchesFound =
1345             readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_LOWERCASE);
1346         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1347
1348         final String PARTIAL_TERM_UPPERCASE = TEST_PARTIAL_TERM_FORE_NAME.toUpperCase();
1349         numMatchesFound =
1350             readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UPPERCASE);
1351         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1352
1353     }
1354
1355     /**
1356      * Read item list by partial term, with at least one Unicode UTF-8 character
1357      * (outside the USASCII range) in the partial term.
1358      */
1359     // FIXME: Test currently fails with a true UTF-8 String - need to investigate why.
1360     // Will be commented out for now until we get this working ...
1361 /*
1362     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1363         groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1364     public void readItemListByPartialTermUTF8(String testName) {
1365         int numMatchesFound = 0;
1366         final String PARTIAL_TERM_UTF8 = TEST_PARTIAL_TERM_SUR_NAME;
1367         if (logger.isDebugEnabled()) {
1368             logger.debug("Attempting match on partial term '" + PARTIAL_TERM_UTF8 + "' ...");
1369         }
1370         numMatchesFound =
1371             readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UTF8);
1372         if (logger.isDebugEnabled()) {
1373             logger.debug("Found " + numMatchesFound + " match(es).");
1374         }
1375         final int NUM_MATCHES_EXPECTED = 1;
1376         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1377     }
1378 */
1379
1380     // Failure outcomes
1381
1382     /**
1383      * Read item list by partial term, where the partial term is not
1384      * expected to be matched by any term in any resource.
1385      */
1386     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1387         groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1388     public void readItemListByNonexistentPartialTerm(String testName) {
1389         int numMatchesFound = 0;
1390         final String NON_EXISTENT_PARTIAL_TERM = "jlmbsoq";
1391         numMatchesFound =
1392             readItemListByPartialTerm(testName, knownResourceId, NON_EXISTENT_PARTIAL_TERM);
1393         final int NUM_MATCHES_EXPECTED = 0;
1394         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1395
1396     }
1397
1398
1399     /**
1400      * Read item list by partial term.
1401      *
1402      * @param testName The name of the test which has invoked this method.
1403      * @param vcsid The CSID of the authority within which partial term matching
1404      *     will be performed.
1405      * @param partialTerm A partial term to match item resources.
1406      * @return The number of item resources matched by the partial term.
1407      */
1408     private int readItemListByPartialTerm(String testName, String vcsid, String partialTerm) {
1409
1410         // Perform setup.
1411         setupReadList(testName);
1412
1413         // Submit the request to the service and store the response.
1414         PersonAuthorityClient client = new PersonAuthorityClient();
1415         ClientResponse<PersonsCommonList> res = null;
1416         if (vcsid != null) {
1417             res = client.readItemList(vcsid, partialTerm);
1418         } else {
1419             Assert.fail("readItemListByPartialTerm passed null csid!");
1420         }
1421         PersonsCommonList list = null;
1422         try {
1423             int statusCode = res.getStatus();
1424
1425             // Check the status code of the response: does it match
1426             // the expected response(s)?
1427             if(logger.isDebugEnabled()){
1428                 logger.debug(testName + ": status = " + statusCode);
1429             }
1430             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1431                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1432             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1433
1434             list = res.getEntity();
1435         } finally {
1436             res.releaseConnection();
1437         }
1438
1439         List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
1440         int nItemsReturned = items.size();
1441
1442         return nItemsReturned;
1443     }
1444
1445     // ---------------------------------------------------------------
1446     // CRUD tests : UPDATE tests
1447     // ---------------------------------------------------------------
1448     // Success outcomes
1449     /* (non-Javadoc)
1450      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1451      */
1452     @Override
1453     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1454         groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1455     public void update(String testName) throws Exception {
1456
1457         // Perform setup.
1458         setupUpdate(testName);
1459
1460         // Retrieve the contents of a resource to update.
1461         PersonAuthorityClient client = new PersonAuthorityClient();
1462         MultipartInput input = null;
1463         ClientResponse<MultipartInput> res = client.read(knownResourceId);
1464         try {
1465                 if(logger.isDebugEnabled()){
1466                     logger.debug(testName + ": read status = " + res.getStatus());
1467                 }
1468                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1469         
1470                 if(logger.isDebugEnabled()){
1471                     logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1472                 }
1473                 input = res.getEntity();
1474         } finally {
1475                 res.releaseConnection();
1476         }
1477         
1478         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1479                 client.getCommonPartName(), PersonauthoritiesCommon.class);
1480         Assert.assertNotNull(personAuthority);
1481
1482         // Update the contents of this resource.
1483         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1484         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1485         if(logger.isDebugEnabled()){
1486             logger.debug("to be updated PersonAuthority");
1487             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1488         }
1489
1490         // Submit the updated resource to the service and store the response.
1491         MultipartOutput output = new MultipartOutput();
1492         OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1493         commonPart.getHeaders().add("label", client.getCommonPartName());
1494         res = client.update(knownResourceId, output);
1495         try {
1496                 int statusCode = res.getStatus();
1497         
1498                 // Check the status code of the response: does it match the expected response(s)?
1499                 if(logger.isDebugEnabled()){
1500                     logger.debug(testName + ": status = " + statusCode);
1501                 }
1502                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1503                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1504                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1505         
1506                 // Retrieve the updated resource and verify that its contents exist.
1507                 input = (MultipartInput) res.getEntity();
1508         } finally {
1509                 res.releaseConnection();
1510         }
1511         
1512         PersonauthoritiesCommon updatedPersonAuthority =
1513                 (PersonauthoritiesCommon) extractPart(input,
1514                         client.getCommonPartName(), PersonauthoritiesCommon.class);
1515         Assert.assertNotNull(updatedPersonAuthority);
1516
1517         // Verify that the updated resource received the correct data.
1518         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1519                 personAuthority.getDisplayName(),
1520                 "Data in updated object did not match submitted data.");
1521     }
1522
1523     /**
1524      * Update item.
1525      *
1526      * @param testName the test name
1527      * @throws Exception the exception
1528      */
1529     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1530         groups = {"update"}, dependsOnMethods = {"update"})
1531     public void updateItem(String testName) throws Exception {
1532
1533         // Perform setup.
1534         setupUpdate(testName);
1535
1536         // Retrieve the contents of a resource to update.
1537         PersonAuthorityClient client = new PersonAuthorityClient();
1538         MultipartInput input = null;
1539         ClientResponse<MultipartInput> res =
1540                 client.readItem(knownResourceId, knownItemResourceId);
1541         try {
1542                 if(logger.isDebugEnabled()){
1543                     logger.debug(testName + ": read status = " + res.getStatus());
1544                 }
1545                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1546         
1547                 if(logger.isDebugEnabled()){
1548                     logger.debug("got Person to update with ID: " +
1549                         knownItemResourceId +
1550                         " in PersonAuthority: " + knownResourceId );
1551                 }
1552                 input = res.getEntity();
1553         } finally {
1554                 res.releaseConnection();
1555         }
1556         
1557         PersonsCommon person = (PersonsCommon) extractPart(input,
1558                 client.getItemCommonPartName(), PersonsCommon.class);
1559         Assert.assertNotNull(person);
1560         
1561         if (logger.isDebugEnabled() == true) {
1562                 logger.debug("About to update the following person...");
1563                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1564         }
1565
1566         // Update the contents of this resource.
1567         person.setCsid(null);
1568         person.setForeName("updated-" + person.getForeName());
1569         if(logger.isDebugEnabled()){
1570             logger.debug("to be updated Person");
1571             logger.debug(objectAsXmlString(person,
1572                 PersonsCommon.class));
1573         }    
1574         
1575         // Submit the updated resource to the service and store the response.
1576         MultipartOutput output = new MultipartOutput();
1577         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1578         commonPart.getHeaders().add("label", client.getItemCommonPartName());
1579         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1580         try {
1581                 int statusCode = res.getStatus();
1582         
1583                 // Check the status code of the response: does it match the expected response(s)?
1584                 if(logger.isDebugEnabled()){
1585                     logger.debug(testName + ": status = " + statusCode);
1586                 }
1587                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1588                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1589                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1590         
1591                 // Retrieve the updated resource and verify that its contents exist.
1592                 input = (MultipartInput) res.getEntity();
1593         } finally {
1594                 res.releaseConnection();
1595         }
1596         
1597         PersonsCommon updatedPerson =
1598                 (PersonsCommon) extractPart(input,
1599                         client.getItemCommonPartName(), PersonsCommon.class);
1600         Assert.assertNotNull(updatedPerson);
1601         
1602         if (logger.isDebugEnabled() == true) {
1603                 logger.debug("Updated to following person to:");
1604                 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1605         }        
1606
1607         // Verify that the updated resource received the correct data.
1608         Assert.assertEquals(updatedPerson.getForeName(),
1609                 person.getForeName(),
1610                 "Data in updated Person did not match submitted data.");
1611     }
1612
1613     /**
1614      * Update contact.
1615      *
1616      * @param testName the test name
1617      * @throws Exception the exception
1618      */
1619     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1620         groups = {"update"}, dependsOnMethods = {"updateItem"})
1621     public void updateContact(String testName) throws Exception {
1622         // Perform setup.
1623         setupUpdate(testName);
1624
1625         // Retrieve the contents of a resource to update.
1626         PersonAuthorityClient client = new PersonAuthorityClient();
1627         MultipartInput input = null;
1628         ClientResponse<MultipartInput> res =
1629                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1630         try {
1631                 if(logger.isDebugEnabled()){
1632                     logger.debug(testName + ": read status = " + res.getStatus());
1633                 }
1634                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1635         
1636                 if(logger.isDebugEnabled()){
1637                     logger.debug("got Contact to update with ID: " +
1638                         knownContactResourceId +
1639                         " in item: " + knownItemResourceId +
1640                         " in parent: " + knownResourceId );
1641                 }
1642                 input = res.getEntity();
1643         } finally {
1644                 res.releaseConnection();
1645         }
1646         
1647         ContactsCommon contact = (ContactsCommon) extractPart(input,
1648                 new ContactClient().getCommonPartName(), ContactsCommon.class);
1649         Assert.assertNotNull(contact);
1650
1651         // Update the contents of this resource.
1652         contact.setAddressPlace("updated-" + contact.getAddressPlace());
1653         if(logger.isDebugEnabled()){
1654             logger.debug("to be updated Contact");
1655             logger.debug(objectAsXmlString(contact,
1656                 ContactsCommon.class));
1657         }
1658
1659         // Submit the updated resource to the service and store the response.
1660         MultipartOutput output = new MultipartOutput();
1661         OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1662         commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1663         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1664         try {
1665                 int statusCode = res.getStatus();
1666         
1667                 // Check the status code of the response: does it match the expected response(s)?
1668                 if(logger.isDebugEnabled()){
1669                     logger.debug(testName + ": status = " + statusCode);
1670                 }
1671                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1672                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1673                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1674         
1675                 // Retrieve the updated resource and verify that its contents exist.
1676                 input = (MultipartInput) res.getEntity();
1677         } finally {
1678                 res.releaseConnection();
1679         }
1680         ContactsCommon updatedContact =
1681                 (ContactsCommon) extractPart(input,
1682                         new ContactClient().getCommonPartName(), ContactsCommon.class);
1683         Assert.assertNotNull(updatedContact);
1684
1685         // Verify that the updated resource received the correct data.
1686         Assert.assertEquals(updatedContact.getAddressPlace(),
1687                 contact.getAddressPlace(),
1688                 "Data in updated Contact did not match submitted data.");
1689     }
1690
1691     // Failure outcomes
1692     // Placeholders until the three tests below can be uncommented.
1693     // See Issue CSPACE-401.
1694     /* (non-Javadoc)
1695      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1696      */
1697     @Override
1698     public void updateWithEmptyEntityBody(String testName) throws Exception {
1699         //Should this really be empty?
1700     }
1701
1702     /* (non-Javadoc)
1703      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1704      */
1705     @Override
1706     public void updateWithMalformedXml(String testName) throws Exception {
1707         //Should this really be empty?
1708     }
1709
1710     /* (non-Javadoc)
1711      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1712      */
1713     @Override
1714     public void updateWithWrongXmlSchema(String testName) throws Exception {
1715         //Should this really be empty?
1716     }
1717
1718 /*
1719     @Override
1720     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1721         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1722     public void updateWithEmptyEntityBody(String testName) throws Exception {
1723
1724     // Perform setup.
1725     setupUpdateWithEmptyEntityBody(testName);
1726
1727     // Submit the request to the service and store the response.
1728     String method = REQUEST_TYPE.httpMethodName();
1729     String url = getResourceURL(knownResourceId);
1730     String mediaType = MediaType.APPLICATION_XML;
1731     final String entity = "";
1732     int statusCode = submitRequest(method, url, mediaType, entity);
1733
1734     // Check the status code of the response: does it match
1735     // the expected response(s)?
1736     if(logger.isDebugEnabled()){
1737         logger.debug(testName + ": url=" + url +
1738             " status=" + statusCode);
1739      }
1740     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1741     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1742     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1743     }
1744
1745     @Override
1746     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1747         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1748     public void updateWithMalformedXml(String testName) throws Exception {
1749
1750     // Perform setup.
1751     setupUpdateWithMalformedXml(testName);
1752
1753     // Submit the request to the service and store the response.
1754     String method = REQUEST_TYPE.httpMethodName();
1755     String url = getResourceURL(knownResourceId);
1756     String mediaType = MediaType.APPLICATION_XML;
1757     final String entity = MALFORMED_XML_DATA;
1758     int statusCode = submitRequest(method, url, mediaType, entity);
1759
1760     // Check the status code of the response: does it match
1761     // the expected response(s)?
1762     if(logger.isDebugEnabled()){
1763         logger.debug(testName + ": url=" + url +
1764            " status=" + statusCode);
1765      }
1766     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1767     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1768     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1769     }
1770
1771     @Override
1772     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1773         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1774     public void updateWithWrongXmlSchema(String testName) throws Exception {
1775
1776     // Perform setup.
1777     setupUpdateWithWrongXmlSchema(testName);
1778
1779     // Submit the request to the service and store the response.
1780     String method = REQUEST_TYPE.httpMethodName();
1781     String url = getResourceURL(knownResourceId);
1782     String mediaType = MediaType.APPLICATION_XML;
1783     final String entity = WRONG_XML_SCHEMA_DATA;
1784     int statusCode = submitRequest(method, url, mediaType, entity);
1785
1786     // Check the status code of the response: does it match
1787     // the expected response(s)?
1788     if(logger.isDebugEnabled()){
1789         logger.debug("updateWithWrongXmlSchema: url=" + url +
1790             " status=" + statusCode);
1791      }
1792     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1793     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1794     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1795     }
1796 */
1797
1798     /* (non-Javadoc)
1799  * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1800  */
1801 @Override
1802     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1803         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1804     public void updateNonExistent(String testName) throws Exception {
1805
1806         // Perform setup.
1807         setupUpdateNonExistent(testName);
1808
1809         // Submit the request to the service and store the response.
1810         // Note: The ID(s) used when creating the request payload may be arbitrary.
1811         // The only relevant ID may be the one used in update(), below.
1812         PersonAuthorityClient client = new PersonAuthorityClient();
1813         String displayName = "displayName-NON_EXISTENT_ID";
1814         String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1815         MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1816                                 displayName, fullRefName, client.getCommonPartName());
1817         ClientResponse<MultipartInput> res =
1818                 client.update(NON_EXISTENT_ID, multipart);
1819         try {
1820                 int statusCode = res.getStatus();
1821         
1822                 // Check the status code of the response: does it match
1823                 // the expected response(s)?
1824                 if(logger.isDebugEnabled()){
1825                     logger.debug(testName + ": status = " + statusCode);
1826                 }
1827                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1828                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1829                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1830         } finally {
1831                 res.releaseConnection();
1832         }
1833     }
1834
1835     /**
1836      * Update non existent item.
1837      *
1838      * @param testName the test name
1839      * @throws Exception the exception
1840      */
1841     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1842         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1843     public void updateNonExistentItem(String testName) throws Exception {
1844
1845         // Perform setup.
1846         setupUpdateNonExistent(testName);
1847
1848         // Submit the request to the service and store the response.
1849         // Note: The ID used in this 'create' call may be arbitrary.
1850         // The only relevant ID may be the one used in update(), below.
1851         PersonAuthorityClient client = new PersonAuthorityClient();
1852         Map<String, String> nonexMap = new HashMap<String,String>();
1853         nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1854         nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1855         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1856         MultipartOutput multipart = 
1857         PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, 
1858                         PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1859                         client.getItemCommonPartName() );
1860         ClientResponse<MultipartInput> res =
1861                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1862         try {
1863                 int statusCode = res.getStatus();
1864         
1865                 // Check the status code of the response: does it match
1866                 // the expected response(s)?
1867                 if(logger.isDebugEnabled()){
1868                     logger.debug(testName + ": status = " + statusCode);
1869                 }
1870                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1871                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1872                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1873         } finally {
1874                 res.releaseConnection();
1875         }
1876     }
1877
1878     /**
1879      * Update non existent contact.
1880      *
1881      * @param testName the test name
1882      * @throws Exception the exception
1883      */
1884     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1885         groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1886     public void updateNonExistentContact(String testName) throws Exception {
1887         // Currently a no-op test
1888     }
1889
1890     // ---------------------------------------------------------------
1891     // CRUD tests : DELETE tests
1892     // ---------------------------------------------------------------
1893     // Success outcomes
1894
1895     // Note: delete sub-resources in ascending hierarchical order,
1896     // before deleting their parents.
1897
1898     /**
1899      * Delete contact.
1900      *
1901      * @param testName the test name
1902      * @throws Exception the exception
1903      */
1904     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, 
1905         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1906     public void deleteContact(String testName) throws Exception {
1907
1908         // Perform setup.
1909         setupDelete(testName);
1910
1911          if(logger.isDebugEnabled()){
1912             logger.debug("parentcsid =" + knownResourceId +
1913                 " itemcsid = " + knownItemResourceId +
1914                 " csid = " + knownContactResourceId);
1915         }
1916
1917         // Submit the request to the service and store the response.
1918         PersonAuthorityClient client = new PersonAuthorityClient();
1919         ClientResponse<Response> res =
1920             client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1921         int statusCode = res.getStatus();
1922         res.releaseConnection();
1923
1924         // Check the status code of the response: does it match
1925         // the expected response(s)?
1926         if(logger.isDebugEnabled()){
1927             logger.debug(testName + ": status = " + statusCode);
1928         }
1929         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1930                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1931         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1932     }
1933
1934    /**
1935     * Delete item.
1936     *
1937     * @param testName the test name
1938     * @throws Exception the exception
1939     */
1940    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1941         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1942     public void deleteItem(String testName) throws Exception {
1943
1944         // Perform setup.
1945         setupDelete(testName);
1946
1947         if(logger.isDebugEnabled()){
1948             logger.debug("parentcsid =" + knownResourceId +
1949                 " itemcsid = " + knownItemResourceId);
1950         }
1951
1952         // Submit the request to the service and store the response.
1953         PersonAuthorityClient client = new PersonAuthorityClient();
1954         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1955         int statusCode = res.getStatus();
1956         res.releaseConnection();
1957
1958         // Check the status code of the response: does it match
1959         // the expected response(s)?
1960         if(logger.isDebugEnabled()){
1961             logger.debug(testName + ": status = " + statusCode);
1962         }
1963         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1964                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1965         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1966     }
1967
1968     /* (non-Javadoc)
1969      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1970      */
1971     @Override
1972     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1973         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1974     public void delete(String testName) throws Exception {
1975
1976         // Perform setup.
1977         setupDelete(testName);
1978
1979         if(logger.isDebugEnabled()){
1980             logger.debug("parentcsid =" + knownResourceId);
1981         }
1982
1983         // Submit the request to the service and store the response.
1984         PersonAuthorityClient client = new PersonAuthorityClient();
1985         ClientResponse<Response> res = client.delete(knownResourceId);
1986         int statusCode = res.getStatus();
1987         res.releaseConnection();
1988
1989         // Check the status code of the response: does it match
1990         // the expected response(s)?
1991         if(logger.isDebugEnabled()){
1992             logger.debug(testName + ": status = " + statusCode);
1993         }
1994         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1995                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1996         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1997     }
1998
1999     // Failure outcomes
2000     /* (non-Javadoc)
2001      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
2002      */
2003     @Override
2004     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2005         groups = {"delete"}, dependsOnMethods = {"delete"})
2006     public void deleteNonExistent(String testName) throws Exception {
2007
2008         // Perform setup.
2009         setupDeleteNonExistent(testName);
2010
2011         // Submit the request to the service and store the response.
2012         PersonAuthorityClient client = new PersonAuthorityClient();
2013         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
2014         int statusCode = res.getStatus();
2015         res.releaseConnection();
2016
2017         // Check the status code of the response: does it match
2018         // the expected response(s)?
2019         if(logger.isDebugEnabled()){
2020             logger.debug(testName + ": status = " + statusCode);
2021         }
2022         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2023                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2024         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2025     }
2026
2027     /**
2028      * Delete non existent item.
2029      *
2030      * @param testName the test name
2031      */
2032     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2033         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2034     public void deleteNonExistentItem(String testName) {
2035
2036         // Perform setup.
2037         setupDeleteNonExistent(testName);
2038
2039         // Submit the request to the service and store the response.
2040         PersonAuthorityClient client = new PersonAuthorityClient();
2041         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
2042         int statusCode = res.getStatus();
2043         res.releaseConnection();
2044
2045         // Check the status code of the response: does it match
2046         // the expected response(s)?
2047         if(logger.isDebugEnabled()){
2048             logger.debug(testName + ": status = " + statusCode);
2049         }
2050         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2051                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2052         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2053     }
2054
2055     /**
2056      * Delete non existent contact.
2057      *
2058      * @param testName the test name
2059      */
2060     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2061         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2062     public void deleteNonExistentContact(String testName) {
2063
2064         // Perform setup.
2065         setupDeleteNonExistent(testName);
2066
2067         // Submit the request to the service and store the response.
2068         PersonAuthorityClient client = new PersonAuthorityClient();
2069         ClientResponse<Response> res =
2070             client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2071         int statusCode = res.getStatus();
2072         res.releaseConnection();
2073
2074         // Check the status code of the response: does it match
2075         // the expected response(s)?
2076         if(logger.isDebugEnabled()){
2077             logger.debug(testName + ": status = " + statusCode);
2078         }
2079         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2080                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2081         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2082     }
2083
2084     // ---------------------------------------------------------------
2085     // Utility tests : tests of code used in tests above
2086     // ---------------------------------------------------------------
2087     /**
2088      * Tests the code for manually submitting data that is used by several
2089      * of the methods above.
2090      */
2091     @Test(dependsOnMethods = {"create", "read"})
2092     public void testSubmitRequest() {
2093
2094         // Expected status code: 200 OK
2095         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2096
2097         // Submit the request to the service and store the response.
2098         String method = ServiceRequestType.READ.httpMethodName();
2099         String url = getResourceURL(knownResourceId);
2100         int statusCode = submitRequest(method, url);
2101
2102         // Check the status code of the response: does it match
2103         // the expected response(s)?
2104         if(logger.isDebugEnabled()){
2105             logger.debug("testSubmitRequest: url=" + url +
2106                 " status=" + statusCode);
2107         }
2108         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2109
2110     }
2111
2112     /**
2113      * Test item submit request.
2114      */
2115     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2116     public void testItemSubmitRequest() {
2117
2118         // Expected status code: 200 OK
2119         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2120
2121         // Submit the request to the service and store the response.
2122         String method = ServiceRequestType.READ.httpMethodName();
2123         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2124         int statusCode = submitRequest(method, url);
2125
2126         // Check the status code of the response: does it match
2127         // the expected response(s)?
2128         if(logger.isDebugEnabled()){
2129             logger.debug("testItemSubmitRequest: url=" + url +
2130                 " status=" + statusCode);
2131         }
2132         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2133
2134     }
2135
2136     /**
2137      * Test contact submit request.
2138      */
2139     @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2140     public void testContactSubmitRequest() {
2141
2142         // Expected status code: 200 OK
2143         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2144
2145         // Submit the request to the service and store the response.
2146         String method = ServiceRequestType.READ.httpMethodName();
2147         String url = getContactResourceURL(knownResourceId,
2148             knownItemResourceId, knownContactResourceId);
2149         int statusCode = submitRequest(method, url);
2150
2151         // Check the status code of the response: does it match
2152         // the expected response(s)?
2153         if(logger.isDebugEnabled()){
2154             logger.debug("testItemSubmitRequest: url=" + url +
2155                 " status=" + statusCode);
2156         }
2157         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2158
2159     }
2160
2161
2162     // ---------------------------------------------------------------
2163     // Cleanup of resources created during testing
2164     // ---------------------------------------------------------------
2165     
2166     /**
2167      * Deletes all resources created by tests, after all tests have been run.
2168      *
2169      * This cleanup method will always be run, even if one or more tests fail.
2170      * For this reason, it attempts to remove all resources created
2171      * at any point during testing, even if some of those resources
2172      * may be expected to be deleted by certain tests.
2173      */
2174
2175     @AfterClass(alwaysRun=true)
2176     @Override
2177     public void cleanUp() {
2178         String noTest = System.getProperty("noTestCleanup");
2179         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2180             if (logger.isDebugEnabled()) {
2181                 logger.debug("Skipping Cleanup phase ...");
2182             }
2183             return;
2184         }
2185         if (logger.isDebugEnabled()) {
2186             logger.debug("Cleaning up temporary resources created for testing ...");
2187         }
2188         String parentResourceId;
2189         String itemResourceId;
2190         String contactResourceId;
2191         // Clean up contact resources.
2192         PersonAuthorityClient client = new PersonAuthorityClient();
2193         parentResourceId = knownResourceId;
2194         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2195             contactResourceId = entry.getKey();
2196             itemResourceId = entry.getValue();
2197             // Note: Any non-success responses from the delete operation
2198             // below are ignored and not reported.
2199             ClientResponse<Response> res =
2200                 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2201             res.releaseConnection();
2202         }
2203         // Clean up item resources.
2204         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2205             itemResourceId = entry.getKey();
2206             parentResourceId = entry.getValue();
2207             // Note: Any non-success responses from the delete operation
2208             // below are ignored and not reported.
2209             ClientResponse<Response> res =
2210                 client.deleteItem(parentResourceId, itemResourceId);
2211             res.releaseConnection();
2212         }
2213         // Clean up parent resources.
2214         super.cleanUp();
2215     }
2216
2217     // ---------------------------------------------------------------
2218     // Utility methods used by tests above
2219     // ---------------------------------------------------------------
2220     /* (non-Javadoc)
2221      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2222      */
2223     @Override
2224     public String getServicePathComponent() {
2225         return SERVICE_PATH_COMPONENT;
2226     }
2227
2228     /**
2229      * Gets the item service path component.
2230      *
2231      * @return the item service path component
2232      */
2233     public String getItemServicePathComponent() {
2234         return ITEM_SERVICE_PATH_COMPONENT;
2235     }
2236
2237     /**
2238      * Gets the contact service path component.
2239      *
2240      * @return the contact service path component
2241      */
2242     public String getContactServicePathComponent() {
2243         return CONTACT_SERVICE_PATH_COMPONENT;
2244     }
2245
2246     /**
2247      * Returns the root URL for the item service.
2248      *
2249      * This URL consists of a base URL for all services, followed by
2250      * a path component for the owning parent, followed by the
2251      * path component for the items.
2252      *
2253      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2254      * parent authority resource of the relevant item resource.
2255      *
2256      * @return The root URL for the item service.
2257      */
2258     protected String getItemServiceRootURL(String parentResourceIdentifier) {
2259         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2260     }
2261
2262     /**
2263      * Returns the URL of a specific item resource managed by a service, and
2264      * designated by an identifier (such as a universally unique ID, or UUID).
2265      *
2266      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2267      * parent authority resource of the relevant item resource.
2268      *
2269      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2270      * item resource.
2271      *
2272      * @return The URL of a specific item resource managed by a service.
2273      */
2274     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2275         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2276     }
2277
2278
2279     /**
2280      * Returns the root URL for the contact service.
2281      *
2282      * This URL consists of a base URL for all services, followed by
2283      * a path component for the owning authority, followed by the
2284      * path component for the owning item, followed by the path component
2285      * for the contact service.
2286      *
2287      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2288      * parent authority resource of the relevant item resource.
2289      *
2290      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2291      * item resource.
2292      *
2293      * @return The root URL for the contact service.
2294      */
2295     protected String getContactServiceRootURL(String parentResourceIdentifier,
2296         String itemResourceIdentifier) {
2297         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2298                 getContactServicePathComponent();
2299     }
2300
2301     /**
2302      * Returns the URL of a specific contact resource managed by a service, and
2303      * designated by an identifier (such as a universally unique ID, or UUID).
2304      *
2305      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2306      * parent resource of the relevant item resource.
2307      *
2308      * @param  resourceIdentifier  An identifier (such as a UUID) for an
2309      * item resource.
2310      *
2311      * @return The URL of a specific resource managed by a service.
2312      */
2313     protected String getContactResourceURL(String parentResourceIdentifier,
2314         String itemResourceIdentifier, String contactResourceIdentifier) {
2315         return getContactServiceRootURL(parentResourceIdentifier,
2316             itemResourceIdentifier) + "/" + contactResourceIdentifier;
2317     }
2318 }