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