]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
5f5c4d95aff1a9c9665140025ed61773adcdc76c
[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         ContactsCommonList list = null;
1154         ClientResponse<ContactsCommonList> res =
1155                 client.readContactList(parentcsid, itemcsid);
1156         list = res.getEntity();
1157         int statusCode = res.getStatus();
1158
1159         // Check the status code of the response: does it match
1160         // the expected response(s)?
1161         if(logger.isDebugEnabled()){
1162             logger.debug(testName + ": status = " + statusCode);
1163         }
1164         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1165                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1166         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1167
1168         List<ContactsCommonList.ContactListItem> listitems =
1169             list.getContactListItem();
1170         int nItemsReturned = listitems.size();
1171         // There will be one item created, associated with a
1172         // known parent resource, by the createItem test.
1173         //
1174         // In addition, there will be 'nItemsToCreateInList'
1175         // additional items created by the createItemList test,
1176         // all associated with the same parent resource.
1177         int nExpectedItems = nItemsToCreateInList + 1;
1178         if(logger.isDebugEnabled()){
1179             logger.debug(testName + ": Expected "
1180                         + nExpectedItems +" items; got: "+nItemsReturned);
1181         }
1182         Assert.assertEquals(nItemsReturned, nExpectedItems);
1183
1184         int i = 0;
1185         for (ContactsCommonList.ContactListItem listitem : listitems) {
1186                 // Optionally output additional data about list members for debugging.
1187                 boolean showDetails = false;
1188                 if (showDetails && logger.isDebugEnabled()) {
1189                 logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
1190                         listitem.getCsid());
1191                 logger.debug("  " + testName + ": list-item[" + i + "] addressPlace=" +
1192                         listitem.getAddressPlace());
1193                 logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
1194                         listitem.getUri());
1195             }
1196             i++;
1197         }
1198     }
1199
1200     // Failure outcomes
1201     // None at present.
1202     
1203     // ---------------------------------------------------------------
1204     // CRUD tests : UPDATE tests
1205     // ---------------------------------------------------------------
1206     // Success outcomes
1207     /* (non-Javadoc)
1208      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1209      */
1210     @Override
1211     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1212         groups = {"update"}, dependsOnGroups = {"read", "readList"})
1213     public void update(String testName) throws Exception {
1214
1215         if (logger.isDebugEnabled()) {
1216             logger.debug(testBanner(testName, CLASS_NAME));
1217         }
1218         // Perform setup.
1219         setupUpdate();
1220
1221         // Retrieve the contents of a resource to update.
1222         OrgAuthorityClient client = new OrgAuthorityClient();
1223         ClientResponse<MultipartInput> res =
1224                 client.read(knownResourceId);
1225         if(logger.isDebugEnabled()){
1226             logger.debug(testName + ": read status = " + res.getStatus());
1227         }
1228         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1229
1230         if(logger.isDebugEnabled()){
1231             logger.debug("got OrgAuthority to update with ID: " + knownResourceId);
1232         }
1233         MultipartInput input = (MultipartInput) res.getEntity();
1234         OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input,
1235                 client.getCommonPartName(), OrgauthoritiesCommon.class);
1236         Assert.assertNotNull(orgAuthority);
1237
1238         // Update the contents of this resource.
1239         orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName());
1240         orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType());
1241         if(logger.isDebugEnabled()){
1242             logger.debug("to be updated OrgAuthority");
1243             logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class));
1244         }
1245
1246         // Submit the updated resource to the service and store the response.
1247         MultipartOutput output = new MultipartOutput();
1248         OutputPart commonPart = output.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE);
1249         commonPart.getHeaders().add("label", client.getCommonPartName());
1250         res = client.update(knownResourceId, output);
1251         int statusCode = res.getStatus();
1252
1253         // Check the status code of the response: does it match the expected response(s)?
1254         if(logger.isDebugEnabled()){
1255             logger.debug(testName + ": status = " + statusCode);
1256         }
1257         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1258                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1259         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1260
1261         // Retrieve the updated resource and verify that its contents exist.
1262         input = (MultipartInput) res.getEntity();
1263         OrgauthoritiesCommon updatedOrgAuthority =
1264                 (OrgauthoritiesCommon) extractPart(input,
1265                         client.getCommonPartName(), OrgauthoritiesCommon.class);
1266         Assert.assertNotNull(updatedOrgAuthority);
1267
1268         // Verify that the updated resource received the correct data.
1269         Assert.assertEquals(updatedOrgAuthority.getDisplayName(),
1270                 orgAuthority.getDisplayName(),
1271                 "Data in updated object did not match submitted data.");
1272     }
1273
1274     /**
1275      * Update item.
1276      *
1277      * @param testName the test name
1278      * @throws Exception the exception
1279      */
1280     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1281         groups = {"update"}, dependsOnMethods = {"update"})
1282     public void updateItem(String testName) throws Exception {
1283
1284         if (logger.isDebugEnabled()) {
1285             logger.debug(testBanner(testName, CLASS_NAME));
1286         }
1287         // Perform setup.
1288         setupUpdate();
1289
1290         // Retrieve the contents of a resource to update.
1291         OrgAuthorityClient client = new OrgAuthorityClient();
1292         ClientResponse<MultipartInput> res =
1293                 client.readItem(knownResourceId, knownItemResourceId);
1294         if(logger.isDebugEnabled()){
1295             logger.debug(testName + ": read status = " + res.getStatus());
1296         }
1297         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1298
1299         if(logger.isDebugEnabled()){
1300             logger.debug("got Organization to update with ID: " +
1301                 knownItemResourceId +
1302                 " in OrgAuthority: " + knownResourceId );
1303         }
1304         MultipartInput input = (MultipartInput) res.getEntity();
1305         OrganizationsCommon organization = (OrganizationsCommon) extractPart(input,
1306                 client.getItemCommonPartName(), OrganizationsCommon.class);
1307         Assert.assertNotNull(organization);
1308
1309         // Update the contents of this resource.
1310         organization.setCsid(null);
1311         organization.setShortName("updated-" + organization.getShortName());
1312         if(logger.isDebugEnabled()){
1313             logger.debug("to be updated Organization");
1314             logger.debug(objectAsXmlString(organization,
1315                 OrganizationsCommon.class));
1316         }
1317
1318         // Submit the updated resource to the service and store the response.
1319         MultipartOutput output = new MultipartOutput();
1320         OutputPart commonPart = output.addPart(organization, MediaType.APPLICATION_XML_TYPE);
1321         commonPart.getHeaders().add("label", client.getItemCommonPartName());
1322         res = client.updateItem(knownResourceId, knownItemResourceId, output);
1323         int statusCode = res.getStatus();
1324
1325         // Check the status code of the response: does it match the expected response(s)?
1326         if(logger.isDebugEnabled()){
1327             logger.debug(testName + ": status = " + statusCode);
1328         }
1329         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1330                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1331         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1332
1333         // Retrieve the updated resource and verify that its contents exist.
1334         input = (MultipartInput) res.getEntity();
1335         OrganizationsCommon updatedOrganization =
1336                 (OrganizationsCommon) extractPart(input,
1337                         client.getItemCommonPartName(), OrganizationsCommon.class);
1338         Assert.assertNotNull(updatedOrganization);
1339
1340         // Verify that the updated resource received the correct data.
1341         Assert.assertEquals(updatedOrganization.getShortName(),
1342                 organization.getShortName(),
1343                 "Data in updated Organization did not match submitted data.");
1344     }
1345
1346     /**
1347      * Update contact.
1348      *
1349      * @param testName the test name
1350      * @throws Exception the exception
1351      */
1352     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1353         groups = {"update"}, dependsOnMethods = {"updateItem"})
1354     public void updateContact(String testName) throws Exception {
1355
1356         if (logger.isDebugEnabled()) {
1357             logger.debug(testBanner(testName, CLASS_NAME));
1358         }
1359         // Perform setup.
1360         setupUpdate();
1361
1362         // Retrieve the contents of a resource to update.
1363         OrgAuthorityClient client = new OrgAuthorityClient();
1364         ClientResponse<MultipartInput> res =
1365                 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1366         if(logger.isDebugEnabled()){
1367             logger.debug(testName + ": read status = " + res.getStatus());
1368         }
1369         Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1370
1371         if(logger.isDebugEnabled()){
1372             logger.debug("got Contact to update with ID: " +
1373                 knownContactResourceId +
1374                 " in item: " + knownItemResourceId +
1375                 " in parent: " + knownResourceId );
1376         }
1377         MultipartInput input = (MultipartInput) res.getEntity();
1378         ContactsCommon contact = (ContactsCommon) extractPart(input,
1379                 new ContactClient().getCommonPartName(), ContactsCommon.class);
1380         Assert.assertNotNull(contact);
1381
1382         // Update the contents of this resource.
1383         contact.setAddressPlace("updated-" + contact.getAddressPlace());
1384         if(logger.isDebugEnabled()){
1385             logger.debug("to be updated Contact");
1386             logger.debug(objectAsXmlString(contact,
1387                 ContactsCommon.class));
1388         }
1389
1390         // Submit the updated resource to the service and store the response.
1391         MultipartOutput output = new MultipartOutput();
1392         OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1393         commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1394         res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1395         int statusCode = res.getStatus();
1396
1397         // Check the status code of the response: does it match the expected response(s)?
1398         if(logger.isDebugEnabled()){
1399             logger.debug(testName + ": status = " + statusCode);
1400         }
1401         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1402                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1403         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1404
1405         // Retrieve the updated resource and verify that its contents exist.
1406         input = (MultipartInput) res.getEntity();
1407         ContactsCommon updatedContact =
1408                 (ContactsCommon) extractPart(input,
1409                         new ContactClient().getCommonPartName(), ContactsCommon.class);
1410         Assert.assertNotNull(updatedContact);
1411
1412         // Verify that the updated resource received the correct data.
1413         Assert.assertEquals(updatedContact.getAddressPlace(),
1414                 contact.getAddressPlace(),
1415                 "Data in updated Contact did not match submitted data.");
1416     }
1417
1418     // Failure outcomes
1419     // Placeholders until the three tests below can be uncommented.
1420     // See Issue CSPACE-401.
1421     /* (non-Javadoc)
1422      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1423      */
1424     @Override
1425     public void updateWithEmptyEntityBody(String testName) throws Exception {
1426         //Should this really be empty?
1427     }
1428
1429     /* (non-Javadoc)
1430      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1431      */
1432     @Override
1433     public void updateWithMalformedXml(String testName) throws Exception {
1434         //Should this really be empty?
1435     }
1436
1437     /* (non-Javadoc)
1438      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1439      */
1440     @Override
1441     public void updateWithWrongXmlSchema(String testName) throws Exception {
1442         //Should this really be empty?
1443     }
1444
1445 /*
1446     @Override
1447     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1448         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1449     public void updateWithEmptyEntityBody(String testName) throws Exception {
1450
1451         if (logger.isDebugEnabled()) {
1452             logger.debug(testBanner(testName, CLASS_NAME));
1453         }
1454         // Perform setup.
1455         setupUpdateWithEmptyEntityBody();
1456
1457         // Submit the request to the service and store the response.
1458         String method = REQUEST_TYPE.httpMethodName();
1459         String url = getResourceURL(knownResourceId);
1460         String mediaType = MediaType.APPLICATION_XML;
1461         final String entity = "";
1462         int statusCode = submitRequest(method, url, mediaType, entity);
1463
1464         // Check the status code of the response: does it match
1465         // the expected response(s)?
1466         if(logger.isDebugEnabled()){
1467             logger.debug(testName + ": url=" + url +
1468                 " status=" + statusCode);
1469          }
1470         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1471         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1472         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1473     }
1474
1475     @Override
1476     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1477         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1478     public void updateWithMalformedXml(String testName) throws Exception {
1479
1480         if (logger.isDebugEnabled()) {
1481             logger.debug(testBanner(testName, CLASS_NAME));
1482         }
1483         // Perform setup.
1484         setupUpdateWithMalformedXml();
1485
1486         // Submit the request to the service and store the response.
1487         String method = REQUEST_TYPE.httpMethodName();
1488         String url = getResourceURL(knownResourceId);
1489         String mediaType = MediaType.APPLICATION_XML;
1490         final String entity = MALFORMED_XML_DATA;
1491         int statusCode = submitRequest(method, url, mediaType, entity);
1492
1493         // Check the status code of the response: does it match
1494         // the expected response(s)?
1495         if(logger.isDebugEnabled()){
1496             logger.debug(testName + ": url=" + url +
1497                " status=" + statusCode);
1498          }
1499         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1500         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1501         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1502         }
1503
1504         @Override
1505         @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1506             groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1507         public void updateWithWrongXmlSchema(String testName) throws Exception {
1508
1509         // Perform setup.
1510         setupUpdateWithWrongXmlSchema(testName, logger);
1511
1512         // Submit the request to the service and store the response.
1513         String method = REQUEST_TYPE.httpMethodName();
1514         String url = getResourceURL(knownResourceId);
1515         String mediaType = MediaType.APPLICATION_XML;
1516         final String entity = WRONG_XML_SCHEMA_DATA;
1517         int statusCode = submitRequest(method, url, mediaType, entity);
1518
1519         // Check the status code of the response: does it match
1520         // the expected response(s)?
1521         if(logger.isDebugEnabled()){
1522             logger.debug("updateWithWrongXmlSchema: url=" + url +
1523                 " status=" + statusCode);
1524          }
1525         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1526         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1527         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1528     }
1529 */
1530
1531     /* (non-Javadoc)
1532  * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1533  */
1534 @Override
1535     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1536         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1537     public void updateNonExistent(String testName) throws Exception {
1538
1539         if (logger.isDebugEnabled()) {
1540             logger.debug(testBanner(testName, CLASS_NAME));
1541         }
1542         // Perform setup.
1543         setupUpdateNonExistent();
1544
1545         // Submit the request to the service and store the response.
1546         // Note: The ID used in this 'create' call may be arbitrary.
1547         // The only relevant ID may be the one used in update(), below.
1548         OrgAuthorityClient client = new OrgAuthorityClient();
1549         MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID);
1550         ClientResponse<MultipartInput> res =
1551                 client.update(NON_EXISTENT_ID, multipart);
1552         int statusCode = res.getStatus();
1553
1554         // Check the status code of the response: does it match
1555         // the expected response(s)?
1556         if(logger.isDebugEnabled()){
1557             logger.debug(testName + ": status = " + statusCode);
1558         }
1559         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1560                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1561         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1562     }
1563
1564     /**
1565      * Update non existent item.
1566      *
1567      * @param testName the test name
1568      * @throws Exception the exception
1569      */
1570     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1571         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1572     public void updateNonExistentItem(String testName) throws Exception {
1573
1574         if (logger.isDebugEnabled()) {
1575             logger.debug(testBanner(testName, CLASS_NAME));
1576         }
1577         // Perform setup.
1578         setupUpdateNonExistent();
1579
1580         // Submit the request to the service and store the response.
1581         // Note: The ID(s) used when creating the request payload may be arbitrary.
1582         // The only relevant ID may be the one used in update(), below.
1583         OrgAuthorityClient client = new OrgAuthorityClient();
1584         Map<String, String> nonexOrgMap = new HashMap<String,String>();
1585         nonexOrgMap.put(OrganizationJAXBSchema.SHORT_NAME, "Non-existent");
1586         String refName = OrgAuthorityClientUtils.createOrganizationRefName(knownResourceRefName, NON_EXISTENT_ID, true);
1587         MultipartOutput multipart = 
1588                 OrgAuthorityClientUtils.createOrganizationInstance(
1589                         NON_EXISTENT_ID, refName,
1590                         nonexOrgMap, client.getItemCommonPartName() );
1591         ClientResponse<MultipartInput> res =
1592                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1593         int statusCode = res.getStatus();
1594
1595         // Check the status code of the response: does it match
1596         // the expected response(s)?
1597         if(logger.isDebugEnabled()){
1598             logger.debug(testName + ": status = " + statusCode);
1599         }
1600         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1601                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1602         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1603     }
1604
1605     /**
1606      * Update non existent contact.
1607      *
1608      * @param testName the test name
1609      * @throws Exception the exception
1610      */
1611     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1612         groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1613     public void updateNonExistentContact(String testName) throws Exception {
1614         // Currently a no-op test
1615     }
1616
1617     // ---------------------------------------------------------------
1618     // CRUD tests : DELETE tests
1619     // ---------------------------------------------------------------
1620     // Success outcomes
1621
1622     // Note: delete sub-resources in ascending hierarchical order,
1623     // before deleting their parents.
1624
1625     /**
1626      * Delete contact.
1627      *
1628      * @param testName the test name
1629      * @throws Exception the exception
1630      */
1631     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1632         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1633     public void deleteContact(String testName) throws Exception {
1634
1635         if (logger.isDebugEnabled()) {
1636             logger.debug(testBanner(testName, CLASS_NAME));
1637         }
1638         // Perform setup.
1639         setupDelete();
1640
1641          if(logger.isDebugEnabled()){
1642             logger.debug("parentcsid =" + knownResourceId +
1643                 " itemcsid = " + knownItemResourceId +
1644                 " csid = " + knownContactResourceId);
1645         }
1646
1647         // Submit the request to the service and store the response.
1648         OrgAuthorityClient client = new OrgAuthorityClient();
1649         ClientResponse<Response> res =
1650             client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1651         int statusCode = res.getStatus();
1652
1653         // Check the status code of the response: does it match
1654         // the expected response(s)?
1655         if(logger.isDebugEnabled()){
1656             logger.debug(testName + ": status = " + statusCode);
1657         }
1658         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1659                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1660         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1661     }
1662
1663    /**
1664     * Delete item.
1665     *
1666     * @param testName the test name
1667     * @throws Exception the exception
1668     */
1669    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1670         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1671     public void deleteItem(String testName) throws Exception {
1672
1673         if (logger.isDebugEnabled()) {
1674             logger.debug(testBanner(testName, CLASS_NAME));
1675         }
1676         // Perform setup.
1677         setupDelete();
1678
1679         if(logger.isDebugEnabled()){
1680             logger.debug("parentcsid =" + knownResourceId +
1681                 " itemcsid = " + knownItemResourceId);
1682         }
1683
1684         // Submit the request to the service and store the response.
1685         OrgAuthorityClient client = new OrgAuthorityClient();
1686         ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1687         int statusCode = res.getStatus();
1688
1689         // Check the status code of the response: does it match
1690         // the expected response(s)?
1691         if(logger.isDebugEnabled()){
1692             logger.debug(testName + ": status = " + statusCode);
1693         }
1694         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1695                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1696         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1697     }
1698
1699     /* (non-Javadoc)
1700      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1701      */
1702     @Override
1703     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1704         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1705     public void delete(String testName) throws Exception {
1706
1707         if (logger.isDebugEnabled()) {
1708             logger.debug(testBanner(testName, CLASS_NAME));
1709         }
1710         // Perform setup.
1711         setupDelete();
1712
1713         if(logger.isDebugEnabled()){
1714             logger.debug("parentcsid =" + knownResourceId);
1715         }
1716
1717         // Submit the request to the service and store the response.
1718         OrgAuthorityClient client = new OrgAuthorityClient();
1719         ClientResponse<Response> res = client.delete(knownResourceId);
1720         int statusCode = res.getStatus();
1721
1722         // Check the status code of the response: does it match
1723         // the expected response(s)?
1724         if(logger.isDebugEnabled()){
1725             logger.debug(testName + ": status = " + statusCode);
1726         }
1727         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1728                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1729         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1730     }
1731
1732     // Failure outcomes
1733     /* (non-Javadoc)
1734      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1735      */
1736     @Override
1737     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1738         groups = {"delete"}, dependsOnMethods = {"delete"})
1739     public void deleteNonExistent(String testName) throws Exception {
1740
1741         if (logger.isDebugEnabled()) {
1742             logger.debug(testBanner(testName, CLASS_NAME));
1743         }
1744         // Perform setup.
1745         setupDeleteNonExistent();
1746
1747         // Submit the request to the service and store the response.
1748         OrgAuthorityClient client = new OrgAuthorityClient();
1749         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1750         int statusCode = res.getStatus();
1751
1752         // Check the status code of the response: does it match
1753         // the expected response(s)?
1754         if(logger.isDebugEnabled()){
1755             logger.debug(testName + ": status = " + statusCode);
1756         }
1757         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1758                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1759         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1760     }
1761
1762     /**
1763      * Delete non existent item.
1764      *
1765      * @param testName the test name
1766      */
1767     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1768         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1769     public void deleteNonExistentItem(String testName) {
1770
1771         if (logger.isDebugEnabled()) {
1772             logger.debug(testBanner(testName, CLASS_NAME));
1773         }
1774         // Perform setup.
1775         setupDeleteNonExistent();
1776
1777         // Submit the request to the service and store the response.
1778         OrgAuthorityClient client = new OrgAuthorityClient();
1779         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1780         int statusCode = res.getStatus();
1781
1782         // Check the status code of the response: does it match
1783         // the expected response(s)?
1784         if(logger.isDebugEnabled()){
1785             logger.debug(testName + ": status = " + statusCode);
1786         }
1787         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1788                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1789         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1790     }
1791
1792     /**
1793      * Delete non existent contact.
1794      *
1795      * @param testName the test name
1796      */
1797     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1798         groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1799     public void deleteNonExistentContact(String testName) {
1800
1801         if (logger.isDebugEnabled()) {
1802             logger.debug(testBanner(testName, CLASS_NAME));
1803         }
1804         // Perform setup.
1805         setupDeleteNonExistent();
1806
1807         // Submit the request to the service and store the response.
1808         OrgAuthorityClient client = new OrgAuthorityClient();
1809         ClientResponse<Response> res =
1810             client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1811         int statusCode = res.getStatus();
1812
1813         // Check the status code of the response: does it match
1814         // the expected response(s)?
1815         if(logger.isDebugEnabled()){
1816             logger.debug(testName + ": status = " + statusCode);
1817         }
1818         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1819                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1820         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1821     }
1822
1823     // ---------------------------------------------------------------
1824     // Utility tests : tests of code used in tests above
1825     // ---------------------------------------------------------------
1826     /**
1827      * Tests the code for manually submitting data that is used by several
1828      * of the methods above.
1829      */
1830     @Test(dependsOnMethods = {"create", "read"})
1831     public void testSubmitRequest() {
1832
1833         // Expected status code: 200 OK
1834         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1835
1836         // Submit the request to the service and store the response.
1837         String method = ServiceRequestType.READ.httpMethodName();
1838         String url = getResourceURL(knownResourceId);
1839         int statusCode = submitRequest(method, url);
1840
1841         // Check the status code of the response: does it match
1842         // the expected response(s)?
1843         if(logger.isDebugEnabled()){
1844             logger.debug("testSubmitRequest: url=" + url +
1845                 " status=" + statusCode);
1846         }
1847         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1848
1849     }
1850
1851     /**
1852      * Test item submit request.
1853      */
1854     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1855     public void testItemSubmitRequest() {
1856
1857         // Expected status code: 200 OK
1858         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1859
1860         // Submit the request to the service and store the response.
1861         String method = ServiceRequestType.READ.httpMethodName();
1862         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1863         int statusCode = submitRequest(method, url);
1864
1865         // Check the status code of the response: does it match
1866         // the expected response(s)?
1867         if(logger.isDebugEnabled()){
1868             logger.debug("testItemSubmitRequest: url=" + url +
1869                 " status=" + statusCode);
1870         }
1871         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1872
1873     }
1874
1875     /**
1876      * Test contact submit request.
1877      */
1878     @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
1879     public void testContactSubmitRequest() {
1880
1881         // Expected status code: 200 OK
1882         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1883
1884         // Submit the request to the service and store the response.
1885         String method = ServiceRequestType.READ.httpMethodName();
1886         String url = getContactResourceURL(knownResourceId,
1887             knownItemResourceId, knownContactResourceId);
1888         int statusCode = submitRequest(method, url);
1889
1890         // Check the status code of the response: does it match
1891         // the expected response(s)?
1892         if(logger.isDebugEnabled()){
1893             logger.debug("testItemSubmitRequest: url=" + url +
1894                 " status=" + statusCode);
1895         }
1896         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1897
1898     }
1899
1900
1901     // ---------------------------------------------------------------
1902     // Cleanup of resources created during testing
1903     // ---------------------------------------------------------------
1904     
1905     /**
1906      * Deletes all resources created by tests, after all tests have been run.
1907      *
1908      * This cleanup method will always be run, even if one or more tests fail.
1909      * For this reason, it attempts to remove all resources created
1910      * at any point during testing, even if some of those resources
1911      * may be expected to be deleted by certain tests.
1912      */
1913
1914     @AfterClass(alwaysRun=true)
1915     @Override
1916     public void cleanUp() {
1917         String noTest = System.getProperty("noTestCleanup");
1918         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1919             if (logger.isDebugEnabled()) {
1920                 logger.debug("Skipping Cleanup phase ...");
1921             }
1922             return;
1923         }
1924         if (logger.isDebugEnabled()) {
1925             logger.debug("Cleaning up temporary resources created for testing ...");
1926         }
1927         
1928         String parentResourceId;
1929         String itemResourceId;
1930         String contactResourceId;
1931         // Clean up contact resources.
1932         parentResourceId = knownResourceId;
1933         OrgAuthorityClient client = new OrgAuthorityClient();
1934         for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
1935             contactResourceId = entry.getKey();
1936             itemResourceId = entry.getValue();
1937             // Note: Any non-success responses from the delete operation
1938             // below are ignored and not reported.
1939             ClientResponse<Response> res =
1940                 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
1941             res.releaseConnection();
1942         }
1943         // Clean up item resources.
1944         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1945             itemResourceId = entry.getKey();
1946             parentResourceId = entry.getValue();
1947             // Note: Any non-success responses from the delete operation
1948             // below are ignored and not reported.
1949             ClientResponse<Response> res =
1950                 client.deleteItem(parentResourceId, itemResourceId);
1951             res.releaseConnection();
1952         }
1953         // Clean up parent resources.
1954         super.cleanUp();
1955         
1956     }
1957
1958     // ---------------------------------------------------------------
1959     // Utility methods used by tests above
1960     // ---------------------------------------------------------------
1961     /* (non-Javadoc)
1962      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1963      */
1964     @Override
1965     public String getServicePathComponent() {
1966         return SERVICE_PATH_COMPONENT;
1967     }
1968
1969     /**
1970      * Gets the item service path component.
1971      *
1972      * @return the item service path component
1973      */
1974     public String getItemServicePathComponent() {
1975         return ITEM_SERVICE_PATH_COMPONENT;
1976     }
1977
1978     /**
1979      * Gets the contact service path component.
1980      *
1981      * @return the contact service path component
1982      */
1983     public String getContactServicePathComponent() {
1984         return CONTACT_SERVICE_PATH_COMPONENT;
1985     }
1986
1987     /**
1988      * Returns the root URL for the item service.
1989      *
1990      * This URL consists of a base URL for all services, followed by
1991      * a path component for the owning parent, followed by the
1992      * path component for the items.
1993      *
1994      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1995      * parent authority resource of the relevant item resource.
1996      *
1997      * @return The root URL for the item service.
1998      */
1999     protected String getItemServiceRootURL(String parentResourceIdentifier) {
2000         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2001     }
2002
2003     /**
2004      * Returns the URL of a specific item resource managed by a service, and
2005      * designated by an identifier (such as a universally unique ID, or UUID).
2006      *
2007      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2008      * parent authority resource of the relevant item resource.
2009      *
2010      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2011      * item resource.
2012      *
2013      * @return The URL of a specific item resource managed by a service.
2014      */
2015     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2016         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2017     }
2018
2019
2020     /**
2021      * Returns the root URL for the contact service.
2022      *
2023      * This URL consists of a base URL for all services, followed by
2024      * a path component for the owning authority, followed by the
2025      * path component for the owning item, followed by the path component
2026      * for the contact service.
2027      *
2028      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2029      * parent authority resource of the relevant item resource.
2030      *
2031      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
2032      * item resource.
2033      *
2034      * @return The root URL for the contact service.
2035      */
2036     protected String getContactServiceRootURL(String parentResourceIdentifier,
2037         String itemResourceIdentifier) {
2038         return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2039                 getContactServicePathComponent();
2040     }
2041
2042     /**
2043      * Returns the URL of a specific contact resource managed by a service, and
2044      * designated by an identifier (such as a universally unique ID, or UUID).
2045      *
2046      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
2047      * parent resource of the relevant item resource.
2048      *
2049      * @param  resourceIdentifier  An identifier (such as a UUID) for an
2050      * item resource.
2051      *
2052      * @return The URL of a specific resource managed by a service.
2053      */
2054     protected String getContactResourceURL(String parentResourceIdentifier,
2055         String itemResourceIdentifier, String contactResourceIdentifier) {
2056         return getContactServiceRootURL(parentResourceIdentifier,
2057             itemResourceIdentifier) + "/" + contactResourceIdentifier;
2058     }
2059
2060     /**
2061      * Creates the org authority instance.
2062      *
2063      * @param identifier the identifier
2064      * @return the multipart output
2065      */
2066     private MultipartOutput createOrgAuthorityInstance(String identifier) {
2067         String displayName = "displayName-" + identifier;
2068         String refName = OrgAuthorityClientUtils.createOrgAuthRefName(displayName, true);
2069         return OrgAuthorityClientUtils.createOrgAuthorityInstance(
2070                                 displayName, refName, 
2071                                 new OrgAuthorityClient().getCommonPartName());
2072     }
2073 }