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