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