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