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