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