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