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