]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
31f726b21854a43fe3cd6f313fd415b328b448e8
[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);
814                 i++;
815             }
816         }
817     }
818
819     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
820     public void readItemList() {
821         readItemList(knownResourceId);
822     }
823
824     private void readItemList(String vcsid) {
825
826         final String testName = "readItemList";
827
828         // Perform setup.
829         setupReadList(testName);
830
831         // Submit the request to the service and store the response.
832         ClientResponse<PersonsCommonList> res =
833                 client.readItemList(vcsid);
834         PersonsCommonList list = res.getEntity();
835         int statusCode = res.getStatus();
836
837         // Check the status code of the response: does it match
838         // the expected response(s)?
839         if(logger.isDebugEnabled()){
840             logger.debug(testName + ": status = " + statusCode);
841         }
842         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
843                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
844         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
845
846         List<PersonsCommonList.PersonListItem> items =
847             list.getPersonListItem();
848         int nItemsReturned = items.size();
849         // There will be one item created, associated with a
850         // known parent resource, by the createItem test.
851         //
852         // In addition, there will be 'nItemsToCreateInList'
853         // additional items created by the createItemList test,
854         // all associated with the same parent resource.
855         int nExpectedItems = nItemsToCreateInList + 1;
856         if(logger.isDebugEnabled()){
857             logger.debug(testName + ": Expected "
858                         + nExpectedItems +" items; got: "+nItemsReturned);
859         }
860         Assert.assertEquals(nItemsReturned, nExpectedItems);
861
862         int i = 0;
863         for (PersonsCommonList.PersonListItem item : items) {
864                 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
865                 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
866                 // Optionally output additional data about list members for debugging.
867                 boolean showDetails = true;
868                 if (showDetails && logger.isDebugEnabled()) {
869                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
870                         item.getCsid());
871                 logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
872                         item.getRefName());
873                 logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
874                         item.getDisplayName());
875                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
876                         item.getUri());
877             }
878             i++;
879         }
880     }
881
882     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
883     public void readContactList() {
884         readContactList(knownResourceId, knownItemResourceId);
885     }
886
887     private void readContactList(String parentcsid, String itemcsid) {
888         final String testName = "readContactList";
889
890         // Perform setup.
891         setupReadList(testName);
892
893         // Submit the request to the service and store the response.
894         ClientResponse<ContactsCommonList> res =
895                 client.readContactList(parentcsid, itemcsid);
896         ContactsCommonList list = res.getEntity();
897         int statusCode = res.getStatus();
898
899         // Check the status code of the response: does it match
900         // the expected response(s)?
901         if(logger.isDebugEnabled()){
902             logger.debug(testName + ": status = " + statusCode);
903         }
904         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
905                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
906         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
907
908         List<ContactsCommonList.ContactListItem> listitems =
909             list.getContactListItem();
910         int nItemsReturned = listitems.size();
911         // There will be one item created, associated with a
912         // known parent resource, by the createItem test.
913         //
914         // In addition, there will be 'nItemsToCreateInList'
915         // additional items created by the createItemList test,
916         // all associated with the same parent resource.
917         int nExpectedItems = nItemsToCreateInList + 1;
918         if(logger.isDebugEnabled()){
919             logger.debug(testName + ": Expected "
920                         + nExpectedItems +" items; got: "+nItemsReturned);
921         }
922         Assert.assertEquals(nItemsReturned, nExpectedItems);
923
924         int i = 0;
925         for (ContactsCommonList.ContactListItem listitem : listitems) {
926                 // Optionally output additional data about list members for debugging.
927                 boolean showDetails = false;
928                 if (showDetails && logger.isDebugEnabled()) {
929                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
930                         listitem.getCsid());
931                 logger.debug("  " + testName + ": list-item[" + i + "] addressPlace=" +
932                         listitem.getAddressPlace());
933                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
934                         listitem.getUri());
935             }
936             i++;
937         }
938     }
939
940     // Failure outcomes
941     // None at present.
942
943     // ---------------------------------------------------------------
944     // CRUD tests : UPDATE tests
945     // ---------------------------------------------------------------
946     // Success outcomes
947     @Override
948     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
949         groups = {"update"}, dependsOnGroups = {"read"})
950     public void update(String testName) throws Exception {
951
952         // Perform setup.
953         setupUpdate(testName);
954
955         // Retrieve the contents of a resource to update.
956         ClientResponse<MultipartInput> res =
957                 client.read(knownResourceId);
958         if(logger.isDebugEnabled()){
959             logger.debug(testName + ": read status = " + res.getStatus());
960         }
961         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
962
963         if(logger.isDebugEnabled()){
964             logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
965         }
966         MultipartInput input = (MultipartInput) res.getEntity();
967         PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
968                 client.getCommonPartName(), PersonauthoritiesCommon.class);
969         Assert.assertNotNull(personAuthority);
970
971         // Update the contents of this resource.
972         personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
973         personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
974         if(logger.isDebugEnabled()){
975             logger.debug("to be updated PersonAuthority");
976             logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
977         }
978
979         // Submit the updated resource to the service and store the response.
980         MultipartOutput output = new MultipartOutput();
981         OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
982         commonPart.getHeaders().add("label", client.getCommonPartName());
983         res = client.update(knownResourceId, output);
984         int statusCode = res.getStatus();
985
986         // Check the status code of the response: does it match the expected response(s)?
987         if(logger.isDebugEnabled()){
988             logger.debug(testName + ": status = " + statusCode);
989         }
990         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
991                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
992         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
993
994         // Retrieve the updated resource and verify that its contents exist.
995         input = (MultipartInput) res.getEntity();
996         PersonauthoritiesCommon updatedPersonAuthority =
997                 (PersonauthoritiesCommon) extractPart(input,
998                         client.getCommonPartName(), PersonauthoritiesCommon.class);
999         Assert.assertNotNull(updatedPersonAuthority);
1000
1001         // Verify that the updated resource received the correct data.
1002         Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1003                 personAuthority.getDisplayName(),
1004                 "Data in updated object did not match submitted data.");
1005     }
1006
1007     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1008         groups = {"update"}, dependsOnMethods = {"update"})
1009     public void updateItem(String testName) throws Exception {
1010
1011         // Perform setup.
1012         setupUpdate(testName);
1013
1014         ClientResponse<MultipartInput> res =
1015                 client.readItem(knownResourceId, knownItemResourceId);
1016         if(logger.isDebugEnabled()){
1017             logger.debug(testName + ": read status = " + res.getStatus());
1018         }
1019         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1020
1021         if(logger.isDebugEnabled()){
1022             logger.debug("got Person to update with ID: " +
1023                 knownItemResourceId +
1024                 " in PersonAuthority: " + knownResourceId );
1025         }
1026         MultipartInput input = (MultipartInput) res.getEntity();
1027         PersonsCommon person = (PersonsCommon) extractPart(input,
1028                 client.getItemCommonPartName(), PersonsCommon.class);
1029         Assert.assertNotNull(person);
1030
1031         // Update the contents of this resource.
1032         person.setForeName("updated-" + person.getForeName());
1033         if(logger.isDebugEnabled()){
1034             logger.debug("to be updated Person");
1035             logger.debug(objectAsXmlString(person,
1036                 PersonsCommon.class));
1037         }
1038
1039         // Submit the updated resource to the service and store the response.
1040         MultipartOutput output = new MultipartOutput();
1041         OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1042         commonPart.getHeaders().add("label", client.getItemCommonPartName());
1043         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1044         int statusCode = res.getStatus();
1045
1046         // Check the status code of the response: does it match the expected response(s)?
1047         if(logger.isDebugEnabled()){
1048             logger.debug(testName + ": status = " + statusCode);
1049         }
1050         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1051                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1052         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1053
1054         // Retrieve the updated resource and verify that its contents exist.
1055         input = (MultipartInput) res.getEntity();
1056         PersonsCommon updatedPerson =
1057                 (PersonsCommon) extractPart(input,
1058                         client.getItemCommonPartName(), PersonsCommon.class);
1059         Assert.assertNotNull(updatedPerson);
1060
1061         // Verify that the updated resource received the correct data.
1062         Assert.assertEquals(updatedPerson.getForeName(),
1063                 person.getForeName(),
1064                 "Data in updated Person did not match submitted data.");
1065     }
1066
1067     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1068         groups = {"update"}, dependsOnMethods = {"updateItem"})
1069     public void updateContact(String testName) throws Exception {
1070
1071         // Perform setup.
1072         setupUpdate(testName);
1073
1074         ClientResponse<MultipartInput> res =
1075                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1076         if(logger.isDebugEnabled()){
1077             logger.debug(testName + ": read status = " + res.getStatus());
1078         }
1079         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1080
1081         if(logger.isDebugEnabled()){
1082             logger.debug("got Contact to update with ID: " +
1083                 knownContactResourceId +
1084                 " in item: " + knownItemResourceId +
1085                 " in parent: " + knownResourceId );
1086         }
1087         MultipartInput input = (MultipartInput) res.getEntity();
1088         ContactsCommon contact = (ContactsCommon) extractPart(input,
1089                 contactClient.getCommonPartName(), ContactsCommon.class);
1090         Assert.assertNotNull(contact);
1091
1092         // Update the contents of this resource.
1093         contact.setAddressPlace("updated-" + contact.getAddressPlace());
1094         if(logger.isDebugEnabled()){
1095             logger.debug("to be updated Contact");
1096             logger.debug(objectAsXmlString(contact,
1097                 ContactsCommon.class));
1098         }
1099
1100         // Submit the updated resource to the service and store the response.
1101         MultipartOutput output = new MultipartOutput();
1102         OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1103         commonPart.getHeaders().add("label", contactClient.getCommonPartName());
1104         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1105         int statusCode = res.getStatus();
1106
1107         // Check the status code of the response: does it match the expected response(s)?
1108         if(logger.isDebugEnabled()){
1109             logger.debug(testName + ": status = " + statusCode);
1110         }
1111         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1112                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1113         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1114
1115         // Retrieve the updated resource and verify that its contents exist.
1116         input = (MultipartInput) res.getEntity();
1117         ContactsCommon updatedContact =
1118                 (ContactsCommon) extractPart(input,
1119                         contactClient.getCommonPartName(), ContactsCommon.class);
1120         Assert.assertNotNull(updatedContact);
1121
1122         // Verify that the updated resource received the correct data.
1123         Assert.assertEquals(updatedContact.getAddressPlace(),
1124                 contact.getAddressPlace(),
1125                 "Data in updated Contact did not match submitted data.");
1126     }
1127
1128     // Failure outcomes
1129     // Placeholders until the three tests below can be uncommented.
1130     // See Issue CSPACE-401.
1131     @Override
1132     public void updateWithEmptyEntityBody(String testName) throws Exception {
1133     }
1134
1135     @Override
1136     public void updateWithMalformedXml(String testName) throws Exception {
1137     }
1138
1139     @Override
1140     public void updateWithWrongXmlSchema(String testName) throws Exception {
1141     }
1142
1143 /*
1144     @Override
1145     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1146         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1147     public void updateWithEmptyEntityBody(String testName) throws Exception {
1148
1149     // Perform setup.
1150     setupUpdateWithEmptyEntityBody(testName);
1151
1152     // Submit the request to the service and store the response.
1153     String method = REQUEST_TYPE.httpMethodName();
1154     String url = getResourceURL(knownResourceId);
1155     String mediaType = MediaType.APPLICATION_XML;
1156     final String entity = "";
1157     int statusCode = submitRequest(method, url, mediaType, entity);
1158
1159     // Check the status code of the response: does it match
1160     // the expected response(s)?
1161     if(logger.isDebugEnabled()){
1162         logger.debug(testName + ": url=" + url +
1163             " status=" + statusCode);
1164      }
1165     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1166     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1167     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1168     }
1169
1170     @Override
1171     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1172         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1173     public void updateWithMalformedXml(String testName) throws Exception {
1174
1175     // Perform setup.
1176     setupUpdateWithMalformedXml(testName);
1177
1178     // Submit the request to the service and store the response.
1179     String method = REQUEST_TYPE.httpMethodName();
1180     String url = getResourceURL(knownResourceId);
1181     String mediaType = MediaType.APPLICATION_XML;
1182     final String entity = MALFORMED_XML_DATA;
1183     int statusCode = submitRequest(method, url, mediaType, entity);
1184
1185     // Check the status code of the response: does it match
1186     // the expected response(s)?
1187     if(logger.isDebugEnabled()){
1188         logger.debug(testName + ": url=" + url +
1189            " status=" + statusCode);
1190      }
1191     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1192     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1193     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1194     }
1195
1196     @Override
1197     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1198         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1199     public void updateWithWrongXmlSchema(String testName) throws Exception {
1200
1201     // Perform setup.
1202     setupUpdateWithWrongXmlSchema(testName);
1203
1204     // Submit the request to the service and store the response.
1205     String method = REQUEST_TYPE.httpMethodName();
1206     String url = getResourceURL(knownResourceId);
1207     String mediaType = MediaType.APPLICATION_XML;
1208     final String entity = WRONG_XML_SCHEMA_DATA;
1209     int statusCode = submitRequest(method, url, mediaType, entity);
1210
1211     // Check the status code of the response: does it match
1212     // the expected response(s)?
1213     if(logger.isDebugEnabled()){
1214         logger.debug("updateWithWrongXmlSchema: url=" + url +
1215             " status=" + statusCode);
1216      }
1217     Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1218     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1219     Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1220     }
1221 */
1222
1223     @Override
1224     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1225         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1226     public void updateNonExistent(String testName) throws Exception {
1227
1228         // Perform setup.
1229         setupUpdateNonExistent(testName);
1230
1231         // Submit the request to the service and store the response.
1232         // Note: The ID(s) used when creating the request payload may be arbitrary.
1233         // The only relevant ID may be the one used in update(), below.
1234         String displayName = "displayName-NON_EXISTENT_ID";
1235         String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1236         MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1237                                 displayName, fullRefName, client.getCommonPartName());
1238         ClientResponse<MultipartInput> res =
1239                 client.update(NON_EXISTENT_ID, multipart);
1240         int statusCode = res.getStatus();
1241
1242         // Check the status code of the response: does it match
1243         // the expected response(s)?
1244         if(logger.isDebugEnabled()){
1245             logger.debug(testName + ": status = " + statusCode);
1246         }
1247         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1248                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1249         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1250     }
1251
1252     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1253         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1254     public void updateNonExistentItem(String testName) throws Exception {
1255
1256         // Perform setup.
1257         setupUpdateNonExistent(testName);
1258
1259         // Submit the request to the service and store the response.
1260         // Note: The ID used in this 'create' call may be arbitrary.
1261         // The only relevant ID may be the one used in update(), below.
1262
1263         // The only relevant ID may be the one used in update(), below.
1264         Map<String, String> nonexMap = new HashMap<String,String>();
1265         nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1266         nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1267         nonexMap.put(PersonJAXBSchema.GENDER, "male");
1268         MultipartOutput multipart = 
1269         PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID, 
1270                         PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1271                         client.getItemCommonPartName() );
1272         ClientResponse<MultipartInput> res =
1273                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1274         int statusCode = res.getStatus();
1275
1276         // Check the status code of the response: does it match
1277         // the expected response(s)?
1278         if(logger.isDebugEnabled()){
1279             logger.debug(testName + ": status = " + statusCode);
1280         }
1281         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1282                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1283         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1284     }
1285
1286     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1287         groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1288     public void updateNonExistentContact(String testName) throws Exception {
1289         // Currently a no-op test
1290     }
1291
1292     // ---------------------------------------------------------------
1293     // CRUD tests : DELETE tests
1294     // ---------------------------------------------------------------
1295     // Success outcomes
1296
1297     // Note: delete sub-resources in ascending hierarchical order,
1298     // before deleting their parents.
1299
1300     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, 
1301         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1302     public void deleteContact(String testName) throws Exception {
1303
1304         // Perform setup.
1305         setupDelete(testName);
1306
1307          if(logger.isDebugEnabled()){
1308             logger.debug("parentcsid =" + knownResourceId +
1309                 " itemcsid = " + knownItemResourceId +
1310                 " csid = " + knownContactResourceId);
1311         }
1312
1313         // Submit the request to the service and store the response.
1314         ClientResponse<Response> res =
1315             client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1316         int statusCode = res.getStatus();
1317
1318         // Check the status code of the response: does it match
1319         // the expected response(s)?
1320         if(logger.isDebugEnabled()){
1321             logger.debug(testName + ": status = " + statusCode);
1322         }
1323         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1324                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1325         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1326     }
1327
1328    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1329         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1330     public void deleteItem(String testName) throws Exception {
1331
1332         // Perform setup.
1333         setupDelete(testName);
1334
1335         if(logger.isDebugEnabled()){
1336             logger.debug("parentcsid =" + knownResourceId +
1337                 " itemcsid = " + knownItemResourceId);
1338         }
1339
1340         // Submit the request to the service and store the response.
1341         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1342         int statusCode = res.getStatus();
1343
1344         // Check the status code of the response: does it match
1345         // the expected response(s)?
1346         if(logger.isDebugEnabled()){
1347             logger.debug(testName + ": status = " + statusCode);
1348         }
1349         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1350                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1351         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1352     }
1353
1354     @Override
1355     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1356         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1357     public void delete(String testName) throws Exception {
1358
1359         // Perform setup.
1360         setupDelete(testName);
1361
1362         if(logger.isDebugEnabled()){
1363             logger.debug("parentcsid =" + knownResourceId);
1364         }
1365
1366         // Submit the request to the service and store the response.
1367         ClientResponse<Response> res = client.delete(knownResourceId);
1368         int statusCode = res.getStatus();
1369
1370         // Check the status code of the response: does it match
1371         // the expected response(s)?
1372         if(logger.isDebugEnabled()){
1373             logger.debug(testName + ": status = " + statusCode);
1374         }
1375         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1376                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1377         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1378     }
1379
1380     // Failure outcomes
1381     @Override
1382     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1383         groups = {"delete"}, dependsOnMethods = {"delete"})
1384     public void deleteNonExistent(String testName) throws Exception {
1385
1386         // Perform setup.
1387         setupDeleteNonExistent(testName);
1388
1389         // Submit the request to the service and store the response.
1390         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1391         int statusCode = res.getStatus();
1392
1393         // Check the status code of the response: does it match
1394         // the expected response(s)?
1395         if(logger.isDebugEnabled()){
1396             logger.debug(testName + ": status = " + statusCode);
1397         }
1398         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1399                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1400         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1401     }
1402
1403     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1404         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1405     public void deleteNonExistentItem(String testName) {
1406
1407         // Perform setup.
1408         setupDeleteNonExistent(testName);
1409
1410         // Submit the request to the service and store the response.
1411         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1412         int statusCode = res.getStatus();
1413
1414         // Check the status code of the response: does it match
1415         // the expected response(s)?
1416         if(logger.isDebugEnabled()){
1417             logger.debug(testName + ": status = " + statusCode);
1418         }
1419         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1420                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1421         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1422     }
1423
1424     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1425         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1426     public void deleteNonExistentContact(String testName) {
1427
1428         // Perform setup.
1429         setupDeleteNonExistent(testName);
1430
1431         // Submit the request to the service and store the response.
1432         ClientResponse<Response> res =
1433             client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1434         int statusCode = res.getStatus();
1435
1436         // Check the status code of the response: does it match
1437         // the expected response(s)?
1438         if(logger.isDebugEnabled()){
1439             logger.debug(testName + ": status = " + statusCode);
1440         }
1441         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1442                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1443         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1444     }
1445
1446     // ---------------------------------------------------------------
1447     // Utility tests : tests of code used in tests above
1448     // ---------------------------------------------------------------
1449     /**
1450      * Tests the code for manually submitting data that is used by several
1451      * of the methods above.
1452      */
1453     @Test(dependsOnMethods = {"create", "read"})
1454     public void testSubmitRequest() {
1455
1456         // Expected status code: 200 OK
1457         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1458
1459         // Submit the request to the service and store the response.
1460         String method = ServiceRequestType.READ.httpMethodName();
1461         String url = getResourceURL(knownResourceId);
1462         int statusCode = submitRequest(method, url);
1463
1464         // Check the status code of the response: does it match
1465         // the expected response(s)?
1466         if(logger.isDebugEnabled()){
1467             logger.debug("testSubmitRequest: url=" + url +
1468                 " status=" + statusCode);
1469         }
1470         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1471
1472     }
1473
1474     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1475     public void testItemSubmitRequest() {
1476
1477         // Expected status code: 200 OK
1478         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1479
1480         // Submit the request to the service and store the response.
1481         String method = ServiceRequestType.READ.httpMethodName();
1482         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1483         int statusCode = submitRequest(method, url);
1484
1485         // Check the status code of the response: does it match
1486         // the expected response(s)?
1487         if(logger.isDebugEnabled()){
1488             logger.debug("testItemSubmitRequest: url=" + url +
1489                 " status=" + statusCode);
1490         }
1491         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1492
1493     }
1494
1495     @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1496     public void testContactSubmitRequest() {
1497
1498         // Expected status code: 200 OK
1499         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1500
1501         // Submit the request to the service and store the response.
1502         String method = ServiceRequestType.READ.httpMethodName();
1503         String url = getContactResourceURL(knownResourceId,
1504             knownItemResourceId, knownContactResourceId);
1505         int statusCode = submitRequest(method, url);
1506
1507         // Check the status code of the response: does it match
1508         // the expected response(s)?
1509         if(logger.isDebugEnabled()){
1510             logger.debug("testItemSubmitRequest: url=" + url +
1511                 " status=" + statusCode);
1512         }
1513         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1514
1515     }
1516
1517
1518     // ---------------------------------------------------------------
1519     // Cleanup of resources created during testing
1520     // ---------------------------------------------------------------
1521     
1522     /**
1523      * Deletes all resources created by tests, after all tests have been run.
1524      *
1525      * This cleanup method will always be run, even if one or more tests fail.
1526      * For this reason, it attempts to remove all resources created
1527      * at any point during testing, even if some of those resources
1528      * may be expected to be deleted by certain tests.
1529      */
1530
1531     @AfterClass(alwaysRun=true)
1532     public void cleanUp() {
1533         if (logger.isDebugEnabled()) {
1534             logger.debug("Cleaning up temporary resources created for testing ...");
1535         }
1536         String parentResourceId;
1537         String itemResourceId;
1538         String contactResourceId;
1539         // Clean up contact resources.
1540         parentResourceId = knownResourceId;
1541         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1542             contactResourceId = entry.getKey();
1543             itemResourceId = entry.getValue();
1544             // Note: Any non-success responses from the delete operation
1545             // below are ignored and not reported.
1546             ClientResponse<Response> res =
1547                 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1548         }
1549         // Clean up item resources.
1550         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1551             itemResourceId = entry.getKey();
1552             parentResourceId = entry.getValue();
1553             // Note: Any non-success responses from the delete operation
1554             // below are ignored and not reported.
1555             ClientResponse<Response> res =
1556                 client.deleteItem(parentResourceId, itemResourceId);
1557         }
1558         // Clean up parent resources.
1559         for (String resourceId : allResourceIdsCreated) {
1560             // Note: Any non-success responses from the delete operation
1561             // below are ignored and not reported.
1562             ClientResponse<Response> res = client.delete(resourceId);
1563         }
1564     }
1565
1566     // ---------------------------------------------------------------
1567     // Utility methods used by tests above
1568     // ---------------------------------------------------------------
1569     @Override
1570     public String getServicePathComponent() {
1571         return SERVICE_PATH_COMPONENT;
1572     }
1573
1574     public String getItemServicePathComponent() {
1575         return ITEM_SERVICE_PATH_COMPONENT;
1576     }
1577
1578     public String getContactServicePathComponent() {
1579         return CONTACT_SERVICE_PATH_COMPONENT;
1580     }
1581
1582     /**
1583      * Returns the root URL for the item service.
1584      *
1585      * This URL consists of a base URL for all services, followed by
1586      * a path component for the owning parent, followed by the
1587      * path component for the items.
1588      *
1589      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1590      * parent authority resource of the relevant item resource.
1591      *
1592      * @return The root URL for the item service.
1593      */
1594     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1595         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1596     }
1597
1598     /**
1599      * Returns the URL of a specific item resource managed by a service, and
1600      * designated by an identifier (such as a universally unique ID, or UUID).
1601      *
1602      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1603      * parent authority resource of the relevant item resource.
1604      *
1605      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1606      * item resource.
1607      *
1608      * @return The URL of a specific item resource managed by a service.
1609      */
1610     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1611         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1612     }
1613
1614
1615     /**
1616      * Returns the root URL for the contact service.
1617      *
1618      * This URL consists of a base URL for all services, followed by
1619      * a path component for the owning authority, followed by the
1620      * path component for the owning item, followed by the path component
1621      * for the contact service.
1622      *
1623      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1624      * parent authority resource of the relevant item resource.
1625      *
1626      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1627      * item resource.
1628      *
1629      * @return The root URL for the contact service.
1630      */
1631     protected String getContactServiceRootURL(String parentResourceIdentifier,
1632         String itemResourceIdentifier) {
1633         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
1634                 getContactServicePathComponent();
1635     }
1636
1637     /**
1638      * Returns the URL of a specific contact resource managed by a service, and
1639      * designated by an identifier (such as a universally unique ID, or UUID).
1640      *
1641      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1642      * parent resource of the relevant item resource.
1643      *
1644      * @param  resourceIdentifier  An identifier (such as a UUID) for an
1645      * item resource.
1646      *
1647      * @return The URL of a specific resource managed by a service.
1648      */
1649     protected String getContactResourceURL(String parentResourceIdentifier,
1650         String itemResourceIdentifier, String contactResourceIdentifier) {
1651         return getContactServiceRootURL(parentResourceIdentifier,
1652             itemResourceIdentifier) + "/" + contactResourceIdentifier;
1653     }
1654 }