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