]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
392721e8e1fc1f4aa0bce77aad0f06953396f9f9
[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     private final String REFNAME = "refName";
76     private final String TERM_DISPLAY_NAME = "termDisplayName";
77     // private final String TERM_DISPLAY_NAME_ELPATH =
78     //        NuxeoUtils.getPrimaryElPathPropertyName(null,
79     //            new PersonAuthorityClient().getTermInfoGroupXpathBase(), TERM_DISPLAY_NAME);
80
81     @Override
82     public String getServicePathComponent() {
83         return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
84     }
85
86     @Override
87     protected String getServiceName() {
88         return PersonAuthorityClient.SERVICE_NAME;
89     }
90
91     public String getItemServicePathComponent() {
92         return AuthorityClient.ITEMS;
93     }
94     /** The test forename. */
95     final String TEST_FORE_NAME = "John";
96     /** The test middle name. */
97     final String TEST_MIDDLE_NAME = null;
98     /** The test surname. */
99     final String TEST_SUR_NAME = "Wayne";
100     /** The test birthdate. */
101     final String TEST_BIRTH_DATE = "May 26, 1907";
102     /** The test death date. */
103     final String TEST_DEATH_DATE = "June 11, 1979";
104     //private String knownResourceRefName = null;
105     private String knownItemResourceShortIdentifer = null;
106     // The resource ID of an item resource used for partial term matching tests.
107     private String knownItemPartialTermResourceId = null;
108     /** The known contact resource id. */
109     private String knownContactResourceId = null;
110     /** The all contact resource ids created. */
111     private Map<String, String> allContactResourceIdsCreated =
112             new HashMap<String, String>();
113
114     protected void setKnownResource(String id, String shortIdentifer,
115             String refName) {
116         knownResourceId = id;
117         knownResourceShortIdentifer = shortIdentifer;
118         //knownResourceRefName = refName;
119     }
120
121     protected void setKnownItemResource(String id, String shortIdentifer) {
122         knownItemResourceId = id;
123         knownItemResourceShortIdentifer = shortIdentifer;
124     }
125
126     /* (non-Javadoc)
127      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
128      */
129     @Override
130     protected CollectionSpaceClient getClientInstance() {
131         return new PersonAuthorityClient();
132     }
133
134     // ---------------------------------------------------------------
135     // CRUD tests : CREATE tests
136     // ---------------------------------------------------------------
137     // Success outcomes
138     /* (non-Javadoc)
139      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
140      */
141     @Override
142 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
143 //    groups = {"create"})
144     public void create(String testName) throws Exception {
145         // Perform setup, such as initializing the type of service request
146         // (e.g. CREATE, DELETE), its valid and expected status codes, and
147         // its associated HTTP method name (e.g. POST, DELETE).
148         setupCreate();
149
150         // Submit the request to the service and store the response.
151         PersonAuthorityClient client = new PersonAuthorityClient();
152         String shortId = createIdentifier();
153         String displayName = "displayName-" + shortId;
154         //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
155         PoxPayloadOut multipart =
156                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
157                 displayName, shortId, client.getCommonPartName());
158
159         String newID = null;
160         ClientResponse<Response> res = client.create(multipart);
161         try {
162                 assertStatusCode(res, testName);
163             newID = extractId(res);
164         } finally {
165                 if (res != null) {
166                         res.releaseConnection();
167                 }
168         }
169         // Save values for additional tests
170         if (knownResourceId == null) {
171             setKnownResource(newID, shortId, null ); //baseRefName);
172             if (logger.isDebugEnabled()) {
173                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
174             }
175         }
176         // Store the IDs from every resource created by tests,
177         // so they can be deleted after tests have been run.
178         allResourceIdsCreated.add(newID);
179     }
180
181     @Override
182     protected PoxPayloadOut createInstance(String identifier) {
183         PersonAuthorityClient client = new PersonAuthorityClient();
184         String displayName = "displayName-" + identifier;
185         PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
186                 displayName, identifier, client.getCommonPartName());
187         return multipart;
188     }
189
190     @Override
191     protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
192         String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
193         
194         HashMap<String, String> personInfo = new HashMap<String, String>();
195         String shortId = "johnWayneTempActor";
196         personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
197         
198         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
199         PersonTermGroup term = new PersonTermGroup();
200         term.setTermDisplayName("John Wayne Temp");
201         term.setTermName("JohnWayneTemp");
202         terms.add(term);
203         
204         return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, terms, headerLabel);
205     }
206
207     /**
208      * Creates an item in an authority, using test data.
209      *
210      * @param vcsid the vcsid
211      * @param authRefName the auth ref name
212      * @return the string
213      */
214     @Override
215     protected String createItemInAuthority(String vcsid) {
216
217         final String testName = "createItemInAuthority";
218         if (logger.isDebugEnabled()) {
219             logger.debug(testName + ":" + vcsid + "...");
220         }
221
222         Map<String, String> johnWayneMap = new HashMap<String, String>();
223         //
224         // Fill the property map
225         //
226         String shortId = "johnWayneActor";
227         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
228         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
229         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
230         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
231         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
232         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better"
233                 + "known by his stage name John Wayne, was an American film actor, director "
234                 + "and producer. He epitomized rugged masculinity and has become an enduring "
235                 + "American icon. He is famous for his distinctive voice, walk and height. "
236                 + "He was also known for his conservative political views and his support in "
237                 + "the 1950s for anti-communist positions.");
238
239         List<PersonTermGroup> johnWayneTerms = new ArrayList<PersonTermGroup>();
240         PersonTermGroup term = new PersonTermGroup();
241         term.setTermDisplayName("John Wayne DisplayName");
242         term.setTermName("John Wayne");
243         term.setForeName(TEST_FORE_NAME);
244         term.setSurName(TEST_SUR_NAME);
245         johnWayneTerms.add(term);
246
247         Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String, List<String>>();
248         List<String> johnWayneGroups = new ArrayList<String>();
249         johnWayneGroups.add("Irish");
250         johnWayneGroups.add("Scottish");
251         johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
252
253         return createItemInAuthority(vcsid, null /*authRefName*/, shortId, johnWayneMap, johnWayneTerms, johnWayneRepeatablesMap);
254
255     }
256
257     /**
258      * Creates an item in an authority.
259      *
260      * @param vcsid the vcsid
261      * @param authRefName the auth ref name
262      * @param itemFieldProperties a set of properties specifying the values of fields.
263      * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
264      * @return the string
265      */
266     private String createItemInAuthority(String vcsid, String authRefName, String shortId,
267             Map itemFieldProperties, List<PersonTermGroup> terms, Map itemRepeatableFieldProperties) {
268
269         final String testName = "createItemInAuthority";
270         if (logger.isDebugEnabled()) {
271             logger.debug(testName + ":" + vcsid + "...");
272         }
273
274         // Submit the request to the service and store the response.
275         PersonAuthorityClient client = new PersonAuthorityClient();
276         PoxPayloadOut multipart =
277                 PersonAuthorityClientUtils.createPersonInstance(vcsid, null /*authRefName*/, itemFieldProperties,
278                 terms, itemRepeatableFieldProperties, client.getItemCommonPartName());
279         setupCreate();
280         ClientResponse<Response> res = client.createItem(vcsid, multipart);
281         String newID = null;
282         try {
283                 assertStatusCode(res, testName);
284             newID = PersonAuthorityClientUtils.extractId(res);
285         } finally {
286                 if (res != null) {
287                         res.releaseConnection();
288                 }
289         }
290
291         // Store the ID returned from the first item resource created
292         // for additional tests below.
293         if (knownItemResourceId == null) {
294             setKnownItemResource(newID, shortId);
295             if (logger.isDebugEnabled()) {
296                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
297             }
298         }
299         if (logger.isDebugEnabled()) {
300             logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")");
301         }
302
303         // Store the IDs from any item resources created
304         // by tests, along with the IDs of their parents, so these items
305         // can be deleted after all tests have been run.
306         allResourceItemIdsCreated.put(newID, vcsid);
307
308         return newID;
309     }
310
311     /**
312      * Creates the contact.
313      *
314      * @param testName the test name
315      */
316     @Test(dataProvider = "testName", groups = {"create"},
317                 dependsOnMethods = {"createItem"})
318     public void createContact(String testName) {
319         setupCreate();
320         String newID = createContactInItem(knownResourceId, knownItemResourceId);
321     }
322
323     /**
324      * Creates the contact in item.
325      *
326      * @param parentcsid the parentcsid
327      * @param itemcsid the itemcsid
328      * @return the string
329      */
330     private String createContactInItem(String parentcsid, String itemcsid) {
331
332         final String testName = "createContactInItem";
333         if (logger.isDebugEnabled()) {
334             logger.debug(testName + ":...");
335         }
336         // Submit the request to the service and store the response.
337         PersonAuthorityClient client = new PersonAuthorityClient();
338         String identifier = createIdentifier();
339         PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
340                 itemcsid, identifier, new ContactClient().getCommonPartName());
341
342         setupCreate();
343         ClientResponse<Response> res =
344                 client.createContact(parentcsid, itemcsid, multipart);
345         String newID = null;
346         try {
347                 assertStatusCode(res, testName);
348             newID = PersonAuthorityClientUtils.extractId(res);
349         } finally {
350                 if (res != null) {
351                         res.releaseConnection();
352                 }
353         }
354
355         // Store the ID returned from the first contact resource created
356         // for additional tests below.
357         if (knownContactResourceId == null) {
358             knownContactResourceId = newID;
359             if (logger.isDebugEnabled()) {
360                 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
361             }
362         }
363
364         // Store the IDs from any contact resources created
365         // by tests, along with the IDs of their parent items,
366         // so these items can be deleted after all tests have been run.
367         allContactResourceIdsCreated.put(newID, itemcsid);
368
369         return newID;
370     }
371
372     /**
373      * Attempts to create an authority with an short identifier that contains
374      * non-word characters.
375      *
376      * @param testName the test name
377      */
378     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"})
379     public void createWithShortIdNonWordChars(String testName) throws Exception {
380         testExpectedStatusCode = STATUS_BAD_REQUEST;
381         testRequestType = ServiceRequestType.CREATE;
382         testSetup(testExpectedStatusCode, testRequestType);
383
384         // Create the payload to be included in the body of the request
385         PersonAuthorityClient client = new PersonAuthorityClient();
386         String shortId = createIdentifier() + "*" + createIdentifier();
387         String displayName = "displayName-" + shortId;
388         PoxPayloadOut multipart =
389                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
390                 displayName, shortId, client.getCommonPartName());
391
392         // Submit the request to the service and store the response.
393         ClientResponse<Response> res = client.create(multipart);
394
395         // Check the status code of the response: does it match
396         // the expected response(s)?
397         try {
398                 assertStatusCode(res, testName);
399         } finally {
400                 if (res != null) {
401                         res.releaseConnection();
402                 }
403         }
404     }
405
406     /**
407      * Attempts to create an item with an short identifier that contains
408      * non-word characters.
409      *
410      * @param testName the test name
411      */
412     @Test(dataProvider = "testName", groups = {"create", "nonWordCharsInShortId"},
413                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractServiceTestImpl.create"})
414     public void createItemWithShortIdNonWordChars(String testName) {
415         testExpectedStatusCode = STATUS_BAD_REQUEST;
416         testRequestType = ServiceRequestType.CREATE;
417         testSetup(testExpectedStatusCode, testRequestType);
418
419         PersonAuthorityClient client = new PersonAuthorityClient();
420         // Create the payload to be included in the body of the request
421         String shortId = "7-Eleven";
422         Map<String, String> fieldProperties = new HashMap<String, String>();
423         fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
424         
425         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
426         PersonTermGroup term = new PersonTermGroup();
427         term.setTermDisplayName(shortId);
428         term.setTermName(shortId);
429         terms.add(term);
430         
431         final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
432         PoxPayloadOut multipart =
433                 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
434                 null /*knownResourceRefName*/, fieldProperties, terms,
435                 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
436
437         // Send the request and receive a response
438         ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
439         // Check the status code of the response: does it match
440         // the expected response(s)?
441         try {
442                 assertStatusCode(res, testName);
443         } finally {
444                 if (res != null) {
445                         res.releaseConnection();
446                 }
447         }
448     }
449
450     // ---------------------------------------------------------------
451     // CRUD tests : CREATE LIST tests
452     // ---------------------------------------------------------------
453     // Success outcomes
454     /* (non-Javadoc)
455      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
456      */
457     @Override
458 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
459 //    groups = {"createList"}, dependsOnGroups = {"create"})
460     public void createList(String testName) throws Exception {
461         for (int i = 0; i < nItemsToCreateInList; i++) {
462             create(testName);
463         }
464     }
465
466     /**
467      * Creates the contact list.
468      *
469      * @param testName the test name
470      * @throws Exception the exception
471      */
472     @Test(dataProvider = "testName", groups = {"createList"},
473                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.createItemList"})
474     public void createContactList(String testName) throws Exception {
475         // Add contacts to the initially-created, known item record.
476         for (int j = 0; j < nItemsToCreateInList; j++) {
477             createContact(testName);
478         }
479     }
480
481     // ---------------------------------------------------------------
482     // CRUD tests : READ tests
483     // ---------------------------------------------------------------
484     // Success outcomes
485     /* (non-Javadoc)
486      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
487      */
488     @Override
489 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
490 //    groups = {"read"}, dependsOnGroups = {"create"})
491     public void read(String testName) throws Exception {
492         readInternal(testName, knownResourceId, null);
493     }
494
495     /**
496      * Read by name.
497      *
498      * @param testName the test name
499      * @throws Exception the exception
500      */
501     @Override
502 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
503 //    groups = {"read"}, dependsOnMethods = {"read"})
504     public void readByName(String testName) throws Exception {
505         readInternal(testName, null, knownResourceShortIdentifer);
506     }
507
508     protected void readInternal(String testName, String CSID, String shortId) {
509         // Submit the request to the service and store the response.
510         PersonAuthorityClient client = new PersonAuthorityClient();
511         ClientResponse<String> res = null;
512         setupRead();
513         if (CSID != null) {
514             res = client.read(CSID);
515         } else if (shortId != null) {
516             res = client.readByName(shortId);
517         } else {
518             Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
519         }
520         try {
521             assertStatusCode(res, testName);
522             //FIXME: remove the following try catch once Aron fixes signatures
523             try {
524                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
525                 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
526                         client.getCommonPartName(), PersonauthoritiesCommon.class);
527                 Assert.assertNotNull(personAuthority);
528             } catch (Exception e) {
529                 throw new RuntimeException(e);
530             }
531         } finally {
532                 if (res != null) {
533                 res.releaseConnection();
534             }
535         }
536     }
537
538     /**
539      * Read named item.
540      *
541      * @param testName the test name
542      * @throws Exception the exception
543      */
544     @Test(dataProvider = "testName", groups = {"readItem", "readNamedItemInNamedAuth"},
545                 dependsOnMethods = {"readItemInNamedAuth"})
546     public void readNamedItem(String testName) throws Exception {
547         readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
548     }
549
550     /**
551      * Read item in Named Auth.
552      *
553      * @param testName the test name
554      * @throws Exception the exception
555      */
556     @Test(dataProvider = "testName", groups = {"readItem"},
557                 dependsOnMethods = {"readItem"})
558     public void readItemInNamedAuth(String testName) throws Exception {
559         readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
560     }
561
562     
563     /**
564      * Read Named item in Named Auth.
565      *
566      * @param testName the test name
567      * @throws Exception the exception
568      */
569     @Test(dataProvider = "testName", groups = {"readItem"},
570                 dependsOnMethods = {"readNamedItem"})
571     public void readNamedItemInNamedAuth(String testName) throws Exception {
572         readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
573     }
574
575     protected void readItemInternal(String testName,
576             String authCSID, String authShortId, String itemCSID, String itemShortId)
577             throws Exception {
578
579         if (logger.isDebugEnabled()) {
580             logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/"
581                     + ((itemCSID != null) ? authCSID : itemShortId));
582         }
583
584         // Submit the request to the service and store the response.
585         PersonAuthorityClient client = new PersonAuthorityClient();
586         setupRead();
587         ClientResponse<String> res = null;
588         if (authCSID != null) {
589             if (itemCSID != null) {
590                 res = client.readItem(authCSID, itemCSID);
591             } else if (itemShortId != null) {
592                 res = client.readNamedItem(authCSID, itemShortId);
593             } else {
594                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
595             }
596         } else if (authShortId != null) {
597             if (itemCSID != null) {
598                 res = client.readItemInNamedAuthority(authShortId, itemCSID);
599             } else if (itemShortId != null) {
600                 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
601             } else {
602                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
603             }
604         } else {
605             Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
606         }
607         try {
608             assertStatusCode(res, testName);
609             // Check whether we've received a person.
610             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
611             PersonsCommon person = (PersonsCommon) extractPart(input,
612                     client.getItemCommonPartName(), PersonsCommon.class);
613             Assert.assertNotNull(person);
614             boolean showFull = true;
615             if (showFull && logger.isDebugEnabled()) {
616                 logger.debug(testName + ": returned payload:");
617                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
618             }
619
620             // Check that the person item is within the expected Person Authority.
621             Assert.assertEquals(person.getInAuthority(), knownResourceId);
622
623             // Verify the number and contents of values in a repeatable field,
624             // as created in the instance record used for testing.
625             List<String> groups = person.getGroups().getGroup();
626             Assert.assertTrue(groups.size() > 0);
627             Assert.assertNotNull(groups.get(0));
628         } finally {
629                 if (res != null) {
630                 res.releaseConnection();
631             }
632         }
633     }
634     
635     // FIXME: This test depends on server-side validation logic to require
636     // a non-null (and potentially, non-empty) displayname for each term,
637     // and will fail if that validation is not present.
638
639     /**
640      * Verify illegal item display name.
641      *
642      * @param testName the test name
643      * @throws Exception the exception
644      */
645     @Test(dataProvider = "testName", groups = {"update"})
646     public void verifyIllegalItemDisplayName(String testName) throws Exception {
647         // Perform setup for read.
648         setupRead();
649
650         // Submit the request to the service and store the response.
651         PersonAuthorityClient client = new PersonAuthorityClient();
652         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
653         PoxPayloadIn input = null;
654         try {
655             assertStatusCode(res, testName);
656             input = new PoxPayloadIn(res.getEntity());
657         } finally {
658                 if (res != null) {
659                 res.releaseConnection();
660             }
661         }
662         //
663         // Make an invalid UPDATE request, without a display name
664         //
665         PersonsCommon person = (PersonsCommon) extractPart(input,
666                 client.getItemCommonPartName(), PersonsCommon.class);
667         Assert.assertNotNull(person);
668         // Try to Update with no displayName
669         List<PersonTermGroup> johnWayneTerms = new ArrayList<PersonTermGroup>();
670         PersonTermGroup term = new PersonTermGroup();
671         term.setTermDisplayName("John Wayne DisplayName");
672         term.setTermName("John Wayne");
673         term.setForeName(TEST_FORE_NAME);
674         term.setSurName(TEST_SUR_NAME);
675         johnWayneTerms.add(term);
676         
677         PersonTermGroupList termList = person.getPersonTermGroupList();
678         Assert.assertNotNull(termList);
679         List<PersonTermGroup> terms = termList.getPersonTermGroup();
680         Assert.assertNotNull(terms);
681         terms.get(0).setTermDisplayName(null);
682
683         // Submit the updated resource to the service and store the response.
684         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
685         PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person);
686         setupUpdateWithInvalidBody();
687         res = client.updateItem(knownResourceId, knownItemResourceId, output);
688         try {
689             assertStatusCode(res, testName);
690         } finally {
691                 if (res != null) {
692                 res.releaseConnection();
693             }
694         }
695     }
696
697     /**
698      * Read contact.
699      *
700      * @param testName the test name
701      * @throws Exception the exception
702      */
703     @Test(dataProvider = "testName", groups = {"readItem"},
704                 dependsOnMethods = {"createContact", "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItem"})
705     public void readContact(String testName) throws Exception {
706         // Perform setup.
707         setupRead();
708
709         // Submit the request to the service and store the response.
710         PersonAuthorityClient client = new PersonAuthorityClient();
711         PoxPayloadIn input = null;
712         ClientResponse<String> res =
713                 client.readContact(knownResourceId, knownItemResourceId,
714                 knownContactResourceId);
715         try {
716             assertStatusCode(res, testName);
717             // Check whether we've received a contact.
718             input = new PoxPayloadIn(res.getEntity());
719         } finally {
720                 if (res != null) {
721                 res.releaseConnection();
722             }
723         }
724
725         ContactsCommon contact = (ContactsCommon) extractPart(input,
726                 new ContactClient().getCommonPartName(), ContactsCommon.class);
727         Assert.assertNotNull(contact);
728         boolean showFull = true;
729         if (showFull && logger.isDebugEnabled()) {
730             logger.debug(testName + ": returned payload:");
731             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
732         }
733         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
734         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
735
736     }
737
738     /**
739      * Read contact non existent.
740      *
741      * @param testName the test name
742      */
743     @Test(dataProvider = "testName", groups = {"readItem"},
744                 dependsOnMethods = {"readContact"})
745     public void readContactNonExistent(String testName) {
746         // Perform setup.
747         setupReadNonExistent();
748
749         // Submit the request to the service and store the response.
750         PersonAuthorityClient client = new PersonAuthorityClient();
751         ClientResponse<String> res =
752                 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
753         try {
754             assertStatusCode(res, testName);
755         } finally {
756                 if (res != null) {
757                 res.releaseConnection();
758             }
759         }
760     }
761
762     // ---------------------------------------------------------------
763     // CRUD tests : READ_LIST tests
764     // ---------------------------------------------------------------
765
766     /**
767      * Read item list.
768      */
769     @Override
770 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
771 //    groups = {"readList"}, dependsOnMethods = {"readList"})
772     public void readItemList(String testName) {
773         readItemList(knownAuthorityWithItems, null, testName);
774     }
775
776     /**
777      * Read item list by authority name.
778      */
779     @Override
780 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
781 //    groups = {"readList"}, dependsOnMethods = {"readItemList"})
782     public void readItemListByName(String testName) {
783         readItemList(null, READITEMS_SHORT_IDENTIFIER, testName);
784     }
785
786     /**
787      * Read item list.
788      *
789      * @param vcsid the vcsid
790      * @param name the name
791      */
792     private void readItemList(String vcsid, String name, String testName) {
793         setupReadList();
794         // Submit the request to the service and store the response.
795         PersonAuthorityClient client = new PersonAuthorityClient();
796         ClientResponse<AbstractCommonList> res = null;
797         if (vcsid != null) {
798             res = client.readItemList(vcsid, null, null);
799         } else if (name != null) {
800             res = client.readItemListForNamedAuthority(name, null, null);
801         } else {
802             Assert.fail("readItemList passed null csid and name!");
803         }
804         AbstractCommonList list = null;
805         try {
806             assertStatusCode(res, testName);
807             list = res.getEntity();
808         } finally {
809                 if (res != null) {
810                 res.releaseConnection();
811             }
812         }
813
814         List<AbstractCommonList.ListItem> items = list.getListItem();
815         int nItemsReturned = items.size();
816         // There will be 'nItemsToCreateInList'
817         // items created by the createItemList test,
818         // all associated with the same parent resource.
819         int nExpectedItems = nItemsToCreateInList;
820         if (logger.isDebugEnabled()) {
821             logger.debug(testName + ": Expected "
822                     + nExpectedItems + " items; got: " + nItemsReturned);
823         }
824         Assert.assertEquals(nItemsReturned, nExpectedItems);
825
826         for (AbstractCommonList.ListItem item : items) {
827             String value =
828                     AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
829             Assert.assertTrue((null != value), "Item refName is null!");
830             
831             value =
832                     AbstractCommonListUtils.ListItemGetElementValue(item, TERM_DISPLAY_NAME);
833             Assert.assertTrue((null != value), "Item displayName is null!");
834         }
835         if (logger.isTraceEnabled()) {
836             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
837         }
838     }
839
840     /**
841      * Read contact list.
842      */
843     @Test(groups = {"readList"},
844                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"})
845     public void readContactList() {
846         readContactList(knownResourceId, knownItemResourceId);
847     }
848
849     /**
850      * Read contact list.
851      *
852      * @param parentcsid the parentcsid
853      * @param itemcsid the itemcsid
854      */
855     private void readContactList(String parentcsid, String itemcsid) {
856         final String testName = "readContactList";
857
858         // Perform setup.
859         setupReadList();
860
861         // Submit the request to the service and store the response.
862         PersonAuthorityClient client = new PersonAuthorityClient();
863         AbstractCommonList list = null;
864         ClientResponse<AbstractCommonList> res =
865                 client.readContactList(parentcsid, itemcsid);
866         try {
867             assertStatusCode(res, testName);
868             list = res.getEntity();
869         } finally {
870                 if (res != null) {
871                 res.releaseConnection();
872             }
873         }
874
875         List<AbstractCommonList.ListItem> listitems =
876                 list.getListItem();
877         int nItemsReturned = listitems.size();
878         // There will be one item created, associated with a
879         // known parent resource, by the createItem test.
880         //
881         // In addition, there will be 'nItemsToCreateInList'
882         // additional items created by the createItemList test,
883         // all associated with the same parent resource.
884         int nExpectedItems = nItemsToCreateInList + 1;
885         if (logger.isDebugEnabled()) {
886             logger.debug(testName + ": Expected "
887                     + nExpectedItems + " items; got: " + nItemsReturned);
888         }
889         Assert.assertEquals(nItemsReturned, nExpectedItems);
890         
891         // Optionally output additional data about list members for debugging.
892         boolean iterateThroughList = false;
893         if (iterateThroughList && logger.isDebugEnabled()) {
894             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
895         }
896     }
897
898     // Failure outcomes
899     // There are no failure outcome tests at present.
900     // ---------------------------------------------------------------
901     // CRUD tests : UPDATE tests
902     // ---------------------------------------------------------------
903     // Success outcomes
904     /* (non-Javadoc)
905      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
906      */
907     @Override
908 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
909 //    groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
910     public void update(String testName) throws Exception {
911         // Retrieve the contents of a resource to update.
912         PersonAuthorityClient client = new PersonAuthorityClient();
913         PoxPayloadIn input = null;
914         setupRead();
915         ClientResponse<String> res = client.read(knownResourceId);
916         try {
917             assertStatusCode(res, testName);
918             if (logger.isDebugEnabled()) {
919                 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
920             }
921             input = new PoxPayloadIn(res.getEntity());
922         } finally {
923                 if (res != null) {
924                 res.releaseConnection();
925             }
926         }
927
928         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
929                 client.getCommonPartName(), PersonauthoritiesCommon.class);
930         Assert.assertNotNull(personAuthority);
931
932         // Update the contents of this resource.
933         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
934         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
935         if (logger.isDebugEnabled()) {
936             logger.debug("to be updated PersonAuthority");
937             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
938         }
939
940         // Submit the updated resource to the service and store the response.
941         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
942         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), personAuthority);
943         setupUpdate();
944         res = client.update(knownResourceId, output);
945         try {
946             assertStatusCode(res, testName);
947             // Retrieve the updated resource and verify that its contents exist.
948             input = new PoxPayloadIn(res.getEntity());
949         } finally {
950                 if (res != null) {
951                 res.releaseConnection();
952             }
953         }
954
955         PersonauthoritiesCommon updatedPersonAuthority =
956                 (PersonauthoritiesCommon) extractPart(input,
957                 client.getCommonPartName(), PersonauthoritiesCommon.class);
958         Assert.assertNotNull(updatedPersonAuthority);
959
960         // Verify that the updated resource received the correct data.
961         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
962                 personAuthority.getDisplayName(),
963                 "Data in updated object did not match submitted data.");
964     }
965
966     /**
967      * Update item.
968      *
969      * @param testName the test name
970      * @throws Exception the exception
971      */
972     @Override
973 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
974 //    groups = {"update"}, dependsOnMethods = {"update"})
975     public void updateItem(String testName) throws Exception {
976         // Retrieve the contents of a resource to update.
977         PersonAuthorityClient client = new PersonAuthorityClient();
978         PoxPayloadIn input = null;
979         setupRead();
980         ClientResponse<String> res =
981                 client.readItem(knownResourceId, knownItemResourceId);
982         try {
983             assertStatusCode(res, testName);
984             if (logger.isDebugEnabled()) {
985                 logger.debug("got Person to update with ID: "
986                         + knownItemResourceId
987                         + " in PersonAuthority: " + knownResourceId);
988             }
989             input = new PoxPayloadIn(res.getEntity());
990         } finally {
991                 if (res != null) {
992                 res.releaseConnection();
993             }
994         }
995
996         PersonsCommon person = (PersonsCommon) extractPart(input,
997                 client.getItemCommonPartName(), PersonsCommon.class);
998         Assert.assertNotNull(person);
999
1000         if (logger.isDebugEnabled() == true) {
1001             logger.debug("About to update the following person...");
1002             logger.debug(objectAsXmlString(person, PersonsCommon.class));
1003         }
1004
1005         // Update the contents of this resource.
1006         person.setCsid(null);
1007         PersonTermGroupList termList = person.getPersonTermGroupList();
1008         Assert.assertNotNull(termList);
1009         List<PersonTermGroup> terms = termList.getPersonTermGroup();
1010         Assert.assertNotNull(terms);
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.setForeName("John");
1434         term.setSurName("Wayne");
1435         terms.add(term);
1436         
1437         Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1438         PoxPayloadOut result =
1439                 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1440                 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1441                 nonexMap, terms, nonexRepeatablesMap, commonPartName);
1442         return result;
1443     }
1444         
1445
1446         @Override
1447         protected PersonauthoritiesCommon updateInstance(
1448                         PersonauthoritiesCommon commonPartObject) {
1449                 // TODO Auto-generated method stub
1450                 return null;
1451         }
1452
1453         @Override
1454         protected void compareUpdatedInstances(PersonauthoritiesCommon original,
1455                         PersonauthoritiesCommon updated) throws Exception {
1456                 // TODO Auto-generated method stub
1457         }
1458
1459         @Override
1460         protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
1461                 // Do nothing for now.  Add more 'read' validation checks here if applicable.
1462         }
1463 }