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