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