]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
1fce517d49a0bc6b7ae1daf812695864520e05da
[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.setDisplayNameComputed(true);
553         person.setForeName("updated-" + TEST_FORE_NAME);
554         expectedDisplayName = 
555             PersonAuthorityClientUtils.prepareDefaultDisplayName(
556                 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, 
557                 TEST_BIRTH_DATE, TEST_DEATH_DATE);
558
559         // Submit the updated resource to the service and store the response.
560         MultipartOutput output = new MultipartOutput();
561         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
562         commonPart.getHeaders().add("label", client.getItemCommonPartName());
563         res = client.updateItem(knownResourceId, knownItemResourceId, output);
564         statusCode = res.getStatus();
565
566         // Check the status code of the response: does it match the expected response(s)?
567         if(logger.isDebugEnabled()){
568             logger.debug("updateItem: status = " + statusCode);
569         }
570         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
571                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
572         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
573
574         // Retrieve the updated resource and verify that its contents exist.
575         input = (MultipartInput) res.getEntity();
576         PersonsCommon updatedPerson =
577                 (PersonsCommon) extractPart(input,
578                         client.getItemCommonPartName(), PersonsCommon.class);
579         Assert.assertNotNull(updatedPerson);
580
581         // Verify that the updated resource received the correct data.
582         Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
583             "Updated ForeName in Person did not match submitted data.");
584         // Verify that the updated resource computes the right displayName.
585         Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
586             "Updated ForeName in Person not reflected in computed DisplayName.");
587
588         // Now Update the displayName, not computed and verify the computed name is overriden.
589         person.setDisplayNameComputed(false);
590         expectedDisplayName = "TestName";
591         person.setDisplayName(expectedDisplayName);
592
593         // Submit the updated resource to the service and store the response.
594         output = new MultipartOutput();
595         commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
596         commonPart.getHeaders().add("label", client.getItemCommonPartName());
597         res = client.updateItem(knownResourceId, knownItemResourceId, output);
598         statusCode = res.getStatus();
599
600         // Check the status code of the response: does it match the expected response(s)?
601         if(logger.isDebugEnabled()){
602             logger.debug("updateItem: status = " + statusCode);
603         }
604         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
605                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
606         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
607
608         // Retrieve the updated resource and verify that its contents exist.
609         input = (MultipartInput) res.getEntity();
610         updatedPerson =
611                 (PersonsCommon) extractPart(input,
612                         client.getItemCommonPartName(), PersonsCommon.class);
613         Assert.assertNotNull(updatedPerson);
614
615         // Verify that the updated resource received the correct data.
616         Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
617                 "Updated displayNameComputed in Person did not match submitted data.");
618         // Verify that the updated resource computes the right displayName.
619         Assert.assertEquals(updatedPerson.getDisplayName(),
620                         expectedDisplayName,
621                 "Updated DisplayName (not computed) in Person not stored.");
622     }
623
624     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
625             dependsOnMethods = {"verifyItemDisplayName"})
626     public void verifyIllegalItemDisplayName(String testName) throws Exception {
627
628         // Perform setup.
629         setupUpdateWithWrongXmlSchema(testName);
630
631         // Submit the request to the service and store the response.
632         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
633         int statusCode = res.getStatus();
634
635         // Check the status code of the response: does it match
636         // the expected response(s)?
637         if(logger.isDebugEnabled()){
638             logger.debug(testName + ": status = " + statusCode);
639         }
640         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642         Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
643
644         // Check whether Person has expected displayName.
645         MultipartInput input = (MultipartInput) res.getEntity();
646         PersonsCommon person = (PersonsCommon) extractPart(input,
647                 client.getItemCommonPartName(), PersonsCommon.class);
648         Assert.assertNotNull(person);
649         // Try to Update with computed false and no displayName
650         person.setDisplayNameComputed(false);
651         person.setDisplayName(null);
652
653         // Submit the updated resource to the service and store the response.
654         MultipartOutput output = new MultipartOutput();
655         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
656         commonPart.getHeaders().add("label", client.getItemCommonPartName());
657         res = client.updateItem(knownResourceId, knownItemResourceId, output);
658         statusCode = res.getStatus();
659
660         // Check the status code of the response: does it match the expected response(s)?
661         if(logger.isDebugEnabled()){
662             logger.debug("updateItem: status = " + statusCode);
663         }
664         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
665                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
666         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667     }
668     
669     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
670         groups = {"read"}, dependsOnMethods = {"readItem"})
671     public void readContact(String testName) throws Exception {
672
673         // Perform setup.
674         setupRead(testName);
675
676         // Submit the request to the service and store the response.
677         ClientResponse<MultipartInput> res =
678             client.readContact(knownResourceId, knownItemResourceId,
679             knownContactResourceId);
680         int statusCode = res.getStatus();
681
682         // Check the status code of the response: does it match
683         // the expected response(s)?
684         if(logger.isDebugEnabled()){
685             logger.debug(testName + ": status = " + statusCode);
686         }
687         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
688                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
689         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
690
691         // Check whether we've received a contact.
692         MultipartInput input = (MultipartInput) res.getEntity();
693         ContactsCommon contact = (ContactsCommon) extractPart(input,
694                 contactClient.getCommonPartName(), ContactsCommon.class);
695         Assert.assertNotNull(contact);
696         boolean showFull = true;
697         if(showFull && logger.isDebugEnabled()){
698             logger.debug(testName + ": returned payload:");
699             logger.debug(objectAsXmlString(contact, ContactsCommon.class));
700         }
701         Assert.assertEquals(contact.getInAuthority(), knownResourceId);
702         Assert.assertEquals(contact.getInItem(), knownItemResourceId);
703
704     }
705
706     // Failure outcomes
707     @Override
708     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
709         groups = {"read"}, dependsOnMethods = {"read"})
710     public void readNonExistent(String testName) {
711
712         // Perform setup.
713         setupReadNonExistent(testName);
714
715         // Submit the request to the service and store the response.
716         ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
717         int statusCode = res.getStatus();
718
719         // Check the status code of the response: does it match
720         // the expected response(s)?
721         if(logger.isDebugEnabled()){
722             logger.debug(testName + ": status = " + statusCode);
723         }
724         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
725                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
726         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
727     }
728
729     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
730         groups = {"read"}, dependsOnMethods = {"readItem"})
731     public void readItemNonExistent(String testName) {
732
733         // Perform setup.
734         setupReadNonExistent(testName);
735
736         // Submit the request to the service and store the response.
737         ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
738         int statusCode = res.getStatus();
739
740         // Check the status code of the response: does it match
741         // the expected response(s)?
742         if(logger.isDebugEnabled()){
743             logger.debug(testName + ": status = " + statusCode);
744         }
745         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
746                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
747         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
748     }
749
750     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751         groups = {"read"}, dependsOnMethods = {"readContact"})
752     public void readContactNonExistent(String testName) {
753
754         // Perform setup.
755         setupReadNonExistent(testName);
756
757         // Submit the request to the service and store the response.
758         ClientResponse<MultipartInput> res =
759             client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
760         int statusCode = res.getStatus();
761
762         // Check the status code of the response: does it match
763         // the expected response(s)?
764         if(logger.isDebugEnabled()){
765             logger.debug(testName + ": status = " + statusCode);
766         }
767         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
768                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
769         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
770     }
771
772     // ---------------------------------------------------------------
773     // CRUD tests : READ_LIST tests
774     // ---------------------------------------------------------------
775     // Success outcomes
776
777     @Override
778     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
779         groups = {"readList"}, dependsOnGroups = {"createList", "read"})
780     public void readList(String testName) throws Exception {
781
782         // Perform setup.
783         setupReadList(testName);
784
785         // Submit the request to the service and store the response.
786         ClientResponse<PersonauthoritiesCommonList> res = client.readList();
787         PersonauthoritiesCommonList list = res.getEntity();
788         int statusCode = res.getStatus();
789
790         // Check the status code of the response: does it match
791         // the expected response(s)?
792         if(logger.isDebugEnabled()){
793             logger.debug(testName + ": status = " + statusCode);
794         }
795         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
796                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
797         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
798
799         // Optionally output additional data about list members for debugging.
800         boolean iterateThroughList = false;
801         if (iterateThroughList && logger.isDebugEnabled()) {
802             List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
803                     list.getPersonauthorityListItem();
804             int i = 0;
805             for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
806                 String csid = item.getCsid();
807                 logger.debug(testName + ": list-item[" + i + "] csid=" +
808                         csid);
809                 logger.debug(testName + ": list-item[" + i + "] displayName=" +
810                         item.getDisplayName());
811                 logger.debug(testName + ": list-item[" + i + "] URI=" +
812                         item.getUri());
813                 readItemList(csid, null);
814                 i++;
815             }
816         }
817     }
818
819     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
820     public void readItemList() {
821         readItemList(knownResourceId, null);
822     }
823
824     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
825     public void readItemListByAuthorityName() {
826         readItemList(null, knownResourceDisplayName);
827     }
828     private void readItemList(String vcsid, String name) {
829
830         final String testName = "readItemList";
831
832         // Perform setup.
833         setupReadList(testName);
834         
835         ClientResponse<PersonsCommonList> res = null;
836         
837         if(vcsid!= null) {
838                 // Submit the request to the service and store the response.
839                 res = client.readItemList(vcsid);
840         } else if(name!= null) {
841                 // Submit the request to the service and store the response.
842                 res = client.readItemListForNamedAuthority(name);
843         } else {
844                 Assert.fail("readItemList passed null csid and name!");
845         }
846         PersonsCommonList list = res.getEntity();
847         int statusCode = res.getStatus();
848
849         // Check the status code of the response: does it match
850         // the expected response(s)?
851         if(logger.isDebugEnabled()){
852             logger.debug(testName + ": status = " + statusCode);
853         }
854         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
855                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
856         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
857
858         List<PersonsCommonList.PersonListItem> items =
859             list.getPersonListItem();
860         int nItemsReturned = items.size();
861         // There will be one item created, associated with a
862         // known parent resource, by the createItem test.
863         //
864         // In addition, there will be 'nItemsToCreateInList'
865         // additional items created by the createItemList test,
866         // all associated with the same parent resource.
867         int nExpectedItems = nItemsToCreateInList + 1;
868         if(logger.isDebugEnabled()){
869             logger.debug(testName + ": Expected "
870                         + nExpectedItems +" items; got: "+nItemsReturned);
871         }
872         Assert.assertEquals(nItemsReturned, nExpectedItems);
873
874         int i = 0;
875         for (PersonsCommonList.PersonListItem item : items) {
876                 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
877                 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
878                 // Optionally output additional data about list members for debugging.
879                 boolean showDetails = true;
880                 if (showDetails && logger.isDebugEnabled()) {
881                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
882                         item.getCsid());
883                 logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
884                         item.getRefName());
885                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
886                         item.getDisplayName());
887                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
888                         item.getUri());
889             }
890             i++;
891         }
892     }
893
894     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
895     public void readContactList() {
896         readContactList(knownResourceId, knownItemResourceId);
897     }
898
899     private void readContactList(String parentcsid, String itemcsid) {
900         final String testName = "readContactList";
901
902         // Perform setup.
903         setupReadList(testName);
904
905         // Submit the request to the service and store the response.
906         ClientResponse<ContactsCommonList> res =
907                 client.readContactList(parentcsid, itemcsid);
908         ContactsCommonList list = res.getEntity();
909         int statusCode = res.getStatus();
910
911         // Check the status code of the response: does it match
912         // the expected response(s)?
913         if(logger.isDebugEnabled()){
914             logger.debug(testName + ": status = " + statusCode);
915         }
916         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
917                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
918         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
919
920         List<ContactsCommonList.ContactListItem> listitems =
921             list.getContactListItem();
922         int nItemsReturned = listitems.size();
923         // There will be one item created, associated with a
924         // known parent resource, by the createItem test.
925         //
926         // In addition, there will be 'nItemsToCreateInList'
927         // additional items created by the createItemList test,
928         // all associated with the same parent resource.
929         int nExpectedItems = nItemsToCreateInList + 1;
930         if(logger.isDebugEnabled()){
931             logger.debug(testName + ": Expected "
932                         + nExpectedItems +" items; got: "+nItemsReturned);
933         }
934         Assert.assertEquals(nItemsReturned, nExpectedItems);
935
936         int i = 0;
937         for (ContactsCommonList.ContactListItem listitem : listitems) {
938                 // Optionally output additional data about list members for debugging.
939                 boolean showDetails = false;
940                 if (showDetails && logger.isDebugEnabled()) {
941                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
942                         listitem.getCsid());
943                 logger.debug("  " + testName + ": list-item[" + i + "] addressPlace=" +
944                         listitem.getAddressPlace());
945                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
946                         listitem.getUri());
947             }
948             i++;
949         }
950     }
951
952     // Failure outcomes
953     // None at present.
954
955     // ---------------------------------------------------------------
956     // CRUD tests : UPDATE tests
957     // ---------------------------------------------------------------
958     // Success outcomes
959     @Override
960     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
961         groups = {"update"}, dependsOnGroups = {"read", "readList"})
962     public void update(String testName) throws Exception {
963
964         // Perform setup.
965         setupUpdate(testName);
966
967         // Retrieve the contents of a resource to update.
968         ClientResponse<MultipartInput> res =
969                 client.read(knownResourceId);
970         if(logger.isDebugEnabled()){
971             logger.debug(testName + ": read status = " + res.getStatus());
972         }
973         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
974
975         if(logger.isDebugEnabled()){
976             logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
977         }
978         MultipartInput input = (MultipartInput) res.getEntity();
979         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
980                 client.getCommonPartName(), PersonauthoritiesCommon.class);
981         Assert.assertNotNull(personAuthority);
982
983         // Update the contents of this resource.
984         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
985         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
986         if(logger.isDebugEnabled()){
987             logger.debug("to be updated PersonAuthority");
988             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
989         }
990
991         // Submit the updated resource to the service and store the response.
992         MultipartOutput output = new MultipartOutput();
993         OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
994         commonPart.getHeaders().add("label", client.getCommonPartName());
995         res = client.update(knownResourceId, output);
996         int statusCode = res.getStatus();
997
998         // Check the status code of the response: does it match the expected response(s)?
999         if(logger.isDebugEnabled()){
1000             logger.debug(testName + ": status = " + statusCode);
1001         }
1002         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1003                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1004         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1005
1006         // Retrieve the updated resource and verify that its contents exist.
1007         input = (MultipartInput) res.getEntity();
1008         PersonauthoritiesCommon updatedPersonAuthority =
1009                 (PersonauthoritiesCommon) extractPart(input,
1010                         client.getCommonPartName(), PersonauthoritiesCommon.class);
1011         Assert.assertNotNull(updatedPersonAuthority);
1012
1013         // Verify that the updated resource received the correct data.
1014         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1015                 personAuthority.getDisplayName(),
1016                 "Data in updated object did not match submitted data.");
1017     }
1018
1019     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1020         groups = {"update"}, dependsOnMethods = {"update"})
1021     public void updateItem(String testName) throws Exception {
1022
1023         // Perform setup.
1024         setupUpdate(testName);
1025
1026         ClientResponse<MultipartInput> res =
1027                 client.readItem(knownResourceId, knownItemResourceId);
1028         if(logger.isDebugEnabled()){
1029             logger.debug(testName + ": read status = " + res.getStatus());
1030         }
1031         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1032
1033         if(logger.isDebugEnabled()){
1034             logger.debug("got Person to update with ID: " +
1035                 knownItemResourceId +
1036                 " in PersonAuthority: " + knownResourceId );
1037         }
1038         MultipartInput input = (MultipartInput) res.getEntity();
1039         PersonsCommon person = (PersonsCommon) extractPart(input,
1040                 client.getItemCommonPartName(), PersonsCommon.class);
1041         Assert.assertNotNull(person);
1042
1043         // Update the contents of this resource.
1044         person.setForeName("updated-" + person.getForeName());
1045         if(logger.isDebugEnabled()){
1046             logger.debug("to be updated Person");
1047             logger.debug(objectAsXmlString(person,
1048                 PersonsCommon.class));
1049         }
1050
1051         // Submit the updated resource to the service and store the response.
1052         MultipartOutput output = new MultipartOutput();
1053         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1054         commonPart.getHeaders().add("label", client.getItemCommonPartName());
1055         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1056         int statusCode = res.getStatus();
1057
1058         // Check the status code of the response: does it match the expected response(s)?
1059         if(logger.isDebugEnabled()){
1060             logger.debug(testName + ": status = " + statusCode);
1061         }
1062         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1063                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1064         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1065
1066         // Retrieve the updated resource and verify that its contents exist.
1067         input = (MultipartInput) res.getEntity();
1068         PersonsCommon updatedPerson =
1069                 (PersonsCommon) extractPart(input,
1070                         client.getItemCommonPartName(), PersonsCommon.class);
1071         Assert.assertNotNull(updatedPerson);
1072
1073         // Verify that the updated resource received the correct data.
1074         Assert.assertEquals(updatedPerson.getForeName(),
1075                 person.getForeName(),
1076                 "Data in updated Person did not match submitted data.");
1077     }
1078
1079     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1080         groups = {"update"}, dependsOnMethods = {"updateItem"})
1081     public void updateContact(String testName) throws Exception {
1082
1083         // Perform setup.
1084         setupUpdate(testName);
1085
1086         ClientResponse<MultipartInput> res =
1087                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1088         if(logger.isDebugEnabled()){
1089             logger.debug(testName + ": read status = " + res.getStatus());
1090         }
1091         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1092
1093         if(logger.isDebugEnabled()){
1094             logger.debug("got Contact to update with ID: " +
1095                 knownContactResourceId +
1096                 " in item: " + knownItemResourceId +
1097                 " in parent: " + knownResourceId );
1098         }
1099         MultipartInput input = (MultipartInput) res.getEntity();
1100         ContactsCommon contact = (ContactsCommon) extractPart(input,
1101                 contactClient.getCommonPartName(), ContactsCommon.class);
1102         Assert.assertNotNull(contact);
1103
1104         // Update the contents of this resource.
1105         contact.setAddressPlace("updated-" + contact.getAddressPlace());
1106         if(logger.isDebugEnabled()){
1107             logger.debug("to be updated Contact");
1108             logger.debug(objectAsXmlString(contact,
1109                 ContactsCommon.class));
1110         }
1111
1112         // Submit the updated resource to the service and store the response.
1113         MultipartOutput output = new MultipartOutput();
1114         OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1115         commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1116         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1117         int statusCode = res.getStatus();
1118
1119         // Check the status code of the response: does it match the expected response(s)?
1120         if(logger.isDebugEnabled()){
1121             logger.debug(testName + ": status = " + statusCode);
1122         }
1123         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1126
1127         // Retrieve the updated resource and verify that its contents exist.
1128         input = (MultipartInput) res.getEntity();
1129         ContactsCommon updatedContact =
1130                 (ContactsCommon) extractPart(input,
1131                         contactClient.getCommonPartName(), ContactsCommon.class);
1132         Assert.assertNotNull(updatedContact);
1133
1134         // Verify that the updated resource received the correct data.
1135         Assert.assertEquals(updatedContact.getAddressPlace(),
1136                 contact.getAddressPlace(),
1137                 "Data in updated Contact did not match submitted data.");
1138     }
1139
1140     // Failure outcomes
1141     // Placeholders until the three tests below can be uncommented.
1142     // See Issue CSPACE-401.
1143     @Override
1144     public void updateWithEmptyEntityBody(String testName) throws Exception {
1145     }
1146
1147     @Override
1148     public void updateWithMalformedXml(String testName) throws Exception {
1149     }
1150
1151     @Override
1152     public void updateWithWrongXmlSchema(String testName) throws Exception {
1153     }
1154
1155 /*
1156     @Override
1157     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1158         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1159     public void updateWithEmptyEntityBody(String testName) throws Exception {
1160
1161     // Perform setup.
1162     setupUpdateWithEmptyEntityBody(testName);
1163
1164     // Submit the request to the service and store the response.
1165     String method = REQUEST_TYPE.httpMethodName();
1166     String url = getResourceURL(knownResourceId);
1167     String mediaType = MediaType.APPLICATION_XML;
1168     final String entity = "";
1169     int statusCode = submitRequest(method, url, mediaType, entity);
1170
1171     // Check the status code of the response: does it match
1172     // the expected response(s)?
1173     if(logger.isDebugEnabled()){
1174         logger.debug(testName + ": url=" + url +
1175             " status=" + statusCode);
1176      }
1177     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1178     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1179     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1180     }
1181
1182     @Override
1183     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1184         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1185     public void updateWithMalformedXml(String testName) throws Exception {
1186
1187     // Perform setup.
1188     setupUpdateWithMalformedXml(testName);
1189
1190     // Submit the request to the service and store the response.
1191     String method = REQUEST_TYPE.httpMethodName();
1192     String url = getResourceURL(knownResourceId);
1193     String mediaType = MediaType.APPLICATION_XML;
1194     final String entity = MALFORMED_XML_DATA;
1195     int statusCode = submitRequest(method, url, mediaType, entity);
1196
1197     // Check the status code of the response: does it match
1198     // the expected response(s)?
1199     if(logger.isDebugEnabled()){
1200         logger.debug(testName + ": url=" + url +
1201            " status=" + statusCode);
1202      }
1203     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1204     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1205     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1206     }
1207
1208     @Override
1209     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1210         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1211     public void updateWithWrongXmlSchema(String testName) throws Exception {
1212
1213     // Perform setup.
1214     setupUpdateWithWrongXmlSchema(testName);
1215
1216     // Submit the request to the service and store the response.
1217     String method = REQUEST_TYPE.httpMethodName();
1218     String url = getResourceURL(knownResourceId);
1219     String mediaType = MediaType.APPLICATION_XML;
1220     final String entity = WRONG_XML_SCHEMA_DATA;
1221     int statusCode = submitRequest(method, url, mediaType, entity);
1222
1223     // Check the status code of the response: does it match
1224     // the expected response(s)?
1225     if(logger.isDebugEnabled()){
1226         logger.debug("updateWithWrongXmlSchema: url=" + url +
1227             " status=" + statusCode);
1228      }
1229     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1230     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1231     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1232     }
1233 */
1234
1235     @Override
1236     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1237         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1238     public void updateNonExistent(String testName) throws Exception {
1239
1240         // Perform setup.
1241         setupUpdateNonExistent(testName);
1242
1243         // Submit the request to the service and store the response.
1244         // Note: The ID(s) used when creating the request payload may be arbitrary.
1245         // The only relevant ID may be the one used in update(), below.
1246         String displayName = "displayName-NON_EXISTENT_ID";
1247         String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1248         MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1249                                 displayName, fullRefName, client.getCommonPartName());
1250         ClientResponse<MultipartInput> res =
1251                 client.update(NON_EXISTENT_ID, multipart);
1252         int statusCode = res.getStatus();
1253
1254         // Check the status code of the response: does it match
1255         // the expected response(s)?
1256         if(logger.isDebugEnabled()){
1257             logger.debug(testName + ": status = " + statusCode);
1258         }
1259         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1260                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1261         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1262     }
1263
1264     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1265         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1266     public void updateNonExistentItem(String testName) throws Exception {
1267
1268         // Perform setup.
1269         setupUpdateNonExistent(testName);
1270
1271         // Submit the request to the service and store the response.
1272         // Note: The ID used in this 'create' call may be arbitrary.
1273         // The only relevant ID may be the one used in update(), below.
1274
1275         // The only relevant ID may be the one used in update(), below.
1276         Map<String, String> nonexMap = new HashMap<String,String>();
1277         nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1278         nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1279         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1280         MultipartOutput multipart = 
1281         PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, 
1282                         PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1283                         client.getItemCommonPartName() );
1284         ClientResponse<MultipartInput> res =
1285                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1286         int statusCode = res.getStatus();
1287
1288         // Check the status code of the response: does it match
1289         // the expected response(s)?
1290         if(logger.isDebugEnabled()){
1291             logger.debug(testName + ": status = " + statusCode);
1292         }
1293         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1294                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1295         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1296     }
1297
1298     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1299         groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1300     public void updateNonExistentContact(String testName) throws Exception {
1301         // Currently a no-op test
1302     }
1303
1304     // ---------------------------------------------------------------
1305     // CRUD tests : DELETE tests
1306     // ---------------------------------------------------------------
1307     // Success outcomes
1308
1309     // Note: delete sub-resources in ascending hierarchical order,
1310     // before deleting their parents.
1311
1312     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, 
1313         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1314     public void deleteContact(String testName) throws Exception {
1315
1316         // Perform setup.
1317         setupDelete(testName);
1318
1319          if(logger.isDebugEnabled()){
1320             logger.debug("parentcsid =" + knownResourceId +
1321                 " itemcsid = " + knownItemResourceId +
1322                 " csid = " + knownContactResourceId);
1323         }
1324
1325         // Submit the request to the service and store the response.
1326         ClientResponse<Response> res =
1327             client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1328         int statusCode = res.getStatus();
1329
1330         // Check the status code of the response: does it match
1331         // the expected response(s)?
1332         if(logger.isDebugEnabled()){
1333             logger.debug(testName + ": status = " + statusCode);
1334         }
1335         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1336                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1337         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1338     }
1339
1340    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1341         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1342     public void deleteItem(String testName) throws Exception {
1343
1344         // Perform setup.
1345         setupDelete(testName);
1346
1347         if(logger.isDebugEnabled()){
1348             logger.debug("parentcsid =" + knownResourceId +
1349                 " itemcsid = " + knownItemResourceId);
1350         }
1351
1352         // Submit the request to the service and store the response.
1353         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1354         int statusCode = res.getStatus();
1355
1356         // Check the status code of the response: does it match
1357         // the expected response(s)?
1358         if(logger.isDebugEnabled()){
1359             logger.debug(testName + ": status = " + statusCode);
1360         }
1361         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1362                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1363         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1364     }
1365
1366     @Override
1367     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1368         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1369     public void delete(String testName) throws Exception {
1370
1371         // Perform setup.
1372         setupDelete(testName);
1373
1374         if(logger.isDebugEnabled()){
1375             logger.debug("parentcsid =" + knownResourceId);
1376         }
1377
1378         // Submit the request to the service and store the response.
1379         ClientResponse<Response> res = client.delete(knownResourceId);
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     // Failure outcomes
1393     @Override
1394     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1395         groups = {"delete"}, dependsOnMethods = {"delete"})
1396     public void deleteNonExistent(String testName) throws Exception {
1397
1398         // Perform setup.
1399         setupDeleteNonExistent(testName);
1400
1401         // Submit the request to the service and store the response.
1402         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1403         int statusCode = res.getStatus();
1404
1405         // Check the status code of the response: does it match
1406         // the expected response(s)?
1407         if(logger.isDebugEnabled()){
1408             logger.debug(testName + ": status = " + statusCode);
1409         }
1410         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1411                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1412         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1413     }
1414
1415     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1416         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1417     public void deleteNonExistentItem(String testName) {
1418
1419         // Perform setup.
1420         setupDeleteNonExistent(testName);
1421
1422         // Submit the request to the service and store the response.
1423         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1424         int statusCode = res.getStatus();
1425
1426         // Check the status code of the response: does it match
1427         // the expected response(s)?
1428         if(logger.isDebugEnabled()){
1429             logger.debug(testName + ": status = " + statusCode);
1430         }
1431         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1432                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1433         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1434     }
1435
1436     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1437         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1438     public void deleteNonExistentContact(String testName) {
1439
1440         // Perform setup.
1441         setupDeleteNonExistent(testName);
1442
1443         // Submit the request to the service and store the response.
1444         ClientResponse<Response> res =
1445             client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1446         int statusCode = res.getStatus();
1447
1448         // Check the status code of the response: does it match
1449         // the expected response(s)?
1450         if(logger.isDebugEnabled()){
1451             logger.debug(testName + ": status = " + statusCode);
1452         }
1453         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1454                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1455         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1456     }
1457
1458     // ---------------------------------------------------------------
1459     // Utility tests : tests of code used in tests above
1460     // ---------------------------------------------------------------
1461     /**
1462      * Tests the code for manually submitting data that is used by several
1463      * of the methods above.
1464      */
1465     @Test(dependsOnMethods = {"create", "read"})
1466     public void testSubmitRequest() {
1467
1468         // Expected status code: 200 OK
1469         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1470
1471         // Submit the request to the service and store the response.
1472         String method = ServiceRequestType.READ.httpMethodName();
1473         String url = getResourceURL(knownResourceId);
1474         int statusCode = submitRequest(method, url);
1475
1476         // Check the status code of the response: does it match
1477         // the expected response(s)?
1478         if(logger.isDebugEnabled()){
1479             logger.debug("testSubmitRequest: url=" + url +
1480                 " status=" + statusCode);
1481         }
1482         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1483
1484     }
1485
1486     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1487     public void testItemSubmitRequest() {
1488
1489         // Expected status code: 200 OK
1490         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1491
1492         // Submit the request to the service and store the response.
1493         String method = ServiceRequestType.READ.httpMethodName();
1494         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1495         int statusCode = submitRequest(method, url);
1496
1497         // Check the status code of the response: does it match
1498         // the expected response(s)?
1499         if(logger.isDebugEnabled()){
1500             logger.debug("testItemSubmitRequest: url=" + url +
1501                 " status=" + statusCode);
1502         }
1503         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1504
1505     }
1506
1507     @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1508     public void testContactSubmitRequest() {
1509
1510         // Expected status code: 200 OK
1511         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1512
1513         // Submit the request to the service and store the response.
1514         String method = ServiceRequestType.READ.httpMethodName();
1515         String url = getContactResourceURL(knownResourceId,
1516             knownItemResourceId, knownContactResourceId);
1517         int statusCode = submitRequest(method, url);
1518
1519         // Check the status code of the response: does it match
1520         // the expected response(s)?
1521         if(logger.isDebugEnabled()){
1522             logger.debug("testItemSubmitRequest: url=" + url +
1523                 " status=" + statusCode);
1524         }
1525         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1526
1527     }
1528
1529
1530     // ---------------------------------------------------------------
1531     // Cleanup of resources created during testing
1532     // ---------------------------------------------------------------
1533     
1534     /**
1535      * Deletes all resources created by tests, after all tests have been run.
1536      *
1537      * This cleanup method will always be run, even if one or more tests fail.
1538      * For this reason, it attempts to remove all resources created
1539      * at any point during testing, even if some of those resources
1540      * may be expected to be deleted by certain tests.
1541      */
1542
1543     @AfterClass(alwaysRun=true)
1544     public void cleanUp() {
1545         if (logger.isDebugEnabled()) {
1546             logger.debug("Cleaning up temporary resources created for testing ...");
1547         }
1548         String parentResourceId;
1549         String itemResourceId;
1550         String contactResourceId;
1551         // Clean up contact resources.
1552         parentResourceId = knownResourceId;
1553         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1554             contactResourceId = entry.getKey();
1555             itemResourceId = entry.getValue();
1556             // Note: Any non-success responses from the delete operation
1557             // below are ignored and not reported.
1558             ClientResponse<Response> res =
1559                 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1560         }
1561         // Clean up item resources.
1562         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1563             itemResourceId = entry.getKey();
1564             parentResourceId = entry.getValue();
1565             // Note: Any non-success responses from the delete operation
1566             // below are ignored and not reported.
1567             ClientResponse<Response> res =
1568                 client.deleteItem(parentResourceId, itemResourceId);
1569         }
1570         // Clean up parent resources.
1571         for (String resourceId : allResourceIdsCreated) {
1572             // Note: Any non-success responses from the delete operation
1573             // below are ignored and not reported.
1574             ClientResponse<Response> res = client.delete(resourceId);
1575         }
1576     }
1577
1578     // ---------------------------------------------------------------
1579     // Utility methods used by tests above
1580     // ---------------------------------------------------------------
1581     @Override
1582     public String getServicePathComponent() {
1583         return SERVICE_PATH_COMPONENT;
1584     }
1585
1586     public String getItemServicePathComponent() {
1587         return ITEM_SERVICE_PATH_COMPONENT;
1588     }
1589
1590     public String getContactServicePathComponent() {
1591         return CONTACT_SERVICE_PATH_COMPONENT;
1592     }
1593
1594     /**
1595      * Returns the root URL for the item service.
1596      *
1597      * This URL consists of a base URL for all services, followed by
1598      * a path component for the owning parent, followed by the
1599      * path component for the items.
1600      *
1601      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1602      * parent authority resource of the relevant item resource.
1603      *
1604      * @return The root URL for the item service.
1605      */
1606     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1607         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1608     }
1609
1610     /**
1611      * Returns the URL of a specific item resource managed by a service, and
1612      * designated by an identifier (such as a universally unique ID, or UUID).
1613      *
1614      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1615      * parent authority resource of the relevant item resource.
1616      *
1617      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1618      * item resource.
1619      *
1620      * @return The URL of a specific item resource managed by a service.
1621      */
1622     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1623         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1624     }
1625
1626
1627     /**
1628      * Returns the root URL for the contact service.
1629      *
1630      * This URL consists of a base URL for all services, followed by
1631      * a path component for the owning authority, followed by the
1632      * path component for the owning item, followed by the path component
1633      * for the contact service.
1634      *
1635      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1636      * parent authority resource of the relevant item resource.
1637      *
1638      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1639      * item resource.
1640      *
1641      * @return The root URL for the contact service.
1642      */
1643     protected String getContactServiceRootURL(String parentResourceIdentifier,
1644         String itemResourceIdentifier) {
1645         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1646                 getContactServicePathComponent();
1647     }
1648
1649     /**
1650      * Returns the URL of a specific contact resource managed by a service, and
1651      * designated by an identifier (such as a universally unique ID, or UUID).
1652      *
1653      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1654      * parent resource of the relevant item resource.
1655      *
1656      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1657      * item resource.
1658      *
1659      * @return The URL of a specific resource managed by a service.
1660      */
1661     protected String getContactResourceURL(String parentResourceIdentifier,
1662         String itemResourceIdentifier, String contactResourceIdentifier) {
1663         return getContactServiceRootURL(parentResourceIdentifier,
1664             itemResourceIdentifier) + "/" + contactResourceIdentifier;
1665     }
1666 }