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