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