]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e86d8265f58ff46d22112f409ea50748ea9516f6
[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         ClientResponse<Response> res = client.create(multipart);
155         try {
156                 assertStatusCode(res, testName);
157             newID = extractId(res);
158         } finally {
159                 if (res != null) {
160                         res.releaseConnection();
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         ClientResponse<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.releaseConnection();
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         ClientResponse<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.releaseConnection();
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         ClientResponse<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.releaseConnection();
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         ClientResponse<String> 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(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.releaseConnection();
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         ClientResponse<String> 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         try {
617             assertStatusCode(res, testName);
618             // Check whether we've received a person.
619             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
620             PersonsCommon person = (PersonsCommon) extractPart(input,
621                     client.getItemCommonPartName(), PersonsCommon.class);
622             Assert.assertNotNull(person);
623             boolean showFull = true;
624             if (showFull && logger.isDebugEnabled()) {
625                 logger.debug(testName + ": returned payload:");
626                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
627             }
628
629             // Check that the person item is within the expected Person Authority.
630             Assert.assertEquals(person.getInAuthority(), knownResourceId);
631
632             // Verify the number and contents of values in a repeatable field,
633             // as created in the instance record used for testing.
634             List<String> groups = person.getGroups().getGroup();
635             Assert.assertTrue(groups.size() > 0);
636             Assert.assertNotNull(groups.get(0));
637         } finally {
638                 if (res != null) {
639                 res.releaseConnection();
640             }
641         }
642     }
643     
644     // Note: This test depends on server-side validation logic to require
645     // a non-null (and potentially, non-empty) displayname for each term,
646     // and will fail if that validation is not present.
647
648     /**
649      * Verify illegal item display name.
650      *
651      * @param testName the test name
652      * @throws Exception the exception
653      */
654     @Test(dataProvider = "testName", groups = {"update"})
655     public void verifyIllegalItemDisplayName(String testName) throws Exception {
656         // Perform setup for read.
657         setupRead();
658
659         // Submit the request to the service and store the response.
660         PersonAuthorityClient client = new PersonAuthorityClient();
661         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
662         PoxPayloadIn input = null;
663         try {
664             assertStatusCode(res, testName);
665             input = new PoxPayloadIn(res.getEntity());
666         } finally {
667                 if (res != null) {
668                 res.releaseConnection();
669             }
670         }
671         //
672         // Make an invalid UPDATE request, without a display name
673         //
674         PersonsCommon person = (PersonsCommon) extractPart(input,
675                 client.getItemCommonPartName(), PersonsCommon.class);
676         Assert.assertNotNull(person);
677         // Try to Update with no displayName
678         PersonTermGroupList termList = person.getPersonTermGroupList();
679         Assert.assertNotNull(termList);
680         List<PersonTermGroup> terms = termList.getPersonTermGroup();
681         Assert.assertNotNull(terms);
682         Assert.assertTrue(terms.size() > 0);
683         terms.get(0).setTermDisplayName(null);
684         terms.get(0).setTermName(null);
685
686         // Submit the updated resource to the service and store the response.
687         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
688         PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person);
689         setupUpdateWithInvalidBody();
690         res = client.updateItem(knownResourceId, knownItemResourceId, output);
691         try {
692             assertStatusCode(res, testName);
693         } finally {
694                 if (res != null) {
695                 res.releaseConnection();
696             }
697         }
698     }
699
700     /**
701      * Read contact.
702      *
703      * @param testName the test name
704      * @throws Exception the exception
705      */
706     @Test(dataProvider = "testName", groups = {"readItem"},
707                 dependsOnMethods = {"createContact", "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItem"})
708     public void readContact(String testName) throws Exception {
709         // Perform setup.
710         setupRead();
711
712         // Submit the request to the service and store the response.
713         PersonAuthorityClient client = new PersonAuthorityClient();
714         PoxPayloadIn input = null;
715         ClientResponse<String> res =
716                 client.readContact(knownResourceId, knownItemResourceId,
717                 knownContactResourceId);
718         try {
719             assertStatusCode(res, testName);
720             // Check whether we've received a contact.
721             input = new PoxPayloadIn(res.getEntity());
722         } finally {
723                 if (res != null) {
724                 res.releaseConnection();
725             }
726         }
727
728         ContactsCommon contact = (ContactsCommon) extractPart(input,
729                 new ContactClient().getCommonPartName(), ContactsCommon.class);
730         Assert.assertNotNull(contact);
731         boolean showFull = true;
732         if (showFull && logger.isDebugEnabled()) {
733             logger.debug(testName + ": returned payload:");
734             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
735         }
736         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
737         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
738
739     }
740
741     /**
742      * Read contact non existent.
743      *
744      * @param testName the test name
745      */
746     @Test(dataProvider = "testName", groups = {"readItem"},
747                 dependsOnMethods = {"readContact"})
748     public void readContactNonExistent(String testName) {
749         // Perform setup.
750         setupReadNonExistent();
751
752         // Submit the request to the service and store the response.
753         PersonAuthorityClient client = new PersonAuthorityClient();
754         ClientResponse<String> res =
755                 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
756         try {
757             assertStatusCode(res, testName);
758         } finally {
759                 if (res != null) {
760                 res.releaseConnection();
761             }
762         }
763     }
764
765     // ---------------------------------------------------------------
766     // CRUD tests : READ_LIST tests
767     // ---------------------------------------------------------------
768
769     /**
770      * Read item list.
771      */
772     @Override
773 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
774 //    groups = {"readList"}, dependsOnMethods = {"readList"})
775     public void readItemList(String testName) {
776         readItemList(knownAuthorityWithItems, null, testName);
777     }
778
779     /**
780      * Read item list by authority name.
781      */
782     @Override
783 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
784 //    groups = {"readList"}, dependsOnMethods = {"readItemList"})
785     public void readItemListByName(String testName) {
786         readItemList(null, READITEMS_SHORT_IDENTIFIER, testName);
787     }
788
789     /**
790      * Read item list.
791      *
792      * @param vcsid the vcsid
793      * @param name the name
794      */
795     private void readItemList(String vcsid, String name, String testName) {
796         setupReadList();
797         // Submit the request to the service and store the response.
798         PersonAuthorityClient client = new PersonAuthorityClient();
799         ClientResponse<AbstractCommonList> res = null;
800         if (vcsid != null) {
801             res = client.readItemList(vcsid, null, null);
802         } else if (name != null) {
803             res = client.readItemListForNamedAuthority(name, null, null);
804         } else {
805             Assert.fail("readItemList passed null csid and name!");
806         }
807         AbstractCommonList list = null;
808         try {
809             assertStatusCode(res, testName);
810             list = res.getEntity();
811         } finally {
812                 if (res != null) {
813                 res.releaseConnection();
814             }
815         }
816
817         List<AbstractCommonList.ListItem> items = list.getListItem();
818         int nItemsReturned = items.size();
819         // There will be 'nItemsToCreateInList'
820         // items created by the createItemList test,
821         // all associated with the same parent resource.
822         int nExpectedItems = nItemsToCreateInList;
823         if (logger.isDebugEnabled()) {
824             logger.debug(testName + ": Expected "
825                     + nExpectedItems + " items; got: " + nItemsReturned);
826         }
827         Assert.assertEquals(nItemsReturned, nExpectedItems);
828
829         for (AbstractCommonList.ListItem item : items) {
830             String value =
831                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.REF_NAME);
832             Assert.assertTrue((null != value), "Item refName is null!");
833             
834             // Per CSPACE-5132, lists items still return a field named displayName,
835             // not termDisplayName, for backward compatibility.
836             // (The format of list items will change significantly in CSPACE-5134.)
837             value =
838                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
839             Assert.assertTrue((null != value), "Item termDisplayName is null!");
840         }
841         if (logger.isTraceEnabled()) {
842             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
843         }
844     }
845
846     /**
847      * Read contact list.
848      */
849     @Test(groups = {"readList"},
850                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"})
851     public void readContactList() {
852         readContactList(knownResourceId, knownItemResourceId);
853     }
854
855     /**
856      * Read contact list.
857      *
858      * @param parentcsid the parentcsid
859      * @param itemcsid the itemcsid
860      */
861     private void readContactList(String parentcsid, String itemcsid) {
862         final String testName = "readContactList";
863
864         // Perform setup.
865         setupReadList();
866
867         // Submit the request to the service and store the response.
868         PersonAuthorityClient client = new PersonAuthorityClient();
869         AbstractCommonList list = null;
870         ClientResponse<AbstractCommonList> res =
871                 client.readContactList(parentcsid, itemcsid);
872         try {
873             assertStatusCode(res, testName);
874             list = res.getEntity();
875         } finally {
876                 if (res != null) {
877                 res.releaseConnection();
878             }
879         }
880
881         List<AbstractCommonList.ListItem> listitems =
882                 list.getListItem();
883         int nItemsReturned = listitems.size();
884         // There will be one item created, associated with a
885         // known parent resource, by the createItem test.
886         //
887         // In addition, there will be 'nItemsToCreateInList'
888         // additional items created by the createItemList test,
889         // all associated with the same parent resource.
890         int nExpectedItems = nItemsToCreateInList + 1;
891         if (logger.isDebugEnabled()) {
892             logger.debug(testName + ": Expected "
893                     + nExpectedItems + " items; got: " + nItemsReturned);
894         }
895         Assert.assertEquals(nItemsReturned, nExpectedItems);
896         
897         // Optionally output additional data about list members for debugging.
898         boolean iterateThroughList = false;
899         if (iterateThroughList && logger.isDebugEnabled()) {
900             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
901         }
902     }
903
904     // Failure outcomes
905     // There are no failure outcome tests at present.
906     // ---------------------------------------------------------------
907     // CRUD tests : UPDATE tests
908     // ---------------------------------------------------------------
909     // Success outcomes
910     /* (non-Javadoc)
911      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
912      */
913     @Override
914 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
915 //    groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
916     public void update(String testName) throws Exception {
917         // Retrieve the contents of a resource to update.
918         PersonAuthorityClient client = new PersonAuthorityClient();
919         PoxPayloadIn input = null;
920         setupRead();
921         ClientResponse<String> res = client.read(knownResourceId);
922         try {
923             assertStatusCode(res, testName);
924             if (logger.isDebugEnabled()) {
925                 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
926             }
927             input = new PoxPayloadIn(res.getEntity());
928         } finally {
929                 if (res != null) {
930                 res.releaseConnection();
931             }
932         }
933
934         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
935                 client.getCommonPartName(), PersonauthoritiesCommon.class);
936         Assert.assertNotNull(personAuthority);
937
938         // Update the contents of this resource.
939         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
940         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
941         if (logger.isDebugEnabled()) {
942             logger.debug("to be updated PersonAuthority");
943             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
944         }
945
946         // Submit the updated resource to the service and store the response.
947         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
948         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), personAuthority);
949         setupUpdate();
950         res = client.update(knownResourceId, output);
951         try {
952             assertStatusCode(res, testName);
953             // Retrieve the updated resource and verify that its contents exist.
954             input = new PoxPayloadIn(res.getEntity());
955         } finally {
956                 if (res != null) {
957                 res.releaseConnection();
958             }
959         }
960
961         PersonauthoritiesCommon updatedPersonAuthority =
962                 (PersonauthoritiesCommon) extractPart(input,
963                 client.getCommonPartName(), PersonauthoritiesCommon.class);
964         Assert.assertNotNull(updatedPersonAuthority);
965
966         // Verify that the updated resource received the correct data.
967         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
968                 personAuthority.getDisplayName(),
969                 "Data in updated object did not match submitted data.");
970     }
971
972     /**
973      * Update item.
974      *
975      * @param testName the test name
976      * @throws Exception the exception
977      */
978     @Override
979 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
980 //    groups = {"update"}, dependsOnMethods = {"update"})
981     public void updateItem(String testName) throws Exception {
982         // Retrieve the contents of a resource to update.
983         PersonAuthorityClient client = new PersonAuthorityClient();
984         PoxPayloadIn input = null;
985         setupRead();
986         ClientResponse<String> res =
987                 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(res.getEntity());
996         } finally {
997                 if (res != null) {
998                 res.releaseConnection();
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(res.getEntity());
1036         } finally {
1037                 if (res != null) {
1038                 res.releaseConnection();
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.releaseConnection();
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.releaseConnection();
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.releaseConnection();
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.releaseConnection();
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.releaseConnection();
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             ClientResponse<Response> res =
1303                     client.deleteItem(parentResourceId, itemResourceId);
1304             res.releaseConnection();
1305         }
1306         // Clean up parent resources.
1307         super.cleanUp();
1308     }
1309
1310     // ---------------------------------------------------------------
1311     // Utility methods used by tests above
1312     // ---------------------------------------------------------------
1313     /**
1314      * Gets the contact service path component.
1315      *
1316      * @return the contact service path component
1317      */
1318     public String getContactServicePathComponent() {
1319         return ContactClient.SERVICE_PATH_COMPONENT;
1320     }
1321
1322     /**
1323      * Returns the root URL for the item service.
1324      *
1325      * This URL consists of a base URL for all services, followed by
1326      * a path component for the owning parent, followed by the
1327      * path component for the items.
1328      *
1329      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1330      * parent authority resource of the relevant item resource.
1331      *
1332      * @return The root URL for the item service.
1333      */
1334     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1335         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1336     }
1337
1338     /**
1339      * Returns the URL of a specific item resource managed by a service, and
1340      * designated by an identifier (such as a universally unique ID, or UUID).
1341      *
1342      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1343      * parent authority resource of the relevant item resource.
1344      *
1345      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1346      * item resource.
1347      *
1348      * @return The URL of a specific item resource managed by a service.
1349      */
1350     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1351         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1352     }
1353
1354     /**
1355      * Returns the root URL for the contact service.
1356      *
1357      * This URL consists of a base URL for all services, followed by
1358      * a path component for the owning authority, followed by the
1359      * path component for the owning item, followed by the path component
1360      * for the contact service.
1361      *
1362      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1363      * parent authority resource of the relevant item resource.
1364      *
1365      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1366      * item resource.
1367      *
1368      * @return The root URL for the contact service.
1369      */
1370     protected String getContactServiceRootURL(String parentResourceIdentifier,
1371             String itemResourceIdentifier) {
1372         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
1373                 + getContactServicePathComponent();
1374     }
1375
1376     /**
1377      * Returns the URL of a specific contact resource managed by a service, and
1378      * designated by an identifier (such as a universally unique ID, or UUID).
1379      *
1380      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1381      * parent resource of the relevant item resource.
1382      *
1383      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1384      * item resource.
1385      *
1386      * @return The URL of a specific resource managed by a service.
1387      */
1388     protected String getContactResourceURL(String parentResourceIdentifier,
1389             String itemResourceIdentifier, String contactResourceIdentifier) {
1390         return getContactServiceRootURL(parentResourceIdentifier,
1391                 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1392     }
1393
1394         @Override
1395         public void authorityTests(String testName) {
1396                 // TODO Auto-generated method stub
1397                 
1398         }
1399    
1400         @Override
1401         protected PersonsCommon updateItemInstance(PersonsCommon personsCommon) {
1402                             
1403             PersonTermGroupList termList = personsCommon.getPersonTermGroupList();
1404             Assert.assertNotNull(termList);
1405             List<PersonTermGroup> terms = termList.getPersonTermGroup();
1406             Assert.assertNotNull(terms);
1407             Assert.assertTrue(terms.size() > 0);
1408             terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName());
1409             terms.get(0).setTermName("updated-" + terms.get(0).getTermName());
1410             personsCommon.setPersonTermGroupList(termList);
1411
1412             return personsCommon;
1413         }
1414
1415         @Override
1416         protected void compareUpdatedItemInstances(PersonsCommon original,
1417                         PersonsCommon updated) throws Exception {
1418             
1419             PersonTermGroupList originalTermList = original.getPersonTermGroupList();
1420             Assert.assertNotNull(originalTermList);
1421             List<PersonTermGroup> originalTerms = originalTermList.getPersonTermGroup();
1422             Assert.assertNotNull(originalTerms);
1423             Assert.assertTrue(originalTerms.size() > 0);
1424             
1425             PersonTermGroupList updatedTermList = updated.getPersonTermGroupList();
1426             Assert.assertNotNull(updatedTermList);
1427             List<PersonTermGroup> updatedTerms = updatedTermList.getPersonTermGroup();
1428             Assert.assertNotNull(updatedTerms);
1429             Assert.assertTrue(updatedTerms.size() > 0);
1430             
1431             Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
1432                 originalTerms.get(0).getTermDisplayName(),
1433                 "Value in updated record did not match submitted data.");
1434         }
1435
1436         @Override
1437         protected PoxPayloadOut createInstance(String commonPartName,
1438                         String identifier) {
1439         String shortId = identifier;
1440         String displayName = "displayName-" + shortId;
1441         PoxPayloadOut result =
1442                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
1443                 displayName, shortId, commonPartName);
1444         return result;
1445         }
1446         
1447         @Override
1448         protected PoxPayloadOut createNonExistenceInstance(String commonPartName,
1449                         String identifier) {
1450         String displayName = "displayName-NON_EXISTENT_ID";
1451         PoxPayloadOut result = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1452                 displayName, "NON_EXISTENT_SHORT_ID", commonPartName);
1453         return result;
1454         }
1455         
1456     protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier) {
1457         Map<String, String> nonexMap = new HashMap<String, String>();
1458         nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1459         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1460         
1461         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
1462         PersonTermGroup term = new PersonTermGroup();
1463         term.setTermDisplayName("John Wayne");
1464         term.setTermName("John Wayne");
1465         term.setForeName("John");
1466         term.setSurName("Wayne");
1467         terms.add(term);
1468         
1469         Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1470         PoxPayloadOut result =
1471                 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1472                 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1473                 nonexMap, terms, nonexRepeatablesMap, commonPartName);
1474         return result;
1475     }
1476                 
1477         @Override
1478         protected PersonauthoritiesCommon updateInstance(PersonauthoritiesCommon personauthoritiesCommon) {
1479                 PersonauthoritiesCommon result = new PersonauthoritiesCommon();
1480                 
1481         result.setDisplayName("updated-" + personauthoritiesCommon.getDisplayName());
1482         result.setVocabType("updated-" + personauthoritiesCommon.getVocabType());
1483         
1484                 return result;
1485         }
1486
1487         @Override
1488         protected void compareUpdatedInstances(PersonauthoritiesCommon original,
1489                         PersonauthoritiesCommon updated) throws Exception {
1490         // Verify that the updated resource received the correct data.
1491         Assert.assertEquals(updated.getDisplayName(),
1492                         original.getDisplayName(),
1493                 "Display name in updated object did not match submitted data.");
1494         }
1495
1496         @Override
1497         protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
1498                 // Do nothing for now.  Add more 'read' validation checks here if applicable.
1499         }
1500         
1501         
1502 }