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