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