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