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