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