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