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