]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
61f815534e0c35bddc767aa8f3abb8c24819667d
[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         ClientResponse<Response> res = client.create(multipart);
155         try {
156                 assertStatusCode(res, testName);
157             newID = extractId(res);
158         } finally {
159                 if (res != null) {
160                         res.releaseConnection();
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 = "johnWayneTempActor";
190         personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
191         
192         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
193         PersonTermGroup term = new PersonTermGroup();
194         term.setTermDisplayName("John Wayne Temp");
195         term.setTermName("JohnWayneTemp");
196         terms.add(term);
197         
198         return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, terms, headerLabel);
199     }
200
201     /**
202      * Creates an item in an authority, using test data.
203      *
204      * @param vcsid the vcsid
205      * @param authRefName the auth ref name
206      * @return the string
207      */
208     @Override
209     protected String createItemInAuthority(String vcsid) {
210
211         final String testName = "createItemInAuthority";
212         if (logger.isDebugEnabled()) {
213             logger.debug(testName + ":" + vcsid + "...");
214         }
215
216         Map<String, String> johnWayneMap = new HashMap<String, String>();
217         //
218         // Fill the property map
219         //
220         String shortId = "johnWayneActor";
221         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
222         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
223         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
224         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
225         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
226         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better"
227                 + "known by his stage name John Wayne, was an American film actor, director "
228                 + "and producer. He epitomized rugged masculinity and has become an enduring "
229                 + "American icon. He is famous for his distinctive voice, walk and height. "
230                 + "He was also known for his conservative political views and his support in "
231                 + "the 1950s for anti-communist positions.");
232
233         List<PersonTermGroup> johnWayneTerms = new ArrayList<PersonTermGroup>();
234         PersonTermGroup term = new PersonTermGroup();
235         term.setTermDisplayName("John Wayne DisplayName");
236         term.setTermName("John Wayne");
237         term.setForeName(TEST_FORE_NAME);
238         term.setSurName(TEST_SUR_NAME);
239         johnWayneTerms.add(term);
240
241         Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String, List<String>>();
242         List<String> johnWayneGroups = new ArrayList<String>();
243         johnWayneGroups.add("Irish");
244         johnWayneGroups.add("Scottish");
245         johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
246
247         return createItemInAuthority(vcsid, null /*authRefName*/, shortId, johnWayneMap, johnWayneTerms, johnWayneRepeatablesMap);
248
249     }
250
251     /**
252      * Creates an item in an authority.
253      *
254      * @param vcsid the vcsid
255      * @param authRefName the auth ref name
256      * @param itemFieldProperties a set of properties specifying the values of fields.
257      * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
258      * @return the string
259      */
260     private String createItemInAuthority(String vcsid, String authRefName, String shortId,
261             Map itemFieldProperties, List<PersonTermGroup> terms, Map itemRepeatableFieldProperties) {
262
263         final String testName = "createItemInAuthority";
264         if (logger.isDebugEnabled()) {
265             logger.debug(testName + ":" + vcsid + "...");
266         }
267
268         // Submit the request to the service and store the response.
269         PersonAuthorityClient client = new PersonAuthorityClient();
270         PoxPayloadOut multipart =
271                 PersonAuthorityClientUtils.createPersonInstance(vcsid, null /*authRefName*/, itemFieldProperties,
272                 terms, itemRepeatableFieldProperties, client.getItemCommonPartName());
273         setupCreate();
274         ClientResponse<Response> res = client.createItem(vcsid, multipart);
275         String newID = null;
276         try {
277                 assertStatusCode(res, testName);
278             newID = PersonAuthorityClientUtils.extractId(res);
279         } finally {
280                 if (res != null) {
281                         res.releaseConnection();
282                 }
283         }
284
285         // Store the ID returned from the first item resource created
286         // for additional tests below.
287         if (knownItemResourceId == null) {
288             setKnownItemResource(newID, shortId);
289             if (logger.isDebugEnabled()) {
290                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
291             }
292         }
293         if (logger.isDebugEnabled()) {
294             logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")");
295         }
296
297         // Store the IDs from any item resources created
298         // by tests, along with the IDs of their parents, so these items
299         // can be deleted after all tests have been run.
300         allResourceItemIdsCreated.put(newID, vcsid);
301
302         return newID;
303     }
304
305     /**
306      * Creates the contact.
307      *
308      * @param testName the test name
309      */
310     @Test(dataProvider = "testName", groups = {"create"},
311                 dependsOnMethods = {"createItem"})
312     public void createContact(String testName) {
313         setupCreate();
314         String newID = createContactInItem(knownResourceId, knownItemResourceId);
315     }
316
317     /**
318      * Creates the contact in item.
319      *
320      * @param parentcsid the parentcsid
321      * @param itemcsid the itemcsid
322      * @return the string
323      */
324     private String createContactInItem(String parentcsid, String itemcsid) {
325
326         final String testName = "createContactInItem";
327         if (logger.isDebugEnabled()) {
328             logger.debug(testName + ":...");
329         }
330         // Submit the request to the service and store the response.
331         PersonAuthorityClient client = new PersonAuthorityClient();
332         String identifier = createIdentifier();
333         PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
334                 itemcsid, identifier, new ContactClient().getCommonPartName());
335
336         setupCreate();
337         ClientResponse<Response> res =
338                 client.createContact(parentcsid, itemcsid, multipart);
339         String newID = null;
340         try {
341                 assertStatusCode(res, testName);
342             newID = PersonAuthorityClientUtils.extractId(res);
343         } finally {
344                 if (res != null) {
345                         res.releaseConnection();
346                 }
347         }
348
349         // Store the ID returned from the first contact resource created
350         // for additional tests below.
351         if (knownContactResourceId == null) {
352             knownContactResourceId = newID;
353             if (logger.isDebugEnabled()) {
354                 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
355             }
356         }
357
358         // Store the IDs from any contact resources created
359         // by tests, along with the IDs of their parent items,
360         // so these items can be deleted after all tests have been run.
361         allContactResourceIdsCreated.put(newID, itemcsid);
362
363         return newID;
364     }
365
366     /**
367      * Attempts to create an authority with an short identifier that contains
368      * non-word characters.
369      *
370      * @param testName the test name
371      */
372     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"})
373     public void createWithShortIdNonWordChars(String testName) throws Exception {
374         testExpectedStatusCode = STATUS_BAD_REQUEST;
375         testRequestType = ServiceRequestType.CREATE;
376         testSetup(testExpectedStatusCode, testRequestType);
377
378         // Create the payload to be included in the body of the request
379         PersonAuthorityClient client = new PersonAuthorityClient();
380         String shortId = createIdentifier() + "*" + createIdentifier();
381         String displayName = "displayName-" + shortId;
382         PoxPayloadOut multipart =
383                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
384                 displayName, shortId, client.getCommonPartName());
385
386         // Submit the request to the service and store the response.
387         ClientResponse<Response> res = client.create(multipart);
388
389         // Check the status code of the response: does it match
390         // the expected response(s)?
391         try {
392                 assertStatusCode(res, testName);
393         } finally {
394                 if (res != null) {
395                         res.releaseConnection();
396                 }
397         }
398     }
399
400     /**
401      * Attempts to create an item with an short identifier that contains
402      * non-word characters.
403      *
404      * @param testName the test name
405      */
406     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"},
407                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractServiceTestImpl.create"})
408     public void createItemWithShortIdNonWordChars(String testName) {
409         testExpectedStatusCode = STATUS_BAD_REQUEST;
410         testRequestType = ServiceRequestType.CREATE;
411         testSetup(testExpectedStatusCode, testRequestType);
412
413         PersonAuthorityClient client = new PersonAuthorityClient();
414         // Create the payload to be included in the body of the request
415         String shortId = "7-Eleven";
416         Map<String, String> fieldProperties = new HashMap<String, String>();
417         fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
418         
419         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
420         PersonTermGroup term = new PersonTermGroup();
421         term.setTermDisplayName(shortId);
422         term.setTermName(shortId);
423         terms.add(term);
424         
425         final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
426         PoxPayloadOut multipart =
427                 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
428                 null /*knownResourceRefName*/, fieldProperties, terms,
429                 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
430
431         // Send the request and receive a response
432         ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
433         // Check the status code of the response: does it match
434         // the expected response(s)?
435         try {
436                 assertStatusCode(res, testName);
437         } finally {
438                 if (res != null) {
439                         res.releaseConnection();
440                 }
441         }
442     }
443
444     // ---------------------------------------------------------------
445     // CRUD tests : CREATE LIST tests
446     // ---------------------------------------------------------------
447     // Success outcomes
448     /* (non-Javadoc)
449      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
450      */
451     @Override
452 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
453 //    groups = {"createList"}, dependsOnGroups = {"create"})
454     public void createList(String testName) throws Exception {
455         for (int i = 0; i < nItemsToCreateInList; i++) {
456             create(testName);
457         }
458     }
459
460     /**
461      * Creates the contact list.
462      *
463      * @param testName the test name
464      * @throws Exception the exception
465      */
466     @Test(dataProvider = "testName", groups = {"createList"},
467                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.createItemList"})
468     public void createContactList(String testName) throws Exception {
469         // Add contacts to the initially-created, known item record.
470         for (int j = 0; j < nItemsToCreateInList; j++) {
471             createContact(testName);
472         }
473     }
474
475     // ---------------------------------------------------------------
476     // CRUD tests : READ tests
477     // ---------------------------------------------------------------
478     // Success outcomes
479     /* (non-Javadoc)
480      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
481      */
482     @Override
483 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
484 //    groups = {"read"}, dependsOnGroups = {"create"})
485     public void read(String testName) throws Exception {
486         readInternal(testName, knownResourceId, null);
487     }
488
489     /**
490      * Read by name.
491      *
492      * @param testName the test name
493      * @throws Exception the exception
494      */
495     @Override
496 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
497 //    groups = {"read"}, dependsOnMethods = {"read"})
498     public void readByName(String testName) throws Exception {
499         readInternal(testName, null, knownResourceShortIdentifer);
500     }
501
502     protected void readInternal(String testName, String CSID, String shortId) {
503         // Submit the request to the service and store the response.
504         PersonAuthorityClient client = new PersonAuthorityClient();
505         ClientResponse<String> res = null;
506         setupRead();
507         if (CSID != null) {
508             res = client.read(CSID);
509         } else if (shortId != null) {
510             res = client.readByName(shortId);
511         } else {
512             Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
513         }
514         try {
515             assertStatusCode(res, testName);
516             //FIXME: remove the following try catch once Aron fixes signatures
517             try {
518                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
519                 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
520                         client.getCommonPartName(), PersonauthoritiesCommon.class);
521                 Assert.assertNotNull(personAuthority);
522             } catch (Exception e) {
523                 throw new RuntimeException(e);
524             }
525         } finally {
526                 if (res != null) {
527                 res.releaseConnection();
528             }
529         }
530     }
531
532     /**
533      * Read named item.
534      *
535      * @param testName the test name
536      * @throws Exception the exception
537      */
538     @Test(dataProvider = "testName", groups = {"readItem", "readNamedItemInNamedAuth"},
539                 dependsOnMethods = {"readItemInNamedAuth"})
540     public void readNamedItem(String testName) throws Exception {
541         readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
542     }
543
544     /**
545      * Read item in Named Auth.
546      *
547      * @param testName the test name
548      * @throws Exception the exception
549      */
550     @Test(dataProvider = "testName", groups = {"readItem"},
551                 dependsOnMethods = {"readItem"})
552     public void readItemInNamedAuth(String testName) throws Exception {
553         readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
554     }
555
556     
557     /**
558      * Read Named item in Named Auth.
559      *
560      * @param testName the test name
561      * @throws Exception the exception
562      */
563     @Test(dataProvider = "testName", groups = {"readItem"},
564                 dependsOnMethods = {"readNamedItem"})
565     public void readNamedItemInNamedAuth(String testName) throws Exception {
566         readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
567     }
568
569     protected void readItemInternal(String testName,
570             String authCSID, String authShortId, String itemCSID, String itemShortId)
571             throws Exception {
572
573         if (logger.isDebugEnabled()) {
574             logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/"
575                     + ((itemCSID != null) ? authCSID : itemShortId));
576         }
577
578         // Submit the request to the service and store the response.
579         PersonAuthorityClient client = new PersonAuthorityClient();
580         setupRead();
581         ClientResponse<String> res = null;
582         if (authCSID != null) {
583             if (itemCSID != null) {
584                 res = client.readItem(authCSID, itemCSID);
585             } else if (itemShortId != null) {
586                 res = client.readNamedItem(authCSID, itemShortId);
587             } else {
588                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
589             }
590         } else if (authShortId != null) {
591             if (itemCSID != null) {
592                 res = client.readItemInNamedAuthority(authShortId, itemCSID);
593             } else if (itemShortId != null) {
594                 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
595             } else {
596                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
597             }
598         } else {
599             Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
600         }
601         try {
602             assertStatusCode(res, testName);
603             // Check whether we've received a person.
604             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
605             PersonsCommon person = (PersonsCommon) extractPart(input,
606                     client.getItemCommonPartName(), PersonsCommon.class);
607             Assert.assertNotNull(person);
608             boolean showFull = true;
609             if (showFull && logger.isDebugEnabled()) {
610                 logger.debug(testName + ": returned payload:");
611                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
612             }
613
614             // Check that the person item is within the expected Person Authority.
615             Assert.assertEquals(person.getInAuthority(), knownResourceId);
616
617             // Verify the number and contents of values in a repeatable field,
618             // as created in the instance record used for testing.
619             List<String> groups = person.getGroups().getGroup();
620             Assert.assertTrue(groups.size() > 0);
621             Assert.assertNotNull(groups.get(0));
622         } finally {
623                 if (res != null) {
624                 res.releaseConnection();
625             }
626         }
627     }
628     
629     // Note: This test depends on server-side validation logic to require
630     // a non-null (and potentially, non-empty) displayname for each term,
631     // and will fail if that validation is not present.
632
633     /**
634      * Verify illegal item display name.
635      *
636      * @param testName the test name
637      * @throws Exception the exception
638      */
639     @Test(dataProvider = "testName", groups = {"update"})
640     public void verifyIllegalItemDisplayName(String testName) throws Exception {
641         // Perform setup for read.
642         setupRead();
643
644         // Submit the request to the service and store the response.
645         PersonAuthorityClient client = new PersonAuthorityClient();
646         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
647         PoxPayloadIn input = null;
648         try {
649             assertStatusCode(res, testName);
650             input = new PoxPayloadIn(res.getEntity());
651         } finally {
652                 if (res != null) {
653                 res.releaseConnection();
654             }
655         }
656         //
657         // Make an invalid UPDATE request, without a display name
658         //
659         PersonsCommon person = (PersonsCommon) extractPart(input,
660                 client.getItemCommonPartName(), PersonsCommon.class);
661         Assert.assertNotNull(person);
662         // Try to Update with no displayName
663         List<PersonTermGroup> johnWayneTerms = new ArrayList<PersonTermGroup>();
664         PersonTermGroup term = new PersonTermGroup();
665         term.setTermDisplayName("John Wayne DisplayName");
666         term.setTermName("John Wayne");
667         term.setForeName(TEST_FORE_NAME);
668         term.setSurName(TEST_SUR_NAME);
669         johnWayneTerms.add(term);
670         
671         PersonTermGroupList termList = person.getPersonTermGroupList();
672         Assert.assertNotNull(termList);
673         List<PersonTermGroup> terms = termList.getPersonTermGroup();
674         Assert.assertNotNull(terms);
675         Assert.assertTrue(terms.size() > 0);
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         Assert.assertTrue(terms.size() > 0);
1011         String foreName = terms.get(0).getForeName();
1012         String updatedForeName = "updated-" + foreName;
1013         terms.get(0).setForeName(updatedForeName);
1014         if (logger.isDebugEnabled()) {
1015             logger.debug("to be updated Person");
1016             logger.debug(objectAsXmlString(person,
1017                     PersonsCommon.class));
1018         }
1019
1020         // Submit the updated resource to the service and store the response.
1021         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1022         PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person);
1023         setupUpdate();
1024         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1025         try {
1026             assertStatusCode(res, testName);
1027             // Retrieve the updated resource and verify that its contents exist.
1028             input = new PoxPayloadIn(res.getEntity());
1029         } finally {
1030                 if (res != null) {
1031                 res.releaseConnection();
1032             }
1033         }
1034
1035         PersonsCommon updatedPerson =
1036                 (PersonsCommon) extractPart(input,
1037                 client.getItemCommonPartName(), PersonsCommon.class);
1038         Assert.assertNotNull(updatedPerson);
1039
1040         if (logger.isDebugEnabled() == true) {
1041             logger.debug("Updated to following person to:");
1042             logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1043         }
1044
1045         // Verify that the updated resource received the correct data.
1046         PersonTermGroupList updatedTermList = person.getPersonTermGroupList();
1047         Assert.assertNotNull(updatedTermList);
1048         List<PersonTermGroup> updatedTerms = termList.getPersonTermGroup();
1049         Assert.assertNotNull(updatedTerms);
1050         Assert.assertEquals(updatedTerms.get(0).getForeName(), updatedForeName,
1051                 "Data in updated Person did not match submitted data.");
1052     }
1053
1054     /**
1055      * Update contact.
1056      *
1057      * @param testName the test name
1058      * @throws Exception the exception
1059      */
1060     @Test(dataProvider = "testName", groups = {"update"},
1061                 dependsOnMethods = {"readContact", "testContactSubmitRequest",
1062                         "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"})
1063     public void updateContact(String testName) throws Exception {
1064         String contactsCommonLabel = new ContactClient().getCommonPartName();
1065
1066         // Retrieve the contents of a resource to update.
1067         PersonAuthorityClient client = new PersonAuthorityClient();
1068         PoxPayloadIn input = null;
1069         setupRead();
1070         ClientResponse<String> res =
1071                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1072         try {
1073             assertStatusCode(res, testName);
1074             if (logger.isDebugEnabled()) {
1075                 logger.debug("got Contact to update with ID: "
1076                         + knownContactResourceId
1077                         + " in item: " + knownItemResourceId
1078                         + " in parent: " + knownResourceId);
1079             }
1080             input = new PoxPayloadIn(res.getEntity());
1081         } finally {
1082                 if (res != null) {
1083                 res.releaseConnection();
1084             }
1085         }
1086
1087         ContactsCommon contact = (ContactsCommon) extractPart(input,
1088                 contactsCommonLabel, ContactsCommon.class);
1089         Assert.assertNotNull(contact);
1090
1091         // Verify the contents of this resource
1092         AddressGroupList addressGroupList = contact.getAddressGroupList();
1093         Assert.assertNotNull(addressGroupList);
1094         List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1095         Assert.assertNotNull(addressGroups);
1096         Assert.assertTrue(addressGroups.size() > 0);
1097         String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1098         Assert.assertNotNull(addressPlace1);
1099
1100         // Update the contents of this resource.
1101         addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1102         contact.setAddressGroupList(addressGroupList);
1103         if (logger.isDebugEnabled()) {
1104             logger.debug("to be updated Contact");
1105             logger.debug(objectAsXmlString(contact,
1106                     ContactsCommon.class));
1107         }
1108
1109         // Submit the updated resource to the service and store the response.
1110         PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1111         PayloadOutputPart commonPart = output.addPart(contactsCommonLabel, contact);
1112         setupUpdate();
1113         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1114         try {
1115             assertStatusCode(res, testName);
1116             // Retrieve the updated resource and verify that its contents exist.
1117             input = new PoxPayloadIn(res.getEntity());;
1118         } finally {
1119                 if (res != null) {
1120                 res.releaseConnection();
1121             }
1122         }
1123         ContactsCommon updatedContact = (ContactsCommon) extractPart(input,
1124                 contactsCommonLabel, ContactsCommon.class);
1125         Assert.assertNotNull(updatedContact);
1126
1127         // Verify that the updated resource received the correct data.
1128         Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1129                 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1130                 "Data in updated object did not match submitted data.");
1131     }
1132
1133     /**
1134      * Update non existent contact.
1135      *
1136      * @param testName the test name
1137      * @throws Exception the exception
1138      */
1139     @Test(dataProvider = "testName", groups = {"update"},
1140                 dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1141     public void updateNonExistentContact(String testName) throws Exception {
1142         // Currently a no-op test
1143     }
1144
1145     // ---------------------------------------------------------------
1146     // CRUD tests : DELETE tests
1147     // ---------------------------------------------------------------
1148     // Success outcomes
1149     // Note: delete sub-resources in ascending hierarchical order,
1150     // before deleting their parents.
1151     /**
1152      * Delete contact.
1153      *
1154      * @param testName the test name
1155      * @throws Exception the exception
1156      */
1157     @Test(dataProvider = "testName", groups = {"delete"},
1158                 dependsOnMethods = {"updateContact"})
1159     public void deleteContact(String testName) throws Exception {
1160         if (logger.isDebugEnabled()) {
1161             logger.debug("parentcsid =" + knownResourceId
1162                     + " itemcsid = " + knownItemResourceId
1163                     + " csid = " + knownContactResourceId);
1164         }
1165
1166         // Submit the request to the service and store the response.
1167         PersonAuthorityClient client = new PersonAuthorityClient();
1168         setupDelete();
1169         ClientResponse<Response> res =
1170                 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1171         try {
1172                 assertStatusCode(res, testName);
1173         } finally {
1174                 if (res != null) {
1175                         res.releaseConnection();
1176                 }
1177         }
1178     }
1179
1180     @Override
1181     public void delete(String testName) throws Exception {
1182         // Do nothing.  See localDelete().  This ensure proper test order.
1183     }
1184     
1185     @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"})    
1186     public void localDelete(String testName) throws Exception {
1187         super.delete(testName);
1188     }
1189
1190     @Override
1191     public void deleteItem(String testName) throws Exception {
1192         // Do nothing.  We need to wait until after the test "localDelete" gets run.  When it does,
1193         // its dependencies will get run first and then we can call the base class' delete method.
1194     }
1195     
1196     @Test(dataProvider = "testName", groups = {"delete"},
1197         dependsOnMethods = {"verifyIllegalItemDisplayName", "testContactSubmitRequest", "deleteContact"})
1198     public void localDeleteItem(String testName) throws Exception {
1199         super.deleteItem(testName);
1200     }
1201
1202     /**
1203      * Delete non existent contact.
1204      *
1205      * @param testName the test name
1206      */
1207     @Test(dataProvider = "testName", groups = {"delete"},
1208                 dependsOnMethods = {"deleteContact"})
1209     public void deleteNonExistentContact(String testName) {
1210         // Submit the request to the service and store the response.
1211         PersonAuthorityClient client = new PersonAuthorityClient();
1212         setupDeleteNonExistent();
1213         ClientResponse<Response> res =
1214                 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1215         try {
1216                 assertStatusCode(res, testName);
1217         } finally {
1218                 if (res != null) {
1219                         res.releaseConnection();
1220                 }
1221         }
1222     }
1223
1224     /**
1225      * Test contact submit request.
1226      */
1227     @Test(dataProvider = "testName",
1228                 dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1229     public void testContactSubmitRequest(String testName) {
1230
1231         // Expected status code: 200 OK
1232         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1233
1234         // Submit the request to the service and store the response.
1235         String method = ServiceRequestType.READ.httpMethodName();
1236         String url = getContactResourceURL(knownResourceId,
1237                 knownItemResourceId, knownContactResourceId);
1238         int statusCode = submitRequest(method, url);
1239
1240         // Check the status code of the response: does it match
1241         // the expected response(s)?
1242         if (logger.isDebugEnabled()) {
1243             logger.debug("testContactSubmitRequest: url=" + url
1244                     + " status=" + statusCode);
1245         }
1246         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1247
1248     }
1249
1250     // ---------------------------------------------------------------
1251     // Cleanup of resources created during testing
1252     // ---------------------------------------------------------------
1253     /**
1254      * Deletes all resources created by tests, after all tests have been run.
1255      *
1256      * This cleanup method will always be run, even if one or more tests fail.
1257      * For this reason, it attempts to remove all resources created
1258      * at any point during testing, even if some of those resources
1259      * may be expected to be deleted by certain tests.
1260      */
1261     @AfterClass(alwaysRun = true)
1262     @Override
1263     public void cleanUp() {
1264         String noTest = System.getProperty("noTestCleanup");
1265         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1266             if (logger.isDebugEnabled()) {
1267                 logger.debug("Skipping Cleanup phase ...");
1268             }
1269             return;
1270         }
1271         if (logger.isDebugEnabled()) {
1272             logger.debug("Cleaning up temporary resources created for testing ...");
1273         }
1274         String parentResourceId;
1275         String itemResourceId;
1276         String contactResourceId;
1277         // Clean up contact resources.
1278         PersonAuthorityClient client = new PersonAuthorityClient();
1279         parentResourceId = knownResourceId;
1280         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1281             contactResourceId = entry.getKey();
1282             itemResourceId = entry.getValue();
1283             // Note: Any non-success responses from the delete operation
1284             // below are ignored and not reported.
1285             ClientResponse<Response> res =
1286                     client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1287             res.releaseConnection();
1288         }
1289         // Clean up item resources.
1290         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1291             itemResourceId = entry.getKey();
1292             parentResourceId = entry.getValue();
1293             // Note: Any non-success responses from the delete operation
1294             // below are ignored and not reported.
1295             ClientResponse<Response> res =
1296                     client.deleteItem(parentResourceId, itemResourceId);
1297             res.releaseConnection();
1298         }
1299         // Clean up parent resources.
1300         super.cleanUp();
1301     }
1302
1303     // ---------------------------------------------------------------
1304     // Utility methods used by tests above
1305     // ---------------------------------------------------------------
1306     /**
1307      * Gets the contact service path component.
1308      *
1309      * @return the contact service path component
1310      */
1311     public String getContactServicePathComponent() {
1312         return ContactClient.SERVICE_PATH_COMPONENT;
1313     }
1314
1315     /**
1316      * Returns the root URL for the item service.
1317      *
1318      * This URL consists of a base URL for all services, followed by
1319      * a path component for the owning parent, followed by the
1320      * path component for the items.
1321      *
1322      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1323      * parent authority resource of the relevant item resource.
1324      *
1325      * @return The root URL for the item service.
1326      */
1327     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1328         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1329     }
1330
1331     /**
1332      * Returns the URL of a specific item resource managed by a service, and
1333      * designated by an identifier (such as a universally unique ID, or UUID).
1334      *
1335      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1336      * parent authority resource of the relevant item resource.
1337      *
1338      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1339      * item resource.
1340      *
1341      * @return The URL of a specific item resource managed by a service.
1342      */
1343     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1344         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1345     }
1346
1347     /**
1348      * Returns the root URL for the contact service.
1349      *
1350      * This URL consists of a base URL for all services, followed by
1351      * a path component for the owning authority, followed by the
1352      * path component for the owning item, followed by the path component
1353      * for the contact service.
1354      *
1355      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1356      * parent authority resource of the relevant item resource.
1357      *
1358      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1359      * item resource.
1360      *
1361      * @return The root URL for the contact service.
1362      */
1363     protected String getContactServiceRootURL(String parentResourceIdentifier,
1364             String itemResourceIdentifier) {
1365         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
1366                 + getContactServicePathComponent();
1367     }
1368
1369     /**
1370      * Returns the URL of a specific contact resource managed by a service, and
1371      * designated by an identifier (such as a universally unique ID, or UUID).
1372      *
1373      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1374      * parent resource of the relevant item resource.
1375      *
1376      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1377      * item resource.
1378      *
1379      * @return The URL of a specific resource managed by a service.
1380      */
1381     protected String getContactResourceURL(String parentResourceIdentifier,
1382             String itemResourceIdentifier, String contactResourceIdentifier) {
1383         return getContactServiceRootURL(parentResourceIdentifier,
1384                 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1385     }
1386
1387         @Override
1388         public void authorityTests(String testName) {
1389                 // TODO Auto-generated method stub
1390                 
1391         }
1392
1393         @Override
1394         protected PersonsCommon updateItemInstance(PersonsCommon authorityItem) {
1395                 // TODO Auto-generated method stub
1396                 return null;
1397         }
1398
1399         @Override
1400         protected void compareUpdatedItemInstances(PersonsCommon original,
1401                         PersonsCommon updated) throws Exception {
1402                 // TODO Auto-generated method stub
1403                 
1404         }
1405
1406         @Override
1407         protected PoxPayloadOut createInstance(String commonPartName,
1408                         String identifier) {
1409         String shortId = identifier;
1410         String displayName = "displayName-" + shortId;
1411         PoxPayloadOut result =
1412                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
1413                 displayName, shortId, commonPartName);
1414         return result;
1415         }
1416         
1417         @Override
1418         protected PoxPayloadOut createNonExistenceInstance(String commonPartName,
1419                         String identifier) {
1420         String displayName = "displayName-NON_EXISTENT_ID";
1421         PoxPayloadOut result = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1422                 displayName, "NON_EXISTENT_SHORT_ID", commonPartName);
1423         return result;
1424         }
1425         
1426     protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier) {
1427         Map<String, String> nonexMap = new HashMap<String, String>();
1428         nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1429         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1430         
1431         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
1432         PersonTermGroup term = new PersonTermGroup();
1433         term.setTermDisplayName("John Wayne");
1434         term.setTermName("John Wayne");
1435         term.setForeName("John");
1436         term.setSurName("Wayne");
1437         terms.add(term);
1438         
1439         Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1440         PoxPayloadOut result =
1441                 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1442                 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1443                 nonexMap, terms, nonexRepeatablesMap, commonPartName);
1444         return result;
1445     }
1446         
1447
1448         @Override
1449         protected PersonauthoritiesCommon updateInstance(
1450                         PersonauthoritiesCommon commonPartObject) {
1451                 // TODO Auto-generated method stub
1452                 return null;
1453         }
1454
1455         @Override
1456         protected void compareUpdatedInstances(PersonauthoritiesCommon original,
1457                         PersonauthoritiesCommon updated) throws Exception {
1458                 // TODO Auto-generated method stub
1459         }
1460
1461         @Override
1462         protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
1463                 // Do nothing for now.  Add more 'read' validation checks here if applicable.
1464         }
1465 }