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