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