]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
aea86f4a89518c735d69aa39427c6fcc7e0dd8d8
[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         PersonTermGroupList termList = person.getPersonTermGroupList();
664         Assert.assertNotNull(termList);
665         List<PersonTermGroup> terms = termList.getPersonTermGroup();
666         Assert.assertNotNull(terms);
667         Assert.assertTrue(terms.size() > 0);
668         terms.get(0).setTermDisplayName(null);
669         terms.get(0).setTermName(null);
670
671         // Submit the updated resource to the service and store the response.
672         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
673         PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person);
674         setupUpdateWithInvalidBody();
675         res = client.updateItem(knownResourceId, knownItemResourceId, output);
676         try {
677             assertStatusCode(res, testName);
678         } finally {
679                 if (res != null) {
680                 res.releaseConnection();
681             }
682         }
683     }
684
685     /**
686      * Read contact.
687      *
688      * @param testName the test name
689      * @throws Exception the exception
690      */
691     @Test(dataProvider = "testName", groups = {"readItem"},
692                 dependsOnMethods = {"createContact", "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItem"})
693     public void readContact(String testName) throws Exception {
694         // Perform setup.
695         setupRead();
696
697         // Submit the request to the service and store the response.
698         PersonAuthorityClient client = new PersonAuthorityClient();
699         PoxPayloadIn input = null;
700         ClientResponse<String> res =
701                 client.readContact(knownResourceId, knownItemResourceId,
702                 knownContactResourceId);
703         try {
704             assertStatusCode(res, testName);
705             // Check whether we've received a contact.
706             input = new PoxPayloadIn(res.getEntity());
707         } finally {
708                 if (res != null) {
709                 res.releaseConnection();
710             }
711         }
712
713         ContactsCommon contact = (ContactsCommon) extractPart(input,
714                 new ContactClient().getCommonPartName(), ContactsCommon.class);
715         Assert.assertNotNull(contact);
716         boolean showFull = true;
717         if (showFull && logger.isDebugEnabled()) {
718             logger.debug(testName + ": returned payload:");
719             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
720         }
721         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
722         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
723
724     }
725
726     /**
727      * Read contact non existent.
728      *
729      * @param testName the test name
730      */
731     @Test(dataProvider = "testName", groups = {"readItem"},
732                 dependsOnMethods = {"readContact"})
733     public void readContactNonExistent(String testName) {
734         // Perform setup.
735         setupReadNonExistent();
736
737         // Submit the request to the service and store the response.
738         PersonAuthorityClient client = new PersonAuthorityClient();
739         ClientResponse<String> res =
740                 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
741         try {
742             assertStatusCode(res, testName);
743         } finally {
744                 if (res != null) {
745                 res.releaseConnection();
746             }
747         }
748     }
749
750     // ---------------------------------------------------------------
751     // CRUD tests : READ_LIST tests
752     // ---------------------------------------------------------------
753
754     /**
755      * Read item list.
756      */
757     @Override
758 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
759 //    groups = {"readList"}, dependsOnMethods = {"readList"})
760     public void readItemList(String testName) {
761         readItemList(knownAuthorityWithItems, null, testName);
762     }
763
764     /**
765      * Read item list by authority name.
766      */
767     @Override
768 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
769 //    groups = {"readList"}, dependsOnMethods = {"readItemList"})
770     public void readItemListByName(String testName) {
771         readItemList(null, READITEMS_SHORT_IDENTIFIER, testName);
772     }
773
774     /**
775      * Read item list.
776      *
777      * @param vcsid the vcsid
778      * @param name the name
779      */
780     private void readItemList(String vcsid, String name, String testName) {
781         setupReadList();
782         // Submit the request to the service and store the response.
783         PersonAuthorityClient client = new PersonAuthorityClient();
784         ClientResponse<AbstractCommonList> res = null;
785         if (vcsid != null) {
786             res = client.readItemList(vcsid, null, null);
787         } else if (name != null) {
788             res = client.readItemListForNamedAuthority(name, null, null);
789         } else {
790             Assert.fail("readItemList passed null csid and name!");
791         }
792         AbstractCommonList list = null;
793         try {
794             assertStatusCode(res, testName);
795             list = res.getEntity();
796         } finally {
797                 if (res != null) {
798                 res.releaseConnection();
799             }
800         }
801
802         List<AbstractCommonList.ListItem> items = list.getListItem();
803         int nItemsReturned = items.size();
804         // There will be 'nItemsToCreateInList'
805         // items created by the createItemList test,
806         // all associated with the same parent resource.
807         int nExpectedItems = nItemsToCreateInList;
808         if (logger.isDebugEnabled()) {
809             logger.debug(testName + ": Expected "
810                     + nExpectedItems + " items; got: " + nItemsReturned);
811         }
812         Assert.assertEquals(nItemsReturned, nExpectedItems);
813
814         for (AbstractCommonList.ListItem item : items) {
815             String value =
816                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.REF_NAME);
817             Assert.assertTrue((null != value), "Item refName is null!");
818             
819             // Per CSPACE-5132, lists items still return a field named displayName,
820             // not termDisplayName, for backward compatibility.
821             // (The format of list items will change significantly in CSPACE-5134.)
822             value =
823                     AbstractCommonListUtils.ListItemGetElementValue(item, AuthorityItemJAXBSchema.DISPLAY_NAME);
824             Assert.assertTrue((null != value), "Item displayName is null!");
825         }
826         if (logger.isTraceEnabled()) {
827             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
828         }
829     }
830
831     /**
832      * Read contact list.
833      */
834     @Test(groups = {"readList"},
835                 dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.readItemList"})
836     public void readContactList() {
837         readContactList(knownResourceId, knownItemResourceId);
838     }
839
840     /**
841      * Read contact list.
842      *
843      * @param parentcsid the parentcsid
844      * @param itemcsid the itemcsid
845      */
846     private void readContactList(String parentcsid, String itemcsid) {
847         final String testName = "readContactList";
848
849         // Perform setup.
850         setupReadList();
851
852         // Submit the request to the service and store the response.
853         PersonAuthorityClient client = new PersonAuthorityClient();
854         AbstractCommonList list = null;
855         ClientResponse<AbstractCommonList> res =
856                 client.readContactList(parentcsid, itemcsid);
857         try {
858             assertStatusCode(res, testName);
859             list = res.getEntity();
860         } finally {
861                 if (res != null) {
862                 res.releaseConnection();
863             }
864         }
865
866         List<AbstractCommonList.ListItem> listitems =
867                 list.getListItem();
868         int nItemsReturned = listitems.size();
869         // There will be one item created, associated with a
870         // known parent resource, by the createItem test.
871         //
872         // In addition, there will be 'nItemsToCreateInList'
873         // additional items created by the createItemList test,
874         // all associated with the same parent resource.
875         int nExpectedItems = nItemsToCreateInList + 1;
876         if (logger.isDebugEnabled()) {
877             logger.debug(testName + ": Expected "
878                     + nExpectedItems + " items; got: " + nItemsReturned);
879         }
880         Assert.assertEquals(nItemsReturned, nExpectedItems);
881         
882         // Optionally output additional data about list members for debugging.
883         boolean iterateThroughList = false;
884         if (iterateThroughList && logger.isDebugEnabled()) {
885             AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
886         }
887     }
888
889     // Failure outcomes
890     // There are no failure outcome tests at present.
891     // ---------------------------------------------------------------
892     // CRUD tests : UPDATE tests
893     // ---------------------------------------------------------------
894     // Success outcomes
895     /* (non-Javadoc)
896      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
897      */
898     @Override
899 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
900 //    groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
901     public void update(String testName) throws Exception {
902         // Retrieve the contents of a resource to update.
903         PersonAuthorityClient client = new PersonAuthorityClient();
904         PoxPayloadIn input = null;
905         setupRead();
906         ClientResponse<String> res = client.read(knownResourceId);
907         try {
908             assertStatusCode(res, testName);
909             if (logger.isDebugEnabled()) {
910                 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
911             }
912             input = new PoxPayloadIn(res.getEntity());
913         } finally {
914                 if (res != null) {
915                 res.releaseConnection();
916             }
917         }
918
919         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
920                 client.getCommonPartName(), PersonauthoritiesCommon.class);
921         Assert.assertNotNull(personAuthority);
922
923         // Update the contents of this resource.
924         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
925         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
926         if (logger.isDebugEnabled()) {
927             logger.debug("to be updated PersonAuthority");
928             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
929         }
930
931         // Submit the updated resource to the service and store the response.
932         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
933         PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), personAuthority);
934         setupUpdate();
935         res = client.update(knownResourceId, output);
936         try {
937             assertStatusCode(res, testName);
938             // Retrieve the updated resource and verify that its contents exist.
939             input = new PoxPayloadIn(res.getEntity());
940         } finally {
941                 if (res != null) {
942                 res.releaseConnection();
943             }
944         }
945
946         PersonauthoritiesCommon updatedPersonAuthority =
947                 (PersonauthoritiesCommon) extractPart(input,
948                 client.getCommonPartName(), PersonauthoritiesCommon.class);
949         Assert.assertNotNull(updatedPersonAuthority);
950
951         // Verify that the updated resource received the correct data.
952         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
953                 personAuthority.getDisplayName(),
954                 "Data in updated object did not match submitted data.");
955     }
956
957     /**
958      * Update item.
959      *
960      * @param testName the test name
961      * @throws Exception the exception
962      */
963     @Override
964 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
965 //    groups = {"update"}, dependsOnMethods = {"update"})
966     public void updateItem(String testName) throws Exception {
967         // Retrieve the contents of a resource to update.
968         PersonAuthorityClient client = new PersonAuthorityClient();
969         PoxPayloadIn input = null;
970         setupRead();
971         ClientResponse<String> res =
972                 client.readItem(knownResourceId, knownItemResourceId);
973         try {
974             assertStatusCode(res, testName);
975             if (logger.isDebugEnabled()) {
976                 logger.debug("got Person to update with ID: "
977                         + knownItemResourceId
978                         + " in PersonAuthority: " + knownResourceId);
979             }
980             input = new PoxPayloadIn(res.getEntity());
981         } finally {
982                 if (res != null) {
983                 res.releaseConnection();
984             }
985         }
986
987         PersonsCommon person = (PersonsCommon) extractPart(input,
988                 client.getItemCommonPartName(), PersonsCommon.class);
989         Assert.assertNotNull(person);
990
991         if (logger.isDebugEnabled() == true) {
992             logger.debug("About to update the following person...");
993             logger.debug(objectAsXmlString(person, PersonsCommon.class));
994         }
995
996         // Update the contents of this resource.
997         person.setCsid(null);
998         PersonTermGroupList termList = person.getPersonTermGroupList();
999         Assert.assertNotNull(termList);
1000         List<PersonTermGroup> terms = termList.getPersonTermGroup();
1001         Assert.assertNotNull(terms);
1002         Assert.assertTrue(terms.size() > 0);
1003         String foreName = terms.get(0).getForeName();
1004         String updatedForeName = "updated-" + foreName;
1005         terms.get(0).setForeName(updatedForeName);
1006         if (logger.isDebugEnabled()) {
1007             logger.debug("to be updated Person");
1008             logger.debug(objectAsXmlString(person,
1009                     PersonsCommon.class));
1010         }
1011
1012         // Submit the updated resource to the service and store the response.
1013         PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1014         PayloadOutputPart commonPart = output.addPart(client.getItemCommonPartName(), person);
1015         setupUpdate();
1016         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1017         try {
1018             assertStatusCode(res, testName);
1019             // Retrieve the updated resource and verify that its contents exist.
1020             input = new PoxPayloadIn(res.getEntity());
1021         } finally {
1022                 if (res != null) {
1023                 res.releaseConnection();
1024             }
1025         }
1026
1027         PersonsCommon updatedPerson =
1028                 (PersonsCommon) extractPart(input,
1029                 client.getItemCommonPartName(), PersonsCommon.class);
1030         Assert.assertNotNull(updatedPerson);
1031
1032         if (logger.isDebugEnabled() == true) {
1033             logger.debug("Updated to following person to:");
1034             logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1035         }
1036
1037         // Verify that the updated resource received the correct data.
1038         PersonTermGroupList updatedTermList = person.getPersonTermGroupList();
1039         Assert.assertNotNull(updatedTermList);
1040         List<PersonTermGroup> updatedTerms = termList.getPersonTermGroup();
1041         Assert.assertNotNull(updatedTerms);
1042         Assert.assertEquals(updatedTerms.get(0).getForeName(), updatedForeName,
1043                 "Data in updated Person did not match submitted data.");
1044     }
1045
1046     /**
1047      * Update contact.
1048      *
1049      * @param testName the test name
1050      * @throws Exception the exception
1051      */
1052     @Test(dataProvider = "testName", groups = {"update"},
1053                 dependsOnMethods = {"readContact", "testContactSubmitRequest",
1054                         "org.collectionspace.services.client.test.AbstractAuthorityServiceTest.updateItem"})
1055     public void updateContact(String testName) throws Exception {
1056         String contactsCommonLabel = new ContactClient().getCommonPartName();
1057
1058         // Retrieve the contents of a resource to update.
1059         PersonAuthorityClient client = new PersonAuthorityClient();
1060         PoxPayloadIn input = null;
1061         setupRead();
1062         ClientResponse<String> res =
1063                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1064         try {
1065             assertStatusCode(res, testName);
1066             if (logger.isDebugEnabled()) {
1067                 logger.debug("got Contact to update with ID: "
1068                         + knownContactResourceId
1069                         + " in item: " + knownItemResourceId
1070                         + " in parent: " + knownResourceId);
1071             }
1072             input = new PoxPayloadIn(res.getEntity());
1073         } finally {
1074                 if (res != null) {
1075                 res.releaseConnection();
1076             }
1077         }
1078
1079         ContactsCommon contact = (ContactsCommon) extractPart(input,
1080                 contactsCommonLabel, ContactsCommon.class);
1081         Assert.assertNotNull(contact);
1082
1083         // Verify the contents of this resource
1084         AddressGroupList addressGroupList = contact.getAddressGroupList();
1085         Assert.assertNotNull(addressGroupList);
1086         List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1087         Assert.assertNotNull(addressGroups);
1088         Assert.assertTrue(addressGroups.size() > 0);
1089         String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1090         Assert.assertNotNull(addressPlace1);
1091
1092         // Update the contents of this resource.
1093         addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1094         contact.setAddressGroupList(addressGroupList);
1095         if (logger.isDebugEnabled()) {
1096             logger.debug("to be updated Contact");
1097             logger.debug(objectAsXmlString(contact,
1098                     ContactsCommon.class));
1099         }
1100
1101         // Submit the updated resource to the service and store the response.
1102         PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1103         PayloadOutputPart commonPart = output.addPart(contactsCommonLabel, contact);
1104         setupUpdate();
1105         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1106         try {
1107             assertStatusCode(res, testName);
1108             // Retrieve the updated resource and verify that its contents exist.
1109             input = new PoxPayloadIn(res.getEntity());;
1110         } finally {
1111                 if (res != null) {
1112                 res.releaseConnection();
1113             }
1114         }
1115         ContactsCommon updatedContact = (ContactsCommon) extractPart(input,
1116                 contactsCommonLabel, ContactsCommon.class);
1117         Assert.assertNotNull(updatedContact);
1118
1119         // Verify that the updated resource received the correct data.
1120         Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1121                 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1122                 "Data in updated object did not match submitted data.");
1123     }
1124
1125     /**
1126      * Update non existent contact.
1127      *
1128      * @param testName the test name
1129      * @throws Exception the exception
1130      */
1131     @Test(dataProvider = "testName", groups = {"update"},
1132                 dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1133     public void updateNonExistentContact(String testName) throws Exception {
1134         // Currently a no-op test
1135     }
1136
1137     // ---------------------------------------------------------------
1138     // CRUD tests : DELETE tests
1139     // ---------------------------------------------------------------
1140     // Success outcomes
1141     // Note: delete sub-resources in ascending hierarchical order,
1142     // before deleting their parents.
1143     /**
1144      * Delete contact.
1145      *
1146      * @param testName the test name
1147      * @throws Exception the exception
1148      */
1149     @Test(dataProvider = "testName", groups = {"delete"},
1150                 dependsOnMethods = {"updateContact"})
1151     public void deleteContact(String testName) throws Exception {
1152         if (logger.isDebugEnabled()) {
1153             logger.debug("parentcsid =" + knownResourceId
1154                     + " itemcsid = " + knownItemResourceId
1155                     + " csid = " + knownContactResourceId);
1156         }
1157
1158         // Submit the request to the service and store the response.
1159         PersonAuthorityClient client = new PersonAuthorityClient();
1160         setupDelete();
1161         ClientResponse<Response> res =
1162                 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1163         try {
1164                 assertStatusCode(res, testName);
1165         } finally {
1166                 if (res != null) {
1167                         res.releaseConnection();
1168                 }
1169         }
1170     }
1171
1172     @Override
1173     public void delete(String testName) throws Exception {
1174         // Do nothing.  See localDelete().  This ensure proper test order.
1175     }
1176     
1177     @Test(dataProvider = "testName", dependsOnMethods = {"localDeleteItem"})    
1178     public void localDelete(String testName) throws Exception {
1179         super.delete(testName);
1180     }
1181
1182     @Override
1183     public void deleteItem(String testName) throws Exception {
1184         // Do nothing.  We need to wait until after the test "localDelete" gets run.  When it does,
1185         // its dependencies will get run first and then we can call the base class' delete method.
1186     }
1187     
1188     @Test(dataProvider = "testName", groups = {"delete"},
1189         dependsOnMethods = {"verifyIllegalItemDisplayName", "testContactSubmitRequest", "deleteContact"})
1190     public void localDeleteItem(String testName) throws Exception {
1191         super.deleteItem(testName);
1192     }
1193
1194     /**
1195      * Delete non existent contact.
1196      *
1197      * @param testName the test name
1198      */
1199     @Test(dataProvider = "testName", groups = {"delete"},
1200                 dependsOnMethods = {"deleteContact"})
1201     public void deleteNonExistentContact(String testName) {
1202         // Submit the request to the service and store the response.
1203         PersonAuthorityClient client = new PersonAuthorityClient();
1204         setupDeleteNonExistent();
1205         ClientResponse<Response> res =
1206                 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1207         try {
1208                 assertStatusCode(res, testName);
1209         } finally {
1210                 if (res != null) {
1211                         res.releaseConnection();
1212                 }
1213         }
1214     }
1215
1216     /**
1217      * Test contact submit request.
1218      */
1219     @Test(dataProvider = "testName",
1220                 dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1221     public void testContactSubmitRequest(String testName) {
1222
1223         // Expected status code: 200 OK
1224         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1225
1226         // Submit the request to the service and store the response.
1227         String method = ServiceRequestType.READ.httpMethodName();
1228         String url = getContactResourceURL(knownResourceId,
1229                 knownItemResourceId, knownContactResourceId);
1230         int statusCode = submitRequest(method, url);
1231
1232         // Check the status code of the response: does it match
1233         // the expected response(s)?
1234         if (logger.isDebugEnabled()) {
1235             logger.debug("testContactSubmitRequest: url=" + url
1236                     + " status=" + statusCode);
1237         }
1238         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1239
1240     }
1241
1242     // ---------------------------------------------------------------
1243     // Cleanup of resources created during testing
1244     // ---------------------------------------------------------------
1245     /**
1246      * Deletes all resources created by tests, after all tests have been run.
1247      *
1248      * This cleanup method will always be run, even if one or more tests fail.
1249      * For this reason, it attempts to remove all resources created
1250      * at any point during testing, even if some of those resources
1251      * may be expected to be deleted by certain tests.
1252      */
1253     @AfterClass(alwaysRun = true)
1254     @Override
1255     public void cleanUp() {
1256         String noTest = System.getProperty("noTestCleanup");
1257         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1258             if (logger.isDebugEnabled()) {
1259                 logger.debug("Skipping Cleanup phase ...");
1260             }
1261             return;
1262         }
1263         if (logger.isDebugEnabled()) {
1264             logger.debug("Cleaning up temporary resources created for testing ...");
1265         }
1266         String parentResourceId;
1267         String itemResourceId;
1268         String contactResourceId;
1269         // Clean up contact resources.
1270         PersonAuthorityClient client = new PersonAuthorityClient();
1271         parentResourceId = knownResourceId;
1272         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1273             contactResourceId = entry.getKey();
1274             itemResourceId = entry.getValue();
1275             // Note: Any non-success responses from the delete operation
1276             // below are ignored and not reported.
1277             ClientResponse<Response> res =
1278                     client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1279             res.releaseConnection();
1280         }
1281         // Clean up item resources.
1282         for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1283             itemResourceId = entry.getKey();
1284             parentResourceId = entry.getValue();
1285             // Note: Any non-success responses from the delete operation
1286             // below are ignored and not reported.
1287             ClientResponse<Response> res =
1288                     client.deleteItem(parentResourceId, itemResourceId);
1289             res.releaseConnection();
1290         }
1291         // Clean up parent resources.
1292         super.cleanUp();
1293     }
1294
1295     // ---------------------------------------------------------------
1296     // Utility methods used by tests above
1297     // ---------------------------------------------------------------
1298     /**
1299      * Gets the contact service path component.
1300      *
1301      * @return the contact service path component
1302      */
1303     public String getContactServicePathComponent() {
1304         return ContactClient.SERVICE_PATH_COMPONENT;
1305     }
1306
1307     /**
1308      * Returns the root URL for the item service.
1309      *
1310      * This URL consists of a base URL for all services, followed by
1311      * a path component for the owning parent, followed by the
1312      * path component for the items.
1313      *
1314      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1315      * parent authority resource of the relevant item resource.
1316      *
1317      * @return The root URL for the item service.
1318      */
1319     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1320         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1321     }
1322
1323     /**
1324      * Returns the URL of a specific item resource managed by a service, and
1325      * designated by an identifier (such as a universally unique ID, or UUID).
1326      *
1327      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1328      * parent authority resource of the relevant item resource.
1329      *
1330      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1331      * item resource.
1332      *
1333      * @return The URL of a specific item resource managed by a service.
1334      */
1335     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1336         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1337     }
1338
1339     /**
1340      * Returns the root URL for the contact service.
1341      *
1342      * This URL consists of a base URL for all services, followed by
1343      * a path component for the owning authority, followed by the
1344      * path component for the owning item, followed by the path component
1345      * for the contact service.
1346      *
1347      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1348      * parent authority resource of the relevant item resource.
1349      *
1350      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1351      * item resource.
1352      *
1353      * @return The root URL for the contact service.
1354      */
1355     protected String getContactServiceRootURL(String parentResourceIdentifier,
1356             String itemResourceIdentifier) {
1357         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
1358                 + getContactServicePathComponent();
1359     }
1360
1361     /**
1362      * Returns the URL of a specific contact resource managed by a service, and
1363      * designated by an identifier (such as a universally unique ID, or UUID).
1364      *
1365      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1366      * parent resource of the relevant item resource.
1367      *
1368      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1369      * item resource.
1370      *
1371      * @return The URL of a specific resource managed by a service.
1372      */
1373     protected String getContactResourceURL(String parentResourceIdentifier,
1374             String itemResourceIdentifier, String contactResourceIdentifier) {
1375         return getContactServiceRootURL(parentResourceIdentifier,
1376                 itemResourceIdentifier) + "/" + contactResourceIdentifier;
1377     }
1378
1379         @Override
1380         public void authorityTests(String testName) {
1381                 // TODO Auto-generated method stub
1382                 
1383         }
1384    
1385         @Override
1386         protected PersonsCommon updateItemInstance(PersonsCommon personsCommon) {
1387             
1388             PersonsCommon result = personsCommon;
1389                 
1390             PersonTermGroupList termList = result.getPersonTermGroupList();
1391             Assert.assertNotNull(termList);
1392             List<PersonTermGroup> terms = termList.getPersonTermGroup();
1393             Assert.assertNotNull(terms);
1394             Assert.assertTrue(terms.size() > 0);
1395             terms.get(0).setTermDisplayName("updated-" + terms.get(0).getTermDisplayName());
1396             terms.get(0).setTermName("updated-" + terms.get(0).getTermName());
1397         
1398             return result;
1399         }
1400
1401         @Override
1402         protected void compareUpdatedItemInstances(PersonsCommon original,
1403                         PersonsCommon updated) throws Exception {
1404             
1405             PersonTermGroupList originalTermList = original.getPersonTermGroupList();
1406             Assert.assertNotNull(originalTermList);
1407             List<PersonTermGroup> originalTerms = originalTermList.getPersonTermGroup();
1408             Assert.assertNotNull(originalTerms);
1409             Assert.assertTrue(originalTerms.size() > 0);
1410             
1411             PersonTermGroupList updatedTermList = updated.getPersonTermGroupList();
1412             Assert.assertNotNull(updatedTermList);
1413             List<PersonTermGroup> updatedTerms = updatedTermList.getPersonTermGroup();
1414             Assert.assertNotNull(updatedTerms);
1415             Assert.assertTrue(updatedTerms.size() > 0);
1416             
1417             Assert.assertEquals(updatedTerms.get(0).getTermDisplayName(),
1418                 originalTerms.get(0).getTermDisplayName(),
1419                 "Value in updated record did not match submitted data.");
1420         }
1421
1422         @Override
1423         protected PoxPayloadOut createInstance(String commonPartName,
1424                         String identifier) {
1425         String shortId = identifier;
1426         String displayName = "displayName-" + shortId;
1427         PoxPayloadOut result =
1428                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
1429                 displayName, shortId, commonPartName);
1430         return result;
1431         }
1432         
1433         @Override
1434         protected PoxPayloadOut createNonExistenceInstance(String commonPartName,
1435                         String identifier) {
1436         String displayName = "displayName-NON_EXISTENT_ID";
1437         PoxPayloadOut result = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1438                 displayName, "NON_EXISTENT_SHORT_ID", commonPartName);
1439         return result;
1440         }
1441         
1442     protected PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier) {
1443         Map<String, String> nonexMap = new HashMap<String, String>();
1444         nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1445         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1446         
1447         List<PersonTermGroup> terms = new ArrayList<PersonTermGroup>();
1448         PersonTermGroup term = new PersonTermGroup();
1449         term.setTermDisplayName("John Wayne");
1450         term.setTermName("John Wayne");
1451         term.setForeName("John");
1452         term.setSurName("Wayne");
1453         terms.add(term);
1454         
1455         Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1456         PoxPayloadOut result =
1457                 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1458                 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1459                 nonexMap, terms, nonexRepeatablesMap, commonPartName);
1460         return result;
1461     }
1462                 
1463         @Override
1464         protected PersonauthoritiesCommon updateInstance(PersonauthoritiesCommon personauthoritiesCommon) {
1465                 PersonauthoritiesCommon result = new PersonauthoritiesCommon();
1466                 
1467         result.setDisplayName("updated-" + personauthoritiesCommon.getDisplayName());
1468         result.setVocabType("updated-" + personauthoritiesCommon.getVocabType());
1469         
1470                 return result;
1471         }
1472
1473         @Override
1474         protected void compareUpdatedInstances(PersonauthoritiesCommon original,
1475                         PersonauthoritiesCommon updated) throws Exception {
1476         // Verify that the updated resource received the correct data.
1477         Assert.assertEquals(updated.getDisplayName(),
1478                         original.getDisplayName(),
1479                 "Display name in updated object did not match submitted data.");
1480         }
1481
1482         @Override
1483         protected void verifyReadItemInstance(PersonsCommon item) throws Exception {
1484                 // Do nothing for now.  Add more 'read' validation checks here if applicable.
1485         }
1486         
1487         
1488 }