]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e6f43feb1d99dc83aadfc752612103af95b13e0a
[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
30 import javax.ws.rs.core.Response;
31
32 import org.collectionspace.services.client.AbstractCommonListUtils;
33 import org.collectionspace.services.client.AuthorityClient;
34 import org.collectionspace.services.client.CollectionSpaceClient;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.client.ContactClient;
38 import org.collectionspace.services.client.ContactClientUtils;
39 import org.collectionspace.services.contact.AddressGroup;
40 import org.collectionspace.services.contact.AddressGroupList;
41 import org.collectionspace.services.contact.ContactsCommon;
42 import org.collectionspace.services.client.PersonAuthorityClient;
43 import org.collectionspace.services.client.PersonAuthorityClientUtils;
44 import org.collectionspace.services.jaxb.AbstractCommonList;
45 import org.collectionspace.services.PersonJAXBSchema;
46 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
47 import org.collectionspace.services.person.PersonauthoritiesCommon;
48 import org.collectionspace.services.person.PersonTermGroup;
49 import org.collectionspace.services.person.PersonTermGroupList;
50 import org.collectionspace.services.person.PersonsCommon;
51
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
57
58 /**
59  * PersonAuthorityServiceTest, carries out tests against a
60  * deployed and running PersonAuthority Service.
61  *
62  * $LastChangedRevision: 753 $
63  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
64  */
65 public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<PersonauthoritiesCommon, PersonsCommon> { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
66
67     /** The logger. */
68     private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
69     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
70     
71     /**
72      * Default constructor.  Used to set the short ID for all tests authority items
73      */
74     public PersonAuthorityServiceTest() {
75         super();
76         TEST_SHORTID = "johnWayneActor";
77     }
78     
79     @Override
80         protected String getTestAuthorityItemShortId() {
81                 return getTestAuthorityItemShortId(true); // The short ID of every person item we create should be unique
82         }
83
84     @Override
85     public String getServicePathComponent() {
86         return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
87     }
88
89     @Override
90     protected String getServiceName() {
91         return PersonAuthorityClient.SERVICE_NAME;
92     }
93
94     public String getItemServicePathComponent() {
95         return AuthorityClient.ITEMS;
96     }
97     
98     /** The test forename. */
99     final String TEST_FORE_NAME = "John";
100     /** The test middle name. */
101     final String TEST_MIDDLE_NAME = null;
102     /** The test surname. */
103     final String TEST_SUR_NAME = "Wayne";
104     /** The test birthdate. */
105     final String TEST_BIRTH_DATE = "May 26, 1907";
106     /** The test death date. */
107     final String TEST_DEATH_DATE = "June 11, 1979";
108     //private String knownResourceRefName = null;
109     private String knownItemResourceShortIdentifer = null;
110     /** The known contact resource id. */
111     private String knownContactResourceId = null;
112     /** The all contact resource ids created. */
113     private Map<String, String> allContactResourceIdsCreated =
114             new HashMap<String, String>();
115
116     
117     protected void setKnownResource(String id, String shortIdentifer,
118             String refName) {
119         knownResourceId = id;
120         knownResourceShortIdentifer = shortIdentifer;
121         //knownResourceRefName = refName;
122     }
123
124     protected void setKnownItemResource(String id, String shortIdentifer) {
125         knownItemResourceId = id;
126         knownItemResourceShortIdentifer = shortIdentifer;
127     }
128
129     /* (non-Javadoc)
130      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
131      */
132     @Override
133     protected CollectionSpaceClient getClientInstance() {
134         return new PersonAuthorityClient();
135     }
136     
137         @Override
138         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
139         return new PersonAuthorityClient(clientPropertiesFilename);
140         }
141
142     // ---------------------------------------------------------------
143     // CRUD tests : CREATE tests
144     // ---------------------------------------------------------------
145
146         /* (non-Javadoc)
147      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
148      */
149     @Override
150     public void create(String testName) throws Exception {
151         // Perform setup, such as initializing the type of service request
152         // (e.g. CREATE, DELETE), its valid and expected status codes, and
153         // its associated HTTP method name (e.g. POST, DELETE).
154         setupCreate();
155
156         // Submit the request to the service and store the response.
157         PersonAuthorityClient client = new PersonAuthorityClient();
158         String shortId = createIdentifier();
159         String displayName = "displayName-" + shortId;
160         //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
161         PoxPayloadOut multipart =
162                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
163                 displayName, shortId, client.getCommonPartName());
164
165         String newID = null;
166         Response res = client.create(multipart);
167         try {
168                 assertStatusCode(res, testName);
169             newID = extractId(res);
170         } finally {
171                 if (res != null) {
172                         res.close();
173                 }
174         }
175         // Save values for additional tests
176         if (knownResourceId == null) {
177             setKnownResource(newID, shortId, null ); //baseRefName);
178             if (logger.isDebugEnabled()) {
179                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
180             }
181         }
182         // Store the IDs from every resource created by tests,
183         // so they can be deleted after tests have been run.
184         allResourceIdsCreated.add(newID);
185     }
186
187     @Override
188     protected PoxPayloadOut createInstance(String identifier) {
189         PersonAuthorityClient client = new PersonAuthorityClient();
190         String displayName = "displayName-" + identifier;
191         PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
192                 displayName, identifier, client.getCommonPartName());
193         return multipart;
194     }
195
196     @Override
197     protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
198         String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
199         
200         HashMap<String, String> personInfo = new HashMap<String, String>();
201         String shortId = "MarkTwainAuthor" + identifier;
202         personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
203         
204         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
205         PersonTermGroup term = new PersonTermGroup();
206         term.setTermDisplayName("Mark Twain Primary");
207         term.setTermName("MarkTwainPrimary");
208         terms.add(term);
209         
210         term = new PersonTermGroup();
211         term.setTermDisplayName("Samuel Langhorne Clemens");
212         term.setTermName("SamuelLanghorneClemens");
213         terms.add(term);        
214         
215         term = new PersonTermGroup();
216         term.setTermDisplayName("Sam Clemens");
217         term.setTermName("SamClemens");
218         terms.add(term);   
219         
220         term = new PersonTermGroup();
221         term.setTermDisplayName("Huck Fin");
222         term.setTermName("Huck Fin");
223         terms.add(term);           
224         
225         return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, terms, headerLabel);
226     }
227
228     
229     /**
230      * Creates an item in an authority, using test data.
231      *
232      * @param vcsid the vcsid
233      * @param authRefName the auth ref name
234      * @return the string
235      */
236     @Override
237     protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId) {
238
239         final String testName = "createItemInAuthority";
240         if (logger.isDebugEnabled()) {
241             logger.debug(testName + ":" + vcsid + "...");
242         }
243
244         Map<String, String> johnWayneMap = new HashMap<String, String>();
245         //
246         // Fill the property map
247         //
248         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
249         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
250         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
251         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
252         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
253         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better"
254                 + "known by his stage name John Wayne, was an American film actor, director "
255                 + "and producer. He epitomized rugged masculinity and has become an enduring "
256                 + "American icon. He is famous for his distinctive voice, walk and height. "
257                 + "He was also known for his conservative political views and his support in "
258                 + "the 1950s for anti-communist positions.");
259
260         List<PersonTermGroup> johnWayneTerms = new ArrayList<PersonTermGroup>();
261         PersonTermGroup term = new PersonTermGroup();
262         term.setTermDisplayName("John Wayne DisplayName");
263         term.setTermName("John Wayne");
264         term.setForeName(TEST_FORE_NAME);
265         term.setSurName(TEST_SUR_NAME);
266         johnWayneTerms.add(term);
267
268         Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String, List<String>>();
269         List<String> johnWayneGroups = new ArrayList<String>();
270         johnWayneGroups.add("Irish");
271         johnWayneGroups.add("Scottish");
272         johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
273
274         return createItemInAuthority(client, vcsid, null /*authRefName*/, shortId, johnWayneMap, johnWayneTerms, johnWayneRepeatablesMap);
275
276     }
277
278     /**
279      * Creates an item in an authority.
280      *
281      * @param vcsid the vcsid
282      * @param authRefName the auth ref name
283      * @param itemFieldProperties a set of properties specifying the values of fields.
284      * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
285      * @return the string
286      */
287     private String createItemInAuthority(AuthorityClient client, String vcsid, String authRefName, String shortId,
288             Map<String, String> itemFieldProperties, List<PersonTermGroup> terms, Map<String, List<String>> itemRepeatableFieldProperties) {
289
290         final String testName = "createItemInAuthority";
291         if (logger.isDebugEnabled()) {
292             logger.debug(testName + ":" + vcsid + "...");
293         }
294
295         // Submit the request to the service and store the response.
296         if (client == null) {
297                 client = new PersonAuthorityClient();
298         }
299         PoxPayloadOut multipart =
300                 PersonAuthorityClientUtils.createPersonInstance(vcsid, null /*authRefName*/, itemFieldProperties,
301                 terms, itemRepeatableFieldProperties, client.getItemCommonPartName());
302         setupCreate();
303         Response res = client.createItem(vcsid, multipart);
304         String newID = null;
305         try {
306                 assertStatusCode(res, testName);
307             newID = PersonAuthorityClientUtils.extractId(res);
308         } finally {
309                 if (res != null) {
310                         res.close();
311                 }
312         }
313
314         // Store the ID returned from the first item resource created
315         // for additional tests below.
316         if (knownItemResourceId == null) {
317             setKnownItemResource(newID, shortId);
318             if (logger.isDebugEnabled()) {
319                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
320             }
321         }
322         
323         if (logger.isDebugEnabled()) {
324             logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")");
325         }
326
327         // Store the IDs from any item resources created
328         // by tests, along with the IDs of their parents, so these items
329         // can be deleted after all tests have been run.
330         allResourceItemIdsCreated.put(newID, vcsid);
331
332         return newID;
333     }
334
335     /**
336      * Creates the contact.
337      *
338      * @param testName the test name
339      */
340     @Test(dataProvider = "testName", groups = {"create"},
341                 dependsOnMethods = {"createItem"})
342     public void createContact(String testName) {
343         setupCreate();
344         createContactInItem(knownResourceId, knownItemResourceId);
345     }
346
347     /**
348      * Creates the contact in item.
349      *
350      * @param parentcsid the parentcsid
351      * @param itemcsid the itemcsid
352      * @return the string
353      */
354     private String createContactInItem(String parentcsid, String itemcsid) {
355
356         final String testName = "createContactInItem";
357         if (logger.isDebugEnabled()) {
358             logger.debug(testName + ":...");
359         }
360         // Submit the request to the service and store the response.
361         PersonAuthorityClient client = new PersonAuthorityClient();
362         String identifier = createIdentifier();
363         PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
364                 itemcsid, identifier, new ContactClient().getCommonPartName());
365
366         setupCreate();
367         Response res = client.createContact(parentcsid, itemcsid, multipart);
368         String newID = null;
369         try {
370                 assertStatusCode(res, testName);
371             newID = PersonAuthorityClientUtils.extractId(res);
372         } finally {
373                 if (res != null) {
374                         res.close();
375                 }
376         }
377
378         // Store the ID returned from the first contact resource created
379         // for additional tests below.
380         if (knownContactResourceId == null) {
381             knownContactResourceId = newID;
382             if (logger.isDebugEnabled()) {
383                 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
384             }
385         }
386
387         // Store the IDs from any contact resources created
388         // by tests, along with the IDs of their parent items,
389         // so these items can be deleted after all tests have been run.
390         allContactResourceIdsCreated.put(newID, itemcsid);
391
392         return newID;
393     }
394
395     /**
396      * Attempts to create an authority with an short identifier that contains
397      * non-word characters.
398      *
399      * @param testName the test name
400      */
401     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"})
402     public void createWithShortIdNonWordChars(String testName) throws Exception {
403         testExpectedStatusCode = STATUS_BAD_REQUEST;
404         testRequestType = ServiceRequestType.CREATE;
405         testSetup(testExpectedStatusCode, testRequestType);
406
407         // Create the payload to be included in the body of the request
408         PersonAuthorityClient client = new PersonAuthorityClient();
409         String shortId = createIdentifier() + "*" + createIdentifier();
410         String displayName = "displayName-" + shortId;
411         PoxPayloadOut multipart =
412                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
413                 displayName, shortId, client.getCommonPartName());
414
415         // Submit the request to the service and store the response.
416         Response res = client.create(multipart);
417         // Check the status code of the response: does it match
418         // the expected response(s)?  We expect failure here.
419         try {
420                 assertStatusCode(res, testName);
421         } finally {
422                 if (res != null) {
423                         res.close();
424                 }
425         }
426     }
427
428     /**
429      * Attempts to create an item with an short identifier that contains
430      * non-word characters.
431      *
432      * @param testName the test name
433      */
434     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"},
435                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractServiceTestImpl.create"})
436     public void createItemWithShortIdNonWordChars(String testName) {
437         testExpectedStatusCode = STATUS_BAD_REQUEST;
438         testRequestType = ServiceRequestType.CREATE;
439         testSetup(testExpectedStatusCode, testRequestType);
440
441         PersonAuthorityClient client = new PersonAuthorityClient();
442         // Create the payload to be included in the body of the request
443         String shortId = "7-Eleven";
444         Map<String, String> fieldProperties = new HashMap<String, String>();
445         fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
446         
447         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
448         PersonTermGroup term = new PersonTermGroup();
449         term.setTermDisplayName(shortId);
450         term.setTermName(shortId);
451         terms.add(term);
452         
453         final Map<String, List<String>> NULL_REPEATABLE_FIELD_PROPERTIES = null;
454         PoxPayloadOut multipart =
455                 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
456                 null /*knownResourceRefName*/, fieldProperties, terms,
457                 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
458
459         // Send the request and receive a response
460         Response res = client.createItem(knownResourceId, multipart);
461         // Check the status code of the response: does it match
462         // the expected response(s)?  We expect failure here, so there will be no
463         // new ID to keep track of for later cleanup.
464         try {
465                 assertStatusCode(res, testName);
466         } finally {
467                 if (res != null) {
468                         res.close();
469                 }
470         }        
471     }
472
473     // ---------------------------------------------------------------
474     // CRUD tests : CREATE LIST tests
475     // ---------------------------------------------------------------
476     // Success outcomes
477     /* (non-Javadoc)
478      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
479      */
480     @Override
481 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
482 //    groups = {"createList"}, dependsOnGroups = {"create"})
483     public void createList(String testName) throws Exception {
484         for (int i = 0; i < nItemsToCreateInList; i++) {
485             create(testName);
486         }
487     }
488
489     /**
490      * Creates the contact list.
491      *
492      * @param testName the test name
493      * @throws Exception the exception
494      */
495     @Test(dataProvider = "testName", groups = {"createList"},
496                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.createItemList"})
497     public void createContactList(String testName) throws Exception {
498         // Add contacts to the initially-created, known item record.
499         for (int j = 0; j < nItemsToCreateInList; j++) {
500             createContact(testName);
501         }
502     }
503
504     // ---------------------------------------------------------------
505     // CRUD tests : READ tests
506     // ---------------------------------------------------------------
507     // Success outcomes
508     /* (non-Javadoc)
509      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
510      */
511     @Override
512 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
513 //    groups = {"read"}, dependsOnGroups = {"create"})
514     public void read(String testName) throws Exception {
515         readInternal(testName, knownResourceId, null);
516     }
517
518     /**
519      * Read by name.
520      *
521      * @param testName the test name
522      * @throws Exception the exception
523      */
524     @Override
525 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
526 //    groups = {"read"}, dependsOnMethods = {"read"})
527     public void readByName(String testName) throws Exception {
528         readInternal(testName, null, knownResourceShortIdentifer);
529     }
530
531     protected void readInternal(String testName, String CSID, String shortId) {
532         // Submit the request to the service and store the response.
533         PersonAuthorityClient client = new PersonAuthorityClient();
534         Response res = null;
535         setupRead();
536         if (CSID != null) {
537             res = client.read(CSID);
538         } else if (shortId != null) {
539             res = client.readByName(shortId);
540         } else {
541             Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
542         }
543         try {
544             assertStatusCode(res, testName);
545             //FIXME: remove the following try catch once Aron fixes signatures
546             try {
547                 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
548                 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
549                         client.getCommonPartName(), PersonauthoritiesCommon.class);
550                 Assert.assertNotNull(personAuthority);
551             } catch (Exception e) {
552                 throw new RuntimeException(e);
553             }
554         } finally {
555                 if (res != null) {
556                 res.close();
557             }
558         }
559     }
560
561     /**
562      * Read named item.
563      *
564      * @param testName the test name
565      * @throws Exception the exception
566      */
567     @Test(dataProvider = "testName", groups = {"readItem", "readNamedItemInNamedAuth"},
568                 dependsOnMethods = {"readItemInNamedAuth"})
569     public void readNamedItem(String testName) throws Exception {
570         readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
571     }
572
573     /**
574      * Read item in Named Auth.
575      *
576      * @param testName the test name
577      * @throws Exception the exception
578      */
579     @Test(dataProvider = "testName", groups = {"readItem"},
580                 dependsOnMethods = {"readItem"})
581     public void readItemInNamedAuth(String testName) throws Exception {
582         readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
583     }
584
585     
586     /**
587      * Read Named item in Named Auth.
588      *
589      * @param testName the test name
590      * @throws Exception the exception
591      */
592     @Test(dataProvider = "testName", groups = {"readItem"},
593                 dependsOnMethods = {"readNamedItem"})
594     public void readNamedItemInNamedAuth(String testName) throws Exception {
595         readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
596     }
597
598     protected void readItemInternal(String testName,
599             String authCSID, String authShortId, String itemCSID, String itemShortId)
600             throws Exception {
601
602         if (logger.isDebugEnabled()) {
603             logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/"
604                     + ((itemCSID != null) ? authCSID : itemShortId));
605         }
606
607         // Submit the request to the service and store the response.
608         PersonAuthorityClient client = new PersonAuthorityClient();
609         setupRead();
610         Response res = null;
611         if (authCSID != null) {
612             if (itemCSID != null) {
613                 res = client.readItem(authCSID, itemCSID);
614             } else if (itemShortId != null) {
615                 res = client.readNamedItem(authCSID, itemShortId);
616             } else {
617                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
618             }
619         } else if (authShortId != null) {
620             if (itemCSID != null) {
621                 res = client.readItemInNamedAuthority(authShortId, itemCSID);
622             } else if (itemShortId != null) {
623                 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
624             } else {
625                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
626             }
627         } else {
628             Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
629         }
630
631         try {
632             assertStatusCode(res, testName);
633             // Check whether we've received a person.
634             PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
635             PersonsCommon person = (PersonsCommon) extractPart(input,
636                     client.getItemCommonPartName(), PersonsCommon.class);
637             Assert.assertNotNull(person);
638             boolean showFull = true;
639             if (showFull && logger.isDebugEnabled()) {
640                 logger.debug(testName + ": returned payload:");
641                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
642             }
643
644             // Check that the person item is within the expected Person Authority.
645             Assert.assertEquals(person.getInAuthority(), knownResourceId);
646
647             // Verify the number and contents of values in a repeatable field,
648             // as created in the instance record used for testing.
649             List<String> groups = person.getGroups().getGroup();
650             Assert.assertTrue(groups.size() > 0);
651             Assert.assertNotNull(groups.get(0));
652         } finally {
653                 if (res != null) {
654                 res.close();
655             }
656         }
657     }
658     
659     // Note: This test depends on server-side validation logic to require
660     // a non-null (and potentially, non-empty) displayname for each term,
661     // and will fail if that validation is not present.
662
663     /**
664      * Verify illegal item display name.
665      *
666      * @param testName the test name
667      * @throws Exception the exception
668      */
669     @Test(dataProvider = "testName", groups = {"update"})
670     public void verifyIllegalItemDisplayName(String testName) throws Exception {
671         // Perform setup for read.
672         setupRead();
673
674         // Submit the request to the service and store the response.
675         PersonAuthorityClient client = new PersonAuthorityClient();
676         Response res = client.readItem(knownResourceId, knownItemResourceId);
677         PoxPayloadIn input = null;
678         try {
679             assertStatusCode(res, testName);
680             input = new PoxPayloadIn(res.readEntity(String.class));
681         } finally {
682                 if (res != null) {
683                 res.close();
684             }
685         }
686         //
687         // Make an invalid UPDATE request, without a display name
688         //
689         PersonsCommon person = (PersonsCommon) extractPart(input,
690                 client.getItemCommonPartName(), PersonsCommon.class);
691         Assert.assertNotNull(person);
692         // Try to Update with no displayName
693         PersonTermGroupList termList = person.getPersonTermGroupList();
694         Assert.assertNotNull(termList);
695         List<PersonTermGroup> terms = termList.getPersonTermGroup();
696         Assert.assertNotNull(terms);
697         Assert.assertTrue(terms.size() > 0);
698         terms.get(0).setTermDisplayName(null);
699         terms.get(0).setTermName(null);
700
701         // Submit the updated resource to the service and store the response.
702         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
703         output.addPart(client.getItemCommonPartName(), person);
704         setupUpdateWithInvalidBody();
705         res = client.updateItem(knownResourceId, knownItemResourceId, output);
706         try {
707             assertStatusCode(res, testName);
708         } finally {
709                 if (res != null) {
710                 res.close();
711             }
712         }
713     }
714
715     /**
716      * Read contact.
717      *
718      * @param testName the test name
719      * @throws Exception the exception
720      */
721     @Test(dataProvider = "testName", groups = {"readItem"},
722                 dependsOnMethods = {"createContact", "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItem"})
723     public void readContact(String testName) throws Exception {
724         // Perform setup.
725         setupRead();
726
727         // Submit the request to the service and store the response.
728         PersonAuthorityClient client = new PersonAuthorityClient();
729         PoxPayloadIn input = null;
730         Response res = client.readContact(knownResourceId, knownItemResourceId,
731                 knownContactResourceId);
732         try {
733             assertStatusCode(res, testName);
734             // Check whether we've received a contact.
735             input = new PoxPayloadIn(res.readEntity(String.class));
736         } finally {
737                 if (res != null) {
738                 res.close();
739             }
740         }
741
742         ContactsCommon contact = (ContactsCommon) extractPart(input,
743                 new ContactClient().getCommonPartName(), ContactsCommon.class);
744         Assert.assertNotNull(contact);
745         boolean showFull = true;
746         if (showFull && logger.isDebugEnabled()) {
747             logger.debug(testName + ": returned payload:");
748             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
749         }
750         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
751         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
752
753     }
754
755     /**
756      * Read contact non existent.
757      *
758      * @param testName the test name
759      */
760     @Test(dataProvider = "testName", groups = {"readItem"}, dependsOnMethods = {"readContact"})
761     public void readContactNonExistent(String testName) {
762         // Perform setup.
763         setupReadNonExistent();
764
765         // Submit the request to the service and store the response.
766         PersonAuthorityClient client = new PersonAuthorityClient();
767         Response res = client.readContact(knownResourceId, knownItemResourceId,
768                         NON_EXISTENT_ID);
769         try {
770             assertStatusCode(res, testName);
771         } finally {
772                 if (res != null) {
773                 res.close();
774             }
775         }
776     }
777
778     // ---------------------------------------------------------------
779     // CRUD tests : READ_LIST tests
780     // ---------------------------------------------------------------
781
782     /**
783      * Read item list override -see immediate superclass.
784      */
785     @Override
786     public void readItemList(String testName) {
787         readItemList(knownAuthorityWithItems, null, testName);
788     }
789
790     /**
791      * Read item list by authority name.
792      */
793     @Override
794     public void readItemListByName(String testName) {
795         readItemList(null, READITEMS_SHORT_IDENTIFIER, testName);
796     }
797
798     /**
799      * Read item list.
800      *
801      * @param vcsid the vcsid
802      * @param name the name
803      */
804     private void readItemList(String vcsid, String name, String testName) {
805         setupReadList();
806         // Submit the request to the service and store the response.
807         PersonAuthorityClient client = new PersonAuthorityClient();
808         Response res = null;
809         if (vcsid != null) {
810             res = client.readItemList(vcsid, null, null);
811         } else if (name != null) {
812             res = client.readItemListForNamedAuthority(name, null, null);
813         } else {
814             Assert.fail("readItemList passed null csid and name!");
815         }
816         AbstractCommonList list = null;
817         try {
818             assertStatusCode(res, testName);
819             list = res.readEntity(AbstractCommonList.class);
820         } finally {
821                 if (res != null) {
822                 res.close();
823             }
824         }
825
826         List<AbstractCommonList.ListItem> items = list.getListItem();
827         int nItemsReturned = items.size();
828         // There will be 'nItemsToCreateInList'
829         // items created by the createItemList test,
830         // all associated with the same parent resource.
831         int nExpectedItems = nItemsToCreateInList;
832         if (logger.isDebugEnabled()) {
833             logger.debug(testName + ": Expected "
834                     + nExpectedItems + " items; got: " + nItemsReturned);
835         }
836         Assert.assertEquals(nItemsReturned, nExpectedItems);
837
838         for (AbstractCommonList.ListItem item : items) {
839             String value =
840                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.REF_NAME);
841             Assert.assertTrue((null != value), "Item refName is null!");
842             
843             // Per CSPACE-5132, lists items still return a field named displayName,
844             // not termDisplayName, for backward compatibility.
845             // (The format of list items will change significantly in CSPACE-5134.)
846             value =
847                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
848             Assert.assertTrue((null != value), "Item termDisplayName is null!");
849         }
850         if (logger.isTraceEnabled()) {
851             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
852         }
853     }
854
855     /**
856      * Read contact list.
857      */
858     @Test(groups = {"readList"},
859                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"})
860     public void readContactList() {
861         readContactList(knownResourceId, knownItemResourceId);
862     }
863
864     /**
865      * Read contact list.
866      *
867      * @param parentcsid the parentcsid
868      * @param itemcsid the itemcsid
869      */
870     private void readContactList(String parentcsid, String itemcsid) {
871         final String testName = "readContactList";
872
873         // Perform setup.
874         setupReadList();
875
876         // Submit the request to the service and store the response.
877         PersonAuthorityClient client = new PersonAuthorityClient();
878         AbstractCommonList list = null;
879         Response res = client.readContactList(parentcsid, itemcsid);
880         try {
881             assertStatusCode(res, testName);
882             list = res.readEntity(AbstractCommonList.class);
883         } finally {
884                 if (res != null) {
885                 res.close();
886             }
887         }
888
889         List<AbstractCommonList.ListItem> listitems =
890                 list.getListItem();
891         int nItemsReturned = listitems.size();
892         // There will be one item created, associated with a
893         // known parent resource, by the createItem test.
894         //
895         // In addition, there will be 'nItemsToCreateInList'
896         // additional items created by the createItemList test,
897         // all associated with the same parent resource.
898         int nExpectedItems = nItemsToCreateInList + 1;
899         if (logger.isDebugEnabled()) {
900             logger.debug(testName + ": Expected "
901                     + nExpectedItems + " items; got: " + nItemsReturned);
902         }
903         Assert.assertEquals(nItemsReturned, nExpectedItems);
904         
905         // Optionally output additional data about list members for debugging.
906         boolean iterateThroughList = false;
907         if (iterateThroughList && logger.isDebugEnabled()) {
908             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
909         }
910     }
911
912     // Failure outcomes
913     // There are no failure outcome tests at present.
914     // ---------------------------------------------------------------
915     // CRUD tests : UPDATE tests
916     // ---------------------------------------------------------------
917     // Success outcomes
918     /* (non-Javadoc)
919      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
920      */
921     @Override
922 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
923 //    groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
924     public void update(String testName) throws Exception {
925         // Retrieve the contents of a resource to update.
926         PersonAuthorityClient client = new PersonAuthorityClient();
927         PoxPayloadIn input = null;
928         setupRead();
929         Response res = client.read(knownResourceId);
930         try {
931             assertStatusCode(res, testName);
932             if (logger.isDebugEnabled()) {
933                 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
934             }
935             input = new PoxPayloadIn(res.readEntity(String.class));
936         } finally {
937                 if (res != null) {
938                 res.close();
939             }
940         }
941
942         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
943                 client.getCommonPartName(), PersonauthoritiesCommon.class);
944         Assert.assertNotNull(personAuthority);
945
946         // Update the contents of this resource.
947         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
948         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
949         if (logger.isDebugEnabled()) {
950             logger.debug("to be updated PersonAuthority");
951             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
952         }
953
954         // Submit the updated resource to the service and store the response.
955         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
956         output.addPart(client.getCommonPartName(), personAuthority);
957         setupUpdate();
958         res = client.update(knownResourceId, output);
959         try {
960             assertStatusCode(res, testName);
961             // Retrieve the updated resource and verify that its contents exist.
962             input = new PoxPayloadIn(res.readEntity(String.class));
963         } finally {
964                 if (res != null) {
965                 res.close();
966             }
967         }
968
969         PersonauthoritiesCommon updatedPersonAuthority =
970                 (PersonauthoritiesCommon) extractPart(input,
971                 client.getCommonPartName(), PersonauthoritiesCommon.class);
972         Assert.assertNotNull(updatedPersonAuthority);
973
974         // Verify that the updated resource received the correct data.
975         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
976                 personAuthority.getDisplayName(),
977                 "Data in updated object did not match submitted data.");
978     }
979
980     /**
981      * Update item override -see immediate superclass.
982      *
983      * @param testName the test name
984      * @throws Exception the exception
985      */
986     @Override
987     public void updateItem(String testName) throws Exception {
988         // Retrieve the contents of a resource to update.
989         PersonAuthorityClient client = new PersonAuthorityClient();
990         PoxPayloadIn input = null;
991         setupRead();
992         Response res = client.readItem(knownResourceId, knownItemResourceId);
993         try {
994             assertStatusCode(res, testName);
995             if (logger.isDebugEnabled()) {
996                 logger.debug("got Person to update with ID: "
997                         + knownItemResourceId
998                         + " in PersonAuthority: " + knownResourceId);
999             }
1000             input = new PoxPayloadIn(res.readEntity(String.class));
1001         } finally {
1002                 if (res != null) {
1003                 res.close();
1004             }
1005         }
1006
1007         PersonsCommon person = (PersonsCommon) extractPart(input,
1008                 client.getItemCommonPartName(), PersonsCommon.class);
1009         Assert.assertNotNull(person);
1010
1011         if (logger.isDebugEnabled() == true) {
1012             logger.debug("About to update the following person...");
1013             logger.debug(objectAsXmlString(person, PersonsCommon.class));
1014         }
1015
1016         // Update the contents of this resource.
1017         person.setCsid(null);
1018         PersonTermGroupList termList = person.getPersonTermGroupList();
1019         Assert.assertNotNull(termList);
1020         List<PersonTermGroup> terms = termList.getPersonTermGroup();
1021         Assert.assertNotNull(terms);
1022         Assert.assertTrue(terms.size() > 0);
1023         String foreName = terms.get(0).getForeName();
1024         String updatedForeName = "updated-" + foreName;
1025         terms.get(0).setForeName(updatedForeName);
1026         if (logger.isDebugEnabled()) {
1027             logger.debug("to be updated Person");
1028             logger.debug(objectAsXmlString(person,
1029                     PersonsCommon.class));
1030         }
1031
1032         // Submit the updated resource to the service and store the response.
1033         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1034         output.addPart(client.getItemCommonPartName(), person);
1035         setupUpdate();
1036         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1037         try {
1038             assertStatusCode(res, testName);
1039             // Retrieve the updated resource and verify that its contents exist.
1040             input = new PoxPayloadIn(res.readEntity(String.class));
1041         } finally {
1042                 if (res != null) {
1043                 res.close();
1044             }
1045         }
1046
1047         PersonsCommon updatedPerson =
1048                 (PersonsCommon) extractPart(input,
1049                 client.getItemCommonPartName(), PersonsCommon.class);
1050         Assert.assertNotNull(updatedPerson);
1051
1052         if (logger.isDebugEnabled() == true) {
1053             logger.debug("Updated to following person to:");
1054             logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1055         }
1056
1057         // Verify that the updated resource received the correct data.
1058         PersonTermGroupList updatedTermList = person.getPersonTermGroupList();
1059         Assert.assertNotNull(updatedTermList);
1060         List<PersonTermGroup> updatedTerms = termList.getPersonTermGroup();
1061         Assert.assertNotNull(updatedTerms);
1062         Assert.assertEquals(updatedTerms.get(0).getForeName(), updatedForeName,
1063                 "Data in updated Person did not match submitted data.");
1064     }
1065
1066     /**
1067      * Update contact.
1068      *
1069      * @param testName the test name
1070      * @throws Exception the exception
1071      */
1072     @Test(dataProvider = "testName", groups = {"update"},
1073                 dependsOnMethods = {"readContact", "testContactSubmitRequest",
1074                         "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"})
1075     public void updateContact(String testName) throws Exception {
1076         String contactsCommonLabel = new ContactClient().getCommonPartName();
1077
1078         // Retrieve the contents of a resource to update.
1079         PersonAuthorityClient client = new PersonAuthorityClient();
1080         PoxPayloadIn input = null;
1081         setupRead();
1082         Response res = client.readContact(knownResourceId, knownItemResourceId,
1083                         knownContactResourceId);
1084         try {
1085             assertStatusCode(res, testName);
1086             if (logger.isDebugEnabled()) {
1087                 logger.debug("got Contact to update with ID: "
1088                         + knownContactResourceId
1089                         + " in item: " + knownItemResourceId
1090                         + " in parent: " + knownResourceId);
1091             }
1092             input = new PoxPayloadIn(res.readEntity(String.class));
1093         } finally {
1094                 if (res != null) {
1095                 res.close();
1096             }
1097         }
1098
1099         ContactsCommon contact = (ContactsCommon) extractPart(input,
1100                 contactsCommonLabel, ContactsCommon.class);
1101         Assert.assertNotNull(contact);
1102
1103         // Verify the contents of this resource
1104         AddressGroupList addressGroupList = contact.getAddressGroupList();
1105         Assert.assertNotNull(addressGroupList);
1106         List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1107         Assert.assertNotNull(addressGroups);
1108         Assert.assertTrue(addressGroups.size() > 0);
1109         String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1110         Assert.assertNotNull(addressPlace1);
1111
1112         // Update the contents of this resource.
1113         addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1114         contact.setAddressGroupList(addressGroupList);
1115         if (logger.isDebugEnabled()) {
1116             logger.debug("to be updated Contact");
1117             logger.debug(objectAsXmlString(contact,
1118                     ContactsCommon.class));
1119         }
1120
1121         // Submit the updated resource to the service and store the response.
1122         PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1123         output.addPart(contactsCommonLabel, contact);
1124         setupUpdate();
1125         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1126         try {
1127             assertStatusCode(res, testName);
1128             // Retrieve the updated resource and verify that its contents exist.
1129             input = new PoxPayloadIn(res.readEntity(String.class));;
1130         } finally {
1131                 if (res != null) {
1132                 res.close();
1133             }
1134         }
1135         ContactsCommon updatedContact = (ContactsCommon) extractPart(input,
1136                 contactsCommonLabel, ContactsCommon.class);
1137         Assert.assertNotNull(updatedContact);
1138
1139         // Verify that the updated resource received the correct data.
1140         Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1141                 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1142                 "Data in updated object did not match submitted data.");
1143     }
1144
1145     /**
1146      * Update non existent contact.
1147      *
1148      * @param testName the test name
1149      * @throws Exception the exception
1150      */
1151     @Test(dataProvider = "testName", groups = {"update"},
1152                 dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1153     public void updateNonExistentContact(String testName) throws Exception {
1154         // Currently a no-op test
1155     }
1156
1157     // ---------------------------------------------------------------
1158     // CRUD tests : DELETE tests
1159     // ---------------------------------------------------------------
1160     // Success outcomes
1161     // Note: delete sub-resources in ascending hierarchical order,
1162     // before deleting their parents.
1163     /**
1164      * Delete contact.
1165      *
1166      * @param testName the test name
1167      * @throws Exception the exception
1168      */
1169     @Test(dataProvider = "testName", groups = {"delete"},
1170                 dependsOnMethods = {"updateContact"})
1171     public void deleteContact(String testName) throws Exception {
1172         if (logger.isDebugEnabled()) {
1173             logger.debug("parentcsid =" + knownResourceId
1174                     + " itemcsid = " + knownItemResourceId
1175                     + " csid = " + knownContactResourceId);
1176         }
1177
1178         // Submit the request to the service and store the response.
1179         PersonAuthorityClient client = new PersonAuthorityClient();
1180         setupDelete();
1181         Response res = client.deleteContact(knownResourceId, knownItemResourceId, 
1182                         knownContactResourceId);
1183         try {
1184                 assertStatusCode(res, testName);
1185         } finally {
1186                 if (res != null) {
1187                         res.close();
1188                 }
1189         }
1190     }
1191
1192     @Override
1193     public void delete(String testName) throws Exception {
1194         // Do nothing.  See localDelete().  This ensure proper test order.
1195     }
1196     
1197     @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"})    
1198     public void localDelete(String testName) throws Exception {
1199         super.delete(testName);
1200     }
1201
1202     @Override
1203     public void deleteItem(String testName) throws Exception {
1204         // Do nothing.  We need to wait until after the test "localDelete" gets run.  When it does,
1205         // its dependencies will get run first and then we can call the base class' delete method.
1206     }
1207     
1208     @Test(dataProvider = "testName", groups = {"delete"},
1209         dependsOnMethods = {"verifyIllegalItemDisplayName", "testContactSubmitRequest", "deleteContact"})
1210     public void localDeleteItem(String testName) throws Exception {
1211         super.deleteItem(testName);
1212     }
1213
1214     /**
1215      * Delete non existent contact.
1216      *
1217      * @param testName the test name
1218      */
1219     @Test(dataProvider = "testName", groups = {"delete"},
1220                 dependsOnMethods = {"deleteContact"})
1221     public void deleteNonExistentContact(String testName) {
1222         // Submit the request to the service and store the response.
1223         PersonAuthorityClient client = new PersonAuthorityClient();
1224         setupDeleteNonExistent();
1225         Response res = client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1226         try {
1227                 assertStatusCode(res, testName);
1228         } finally {
1229                 if (res != null) {
1230                         res.close();
1231                 }
1232         }
1233     }
1234
1235     /**
1236      * Test contact submit request.
1237      */
1238     @Test(dataProvider = "testName",
1239                 dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1240     public void testContactSubmitRequest(String testName) {
1241
1242         // Expected status code: 200 OK
1243         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1244
1245         // Submit the request to the service and store the response.
1246         String method = ServiceRequestType.READ.httpMethodName();
1247         String url = getContactResourceURL(knownResourceId,
1248                 knownItemResourceId, knownContactResourceId);
1249         int statusCode = submitRequest(method, url);
1250
1251         // Check the status code of the response: does it match
1252         // the expected response(s)?
1253         if (logger.isDebugEnabled()) {
1254             logger.debug("testContactSubmitRequest: url=" + url
1255                     + " status=" + statusCode);
1256         }
1257         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1258
1259     }
1260
1261     // ---------------------------------------------------------------
1262     // Cleanup of resources created during testing
1263     // ---------------------------------------------------------------
1264     /**
1265      * Deletes all resources created by tests, after all tests have been run.
1266      *
1267      * This cleanup method will always be run, even if one or more tests fail.
1268      * For this reason, it attempts to remove all resources created
1269      * at any point during testing, even if some of those resources
1270      * may be expected to be deleted by certain tests.
1271      */
1272     @AfterClass(alwaysRun = true)
1273     @Override
1274     public void cleanUp() {
1275         String noTest = System.getProperty("noTestCleanup");
1276         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1277             if (logger.isDebugEnabled()) {
1278                 logger.debug("Skipping Cleanup phase ...");
1279             }
1280             return;
1281         }
1282         
1283         if (logger.isDebugEnabled()) {
1284             logger.debug("Cleaning up temporary resources created for testing ...");
1285         }
1286         
1287         String parentResourceId;
1288         String itemResourceId;
1289         String contactResourceId;
1290         // Clean up contact resources.
1291         PersonAuthorityClient client = new PersonAuthorityClient();
1292         parentResourceId = this.getKnowResourceId();
1293         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1294             contactResourceId = entry.getKey();
1295             itemResourceId = entry.getValue();
1296             // Note: Any non-success responses from the delete operation
1297             // below are ignored and not reported.
1298             Response res = client.deleteContact(parentResourceId, itemResourceId,
1299                         contactResourceId);
1300             res.close();
1301         }
1302         //
1303         // Finally, clean call our superclass' cleanUp method.
1304         //
1305         super.cleanUp();
1306     }
1307
1308     // ---------------------------------------------------------------
1309     // Utility methods used by tests above
1310     // ---------------------------------------------------------------
1311     /**
1312      * Gets the contact service path component.
1313      *
1314      * @return the contact service path component
1315      */
1316     public String getContactServicePathComponent() {
1317         return ContactClient.SERVICE_PATH_COMPONENT;
1318     }
1319
1320     /**
1321      * Returns the root URL for the item service.
1322      *
1323      * This URL consists of a base URL for all services, followed by
1324      * a path component for the owning parent, followed by the
1325      * path component for the items.
1326      *
1327      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1328      * parent authority resource of the relevant item resource.
1329      *
1330      * @return The root URL for the item service.
1331      */
1332     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1333         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1334     }
1335
1336     /**
1337      * Returns the URL of a specific item resource managed by a service, and
1338      * designated by an identifier (such as a universally unique ID, or UUID).
1339      *
1340      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1341      * parent authority resource of the relevant item resource.
1342      *
1343      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1344      * item resource.
1345      *
1346      * @return The URL of a specific item resource managed by a service.
1347      */
1348     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1349         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1350     }
1351
1352     /**
1353      * Returns the root URL for the contact service.
1354      *
1355      * This URL consists of a base URL for all services, followed by
1356      * a path component for the owning authority, followed by the
1357      * path component for the owning item, followed by the path component
1358      * for the contact service.
1359      *
1360      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1361      * parent authority resource of the relevant item resource.
1362      *
1363      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1364      * item resource.
1365      *
1366      * @return The root URL for the contact service.
1367      */
1368     protected String getContactServiceRootURL(String parentResourceIdentifier,
1369             String itemResourceIdentifier) {
1370         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
1371                 + getContactServicePathComponent();
1372     }
1373
1374     /**
1375      * Returns the URL of a specific contact resource managed by a service, and
1376      * designated by an identifier (such as a universally unique ID, or UUID).
1377      *
1378      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1379      * parent resource of the relevant item resource.
1380      *
1381      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1382      * item resource.
1383      *
1384      * @return The URL of a specific resource managed by a service.
1385      */
1386     protected String getContactResourceURL(String parentResourceIdentifier,
1387             String itemResourceIdentifier, String contactResourceIdentifier) {
1388         return getContactServiceRootURL(parentResourceIdentifier,
1389                 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1390     }
1391
1392         @Override
1393         public void authorityTests(String testName) {
1394                 // TODO Auto-generated method stub
1395                 
1396         }
1397    
1398         @Override
1399         protected PersonsCommon updateItemInstance(PersonsCommon personsCommon) {
1400                             
1401             PersonTermGroupList termList = personsCommon.getPersonTermGroupList();
1402             Assert.assertNotNull(termList);
1403             List<PersonTermGroup> terms = termList.getPersonTermGroup();
1404             Assert.assertNotNull(terms);
1405             Assert.assertTrue(terms.size() > 0);
1406             terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName());
1407             terms.get(0).setTermName("updated-" + terms.get(0).getTermName());
1408             personsCommon.setPersonTermGroupList(termList);
1409
1410             return personsCommon;
1411         }
1412
1413         @Override
1414         protected void compareUpdatedItemInstances(PersonsCommon original,
1415                         PersonsCommon updated) throws Exception {
1416             
1417             PersonTermGroupList originalTermList = original.getPersonTermGroupList();
1418             Assert.assertNotNull(originalTermList);
1419             List<PersonTermGroup> originalTerms = originalTermList.getPersonTermGroup();
1420             Assert.assertNotNull(originalTerms);
1421             Assert.assertTrue(originalTerms.size() > 0);
1422             
1423             PersonTermGroupList updatedTermList = updated.getPersonTermGroupList();
1424             Assert.assertNotNull(updatedTermList);
1425             List<PersonTermGroup> updatedTerms = updatedTermList.getPersonTermGroup();
1426             Assert.assertNotNull(updatedTerms);
1427             Assert.assertTrue(updatedTerms.size() > 0);
1428             
1429             Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
1430                 originalTerms.get(0).getTermDisplayName(),
1431                 "Value in updated record did not match submitted data.");
1432         }
1433
1434         @Override
1435         protected PoxPayloadOut createInstance(String commonPartName,
1436                         String identifier) {
1437         String shortId = identifier;
1438         String displayName = "displayName-" + shortId;
1439         PoxPayloadOut result =
1440                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
1441                 displayName, shortId, commonPartName);
1442         return result;
1443         }
1444         
1445         @Override
1446         protected PoxPayloadOut createNonExistenceInstance(String commonPartName,
1447                         String identifier) {
1448         String displayName = "displayName-NON_EXISTENT_ID";
1449         PoxPayloadOut result = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1450                 displayName, "NON_EXISTENT_SHORT_ID", commonPartName);
1451         return result;
1452         }
1453         
1454     protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier) {
1455         Map<String, String> nonexMap = new HashMap<String, String>();
1456         nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1457         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1458         
1459         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
1460         PersonTermGroup term = new PersonTermGroup();
1461         term.setTermDisplayName("John Wayne");
1462         term.setTermName("John Wayne");
1463         term.setForeName("John");
1464         term.setSurName("Wayne");
1465         terms.add(term);
1466         
1467         Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1468         PoxPayloadOut result =
1469                 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1470                 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1471                 nonexMap, terms, nonexRepeatablesMap, commonPartName);
1472         return result;
1473     }
1474                 
1475     @Override
1476         protected PersonauthoritiesCommon updateInstance(PersonauthoritiesCommon personauthoritiesCommon) {
1477                 PersonauthoritiesCommon result = new PersonauthoritiesCommon();
1478                 
1479         result.setDisplayName("updated-" + personauthoritiesCommon.getDisplayName());
1480         result.setVocabType("updated-" + personauthoritiesCommon.getVocabType());
1481         
1482                 return result;
1483         }
1484
1485         @Override
1486         protected void compareUpdatedInstances(PersonauthoritiesCommon original,
1487                         PersonauthoritiesCommon updated) throws Exception {
1488         // Verify that the updated resource received the correct data.
1489         Assert.assertEquals(updated.getDisplayName(),
1490                         original.getDisplayName(),
1491                 "Display name in updated object did not match submitted data.");
1492         }
1493
1494         @Override
1495         protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
1496                 // Do nothing for now.  Add more 'read' validation checks here if applicable.
1497         }        
1498 }