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