]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
ae1ac06361119ef9cebe73fc536f2c7939d31b6f
[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.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
30
31 import org.collectionspace.services.PersonJAXBSchema;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonauthoritiesCommon;
41 import org.collectionspace.services.person.PersonauthoritiesCommonList;
42 import org.collectionspace.services.person.PersonsCommon;
43 import org.collectionspace.services.person.PersonsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
53
54 /**
55  * PersonAuthorityServiceTest, carries out tests against a
56  * deployed and running PersonAuthority Service.
57  *
58  * $LastChangedRevision: 753 $
59  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
60  */
61 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
62
63     /** The logger. */
64     private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
65     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
66
67     // Instance variables specific to this test.
68     /** The service path component. */
69     final String SERVICE_PATH_COMPONENT = "personauthorities";
70     
71     /** The item service path component. */
72     final String ITEM_SERVICE_PATH_COMPONENT = "items";
73     
74     /** The contact service path component. */
75     final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
76     
77     /** The test forename. */
78     final String TEST_FORE_NAME = "John";
79     
80     /** The test middle name. */
81     final String TEST_MIDDLE_NAME = null;
82     
83     /** The test surname. */
84     final String TEST_SUR_NAME = "Wayne";
85     
86     /** The test birthdate. */
87     final String TEST_BIRTH_DATE = "May 26, 1907";
88     
89     /** The test death date. */
90     final String TEST_DEATH_DATE = "June 11, 1979";
91
92     // Hold some values for a recently created item to verify upon read.
93     private String knownResourceId = null;
94     private String knownResourceShortIdentifer = null;
95     private String knownResourceRefName = null;
96     private String knownItemResourceId = null;
97     private String knownItemResourceShortIdentifer = null;
98
99     // The resource ID of an item resource used for partial term matching tests.
100     private String knownItemPartialTermResourceId = null;
101     
102     /** The known contact resource id. */
103     private String knownContactResourceId = null;
104     
105     /** The n items to create in list. */
106     private int nItemsToCreateInList = 3;
107     
108     /** The all item resource ids created. */
109     private Map<String, String> allItemResourceIdsCreated =
110         new HashMap<String, String>();
111     
112     /** The all contact resource ids created. */
113     private Map<String, String> allContactResourceIdsCreated =
114         new HashMap<String, String>();
115
116     protected void setKnownResource( String id, String shortIdentifer,
117                 String refName ) {
118         knownResourceId = id;
119         knownResourceShortIdentifer = shortIdentifer;
120         knownResourceRefName = refName;
121     }
122
123     protected void setKnownItemResource( String id, String shortIdentifer ) {
124         knownItemResourceId = id;
125         knownItemResourceShortIdentifer = shortIdentifer;
126     }
127
128     
129     /* (non-Javadoc)
130      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
131      */
132     @Override
133     protected CollectionSpaceClient getClientInstance() {
134         return new PersonAuthorityClient();
135     }
136     
137     /* (non-Javadoc)
138      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
139      */
140     @Override
141         protected AbstractCommonList getAbstractCommonList(
142                         ClientResponse<AbstractCommonList> response) {
143         return response.getEntity(PersonsCommonList.class);
144     }
145  
146     // ---------------------------------------------------------------
147     // CRUD tests : CREATE tests
148     // ---------------------------------------------------------------
149     // Success outcomes
150     /* (non-Javadoc)
151      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
152      */
153     @Override
154     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
155         groups = {"create"})
156     public void create(String testName) throws Exception {
157         
158         if (logger.isDebugEnabled()) {
159             logger.debug(testBanner(testName, CLASS_NAME));
160         }
161         // Perform setup, such as initializing the type of service request
162         // (e.g. CREATE, DELETE), its valid and expected status codes, and
163         // its associated HTTP method name (e.g. POST, DELETE).
164         setupCreate();
165
166         // Submit the request to the service and store the response.
167         PersonAuthorityClient client = new PersonAuthorityClient();
168         String shortId = createIdentifier();
169         String displayName = "displayName-" + shortId;
170         String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
171         MultipartOutput multipart = 
172             PersonAuthorityClientUtils.createPersonAuthorityInstance(
173             displayName, shortId, client.getCommonPartName());
174         
175         String newID = null;
176         ClientResponse<Response> res = client.create(multipart);
177         try {
178                 int statusCode = res.getStatus();
179         
180                 // Check the status code of the response: does it match
181                 // the expected response(s)?
182                 //
183                 // Specifically:
184                 // Does it fall within the set of valid status codes?
185                 // Does it exactly match the expected status code?
186                 if(logger.isDebugEnabled()){
187                     logger.debug(testName + ": status = " + statusCode);
188                 }
189                 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
190                         invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
191                 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
192         
193                 newID = PersonAuthorityClientUtils.extractId(res);
194         } finally {
195                 res.releaseConnection();
196         }
197         // Save values for additional tests
198         if (knownResourceId == null){
199                 setKnownResource( newID, shortId, baseRefName ); 
200                 if (logger.isDebugEnabled()) {
201                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
202             }
203         }
204         // Store the IDs from every resource created by tests,
205         // so they can be deleted after tests have been run.
206         allResourceIdsCreated.add(newID);
207     }
208
209     /**
210      * Creates the item.
211      *
212      * @param testName the test name
213      */
214     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
215         groups = {"create"}, dependsOnMethods = {"create"})
216     public void createItem(String testName) {
217         if (logger.isDebugEnabled()) {
218             logger.debug(testBanner(testName, CLASS_NAME));
219         }
220         setupCreate();
221         String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
222     }
223
224     /**
225      * Creates the item in authority.
226      *
227      * @param vcsid the vcsid
228      * @param authRefName the auth ref name
229      * @return the string
230      */
231     private String createItemInAuthority(String vcsid, String authRefName) {
232
233         final String testName = "createItemInAuthority";
234         if(logger.isDebugEnabled()){
235             logger.debug(testName + ":...");
236         }
237
238         // Submit the request to the service and store the response.
239         PersonAuthorityClient client = new PersonAuthorityClient();
240         
241         Map<String, String> johnWayneMap = new HashMap<String,String>();
242         //
243         // Fill the property map
244         //
245         String shortId = "johnWayneActor";
246         johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
247         johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
248         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
249         
250         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
251         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
252         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
253         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
254         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
255         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
256         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
257             "known by his stage name John Wayne, was an American film actor, director " +
258             "and producer. He epitomized rugged masculinity and has become an enduring " +
259             "American icon. He is famous for his distinctive voice, walk and height. " +
260             "He was also known for his conservative political views and his support in " +
261             "the 1950s for anti-communist positions.");
262         MultipartOutput multipart = 
263             PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
264                 client.getItemCommonPartName() );
265
266         String newID = null;
267         ClientResponse<Response> res = client.createItem(vcsid, multipart);
268         try {
269                 int statusCode = res.getStatus();
270                 // Check the status code of the response: does it match
271                 // the expected response(s)?
272                 if(logger.isDebugEnabled()){
273                     logger.debug(testName + ": status = " + statusCode);
274                 }
275                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
276                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
277                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
278
279                 newID = PersonAuthorityClientUtils.extractId(res);
280         } finally {
281                 res.releaseConnection();
282         }
283
284         // Store the ID returned from the first item resource created
285         // for additional tests below.
286         if (knownItemResourceId == null){
287                 setKnownItemResource(newID, shortId);
288             if (logger.isDebugEnabled()) {
289                 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);                
290             }
291         }
292
293         // Store the IDs from any item resources created
294         // by tests, along with the IDs of their parents, so these items
295         // can be deleted after all tests have been run.
296         allItemResourceIdsCreated.put(newID, vcsid);
297
298         return newID;
299     }
300
301     /**
302      * Creates the contact.
303      *
304      * @param testName the test name
305      */
306     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
307         groups = {"create"}, dependsOnMethods = {"createItem"})
308     public void createContact(String testName) {
309         if (logger.isDebugEnabled()) {
310             logger.debug(testBanner(testName, CLASS_NAME));
311         }
312         setupCreate();
313         String newID = createContactInItem(knownResourceId, knownItemResourceId);
314     }
315
316    /**
317     * Creates the contact in item.
318     *
319     * @param parentcsid the parentcsid
320     * @param itemcsid the itemcsid
321     * @return the string
322     */
323    private String createContactInItem(String parentcsid, String itemcsid) {
324
325         final String testName = "createContactInItem";
326         if(logger.isDebugEnabled()){
327             logger.debug(testName + ":...");
328         }
329         
330         setupCreate();
331
332         // Submit the request to the service and store the response.
333         PersonAuthorityClient client = new PersonAuthorityClient();
334         String identifier = createIdentifier();
335         MultipartOutput multipart =
336             ContactClientUtils.createContactInstance(parentcsid,
337             itemcsid, identifier, new ContactClient().getCommonPartName());
338         
339         String newID = null;
340         ClientResponse<Response> res =
341              client.createContact(parentcsid, itemcsid, multipart);
342         try {
343                 int statusCode = res.getStatus();
344                 // Check the status code of the response: does it match
345                 // the expected response(s)?
346                 if(logger.isDebugEnabled()){
347                     logger.debug(testName + ": status = " + statusCode);
348                 }
349                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
350                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
351                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
352
353                 newID = PersonAuthorityClientUtils.extractId(res);
354         } finally {
355                 res.releaseConnection();
356         }
357
358         // Store the ID returned from the first contact resource created
359         // for additional tests below.
360         if (knownContactResourceId == null){
361             knownContactResourceId = newID;
362             if (logger.isDebugEnabled()) {
363                 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
364             }
365         }
366
367         // Store the IDs from any contact resources created
368         // by tests, along with the IDs of their parent items,
369         // so these items can be deleted after all tests have been run.
370         allContactResourceIdsCreated.put(newID, itemcsid);
371
372         return newID;
373     }
374
375     // Failure outcomes
376
377     // Placeholders until the three tests below can be uncommented.
378     // See Issue CSPACE-401.
379     /* (non-Javadoc)
380      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
381      */
382     @Override
383     public void createWithEmptyEntityBody(String testName) throws Exception {
384         //Should this really be empty?
385     }
386
387     /* (non-Javadoc)
388      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
389      */
390     @Override
391     public void createWithMalformedXml(String testName) throws Exception {
392         //Should this really be empty?
393     }
394
395     /* (non-Javadoc)
396      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
397      */
398     @Override
399     public void createWithWrongXmlSchema(String testName) throws Exception {
400         //Should this really be empty?
401     }
402
403 /*
404     @Override
405     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
406         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
407     public void createWithEmptyEntityBody(String testName) throws Exception {
408
409         if (logger.isDebugEnabled()) {
410             logger.debug(testBanner(testName, CLASS_NAME));
411         }
412         // Perform setup.
413         setupCreateWithEmptyEntityBody();
414
415         // Submit the request to the service and store the response.
416         String method = REQUEST_TYPE.httpMethodName();
417         String url = getServiceRootURL();
418         String mediaType = MediaType.APPLICATION_XML;
419         final String entity = "";
420         int statusCode = submitRequest(method, url, mediaType, entity);
421
422         // Check the status code of the response: does it match
423         // the expected response(s)?
424         if(logger.isDebugEnabled()) {
425             logger.debug(testName + ": url=" + url +
426                 " status=" + statusCode);
427          }
428         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
429         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
430         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
431     }
432
433     @Override
434     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
435         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
436     public void createWithMalformedXml(String testName) throws Exception {
437
438         if (logger.isDebugEnabled()) {
439             logger.debug(testBanner(testName, CLASS_NAME));
440         }
441         // Perform setup.
442         setupCreateWithMalformedXml();
443
444         // Submit the request to the service and store the response.
445         String method = REQUEST_TYPE.httpMethodName();
446         String url = getServiceRootURL();
447         String mediaType = MediaType.APPLICATION_XML;
448         final String entity = MALFORMED_XML_DATA; // Constant from base class.
449         int statusCode = submitRequest(method, url, mediaType, entity);
450
451         // Check the status code of the response: does it match
452         // the expected response(s)?
453         if(logger.isDebugEnabled()){
454             logger.debug(testName + ": url=" + url +
455                 " status=" + statusCode);
456          }
457         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
458         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
459         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
460     }
461
462     @Override
463     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
464         groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
465     public void createWithWrongXmlSchema(String testName) throws Exception {
466
467         if (logger.isDebugEnabled()) {
468             logger.debug(testBanner(testName, CLASS_NAME));
469         }
470         // Perform setup.
471         setupCreateWithWrongXmlSchema();
472
473         // Submit the request to the service and store the response.
474         String method = REQUEST_TYPE.httpMethodName();
475         String url = getServiceRootURL();
476         String mediaType = MediaType.APPLICATION_XML;
477         final String entity = WRONG_XML_SCHEMA_DATA;
478         int statusCode = submitRequest(method, url, mediaType, entity);
479
480         // Check the status code of the response: does it match
481         // the expected response(s)?
482         if(logger.isDebugEnabled()){
483             logger.debug(testName + ": url=" + url +
484                 " status=" + statusCode);
485          }
486         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
487         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
488         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
489     }
490 */
491
492     // ---------------------------------------------------------------
493     // CRUD tests : CREATE LIST tests
494     // ---------------------------------------------------------------
495     // Success outcomes
496     /* (non-Javadoc)
497  * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
498  */
499     @Override
500     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
501         groups = {"createList"}, dependsOnGroups = {"create"})
502     public void createList(String testName) throws Exception {
503          if (logger.isDebugEnabled()) {
504             logger.debug(testBanner(testName, CLASS_NAME));
505         }
506         for (int i = 0; i < nItemsToCreateInList; i++) {
507             create(testName);
508         }
509     }
510
511     /**
512      * Creates the item list.
513      *
514      * @param testName the test name
515      * @throws Exception the exception
516      */
517     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
518         groups = {"createList"}, dependsOnMethods = {"createList"})
519     public void createItemList(String testName) throws Exception {
520         if (logger.isDebugEnabled()) {
521             logger.debug(testBanner(testName, CLASS_NAME));
522         }
523         // Add items to the initially-created, known parent record.
524         for (int j = 0; j < nItemsToCreateInList; j++) {
525             createItem(testName);
526         }
527     }
528
529     /**
530      * Creates the contact list.
531      *
532      * @param testName the test name
533      * @throws Exception the exception
534      */
535     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
536         groups = {"createList"}, dependsOnMethods = {"createItemList"})
537     public void createContactList(String testName) throws Exception {
538         // Add contacts to the initially-created, known item record.
539         for (int j = 0; j < nItemsToCreateInList; j++) {
540             createContact(testName);
541         }
542     }
543
544     // ---------------------------------------------------------------
545     // CRUD tests : READ tests
546     // ---------------------------------------------------------------
547     // Success outcomes
548     /* (non-Javadoc)
549      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
550      */
551     @Override
552     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
553         groups = {"read"}, dependsOnGroups = {"create"})
554     public void read(String testName) throws Exception {
555         readInternal(testName, knownResourceId, null);
556     }
557
558     /**
559      * Read by name.
560      *
561      * @param testName the test name
562      * @throws Exception the exception
563      */
564     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
565             groups = {"read"}, dependsOnGroups = {"create"})
566         public void readByName(String testName) throws Exception {
567         readInternal(testName, null, knownResourceShortIdentifer);
568     }
569     
570     protected void readInternal(String testName, String CSID, String shortId) {
571         if (logger.isDebugEnabled()) {
572             logger.debug(testBanner(testName, CLASS_NAME));
573         }
574         // Perform setup.
575         setupRead();
576
577         // Submit the request to the service and store the response.
578         PersonAuthorityClient client = new PersonAuthorityClient();
579         ClientResponse<MultipartInput> res = null;
580         if(CSID!=null) {
581             res = client.read(CSID);
582         } else if(shortId!=null) {
583                 res = client.readByName(shortId);
584         } else {
585                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
586         }
587         try {
588                 int statusCode = res.getStatus();
589                 // Check the status code of the response: does it match
590                 // the expected response(s)?
591                 if(logger.isDebugEnabled()){
592                     logger.debug(testName + ": status = " + statusCode);
593                 }
594                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
595                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
596                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
597                 //FIXME: remove the following try catch once Aron fixes signatures
598                 try {
599                     MultipartInput input = (MultipartInput) res.getEntity();
600                     PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
601                             client.getCommonPartName(), PersonauthoritiesCommon.class);
602                     Assert.assertNotNull(personAuthority);
603                 } catch (Exception e) {
604                     throw new RuntimeException(e);
605                 }
606         } finally {
607                 res.releaseConnection();
608         }
609     }
610
611     /**
612      * Read item.
613      *
614      * @param testName the test name
615      * @throws Exception the exception
616      */
617     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
618                 groups = {"readItem"}, dependsOnGroups = {"read"})
619     public void readItem(String testName) throws Exception {
620         readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
621     }
622
623     /**
624      * Read item in Named Auth.
625      *
626      * @param testName the test name
627      * @throws Exception the exception
628      */
629     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
630                 groups = {"readItem"}, dependsOnGroups = {"read"})
631     public void readItemInNamedAuth(String testName) throws Exception {
632         readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
633     }
634
635     /**
636      * Read named item.
637      *
638      * @param testName the test name
639      * @throws Exception the exception
640      */
641     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
642                 groups = {"readItem"}, dependsOnGroups = {"read"})
643     public void readNamedItem(String testName) throws Exception {
644         readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
645     }
646
647     /**
648      * Read Named item in Named Auth.
649      *
650      * @param testName the test name
651      * @throws Exception the exception
652      */
653     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
654                 groups = {"readItem"}, dependsOnGroups = {"read"})
655     public void readNamedItemInNamedAuth(String testName) throws Exception {
656         readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
657     }
658
659     protected void readItemInternal(String testName, 
660                 String authCSID, String authShortId, String itemCSID, String itemShortId) 
661         throws Exception {
662
663         if (logger.isDebugEnabled()) {
664             logger.debug(testBanner(testName, CLASS_NAME));
665         }
666         // Perform setup.
667         setupRead();
668
669         // Submit the request to the service and store the response.
670         PersonAuthorityClient client = new PersonAuthorityClient();
671         ClientResponse<MultipartInput> res = null;
672         if(authCSID!=null) {
673             if(itemCSID!=null) {
674                 res = client.readItem(authCSID, itemCSID);
675             } else if(itemShortId!=null) {
676                 res = client.readNamedItem(authCSID, itemShortId);
677             } else {
678                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
679             }
680         } else if(authShortId!=null) {
681             if(itemCSID!=null) {
682                 res = client.readItemInNamedAuthority(authShortId, itemCSID);
683             } else if(itemShortId!=null) {
684                 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
685             } else {
686                 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
687             }
688         } else {
689                 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
690         }
691         try {
692                 int statusCode = res.getStatus();
693         
694                 // Check the status code of the response: does it match
695                 // the expected response(s)?
696                 if(logger.isDebugEnabled()){
697                     logger.debug(testName + ": status = " + statusCode);
698                 }
699                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702         
703                 // Check whether we've received a person.
704                 MultipartInput input = (MultipartInput) res.getEntity();
705                 PersonsCommon person = (PersonsCommon) extractPart(input,
706                         client.getItemCommonPartName(), PersonsCommon.class);
707                 Assert.assertNotNull(person);
708                 boolean showFull = true;
709                 if(showFull && logger.isDebugEnabled()){
710                     logger.debug(testName + ": returned payload:");
711                     logger.debug(objectAsXmlString(person, PersonsCommon.class));
712                 }
713                 Assert.assertEquals(person.getInAuthority(), knownResourceId);
714         } finally {
715                 res.releaseConnection();
716         }
717     }
718
719     /**
720      * Verify item display name.
721      *
722      * @param testName the test name
723      * @throws Exception the exception
724      */
725     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726         dependsOnMethods = {"readItem", "updateItem"})
727     public void verifyItemDisplayName(String testName) throws Exception {
728         
729          if (logger.isDebugEnabled()) {
730             logger.debug(testBanner(testName, CLASS_NAME));
731         }
732         // Perform setup.
733         setupUpdate();
734
735         // Submit the request to the service and store the response.
736         PersonAuthorityClient client = new PersonAuthorityClient();
737         MultipartInput input =null;
738         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
739         try {
740                 int statusCode = res.getStatus();
741         
742                 // Check the status code of the response: does it match
743                 // the expected response(s)?
744                 if(logger.isDebugEnabled()){
745                     logger.debug(testName + ": status = " + statusCode);
746                 }
747                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
748                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
749                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
750         
751                 // Check whether person has expected displayName.
752                 input = (MultipartInput) res.getEntity();
753         } finally {
754                 res.releaseConnection();
755         }
756                 
757         PersonsCommon person = (PersonsCommon) extractPart(input,
758                 client.getItemCommonPartName(), PersonsCommon.class);
759         Assert.assertNotNull(person);
760         String displayName = person.getDisplayName();
761         // Make sure displayName matches computed form
762         String expectedDisplayName = 
763             PersonAuthorityClientUtils.prepareDefaultDisplayName(
764                 TEST_FORE_NAME, null, TEST_SUR_NAME,
765                 TEST_BIRTH_DATE, TEST_DEATH_DATE);
766         Assert.assertNotNull(displayName, expectedDisplayName);
767     
768         // Update the shortName and verify the computed name is updated.
769         person.setCsid(null);
770         person.setDisplayNameComputed(true);
771         person.setForeName("updated-" + TEST_FORE_NAME);
772         expectedDisplayName = 
773             PersonAuthorityClientUtils.prepareDefaultDisplayName(
774                 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, 
775                 TEST_BIRTH_DATE, TEST_DEATH_DATE);
776
777         // Submit the updated resource to the service and store the response.
778         MultipartOutput output = new MultipartOutput();
779         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
780         commonPart.getHeaders().add("label", client.getItemCommonPartName());
781         res = client.updateItem(knownResourceId, knownItemResourceId, output);
782         try {
783                 int statusCode = res.getStatus();
784         
785                 // Check the status code of the response: does it match the expected response(s)?
786                 if(logger.isDebugEnabled()){
787                     logger.debug("updateItem: status = " + statusCode);
788                 }
789                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
792         
793                 // Retrieve the updated resource and verify that its contents exist.
794                 input = (MultipartInput) res.getEntity();
795         } finally {
796                 res.releaseConnection();
797         }
798         
799         PersonsCommon updatedPerson =
800                 (PersonsCommon) extractPart(input,
801                         client.getItemCommonPartName(), PersonsCommon.class);
802         Assert.assertNotNull(updatedPerson);
803
804         // Verify that the updated resource received the correct data.
805         Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
806             "Updated ForeName in Person did not match submitted data.");
807         // Verify that the updated resource computes the right displayName.
808         Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
809             "Updated ForeName in Person not reflected in computed DisplayName.");
810
811         // Now Update the displayName, not computed and verify the computed name is overriden.
812         person.setDisplayNameComputed(false);
813         expectedDisplayName = "TestName";
814         person.setDisplayName(expectedDisplayName);
815
816         // Submit the updated resource to the service and store the response.
817         output = new MultipartOutput();
818         commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
819         commonPart.getHeaders().add("label", client.getItemCommonPartName());
820         res = client.updateItem(knownResourceId, knownItemResourceId, output);
821         try {
822                 int statusCode = res.getStatus();
823         
824                 // Check the status code of the response: does it match the expected response(s)?
825                 if(logger.isDebugEnabled()){
826                     logger.debug("updateItem: status = " + statusCode);
827                 }
828                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
829                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
830                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
831         
832                 // Retrieve the updated resource and verify that its contents exist.
833                 input = (MultipartInput) res.getEntity();
834         } finally {
835                 res.releaseConnection();
836         }
837         
838         updatedPerson =
839                 (PersonsCommon) extractPart(input,
840                         client.getItemCommonPartName(), PersonsCommon.class);
841         Assert.assertNotNull(updatedPerson);
842
843         // Verify that the updated resource received the correct data.
844         Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
845                 "Updated displayNameComputed in Person did not match submitted data.");
846         // Verify that the updated resource computes the right displayName.
847         Assert.assertEquals(updatedPerson.getDisplayName(),
848                         expectedDisplayName,
849                 "Updated DisplayName (not computed) in Person not stored.");
850     }
851
852     /**
853      * Verify illegal item display name.
854      *
855      * @param testName the test name
856      * @throws Exception the exception
857      */
858     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
859             dependsOnMethods = {"verifyItemDisplayName"})
860     public void verifyIllegalItemDisplayName(String testName) throws Exception {
861
862         if (logger.isDebugEnabled()) {
863             logger.debug(testBanner(testName, CLASS_NAME));
864         }
865         // Perform setup.
866         testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
867         // setupUpdateWithWrongXmlSchema(testName);
868
869         // Submit the request to the service and store the response.
870         PersonAuthorityClient client = new PersonAuthorityClient();
871         MultipartInput input = null;
872         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
873         try {
874                 int statusCode = res.getStatus();
875         
876                 // Check the status code of the response: does it match
877                 // the expected response(s)?
878                 if(logger.isDebugEnabled()){
879                     logger.debug(testName + ": status = " + statusCode);
880                 }
881                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
882                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
883                 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
884         
885                 // Check whether Person has expected displayName.
886                 input = (MultipartInput) res.getEntity();
887         } finally {
888                 res.releaseConnection();
889         }
890         
891         PersonsCommon person = (PersonsCommon) extractPart(input,
892                 client.getItemCommonPartName(), PersonsCommon.class);
893         Assert.assertNotNull(person);
894         // Try to Update with computed false and no displayName
895         person.setDisplayNameComputed(false);
896         person.setDisplayName(null);
897
898         // Submit the updated resource to the service and store the response.
899         MultipartOutput output = new MultipartOutput();
900         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
901         commonPart.getHeaders().add("label", client.getItemCommonPartName());
902         res = client.updateItem(knownResourceId, knownItemResourceId, output);
903         try {
904                 int statusCode = res.getStatus();
905         
906                 // Check the status code of the response: does it match the expected response(s)?
907                 if(logger.isDebugEnabled()){
908                     logger.debug("updateItem: status = " + statusCode);
909                 }
910                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
911                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
912                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
913         } finally {
914                 res.releaseConnection();
915         }
916     }
917     
918     /**
919      * Read contact.
920      *
921      * @param testName the test name
922      * @throws Exception the exception
923      */
924     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
925         groups = {"readItem"}, dependsOnMethods = {"readItem"})
926     public void readContact(String testName) throws Exception {
927         
928         if (logger.isDebugEnabled()) {
929             logger.debug(testBanner(testName, CLASS_NAME));
930         }
931         // Perform setup.
932         setupRead();
933
934         // Submit the request to the service and store the response.
935         PersonAuthorityClient client = new PersonAuthorityClient();
936         MultipartInput input = null;
937         ClientResponse<MultipartInput> res =
938             client.readContact(knownResourceId, knownItemResourceId,
939             knownContactResourceId);
940         try {
941                 int statusCode = res.getStatus();
942         
943                 // Check the status code of the response: does it match
944                 // the expected response(s)?
945                 if(logger.isDebugEnabled()){
946                     logger.debug(testName + ": status = " + statusCode);
947                 }
948                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
949                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
950                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
951         
952                 // Check whether we've received a contact.
953                 input = (MultipartInput) res.getEntity();
954         } finally {
955                 res.releaseConnection();
956         }
957         
958         ContactsCommon contact = (ContactsCommon) extractPart(input,
959                 new ContactClient().getCommonPartName(), ContactsCommon.class);
960         Assert.assertNotNull(contact);
961         boolean showFull = true;
962         if(showFull && logger.isDebugEnabled()){
963             logger.debug(testName + ": returned payload:");
964             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
965         }
966         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
967         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
968
969     }
970
971     // Failure outcomes
972     /* (non-Javadoc)
973      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
974      */
975     @Override
976     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
977         groups = {"read"}, dependsOnMethods = {"read"})
978     public void readNonExistent(String testName) {
979
980         if (logger.isDebugEnabled()) {
981             logger.debug(testBanner(testName, CLASS_NAME));
982         }
983         // Perform setup.
984         setupReadNonExistent();
985
986         // Submit the request to the service and store the response.
987         PersonAuthorityClient client = new PersonAuthorityClient();
988         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
989         try {
990                 int statusCode = res.getStatus();
991                 // Check the status code of the response: does it match
992                 // the expected response(s)?
993                 if(logger.isDebugEnabled()){
994                     logger.debug(testName + ": status = " + statusCode);
995                 }
996                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
997                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
998                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
999         } finally {
1000                 res.releaseConnection();
1001         }
1002     }
1003
1004     /**
1005      * Read item non existent.
1006      *
1007      * @param testName the test name
1008      */
1009     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1010         groups = {"readItem"}, dependsOnMethods = {"readItem"})
1011     public void readItemNonExistent(String testName) {
1012
1013         if (logger.isDebugEnabled()) {
1014             logger.debug(testBanner(testName, CLASS_NAME));
1015         }
1016         // Perform setup.
1017         setupReadNonExistent();
1018
1019         // Submit the request to the service and store the response.
1020         PersonAuthorityClient client = new PersonAuthorityClient();
1021         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1022         try {
1023                 int statusCode = res.getStatus();
1024         
1025                 // Check the status code of the response: does it match
1026                 // the expected response(s)?
1027                 if(logger.isDebugEnabled()){
1028                     logger.debug(testName + ": status = " + statusCode);
1029                 }
1030                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1033         } finally {
1034                 res.releaseConnection();
1035         }
1036     }
1037
1038     /**
1039      * Read contact non existent.
1040      *
1041      * @param testName the test name
1042      */
1043     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1044         groups = {"readItem"}, dependsOnMethods = {"readContact"})
1045     public void readContactNonExistent(String testName) {
1046
1047         if (logger.isDebugEnabled()) {
1048             logger.debug(testBanner(testName, CLASS_NAME));
1049         }
1050         // Perform setup.
1051         setupReadNonExistent();
1052
1053         // Submit the request to the service and store the response.
1054         PersonAuthorityClient client = new PersonAuthorityClient();
1055         ClientResponse<MultipartInput> res =
1056             client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1057         try {
1058                 int statusCode = res.getStatus();
1059         
1060                 // Check the status code of the response: does it match
1061                 // the expected response(s)?
1062                 if(logger.isDebugEnabled()){
1063                     logger.debug(testName + ": status = " + statusCode);
1064                 }
1065                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1066                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1067                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1068         } finally {
1069                 res.releaseConnection();
1070         }
1071     }
1072
1073     // ---------------------------------------------------------------
1074     // CRUD tests : READ_LIST tests
1075     // ---------------------------------------------------------------
1076     // Success outcomes
1077
1078     /* (non-Javadoc)
1079      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1080      */
1081     @Override
1082     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1083         groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1084     public void readList(String testName) throws Exception {
1085
1086         if (logger.isDebugEnabled()) {
1087             logger.debug(testBanner(testName, CLASS_NAME));
1088         }
1089         // Perform setup.
1090         setupReadList();
1091
1092         // Submit the request to the service and store the response.
1093         PersonAuthorityClient client = new PersonAuthorityClient();
1094         PersonauthoritiesCommonList list = null;
1095         ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1096         try {
1097                 int statusCode = res.getStatus();
1098         
1099                 // Check the status code of the response: does it match
1100                 // the expected response(s)?
1101                 if(logger.isDebugEnabled()){
1102                     logger.debug(testName + ": status = " + statusCode);
1103                 }
1104                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1105                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1106                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1107         
1108                 list = res.getEntity();
1109         } finally {
1110                 res.releaseConnection();
1111         }
1112
1113         // Optionally output additional data about list members for debugging.
1114         boolean iterateThroughList = false;
1115         if (iterateThroughList && logger.isDebugEnabled()) {
1116             List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1117                     list.getPersonauthorityListItem();
1118             int i = 0;
1119             for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1120                 String csid = item.getCsid();
1121                 logger.debug(testName + ": list-item[" + i + "] csid=" +
1122                         csid);
1123                 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1124                         item.getDisplayName());
1125                 logger.debug(testName + ": list-item[" + i + "] URI=" +
1126                         item.getUri());
1127                 readItemList(csid, null, testName);
1128                 i++;
1129             }
1130         }
1131     }
1132
1133     /**
1134      * Read item list.
1135      */
1136     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1137                 groups = {"readList"}, dependsOnMethods = {"readList"})
1138     public void readItemList(String testName) {
1139         readItemList(knownResourceId, null, testName);
1140     }
1141
1142     /**
1143      * Read item list by authority name.
1144      */
1145     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1146                 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1147     public void readItemListByAuthorityName(String testName) {
1148         readItemList(null, knownResourceShortIdentifer, testName);
1149     }
1150     
1151     /**
1152      * Read item list.
1153      *
1154      * @param vcsid the vcsid
1155      * @param name the name
1156      */
1157     private void readItemList(String vcsid, String name, String testName) {
1158
1159         // Perform setup.
1160         setupReadList();
1161         
1162         // Submit the request to the service and store the response.
1163         PersonAuthorityClient client = new PersonAuthorityClient();
1164         ClientResponse<PersonsCommonList> res = null;
1165         if (vcsid!= null) {
1166                 res = client.readItemList(vcsid);
1167         } else if (name!= null) {
1168                 res = client.readItemListForNamedAuthority(name);
1169         } else {
1170                 Assert.fail("readItemList passed null csid and name!");
1171         }
1172         PersonsCommonList list = null;
1173         try {
1174                 int statusCode = res.getStatus();
1175         
1176                 // Check the status code of the response: does it match
1177                 // the expected response(s)?
1178                 if(logger.isDebugEnabled()){
1179                     logger.debug(testName + ": status = " + statusCode);
1180                 }
1181                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1182                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1183                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1184
1185                 list = res.getEntity();
1186         } finally {
1187                 res.releaseConnection();
1188         }
1189
1190         List<PersonsCommonList.PersonListItem> items =
1191             list.getPersonListItem();
1192         int nItemsReturned = items.size();
1193         // There will be one item created, associated with a
1194         // known parent resource, by the createItem test.
1195         //
1196         // In addition, there will be 'nItemsToCreateInList'
1197         // additional items created by the createItemList test,
1198         // all associated with the same parent resource.
1199         int nExpectedItems = nItemsToCreateInList + 1;
1200         if(logger.isDebugEnabled()){
1201             logger.debug(testName + ": Expected "
1202                         + nExpectedItems +" items; got: "+nItemsReturned);
1203         }
1204         Assert.assertEquals(nItemsReturned, nExpectedItems);
1205
1206         int i = 0;
1207         for (PersonsCommonList.PersonListItem item : items) {
1208                 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1209                 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1210                 // Optionally output additional data about list members for debugging.
1211                 boolean showDetails = true;
1212                 if (showDetails && logger.isDebugEnabled()) {
1213                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
1214                         item.getCsid());
1215                 logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
1216                         item.getRefName());
1217                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
1218                         item.getDisplayName());
1219                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
1220                         item.getUri());
1221             }
1222             i++;
1223         }
1224     }
1225
1226     /**
1227      * Read contact list.
1228      */
1229     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1230     public void readContactList() {
1231         readContactList(knownResourceId, knownItemResourceId);
1232     }
1233
1234     /**
1235      * Read contact list.
1236      *
1237      * @param parentcsid the parentcsid
1238      * @param itemcsid the itemcsid
1239      */
1240     private void readContactList(String parentcsid, String itemcsid) {
1241         final String testName = "readContactList";
1242
1243         // Perform setup.
1244         setupReadList();
1245
1246         // Submit the request to the service and store the response.
1247         PersonAuthorityClient client = new PersonAuthorityClient();
1248         ContactsCommonList list = null;
1249         ClientResponse<ContactsCommonList> res =
1250                 client.readContactList(parentcsid, itemcsid);
1251         try {
1252                 int statusCode = res.getStatus();
1253         
1254                 // Check the status code of the response: does it match
1255                 // the expected response(s)?
1256                 if(logger.isDebugEnabled()){
1257                     logger.debug(testName + ": status = " + statusCode);
1258                 }
1259                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1260                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1261                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1262         
1263                 list = res.getEntity();
1264         } finally {
1265                 res.releaseConnection();
1266         }
1267         
1268         List<ContactsCommonList.ContactListItem> listitems =
1269             list.getContactListItem();
1270         int nItemsReturned = listitems.size();
1271         // There will be one item created, associated with a
1272         // known parent resource, by the createItem test.
1273         //
1274         // In addition, there will be 'nItemsToCreateInList'
1275         // additional items created by the createItemList test,
1276         // all associated with the same parent resource.
1277         int nExpectedItems = nItemsToCreateInList + 1;
1278         if(logger.isDebugEnabled()){
1279             logger.debug(testName + ": Expected "
1280                         + nExpectedItems +" items; got: "+nItemsReturned);
1281         }
1282         Assert.assertEquals(nItemsReturned, nExpectedItems);
1283
1284         int i = 0;
1285         for (ContactsCommonList.ContactListItem listitem : listitems) {
1286                 // Optionally output additional data about list members for debugging.
1287                 boolean showDetails = false;
1288                 if (showDetails && logger.isDebugEnabled()) {
1289                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
1290                         listitem.getCsid());
1291                 logger.debug("  " + testName + ": list-item[" + i + "] addressPlace=" +
1292                         listitem.getAddressPlace());
1293                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
1294                         listitem.getUri());
1295             }
1296             i++;
1297         }
1298     }
1299
1300     // Failure outcomes
1301
1302     // There are no failure outcome tests at present.
1303
1304     // ---------------------------------------------------------------
1305     // CRUD tests : UPDATE tests
1306     // ---------------------------------------------------------------
1307     // Success outcomes
1308     /* (non-Javadoc)
1309      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1310      */
1311     @Override
1312     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1313         groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1314     public void update(String testName) throws Exception {
1315
1316         if (logger.isDebugEnabled()) {
1317             logger.debug(testBanner(testName, CLASS_NAME));
1318         }
1319         // Perform setup.
1320         setupUpdate();
1321
1322         // Retrieve the contents of a resource to update.
1323         PersonAuthorityClient client = new PersonAuthorityClient();
1324         MultipartInput input = null;
1325         ClientResponse<MultipartInput> res = client.read(knownResourceId);
1326         try {
1327                 if(logger.isDebugEnabled()){
1328                     logger.debug(testName + ": read status = " + res.getStatus());
1329                 }
1330                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1331         
1332                 if(logger.isDebugEnabled()){
1333                     logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1334                 }
1335                 input = res.getEntity();
1336         } finally {
1337                 res.releaseConnection();
1338         }
1339         
1340         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1341                 client.getCommonPartName(), PersonauthoritiesCommon.class);
1342         Assert.assertNotNull(personAuthority);
1343
1344         // Update the contents of this resource.
1345         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1346         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1347         if(logger.isDebugEnabled()){
1348             logger.debug("to be updated PersonAuthority");
1349             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1350         }
1351
1352         // Submit the updated resource to the service and store the response.
1353         MultipartOutput output = new MultipartOutput();
1354         OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1355         commonPart.getHeaders().add("label", client.getCommonPartName());
1356         res = client.update(knownResourceId, output);
1357         try {
1358                 int statusCode = res.getStatus();
1359         
1360                 // Check the status code of the response: does it match the expected response(s)?
1361                 if(logger.isDebugEnabled()){
1362                     logger.debug(testName + ": status = " + statusCode);
1363                 }
1364                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1365                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1366                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1367         
1368                 // Retrieve the updated resource and verify that its contents exist.
1369                 input = (MultipartInput) res.getEntity();
1370         } finally {
1371                 res.releaseConnection();
1372         }
1373         
1374         PersonauthoritiesCommon updatedPersonAuthority =
1375                 (PersonauthoritiesCommon) extractPart(input,
1376                         client.getCommonPartName(), PersonauthoritiesCommon.class);
1377         Assert.assertNotNull(updatedPersonAuthority);
1378
1379         // Verify that the updated resource received the correct data.
1380         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1381                 personAuthority.getDisplayName(),
1382                 "Data in updated object did not match submitted data.");
1383     }
1384
1385     /**
1386      * Update item.
1387      *
1388      * @param testName the test name
1389      * @throws Exception the exception
1390      */
1391     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1392         groups = {"update"}, dependsOnMethods = {"update"})
1393     public void updateItem(String testName) throws Exception {
1394
1395         if (logger.isDebugEnabled()) {
1396             logger.debug(testBanner(testName, CLASS_NAME));
1397         }
1398         // Perform setup.
1399         setupUpdate();
1400
1401         // Retrieve the contents of a resource to update.
1402         PersonAuthorityClient client = new PersonAuthorityClient();
1403         MultipartInput input = null;
1404         ClientResponse<MultipartInput> res =
1405                 client.readItem(knownResourceId, knownItemResourceId);
1406         try {
1407                 if(logger.isDebugEnabled()){
1408                     logger.debug(testName + ": read status = " + res.getStatus());
1409                 }
1410                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1411         
1412                 if(logger.isDebugEnabled()){
1413                     logger.debug("got Person to update with ID: " +
1414                         knownItemResourceId +
1415                         " in PersonAuthority: " + knownResourceId );
1416                 }
1417                 input = res.getEntity();
1418         } finally {
1419                 res.releaseConnection();
1420         }
1421         
1422         PersonsCommon person = (PersonsCommon) extractPart(input,
1423                 client.getItemCommonPartName(), PersonsCommon.class);
1424         Assert.assertNotNull(person);
1425         
1426         if (logger.isDebugEnabled() == true) {
1427                 logger.debug("About to update the following person...");
1428                 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1429         }
1430
1431         // Update the contents of this resource.
1432         person.setCsid(null);
1433         person.setForeName("updated-" + person.getForeName());
1434         if(logger.isDebugEnabled()){
1435             logger.debug("to be updated Person");
1436             logger.debug(objectAsXmlString(person,
1437                 PersonsCommon.class));
1438         }    
1439         
1440         // Submit the updated resource to the service and store the response.
1441         MultipartOutput output = new MultipartOutput();
1442         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1443         commonPart.getHeaders().add("label", client.getItemCommonPartName());
1444         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1445         try {
1446                 int statusCode = res.getStatus();
1447         
1448                 // Check the status code of the response: does it match the expected response(s)?
1449                 if(logger.isDebugEnabled()){
1450                     logger.debug(testName + ": status = " + statusCode);
1451                 }
1452                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1453                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1454                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1455         
1456                 // Retrieve the updated resource and verify that its contents exist.
1457                 input = (MultipartInput) res.getEntity();
1458         } finally {
1459                 res.releaseConnection();
1460         }
1461         
1462         PersonsCommon updatedPerson =
1463                 (PersonsCommon) extractPart(input,
1464                         client.getItemCommonPartName(), PersonsCommon.class);
1465         Assert.assertNotNull(updatedPerson);
1466         
1467         if (logger.isDebugEnabled() == true) {
1468                 logger.debug("Updated to following person to:");
1469                 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1470         }        
1471
1472         // Verify that the updated resource received the correct data.
1473         Assert.assertEquals(updatedPerson.getForeName(),
1474                 person.getForeName(),
1475                 "Data in updated Person did not match submitted data.");
1476     }
1477
1478     /**
1479      * Update contact.
1480      *
1481      * @param testName the test name
1482      * @throws Exception the exception
1483      */
1484     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1485         groups = {"update"}, dependsOnMethods = {"updateItem"})
1486     public void updateContact(String testName) throws Exception {
1487         
1488         if (logger.isDebugEnabled()) {
1489             logger.debug(testBanner(testName, CLASS_NAME));
1490         }
1491         // Perform setup.
1492         setupUpdate();
1493
1494         // Retrieve the contents of a resource to update.
1495         PersonAuthorityClient client = new PersonAuthorityClient();
1496         MultipartInput input = null;
1497         ClientResponse<MultipartInput> res =
1498                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1499         try {
1500                 if(logger.isDebugEnabled()){
1501                     logger.debug(testName + ": read status = " + res.getStatus());
1502                 }
1503                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1504         
1505                 if(logger.isDebugEnabled()){
1506                     logger.debug("got Contact to update with ID: " +
1507                         knownContactResourceId +
1508                         " in item: " + knownItemResourceId +
1509                         " in parent: " + knownResourceId );
1510                 }
1511                 input = res.getEntity();
1512         } finally {
1513                 res.releaseConnection();
1514         }
1515         
1516         ContactsCommon contact = (ContactsCommon) extractPart(input,
1517                 new ContactClient().getCommonPartName(), ContactsCommon.class);
1518         Assert.assertNotNull(contact);
1519
1520         // Update the contents of this resource.
1521         contact.setAddressPlace("updated-" + contact.getAddressPlace());
1522         if(logger.isDebugEnabled()){
1523             logger.debug("to be updated Contact");
1524             logger.debug(objectAsXmlString(contact,
1525                 ContactsCommon.class));
1526         }
1527
1528         // Submit the updated resource to the service and store the response.
1529         MultipartOutput output = new MultipartOutput();
1530         OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1531         commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1532         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1533         try {
1534                 int statusCode = res.getStatus();
1535         
1536                 // Check the status code of the response: does it match the expected response(s)?
1537                 if(logger.isDebugEnabled()){
1538                     logger.debug(testName + ": status = " + statusCode);
1539                 }
1540                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1541                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1542                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1543         
1544                 // Retrieve the updated resource and verify that its contents exist.
1545                 input = (MultipartInput) res.getEntity();
1546         } finally {
1547                 res.releaseConnection();
1548         }
1549         ContactsCommon updatedContact =
1550                 (ContactsCommon) extractPart(input,
1551                         new ContactClient().getCommonPartName(), ContactsCommon.class);
1552         Assert.assertNotNull(updatedContact);
1553
1554         // Verify that the updated resource received the correct data.
1555         Assert.assertEquals(updatedContact.getAddressPlace(),
1556                 contact.getAddressPlace(),
1557                 "Data in updated Contact did not match submitted data.");
1558     }
1559
1560     // Failure outcomes
1561     // Placeholders until the three tests below can be uncommented.
1562     // See Issue CSPACE-401.
1563     /* (non-Javadoc)
1564      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1565      */
1566     @Override
1567     public void updateWithEmptyEntityBody(String testName) throws Exception {
1568         //Should this really be empty?
1569     }
1570
1571     /* (non-Javadoc)
1572      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1573      */
1574     @Override
1575     public void updateWithMalformedXml(String testName) throws Exception {
1576         //Should this really be empty?
1577     }
1578
1579     /* (non-Javadoc)
1580      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1581      */
1582     @Override
1583     public void updateWithWrongXmlSchema(String testName) throws Exception {
1584         //Should this really be empty?
1585     }
1586
1587 /*
1588     @Override
1589     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1590         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1591     public void updateWithEmptyEntityBody(String testName) throws Exception {
1592
1593         if (logger.isDebugEnabled()) {
1594             logger.debug(testBanner(testName, CLASS_NAME));
1595         }
1596         // Perform setup.
1597         setupUpdateWithEmptyEntityBody(testName, logger);
1598
1599         // Submit the request to the service and store the response.
1600         String method = REQUEST_TYPE.httpMethodName();
1601         String url = getResourceURL(knownResourceId);
1602         String mediaType = MediaType.APPLICATION_XML;
1603         final String entity = "";
1604         int statusCode = submitRequest(method, url, mediaType, entity);
1605
1606         // Check the status code of the response: does it match
1607         // the expected response(s)?
1608         if(logger.isDebugEnabled()){
1609             logger.debug(testName + ": url=" + url +
1610                 " status=" + statusCode);
1611          }
1612         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1613         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1614         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1615     }
1616
1617     @Override
1618     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1619         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1620     public void updateWithMalformedXml(String testName) throws Exception {
1621
1622         if (logger.isDebugEnabled()) {
1623             logger.debug(testBanner(testName, CLASS_NAME));
1624         }
1625         // Perform setup.
1626         setupUpdateWithMalformedXml();
1627
1628         // Submit the request to the service and store the response.
1629         String method = REQUEST_TYPE.httpMethodName();
1630         String url = getResourceURL(knownResourceId);
1631         String mediaType = MediaType.APPLICATION_XML;
1632         final String entity = MALFORMED_XML_DATA;
1633         int statusCode = submitRequest(method, url, mediaType, entity);
1634
1635         // Check the status code of the response: does it match
1636         // the expected response(s)?
1637         if(logger.isDebugEnabled()){
1638             logger.debug(testName + ": url=" + url +
1639                " status=" + statusCode);
1640          }
1641         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1642         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1643         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1644     }
1645
1646     @Override
1647     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1648         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1649     public void updateWithWrongXmlSchema(String testName) throws Exception {
1650
1651         if (logger.isDebugEnabled()) {
1652             logger.debug(testBanner(testName, CLASS_NAME));
1653         }
1654         // Perform setup.
1655         setupUpdateWithWrongXmlSchema();
1656
1657         // Submit the request to the service and store the response.
1658         String method = REQUEST_TYPE.httpMethodName();
1659         String url = getResourceURL(knownResourceId);
1660         String mediaType = MediaType.APPLICATION_XML;
1661         final String entity = WRONG_XML_SCHEMA_DATA;
1662         int statusCode = submitRequest(method, url, mediaType, entity);
1663
1664         // Check the status code of the response: does it match
1665         // the expected response(s)?
1666         if(logger.isDebugEnabled()){
1667             logger.debug("updateWithWrongXmlSchema: url=" + url +
1668                 " status=" + statusCode);
1669          }
1670         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1671         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1672         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1673     }
1674 */
1675
1676     /* (non-Javadoc)
1677  * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1678  */
1679 @Override
1680     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1681         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1682     public void updateNonExistent(String testName) throws Exception {
1683
1684         if (logger.isDebugEnabled()) {
1685             logger.debug(testBanner(testName, CLASS_NAME));
1686         }
1687         // Perform setup.
1688         setupUpdateNonExistent();
1689
1690         // Submit the request to the service and store the response.
1691         // Note: The ID(s) used when creating the request payload may be arbitrary.
1692         // The only relevant ID may be the one used in update(), below.
1693         PersonAuthorityClient client = new PersonAuthorityClient();
1694         String displayName = "displayName-NON_EXISTENT_ID";
1695         MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1696                                 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1697         ClientResponse<MultipartInput> res =
1698                 client.update(NON_EXISTENT_ID, multipart);
1699         try {
1700                 int statusCode = res.getStatus();
1701         
1702                 // Check the status code of the response: does it match
1703                 // the expected response(s)?
1704                 if(logger.isDebugEnabled()){
1705                     logger.debug(testName + ": status = " + statusCode);
1706                 }
1707                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1708                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1709                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1710         } finally {
1711                 res.releaseConnection();
1712         }
1713     }
1714
1715     /**
1716      * Update non existent item.
1717      *
1718      * @param testName the test name
1719      * @throws Exception the exception
1720      */
1721     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1722         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1723     public void updateNonExistentItem(String testName) throws Exception {
1724
1725         if (logger.isDebugEnabled()) {
1726             logger.debug(testBanner(testName, CLASS_NAME));
1727         }
1728         // Perform setup.
1729         setupUpdateNonExistent();
1730
1731         // Submit the request to the service and store the response.
1732         // Note: The ID used in this 'create' call may be arbitrary.
1733         // The only relevant ID may be the one used in update(), below.
1734         PersonAuthorityClient client = new PersonAuthorityClient();
1735         Map<String, String> nonexMap = new HashMap<String,String>();
1736         nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1737         nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1738         nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1739         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1740         MultipartOutput multipart = 
1741         PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, 
1742                         PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1743                         nonexMap, client.getItemCommonPartName() );
1744         ClientResponse<MultipartInput> res =
1745                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1746         try {
1747                 int statusCode = res.getStatus();
1748         
1749                 // Check the status code of the response: does it match
1750                 // the expected response(s)?
1751                 if(logger.isDebugEnabled()){
1752                     logger.debug(testName + ": status = " + statusCode);
1753                 }
1754                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1755                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1756                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1757         } finally {
1758                 res.releaseConnection();
1759         }
1760     }
1761
1762     /**
1763      * Update non existent contact.
1764      *
1765      * @param testName the test name
1766      * @throws Exception the exception
1767      */
1768     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1769         groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1770     public void updateNonExistentContact(String testName) throws Exception {
1771         // Currently a no-op test
1772     }
1773
1774     // ---------------------------------------------------------------
1775     // CRUD tests : DELETE tests
1776     // ---------------------------------------------------------------
1777     // Success outcomes
1778
1779     // Note: delete sub-resources in ascending hierarchical order,
1780     // before deleting their parents.
1781
1782     /**
1783      * Delete contact.
1784      *
1785      * @param testName the test name
1786      * @throws Exception the exception
1787      */
1788     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, 
1789         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1790     public void deleteContact(String testName) throws Exception {
1791
1792         if (logger.isDebugEnabled()) {
1793             logger.debug(testBanner(testName, CLASS_NAME));
1794         }
1795         // Perform setup.
1796         setupDelete();
1797
1798          if(logger.isDebugEnabled()){
1799             logger.debug("parentcsid =" + knownResourceId +
1800                 " itemcsid = " + knownItemResourceId +
1801                 " csid = " + knownContactResourceId);
1802         }
1803
1804         // Submit the request to the service and store the response.
1805         PersonAuthorityClient client = new PersonAuthorityClient();
1806         ClientResponse<Response> res =
1807             client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1808         try {
1809                 int statusCode = res.getStatus();
1810         
1811                 // Check the status code of the response: does it match
1812                 // the expected response(s)?
1813                 if(logger.isDebugEnabled()){
1814                     logger.debug(testName + ": status = " + statusCode);
1815                 }
1816                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1817                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1818                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1819             } finally {
1820                 res.releaseConnection();
1821             }
1822     }
1823
1824    /**
1825     * Delete item.
1826     *
1827     * @param testName the test name
1828     * @throws Exception the exception
1829     */
1830    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1831         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1832     public void deleteItem(String testName) throws Exception {
1833
1834         if (logger.isDebugEnabled()) {
1835             logger.debug(testBanner(testName, CLASS_NAME));
1836         }
1837         // Perform setup.
1838         setupDelete();
1839
1840         if(logger.isDebugEnabled()){
1841             logger.debug("parentcsid =" + knownResourceId +
1842                 " itemcsid = " + knownItemResourceId);
1843         }
1844
1845         // Submit the request to the service and store the response.
1846         PersonAuthorityClient client = new PersonAuthorityClient();
1847         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1848         try {
1849                 int statusCode = res.getStatus();
1850         
1851                 // Check the status code of the response: does it match
1852                 // the expected response(s)?
1853                 if(logger.isDebugEnabled()){
1854                     logger.debug(testName + ": status = " + statusCode);
1855                 }
1856                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1857                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1858                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1859             } finally {
1860                 res.releaseConnection();
1861             }
1862     }
1863
1864     /* (non-Javadoc)
1865      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1866      */
1867     @Override
1868     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1869         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1870     public void delete(String testName) throws Exception {
1871
1872         if (logger.isDebugEnabled()) {
1873             logger.debug(testBanner(testName, CLASS_NAME));
1874         }
1875         // Perform setup.
1876         setupDelete();
1877
1878         if(logger.isDebugEnabled()){
1879             logger.debug("parentcsid =" + knownResourceId);
1880         }
1881
1882         // Submit the request to the service and store the response.
1883         PersonAuthorityClient client = new PersonAuthorityClient();
1884         ClientResponse<Response> res = client.delete(knownResourceId);
1885         try {
1886                 int statusCode = res.getStatus();
1887         
1888                 // Check the status code of the response: does it match
1889                 // the expected response(s)?
1890                 if(logger.isDebugEnabled()){
1891                     logger.debug(testName + ": status = " + statusCode);
1892                 }
1893                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1894                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1895                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1896             } finally {
1897                 res.releaseConnection();
1898             }
1899     }
1900
1901     // Failure outcomes
1902     /* (non-Javadoc)
1903      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1904      */
1905     @Override
1906     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1907         groups = {"delete"}, dependsOnMethods = {"delete"})
1908     public void deleteNonExistent(String testName) throws Exception {
1909
1910         if (logger.isDebugEnabled()) {
1911             logger.debug(testBanner(testName, CLASS_NAME));
1912         }
1913         // Perform setup.
1914         setupDeleteNonExistent();
1915
1916         // Submit the request to the service and store the response.
1917         PersonAuthorityClient client = new PersonAuthorityClient();
1918         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1919         try {
1920                 int statusCode = res.getStatus();
1921         
1922                 // Check the status code of the response: does it match
1923                 // the expected response(s)?
1924                 if(logger.isDebugEnabled()){
1925                     logger.debug(testName + ": status = " + statusCode);
1926                 }
1927                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1928                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1929                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1930             } finally {
1931                 res.releaseConnection();
1932             }
1933     }
1934
1935     /**
1936      * Delete non existent item.
1937      *
1938      * @param testName the test name
1939      */
1940     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1941         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1942     public void deleteNonExistentItem(String testName) {
1943
1944         if (logger.isDebugEnabled()) {
1945             logger.debug(testBanner(testName, CLASS_NAME));
1946         }
1947         // Perform setup.
1948         setupDeleteNonExistent();
1949
1950         // Submit the request to the service and store the response.
1951         PersonAuthorityClient client = new PersonAuthorityClient();
1952         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1953         try {
1954                 int statusCode = res.getStatus();
1955         
1956                 // Check the status code of the response: does it match
1957                 // the expected response(s)?
1958                 if(logger.isDebugEnabled()){
1959                     logger.debug(testName + ": status = " + statusCode);
1960                 }
1961                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1962                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1963                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1964             } finally {
1965                 res.releaseConnection();
1966             }
1967     }
1968
1969     /**
1970      * Delete non existent contact.
1971      *
1972      * @param testName the test name
1973      */
1974     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1975         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1976     public void deleteNonExistentContact(String testName) {
1977
1978         if (logger.isDebugEnabled()) {
1979             logger.debug(testBanner(testName, CLASS_NAME));
1980         }
1981         // Perform setup.
1982         setupDeleteNonExistent();
1983
1984         // Submit the request to the service and store the response.
1985         PersonAuthorityClient client = new PersonAuthorityClient();
1986         ClientResponse<Response> res =
1987             client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1988         try {
1989                 int statusCode = res.getStatus();
1990         
1991                 // Check the status code of the response: does it match
1992                 // the expected response(s)?
1993                 if(logger.isDebugEnabled()){
1994                     logger.debug(testName + ": status = " + statusCode);
1995                 }
1996                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1997                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1998                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1999             } finally {
2000                 res.releaseConnection();
2001             }
2002     }
2003
2004     // ---------------------------------------------------------------
2005     // Utility tests : tests of code used in tests above
2006     // ---------------------------------------------------------------
2007     /**
2008      * Tests the code for manually submitting data that is used by several
2009      * of the methods above.
2010      */
2011     @Test(dependsOnMethods = {"create", "read"})
2012     public void testSubmitRequest() {
2013
2014         // Expected status code: 200 OK
2015         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2016
2017         // Submit the request to the service and store the response.
2018         String method = ServiceRequestType.READ.httpMethodName();
2019         String url = getResourceURL(knownResourceId);
2020         int statusCode = submitRequest(method, url);
2021
2022         // Check the status code of the response: does it match
2023         // the expected response(s)?
2024         if(logger.isDebugEnabled()){
2025             logger.debug("testSubmitRequest: url=" + url +
2026                 " status=" + statusCode);
2027         }
2028         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2029
2030     }
2031
2032     /**
2033      * Test item submit request.
2034      */
2035     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2036     public void testItemSubmitRequest() {
2037
2038         // Expected status code: 200 OK
2039         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2040
2041         // Submit the request to the service and store the response.
2042         String method = ServiceRequestType.READ.httpMethodName();
2043         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2044         int statusCode = submitRequest(method, url);
2045
2046         // Check the status code of the response: does it match
2047         // the expected response(s)?
2048         if(logger.isDebugEnabled()){
2049             logger.debug("testItemSubmitRequest: url=" + url +
2050                 " status=" + statusCode);
2051         }
2052         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2053
2054     }
2055
2056     /**
2057      * Test contact submit request.
2058      */
2059     @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2060     public void testContactSubmitRequest() {
2061
2062         // Expected status code: 200 OK
2063         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2064
2065         // Submit the request to the service and store the response.
2066         String method = ServiceRequestType.READ.httpMethodName();
2067         String url = getContactResourceURL(knownResourceId,
2068             knownItemResourceId, knownContactResourceId);
2069         int statusCode = submitRequest(method, url);
2070
2071         // Check the status code of the response: does it match
2072         // the expected response(s)?
2073         if(logger.isDebugEnabled()){
2074             logger.debug("testItemSubmitRequest: url=" + url +
2075                 " status=" + statusCode);
2076         }
2077         Assert.assertEquals(statusCode, EXPECTED_STATUS);
2078
2079     }
2080
2081
2082     // ---------------------------------------------------------------
2083     // Cleanup of resources created during testing
2084     // ---------------------------------------------------------------
2085     
2086     /**
2087      * Deletes all resources created by tests, after all tests have been run.
2088      *
2089      * This cleanup method will always be run, even if one or more tests fail.
2090      * For this reason, it attempts to remove all resources created
2091      * at any point during testing, even if some of those resources
2092      * may be expected to be deleted by certain tests.
2093      */
2094
2095     @AfterClass(alwaysRun=true)
2096     @Override
2097     public void cleanUp() {
2098         String noTest = System.getProperty("noTestCleanup");
2099         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2100             if (logger.isDebugEnabled()) {
2101                 logger.debug("Skipping Cleanup phase ...");
2102             }
2103             return;
2104         }
2105         if (logger.isDebugEnabled()) {
2106             logger.debug("Cleaning up temporary resources created for testing ...");
2107         }
2108         String parentResourceId;
2109         String itemResourceId;
2110         String contactResourceId;
2111         // Clean up contact resources.
2112         PersonAuthorityClient client = new PersonAuthorityClient();
2113         parentResourceId = knownResourceId;
2114         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2115             contactResourceId = entry.getKey();
2116             itemResourceId = entry.getValue();
2117             // Note: Any non-success responses from the delete operation
2118             // below are ignored and not reported.
2119             ClientResponse<Response> res =
2120                 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2121             res.releaseConnection();
2122         }
2123         // Clean up item resources.
2124         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2125             itemResourceId = entry.getKey();
2126             parentResourceId = entry.getValue();
2127             // Note: Any non-success responses from the delete operation
2128             // below are ignored and not reported.
2129             ClientResponse<Response> res =
2130                 client.deleteItem(parentResourceId, itemResourceId);
2131             res.releaseConnection();
2132         }
2133         // Clean up parent resources.
2134         super.cleanUp();
2135     }
2136
2137     // ---------------------------------------------------------------
2138     // Utility methods used by tests above
2139     // ---------------------------------------------------------------
2140     /* (non-Javadoc)
2141      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2142      */
2143     @Override
2144     public String getServicePathComponent() {
2145         return SERVICE_PATH_COMPONENT;
2146     }
2147
2148     /**
2149      * Gets the item service path component.
2150      *
2151      * @return the item service path component
2152      */
2153     public String getItemServicePathComponent() {
2154         return ITEM_SERVICE_PATH_COMPONENT;
2155     }
2156
2157     /**
2158      * Gets the contact service path component.
2159      *
2160      * @return the contact service path component
2161      */
2162     public String getContactServicePathComponent() {
2163         return CONTACT_SERVICE_PATH_COMPONENT;
2164     }
2165
2166     /**
2167      * Returns the root URL for the item service.
2168      *
2169      * This URL consists of a base URL for all services, followed by
2170      * a path component for the owning parent, followed by the
2171      * path component for the items.
2172      *
2173      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2174      * parent authority resource of the relevant item resource.
2175      *
2176      * @return The root URL for the item service.
2177      */
2178     protected String getItemServiceRootURL(String parentResourceIdentifier) {
2179         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2180     }
2181
2182     /**
2183      * Returns the URL of a specific item resource managed by a service, and
2184      * designated by an identifier (such as a universally unique ID, or UUID).
2185      *
2186      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2187      * parent authority resource of the relevant item resource.
2188      *
2189      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2190      * item resource.
2191      *
2192      * @return The URL of a specific item resource managed by a service.
2193      */
2194     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2195         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2196     }
2197
2198
2199     /**
2200      * Returns the root URL for the contact service.
2201      *
2202      * This URL consists of a base URL for all services, followed by
2203      * a path component for the owning authority, followed by the
2204      * path component for the owning item, followed by the path component
2205      * for the contact service.
2206      *
2207      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2208      * parent authority resource of the relevant item resource.
2209      *
2210      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2211      * item resource.
2212      *
2213      * @return The root URL for the contact service.
2214      */
2215     protected String getContactServiceRootURL(String parentResourceIdentifier,
2216         String itemResourceIdentifier) {
2217         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2218                 getContactServicePathComponent();
2219     }
2220
2221     /**
2222      * Returns the URL of a specific contact resource managed by a service, and
2223      * designated by an identifier (such as a universally unique ID, or UUID).
2224      *
2225      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2226      * parent resource of the relevant item resource.
2227      *
2228      * @param  resourceIdentifier  An identifier (such as a UUID) for an
2229      * item resource.
2230      *
2231      * @return The URL of a specific resource managed by a service.
2232      */
2233     protected String getContactResourceURL(String parentResourceIdentifier,
2234         String itemResourceIdentifier, String contactResourceIdentifier) {
2235         return getContactServiceRootURL(parentResourceIdentifier,
2236             itemResourceIdentifier) + "/" + contactResourceIdentifier;
2237     }
2238 }