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