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