]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0507a42769feafd6581809afd332a3153107d05e
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright (c)) 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.client.test;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.collectionspace.services.LocationJAXBSchema;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.ContactClient;
33 import org.collectionspace.services.client.ContactClientUtils;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.contact.ContactsCommon;
38 import org.collectionspace.services.contact.ContactsCommonList;
39 import org.collectionspace.services.client.LocationAuthorityClient;
40 import org.collectionspace.services.client.LocationAuthorityClientUtils;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.location.LocationauthoritiesCommon;
43 import org.collectionspace.services.location.LocationauthoritiesCommonList;
44 import org.collectionspace.services.location.LocationsCommon;
45 import org.collectionspace.services.location.LocationsCommonList;
46
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import org.jboss.resteasy.client.ClientResponse;
50
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
53
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
57
58 /**
59  * LocationAuthorityServiceTest, carries out tests against a
60  * deployed and running LocationAuthority Service.
61  *
62  * $LastChangedRevision: 753 $
63  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
64  */
65 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
66
67     /** The logger. */
68     private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
69     private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
70
71         @Override
72         public String getServicePathComponent() {
73                 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
74         }
75
76         @Override
77         protected String getServiceName() {
78                 return LocationAuthorityClient.SERVICE_NAME;
79         }
80     
81     public String getItemServicePathComponent() {
82         return LocationAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
83     }   
84     
85     // Instance variables specific to this test.
86     
87 //    /** The SERVICE path component. */
88 //    final String SERVICE_PATH_COMPONENT = "locationauthorities";
89 //    
90 //    /** The ITEM service path component. */
91 //    final String ITEM_SERVICE_PATH_COMPONENT = "items";
92 //    
93 //    /** The CONTACT service path component. */
94 //    final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
95     
96     final String TEST_NAME = "Shelf 1";
97     final String TEST_SHORTID = "shelf1";
98     final String TEST_CONDITION_NOTE = "Basically clean";
99     final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
100     final String TEST_SECURITY_NOTE = "Kind of safe";
101     final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
102     final String TEST_ADDRESS = "123 Main Street, Anytown USA";
103     // TODO Make loc type be a controlled vocab term.
104     final String TEST_LOCATION_TYPE = "Shelf";
105     // TODO Make status type be a controlled vocab term.
106     final String TEST_STATUS = "Approved";
107     
108     /** The known resource id. */
109     private String knownResourceId = null;
110     private String knownResourceShortIdentifer = null;
111     private String knownResourceRefName = null;
112     private String knownLocationTypeRefName = null;
113     private String knownItemResourceId = null;
114     private String knownItemResourceShortIdentifer = null;
115     private String knownContactResourceId = null;
116     
117     /** The n items to create in list. */
118     private int nItemsToCreateInList = 3;
119     
120     /** The all resource ids created. */
121     private List<String> allResourceIdsCreated = new ArrayList<String>();
122     
123     /** The all item resource ids created. */
124     private Map<String, String> allItemResourceIdsCreated =
125         new HashMap<String, String>();
126     
127     protected void setKnownResource( String id, String shortIdentifer,
128                 String refName ) {
129         knownResourceId = id;
130         knownResourceShortIdentifer = shortIdentifer;
131         knownResourceRefName = refName;
132     }
133
134     protected void setKnownItemResource( String id, String shortIdentifer ) {
135         knownItemResourceId = id;
136         knownItemResourceShortIdentifer = shortIdentifer;
137     }
138
139     /* (non-Javadoc)
140      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
141      */
142     @Override
143     protected CollectionSpaceClient getClientInstance() {
144         return new LocationAuthorityClient();
145     }
146     
147     /* (non-Javadoc)
148      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
149      */
150     @Override
151         protected AbstractCommonList getAbstractCommonList(
152                         ClientResponse<AbstractCommonList> response) {
153         return response.getEntity(LocationsCommonList.class);
154     }
155
156     // ---------------------------------------------------------------
157     // CRUD tests : CREATE tests
158     // ---------------------------------------------------------------
159     // Success outcomes
160     /* (non-Javadoc)
161      * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
162      */
163     @Override
164     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
165         groups = {"create"})
166     public void create(String testName) throws Exception {
167
168         if (logger.isDebugEnabled()) {
169             logger.debug(testBanner(testName, CLASS_NAME));
170         }
171         // Perform setup, such as initializing the type of service request
172         // (e.g. CREATE, DELETE), its valid and expected status codes, and
173         // its associated HTTP method name (e.g. POST, DELETE).
174         setupCreate();
175
176         // Submit the request to the service and store the response.
177         LocationAuthorityClient client = new LocationAuthorityClient();
178         String shortId = createIdentifier();
179         String displayName = "displayName-" + shortId;
180         String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
181         PoxPayloadOut multipart = 
182             LocationAuthorityClientUtils.createLocationAuthorityInstance(
183             displayName, shortId, client.getCommonPartName());
184         String newID = null;
185         ClientResponse<Response> res = client.create(multipart);
186         try {
187                 int statusCode = res.getStatus();
188         
189                 // Check the status code of the response: does it match
190                 // the expected response(s)?
191                 //
192                 // Specifically:
193                 // Does it fall within the set of valid status codes?
194                 // Does it exactly match the expected status code?
195                 if(logger.isDebugEnabled()){
196                     logger.debug(testName + ": status = " + statusCode);
197                 }
198                 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
199                         invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
200                 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
201         
202                 newID = LocationAuthorityClientUtils.extractId(res);
203         } finally {
204                 res.releaseConnection();
205         }
206         // Store the ID returned from the first resource created
207         // for additional tests below.
208         if (knownResourceId == null){
209                 setKnownResource( newID, shortId, baseRefName );
210             if (logger.isDebugEnabled()) {
211                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
212             }
213         }
214         // Store the IDs from every resource created by tests,
215         // so they can be deleted after tests have been run.
216         allResourceIdsCreated.add(newID);
217     }
218
219     /**
220      * Creates the item.
221      *
222      * @param testName the test name
223      */
224     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
225         groups = {"create"}, dependsOnMethods = {"create"})
226     public void createItem(String testName) {
227         if(logger.isDebugEnabled()){
228             logger.debug(testBanner(testName, CLASS_NAME));
229         }
230         setupCreate();
231         createItemInAuthority(knownResourceId, knownResourceRefName);
232     }
233
234     /**
235      * Creates the item in authority.
236      *
237      * @param vcsid the vcsid
238      * @param authRefName the auth ref name
239      * @return the string
240      */
241     private String createItemInAuthority(String vcsid, String authRefName) {
242
243         final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
244         if(logger.isDebugEnabled()){
245             logger.debug(testBanner(testName, CLASS_NAME));
246         }
247
248         // Submit the request to the service and store the response.
249         LocationAuthorityClient client = new LocationAuthorityClient();
250         Map<String, String> shelf1Map = new HashMap<String,String>();
251         // TODO Make loc type and status be controlled vocabs.
252         shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
253         shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
254         shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
255         shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
256         shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
257         shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
258         shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
259         shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
260         shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
261         
262         String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
263                         authRefName, shelf1Map, client );
264
265         // Store the ID returned from the first item resource created
266         // for additional tests below.
267         if (knownItemResourceId == null){
268                 setKnownItemResource(newID, TEST_SHORTID);
269             if (logger.isDebugEnabled()) {
270                 logger.debug(testName + ": knownItemResourceId=" + newID);
271             }
272         }
273
274         // Store the IDs from any item resources created
275         // by tests, along with the IDs of their parents, so these items
276         // can be deleted after all tests have been run.
277         allItemResourceIdsCreated.put(newID, vcsid);
278
279         return newID;
280     }
281
282
283
284     // Failure outcomes
285
286     // Placeholders until the three tests below can be uncommented.
287     // See Issue CSPACE-401.
288     /* (non-Javadoc)
289      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
290      */
291     @Override
292     public void createWithEmptyEntityBody(String testName) throws Exception {
293     }
294
295     /* (non-Javadoc)
296      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
297      */
298     @Override
299     public void createWithMalformedXml(String testName) throws Exception {
300     }
301
302     /* (non-Javadoc)
303      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
304      */
305     @Override
306     public void createWithWrongXmlSchema(String testName) throws Exception {
307     }
308
309
310     // ---------------------------------------------------------------
311     // CRUD tests : CREATE LIST tests
312     // ---------------------------------------------------------------
313     // Success outcomes
314     /* (non-Javadoc)
315          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
316          */
317     @Override
318     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
319         groups = {"createList"}, dependsOnGroups = {"create"})
320     public void createList(String testName) throws Exception {
321         for (int i = 0; i < nItemsToCreateInList; i++) {
322             create(testName);
323         }
324     }
325
326     /**
327      * Creates the item list.
328      *
329      * @param testName the test name
330      * @throws Exception the exception
331      */
332     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
333         groups = {"createList"}, dependsOnMethods = {"createList"})
334     public void createItemList(String testName) throws Exception {
335         // Add items to the initially-created, known parent record.
336         for (int j = 0; j < nItemsToCreateInList; j++) {
337             createItem(testName);
338         }
339     }
340
341     // ---------------------------------------------------------------
342     // CRUD tests : READ tests
343     // ---------------------------------------------------------------
344     // Success outcomes
345     /* (non-Javadoc)
346      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
347      */
348     @Override
349     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
350         groups = {"read"}, dependsOnGroups = {"create"})
351     public void read(String testName) throws Exception {
352
353         if (logger.isDebugEnabled()) {
354             logger.debug(testBanner(testName, CLASS_NAME));
355         }
356         // Perform setup.
357         setupRead();
358         
359         // Submit the request to the service and store the response.
360         LocationAuthorityClient client = new LocationAuthorityClient();
361         String newID = null;
362         ClientResponse<String> res = client.read(knownResourceId);
363         try {
364                 int statusCode = res.getStatus();
365         
366                 // Check the status code of the response: does it match
367                 // the expected response(s)?
368                 if(logger.isDebugEnabled()){
369                     logger.debug(testName + ": status = " + statusCode);
370                 }
371                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
374                 //FIXME: remove the following try catch once Aron fixes signatures
375                 try {
376                     PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
377                     LocationauthoritiesCommon locationAuthority = 
378                         (LocationauthoritiesCommon) extractPart(input,
379                             client.getCommonPartName(), LocationauthoritiesCommon.class);
380                     Assert.assertNotNull(locationAuthority);
381                 } catch (Exception e) {
382                     throw new RuntimeException(e);
383                 }
384         } finally {
385                 res.releaseConnection();
386         }
387     }
388
389     /**
390      * Read by name.
391      *
392      * @param testName the test name
393      * @throws Exception the exception
394      */
395     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
396             groups = {"read"}, dependsOnGroups = {"create"})
397         public void readByName(String testName) throws Exception {
398
399         if (logger.isDebugEnabled()) {
400             logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
401         }
402         // Perform setup.
403         setupRead();
404
405         // Submit the request to the service and store the response.
406         LocationAuthorityClient client = new LocationAuthorityClient();
407         ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
408         try {
409                 int statusCode = res.getStatus();
410         
411                 // Check the status code of the response: does it match
412                 // the expected response(s)?
413                 if(logger.isDebugEnabled()){
414                     logger.debug(testName + ": status = " + statusCode);
415                 }
416                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
417                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
418                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
419                 //FIXME: remove the following try catch once Aron fixes signatures
420                 try {
421                     PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
422                     LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
423                             client.getCommonPartName(), LocationauthoritiesCommon.class);
424                     Assert.assertNotNull(locationAuthority);
425                 } catch (Exception e) {
426                     throw new RuntimeException(e);
427                 }
428         } finally {
429                 res.releaseConnection();
430         }
431     }
432
433
434     /**
435          * Read item.
436          *
437          * @param testName the test name
438          * @throws Exception the exception
439          */
440     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
441         groups = {"read"}, dependsOnMethods = {"read"})
442     public void readItem(String testName) throws Exception {
443
444         if (logger.isDebugEnabled()) {
445             logger.debug(testBanner(testName, CLASS_NAME));
446         }
447         // Perform setup.
448         setupRead();
449
450         // Submit the request to the service and store the response.
451         LocationAuthorityClient client = new LocationAuthorityClient();
452         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
453         try {
454                 int statusCode = res.getStatus();
455         
456                 // Check the status code of the response: does it match
457                 // the expected response(s)?
458                 if(logger.isDebugEnabled()){
459                     logger.debug(testName + ": status = " + statusCode);
460                 }
461                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
462                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
463                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
464         
465                 // Check whether we've received a location.
466                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
467                 LocationsCommon location = (LocationsCommon) extractPart(input,
468                         client.getItemCommonPartName(), LocationsCommon.class);
469                 Assert.assertNotNull(location);
470                 boolean showFull = true;
471                 if(showFull && logger.isDebugEnabled()){
472                     logger.debug(testName + ": returned payload:");
473                     logger.debug(objectAsXmlString(location, LocationsCommon.class));
474                 }
475                 Assert.assertEquals(location.getInAuthority(), knownResourceId);
476             } finally {
477                 res.releaseConnection();
478             }
479
480     }
481
482     /**
483      * Verify item display name.
484      *
485      * @param testName the test name
486      * @throws Exception the exception
487      */
488     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
489         dependsOnMethods = {"readItem", "updateItem"})
490     public void verifyItemDisplayName(String testName) throws Exception {
491
492         if (logger.isDebugEnabled()) {
493             logger.debug(testBanner(testName, CLASS_NAME));
494         }
495         // Perform setup.
496         setupUpdate();
497
498         // Submit the request to the service and store the response.
499         LocationAuthorityClient client = new LocationAuthorityClient();
500         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
501         try {
502                 int statusCode = res.getStatus();
503         
504                 // Check the status code of the response: does it match
505                 // the expected response(s)?
506                 if(logger.isDebugEnabled()){
507                     logger.debug(testName + ": status = " + statusCode);
508                 }
509                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
510                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
511                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
512         
513                 // Check whether location has expected displayName.
514                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
515                 LocationsCommon location = (LocationsCommon) extractPart(input,
516                         client.getItemCommonPartName(), LocationsCommon.class);
517                 Assert.assertNotNull(location);
518                 String displayName = location.getDisplayName();
519                 // Make sure displayName matches computed form
520                 String expectedDisplayName = 
521                     LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
522                 Assert.assertNotNull(displayName, expectedDisplayName);
523                 
524                 // Update the shortName and verify the computed name is updated.
525                 location.setCsid(null);
526                 location.setDisplayNameComputed(true);
527                 location.setName("updated-" + TEST_NAME);
528                 expectedDisplayName = 
529                     LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
530         
531                 // Submit the updated resource to the service and store the response.
532                 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
533                 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
534                 commonPart.setLabel(client.getItemCommonPartName());
535                 res.releaseConnection();
536                 res = client.updateItem(knownResourceId, knownItemResourceId, output);
537                 statusCode = res.getStatus();
538         
539                 // Check the status code of the response: does it match the expected response(s)?
540                 if(logger.isDebugEnabled()){
541                     logger.debug("updateItem: status = " + statusCode);
542                 }
543                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
546         
547                 // Retrieve the updated resource and verify that its contents exist.
548                 input = new PoxPayloadIn(res.getEntity());
549                 LocationsCommon updatedLocation =
550                         (LocationsCommon) extractPart(input,
551                                 client.getItemCommonPartName(), LocationsCommon.class);
552                 Assert.assertNotNull(updatedLocation);
553         
554                 // Verify that the updated resource received the correct data.
555                 Assert.assertEquals(updatedLocation.getName(), location.getName(),
556                     "Updated ForeName in Location did not match submitted data.");
557                 // Verify that the updated resource computes the right displayName.
558                 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
559                     "Updated ForeName in Location not reflected in computed DisplayName.");
560         
561                 // Now Update the displayName, not computed and verify the computed name is overriden.
562                 location.setDisplayNameComputed(false);
563                 expectedDisplayName = "TestName";
564                 location.setDisplayName(expectedDisplayName);
565         
566                 // Submit the updated resource to the service and store the response.
567                 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
568                 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
569                 commonPart.setLabel(client.getItemCommonPartName());
570                 res.releaseConnection();
571                 res = client.updateItem(knownResourceId, knownItemResourceId, output);
572                 statusCode = res.getStatus();
573         
574                 // Check the status code of the response: does it match the expected response(s)?
575                 if(logger.isDebugEnabled()){
576                     logger.debug("updateItem: status = " + statusCode);
577                 }
578                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
581         
582                 // Retrieve the updated resource and verify that its contents exist.
583                 input = new PoxPayloadIn(res.getEntity());
584                 updatedLocation =
585                         (LocationsCommon) extractPart(input,
586                                 client.getItemCommonPartName(), LocationsCommon.class);
587                 Assert.assertNotNull(updatedLocation);
588         
589                 // Verify that the updated resource received the correct data.
590                 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
591                         "Updated displayNameComputed in Location did not match submitted data.");
592                 // Verify that the updated resource computes the right displayName.
593                 Assert.assertEquals(updatedLocation.getDisplayName(),
594                                 expectedDisplayName,
595                         "Updated DisplayName (not computed) in Location not stored.");
596             } finally {
597                 res.releaseConnection();
598             }
599     }
600
601     /**
602      * Verify illegal item display name.
603      *
604      * @param testName the test name
605      * @throws Exception the exception
606      */
607     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
608             dependsOnMethods = {"verifyItemDisplayName"})
609     public void verifyIllegalItemDisplayName(String testName) throws Exception {
610
611         if (logger.isDebugEnabled()) {
612             logger.debug(testBanner(testName, CLASS_NAME));
613         }
614         // Perform setup.
615         // FIXME: create a setup configuration for this operation.
616         setupUpdateWithWrongXmlSchema();
617
618         // Submit the request to the service and store the response.
619         LocationAuthorityClient client = new LocationAuthorityClient();
620         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
621         try {
622                 int statusCode = res.getStatus();
623         
624                 // Check the status code of the response: does it match
625                 // the expected response(s)?
626                 if(logger.isDebugEnabled()){
627                     logger.debug(testName + ": status = " + statusCode);
628                 }
629                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
630                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
631                 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
632         
633                 // Check whether Location has expected displayName.
634                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
635                 LocationsCommon location = (LocationsCommon) extractPart(input,
636                         client.getItemCommonPartName(), LocationsCommon.class);
637                 Assert.assertNotNull(location);
638                 // Try to Update with computed false and no displayName
639                 location.setDisplayNameComputed(false);
640                 location.setDisplayName(null);
641         
642                 // Submit the updated resource to the service and store the response.
643                 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
644                 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
645                 commonPart.setLabel(client.getItemCommonPartName());
646                 res.releaseConnection();
647                 res = client.updateItem(knownResourceId, knownItemResourceId, output);
648                 statusCode = res.getStatus();
649         
650                 // Check the status code of the response: does it match the expected response(s)?
651                 if(logger.isDebugEnabled()){
652                     logger.debug("updateItem: status = " + statusCode);
653                 }
654                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
657             } finally {
658                 res.releaseConnection();
659             }
660     }
661    
662
663     // Failure outcomes
664     /* (non-Javadoc)
665      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
666      */
667     @Override
668     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
669         groups = {"read"}, dependsOnMethods = {"read"})
670     public void readNonExistent(String testName) {
671
672         if (logger.isDebugEnabled()) {
673             logger.debug(testBanner(testName, CLASS_NAME));
674         }
675         // Perform setup.
676         setupReadNonExistent();
677
678         // Submit the request to the service and store the response.
679         LocationAuthorityClient client = new LocationAuthorityClient();
680         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
681         try {
682                 int statusCode = res.getStatus();
683         
684                 // Check the status code of the response: does it match
685                 // the expected response(s)?
686                 if(logger.isDebugEnabled()){
687                     logger.debug(testName + ": status = " + statusCode);
688                 }
689                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
690                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
691                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692             } finally {
693                 res.releaseConnection();
694             }
695     }
696
697     /**
698      * Read item non existent.
699      *
700      * @param testName the test name
701      */
702     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
703         groups = {"read"}, dependsOnMethods = {"readItem"})
704     public void readItemNonExistent(String testName) {
705
706         if (logger.isDebugEnabled()) {
707             logger.debug(testBanner(testName, CLASS_NAME));
708         }
709         // Perform setup.
710         setupReadNonExistent();
711
712         // Submit the request to the service and store the response.
713         LocationAuthorityClient client = new LocationAuthorityClient();
714         ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
715         try {
716                 int statusCode = res.getStatus();
717         
718                 // Check the status code of the response: does it match
719                 // the expected response(s)?
720                 if(logger.isDebugEnabled()){
721                     logger.debug(testName + ": status = " + statusCode);
722                 }
723                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
724                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
725                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
726             } finally {
727                 res.releaseConnection();
728             }
729     }
730
731
732     // ---------------------------------------------------------------
733     // CRUD tests : READ_LIST tests
734     // ---------------------------------------------------------------
735     // Success outcomes
736
737     /* (non-Javadoc)
738      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
739      */
740     @Override
741     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
742         groups = {"readList"}, dependsOnGroups = {"createList", "read"})
743     public void readList(String testName) throws Exception {
744
745         if (logger.isDebugEnabled()) {
746             logger.debug(testBanner(testName, CLASS_NAME));
747         }
748         // Perform setup.
749         setupReadList();
750
751         // Submit the request to the service and store the response.
752         LocationAuthorityClient client = new LocationAuthorityClient();
753         ClientResponse<LocationauthoritiesCommonList> res = client.readList();
754         try {
755                 LocationauthoritiesCommonList list = res.getEntity();
756                 int statusCode = res.getStatus();
757         
758                 // Check the status code of the response: does it match
759                 // the expected response(s)?
760                 if(logger.isDebugEnabled()){
761                     logger.debug(testName + ": status = " + statusCode);
762                 }
763                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
764                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
765                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
766         
767                 // Optionally output additional data about list members for debugging.
768                 boolean iterateThroughList = false;
769                 if (iterateThroughList && logger.isDebugEnabled()) {
770                     List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
771                             list.getLocationauthorityListItem();
772                     int i = 0;
773                     for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
774                         String csid = item.getCsid();
775                         logger.debug(testName + ": list-item[" + i + "] csid=" +
776                                 csid);
777                         logger.debug(testName + ": list-item[" + i + "] displayName=" +
778                                 item.getDisplayName());
779                         logger.debug(testName + ": list-item[" + i + "] URI=" +
780                                 item.getUri());
781                         readItemList(csid, null);
782                         i++;
783                     }
784                 }
785             } finally {
786                 res.releaseConnection();
787             }
788     }
789
790     /**
791      * Read item list.
792      */
793     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
794     public void readItemList() {
795         String testName = "readItemList";
796         if (logger.isDebugEnabled()) {
797             logger.debug(testBanner(testName, CLASS_NAME));
798         }
799         readItemList(knownResourceId, null);
800     }
801
802     /**
803      * Read item list by authority name.
804      */
805     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
806     public void readItemListByAuthorityName() {
807         String testName = "readItemListByAuthorityName";
808         if (logger.isDebugEnabled()) {
809             logger.debug(testBanner(testName, CLASS_NAME));
810         }
811         readItemList(null, knownResourceShortIdentifer);
812     }
813     
814     /**
815      * Read item list.
816      *
817      * @param vcsid the vcsid
818      * @param name the name
819      */
820     private void readItemList(String vcsid, String shortId) {
821
822         String testName = "readItemList";
823
824         // Perform setup.
825         setupReadList();
826         
827         // Submit the request to the service and store the response.
828         LocationAuthorityClient client = new LocationAuthorityClient();
829         ClientResponse<LocationsCommonList> res = null;
830         if(vcsid!= null) {
831                 res = client.readItemList(vcsid, null, null);
832         } else if(shortId!= null) {
833                 res = client.readItemListForNamedAuthority(shortId, null, null);
834         } else {
835                 Assert.fail("readItemList passed null csid and name!");
836         }
837         try {
838                 LocationsCommonList list = res.getEntity();
839                 int statusCode = res.getStatus();
840         
841                 // Check the status code of the response: does it match
842                 // the expected response(s)?
843                 if(logger.isDebugEnabled()){
844                     logger.debug(testName + ": status = " + statusCode);
845                 }
846                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
847                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
848                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
849         
850                 List<LocationsCommonList.LocationListItem> items =
851                     list.getLocationListItem();
852                 int nItemsReturned = items.size();
853                 // There will be one item created, associated with a
854                 // known parent resource, by the createItem test.
855                 //
856                 // In addition, there will be 'nItemsToCreateInList'
857                 // additional items created by the createItemList test,
858                 // all associated with the same parent resource.
859                 int nExpectedItems = nItemsToCreateInList + 1;
860                 if(logger.isDebugEnabled()){
861                     logger.debug(testName + ": Expected "
862                                 + nExpectedItems +" items; got: "+nItemsReturned);
863                 }
864                 Assert.assertEquals(nItemsReturned, nExpectedItems);
865         
866                 int i = 0;
867                 for (LocationsCommonList.LocationListItem item : items) {
868                         Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
869                         Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
870                         // Optionally output additional data about list members for debugging.
871                         boolean showDetails = true;
872                         if (showDetails && logger.isDebugEnabled()) {
873                         logger.debug("  " + testName + ": list-item[" + i + "] csid=" +
874                                 item.getCsid());
875                         logger.debug("  " + testName + ": list-item[" + i + "] refName=" +
876                                 item.getRefName());
877                         logger.debug("  " + testName + ": list-item[" + i + "] displayName=" +
878                                 item.getDisplayName());
879                         logger.debug("  " + testName + ": list-item[" + i + "] URI=" +
880                                 item.getUri());
881                     }
882                     i++;
883                 }
884             } finally {
885                 res.releaseConnection();
886             }
887     }
888
889
890     // Failure outcomes
891     // None at present.
892
893     // ---------------------------------------------------------------
894     // CRUD tests : UPDATE tests
895     // ---------------------------------------------------------------
896     // Success outcomes
897     /* (non-Javadoc)
898      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
899      */
900     @Override
901     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
902         groups = {"update"}, dependsOnGroups = {"read", "readList"})
903     public void update(String testName) throws Exception {
904
905         if (logger.isDebugEnabled()) {
906             logger.debug(testBanner(testName, CLASS_NAME));
907         }
908         // Perform setup.
909         setupUpdate();
910
911         // Retrieve the contents of a resource to update.
912         LocationAuthorityClient client = new LocationAuthorityClient();
913         ClientResponse<String> res = client.read(knownResourceId);
914         try {
915                 if(logger.isDebugEnabled()){
916                     logger.debug(testName + ": read status = " + res.getStatus());
917                 }
918                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
919         
920                 if(logger.isDebugEnabled()){
921                     logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
922                 }
923                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
924                 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
925                         client.getCommonPartName(), LocationauthoritiesCommon.class);
926                 Assert.assertNotNull(locationAuthority);
927         
928                 // Update the contents of this resource.
929                 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
930                 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
931                 if(logger.isDebugEnabled()){
932                     logger.debug("to be updated LocationAuthority");
933                     logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
934                 }
935         
936                 // Submit the updated resource to the service and store the response.
937                 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
938                 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
939                 commonPart.setLabel(client.getCommonPartName());
940                 res.releaseConnection();
941                 res = client.update(knownResourceId, output);
942                 int statusCode = res.getStatus();
943         
944                 // Check the status code of the response: does it match the expected response(s)?
945                 if(logger.isDebugEnabled()){
946                     logger.debug(testName + ": status = " + statusCode);
947                 }
948                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
949                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
950                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
951         
952                 // Retrieve the updated resource and verify that its contents exist.
953                 input = new PoxPayloadIn(res.getEntity());
954                 LocationauthoritiesCommon updatedLocationAuthority =
955                         (LocationauthoritiesCommon) extractPart(input,
956                                 client.getCommonPartName(), LocationauthoritiesCommon.class);
957                 Assert.assertNotNull(updatedLocationAuthority);
958         
959                 // Verify that the updated resource received the correct data.
960                 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
961                         locationAuthority.getDisplayName(),
962                         "Data in updated object did not match submitted data.");
963             } finally {
964                 res.releaseConnection();
965             }
966     }
967
968     /**
969      * Update item.
970      *
971      * @param testName the test name
972      * @throws Exception the exception
973      */
974     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
975         groups = {"update"}, dependsOnMethods = {"update"})
976     public void updateItem(String testName) throws Exception {
977
978         if (logger.isDebugEnabled()) {
979             logger.debug(testBanner(testName, CLASS_NAME));
980         }
981         // Perform setup.
982         setupUpdate();
983
984         // Retrieve the contents of a resource to update.
985         LocationAuthorityClient client = new LocationAuthorityClient();
986         ClientResponse<String> res =
987                 client.readItem(knownResourceId, knownItemResourceId);
988         try {
989                 if(logger.isDebugEnabled()){
990                     logger.debug(testName + ": read status = " + res.getStatus());
991                 }
992                 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
993         
994                 if(logger.isDebugEnabled()){
995                     logger.debug("got Location to update with ID: " +
996                         knownItemResourceId +
997                         " in LocationAuthority: " + knownResourceId );
998                 }
999                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1000                 LocationsCommon location = (LocationsCommon) extractPart(input,
1001                         client.getItemCommonPartName(), LocationsCommon.class);
1002                 Assert.assertNotNull(location);
1003         
1004                 // Update the contents of this resource.
1005                 location.setCsid(null);
1006                 location.setName("updated-" + location.getName());
1007                 if(logger.isDebugEnabled()){
1008                     logger.debug("to be updated Location");
1009                     logger.debug(objectAsXmlString(location,
1010                         LocationsCommon.class));
1011                 }        
1012         
1013                 // Submit the updated resource to the service and store the response.
1014                 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1015                 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1016                 commonPart.setLabel(client.getItemCommonPartName());
1017                 res.releaseConnection();
1018                 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1019                 int statusCode = res.getStatus();
1020         
1021                 // Check the status code of the response: does it match the expected response(s)?
1022                 if(logger.isDebugEnabled()){
1023                     logger.debug(testName + ": status = " + statusCode);
1024                 }
1025                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1026                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1027                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1028         
1029                 // Retrieve the updated resource and verify that its contents exist.
1030                 input = new PoxPayloadIn(res.getEntity());
1031                 LocationsCommon updatedLocation =
1032                         (LocationsCommon) extractPart(input,
1033                                 client.getItemCommonPartName(), LocationsCommon.class);
1034                 Assert.assertNotNull(updatedLocation);
1035         
1036                 // Verify that the updated resource received the correct data.
1037                 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1038                         "Data in updated Location did not match submitted data.");
1039             } finally {
1040                 res.releaseConnection();
1041             }
1042     }
1043
1044     // Failure outcomes
1045     // Placeholders until the three tests below can be uncommented.
1046     // See Issue CSPACE-401.
1047     /* (non-Javadoc)
1048      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1049      */
1050     @Override
1051     public void updateWithEmptyEntityBody(String testName) throws Exception {
1052     }
1053
1054     /* (non-Javadoc)
1055      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1056      */
1057     @Override
1058     public void updateWithMalformedXml(String testName) throws Exception {
1059     }
1060
1061     /* (non-Javadoc)
1062      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1063      */
1064     @Override
1065     public void updateWithWrongXmlSchema(String testName) throws Exception {
1066     }
1067
1068
1069     /* (non-Javadoc)
1070          * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1071          */
1072 @Override
1073     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1074         groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1075     public void updateNonExistent(String testName) throws Exception {
1076
1077         if (logger.isDebugEnabled()) {
1078             logger.debug(testBanner(testName, CLASS_NAME));
1079         }
1080         // Perform setup.
1081         setupUpdateNonExistent();
1082
1083         // Submit the request to the service and store the response.
1084         // Note: The ID(s) used when creating the request payload may be arbitrary.
1085         // The only relevant ID may be the one used in update(), below.
1086         LocationAuthorityClient client = new LocationAuthorityClient();
1087         String displayName = "displayName-NON_EXISTENT_ID";
1088         PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1089                                 displayName, "nonEx", client.getCommonPartName());
1090         ClientResponse<String> res =
1091                 client.update(NON_EXISTENT_ID, multipart);
1092         try {
1093                 int statusCode = res.getStatus();
1094         
1095                 // Check the status code of the response: does it match
1096                 // the expected response(s)?
1097                 if(logger.isDebugEnabled()){
1098                     logger.debug(testName + ": status = " + statusCode);
1099                 }
1100                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1101                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1102                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1103             } finally {
1104                 res.releaseConnection();
1105             }
1106     }
1107
1108     /**
1109      * Update non existent item.
1110      *
1111      * @param testName the test name
1112      * @throws Exception the exception
1113      */
1114     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1115         groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1116     public void updateNonExistentItem(String testName) throws Exception {
1117
1118         if (logger.isDebugEnabled()) {
1119             logger.debug(testBanner(testName, CLASS_NAME));
1120         }
1121         // Perform setup.
1122         setupUpdateNonExistent();
1123
1124         // Submit the request to the service and store the response.
1125         // Note: The ID used in this 'create' call may be arbitrary.
1126         // The only relevant ID may be the one used in update(), below.
1127         LocationAuthorityClient client = new LocationAuthorityClient();
1128         Map<String, String> nonexMap = new HashMap<String,String>();
1129         nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1130         nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1131         nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1132         nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1133         PoxPayloadOut multipart = 
1134         LocationAuthorityClientUtils.createLocationInstance(
1135                         LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"), 
1136                         nonexMap, client.getItemCommonPartName() );
1137         ClientResponse<String> res =
1138                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1139         try {
1140                 int statusCode = res.getStatus();
1141         
1142                 // Check the status code of the response: does it match
1143                 // the expected response(s)?
1144                 if(logger.isDebugEnabled()){
1145                     logger.debug(testName + ": status = " + statusCode);
1146                 }
1147                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1148                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1149                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1150             } finally {
1151                 res.releaseConnection();
1152             }
1153     }
1154
1155     // ---------------------------------------------------------------
1156     // CRUD tests : DELETE tests
1157     // ---------------------------------------------------------------
1158     // Success outcomes
1159
1160     // Note: delete sub-resources in ascending hierarchical order,
1161     // before deleting their parents.
1162
1163    /**
1164     * Delete item.
1165     *
1166     * @param testName the test name
1167     * @throws Exception the exception
1168     */
1169    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1170         //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1171         groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1172     public void deleteItem(String testName) throws Exception {
1173
1174         if (logger.isDebugEnabled()) {
1175             logger.debug(testBanner(testName, CLASS_NAME));
1176         }
1177         // Perform setup.
1178         setupDelete();
1179
1180         if(logger.isDebugEnabled()){
1181             logger.debug("parentcsid =" + knownResourceId +
1182                 " itemcsid = " + knownItemResourceId);
1183         }
1184
1185         // Submit the request to the service and store the response.
1186         LocationAuthorityClient client = new LocationAuthorityClient();
1187         ClientResponse<Response> res = 
1188                 client.deleteItem(knownResourceId, knownItemResourceId);
1189         try {
1190                 int statusCode = res.getStatus();
1191         
1192                 // Check the status code of the response: does it match
1193                 // the expected response(s)?
1194                 if(logger.isDebugEnabled()){
1195                     logger.debug(testName + ": status = " + statusCode);
1196                 }
1197                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1198                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1199                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1200             } finally {
1201                 res.releaseConnection();
1202             }
1203     }
1204
1205     /* (non-Javadoc)
1206      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1207      */
1208     @Override
1209     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1210         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1211     public void delete(String testName) throws Exception {
1212
1213         if (logger.isDebugEnabled()) {
1214             logger.debug(testBanner(testName, CLASS_NAME));
1215         }
1216         // Perform setup.
1217         setupDelete();
1218
1219         if(logger.isDebugEnabled()){
1220             logger.debug("parentcsid =" + knownResourceId);
1221         }
1222
1223         // Submit the request to the service and store the response.
1224         LocationAuthorityClient client = new LocationAuthorityClient();
1225         ClientResponse<Response> res = client.delete(knownResourceId);
1226         try {
1227                 int statusCode = res.getStatus();
1228         
1229                 // Check the status code of the response: does it match
1230                 // the expected response(s)?
1231                 if(logger.isDebugEnabled()){
1232                     logger.debug(testName + ": status = " + statusCode);
1233                 }
1234                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1235                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1236                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1237             } finally {
1238                 res.releaseConnection();
1239             }
1240     }
1241
1242     // Failure outcomes
1243     /* (non-Javadoc)
1244      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1245      */
1246     @Override
1247     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1248         groups = {"delete"}, dependsOnMethods = {"delete"})
1249     public void deleteNonExistent(String testName) throws Exception {
1250
1251         if (logger.isDebugEnabled()) {
1252             logger.debug(testBanner(testName, CLASS_NAME));
1253         }
1254         // Perform setup.
1255         setupDeleteNonExistent();
1256
1257         // Submit the request to the service and store the response.
1258         LocationAuthorityClient client = new LocationAuthorityClient();
1259         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1260         try {
1261                 int statusCode = res.getStatus();
1262         
1263                 // Check the status code of the response: does it match
1264                 // the expected response(s)?
1265                 if(logger.isDebugEnabled()){
1266                     logger.debug(testName + ": status = " + statusCode);
1267                 }
1268                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1269                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1270                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1271             } finally {
1272                 res.releaseConnection();
1273             }
1274     }
1275
1276     /**
1277      * Delete non existent item.
1278      *
1279      * @param testName the test name
1280      */
1281     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1282         groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1283     public void deleteNonExistentItem(String testName) {
1284
1285         if (logger.isDebugEnabled()) {
1286             logger.debug(testBanner(testName, CLASS_NAME));
1287         }
1288         // Perform setup.
1289         setupDeleteNonExistent();
1290
1291         // Submit the request to the service and store the response.
1292         LocationAuthorityClient client = new LocationAuthorityClient();
1293         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1294         try {
1295                 int statusCode = res.getStatus();
1296         
1297                 // Check the status code of the response: does it match
1298                 // the expected response(s)?
1299                 if(logger.isDebugEnabled()){
1300                     logger.debug(testName + ": status = " + statusCode);
1301                 }
1302                 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1303                         invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1304                 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1305             } finally {
1306                 res.releaseConnection();
1307             }
1308     }
1309
1310     // ---------------------------------------------------------------
1311     // Utility tests : tests of code used in tests above
1312     // ---------------------------------------------------------------
1313     /**
1314      * Tests the code for manually submitting data that is used by several
1315      * of the methods above.
1316      */
1317     @Test(dependsOnMethods = {"create", "read"})
1318     public void testSubmitRequest() {
1319
1320         // Expected status code: 200 OK
1321         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1322
1323         // Submit the request to the service and store the response.
1324         String method = ServiceRequestType.READ.httpMethodName();
1325         String url = getResourceURL(knownResourceId);
1326         int statusCode = submitRequest(method, url);
1327
1328         // Check the status code of the response: does it match
1329         // the expected response(s)?
1330         if(logger.isDebugEnabled()){
1331             logger.debug("testSubmitRequest: url=" + url +
1332                 " status=" + statusCode);
1333         }
1334         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1335
1336     }
1337
1338     /**
1339      * Test item submit request.
1340      */
1341     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1342     public void testItemSubmitRequest() {
1343
1344         // Expected status code: 200 OK
1345         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1346
1347         // Submit the request to the service and store the response.
1348         String method = ServiceRequestType.READ.httpMethodName();
1349         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1350         int statusCode = submitRequest(method, url);
1351
1352         // Check the status code of the response: does it match
1353         // the expected response(s)?
1354         if(logger.isDebugEnabled()){
1355             logger.debug("testItemSubmitRequest: url=" + url +
1356                 " status=" + statusCode);
1357         }
1358         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1359
1360     }
1361
1362     // ---------------------------------------------------------------
1363     // Cleanup of resources created during testing
1364     // ---------------------------------------------------------------
1365     
1366     /**
1367      * Deletes all resources created by tests, after all tests have been run.
1368      *
1369      * This cleanup method will always be run, even if one or more tests fail.
1370      * For this reason, it attempts to remove all resources created
1371      * at any point during testing, even if some of those resources
1372      * may be expected to be deleted by certain tests.
1373      */
1374
1375     @AfterClass(alwaysRun=true)
1376     public void cleanUp() {
1377         String noTest = System.getProperty("noTestCleanup");
1378         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1379             if (logger.isDebugEnabled()) {
1380                 logger.debug("Skipping Cleanup phase ...");
1381             }
1382             return;
1383         }
1384         if (logger.isDebugEnabled()) {
1385             logger.debug("Cleaning up temporary resources created for testing ...");
1386         }
1387         String parentResourceId;
1388         String itemResourceId;
1389         // Clean up contact resources.
1390         LocationAuthorityClient client = new LocationAuthorityClient();
1391         parentResourceId = knownResourceId;
1392         // Clean up item resources.
1393         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1394             itemResourceId = entry.getKey();
1395             parentResourceId = entry.getValue();
1396             // Note: Any non-success responses from the delete operation
1397             // below are ignored and not reported.
1398             ClientResponse<Response> res =
1399                 client.deleteItem(parentResourceId, itemResourceId);
1400                 res.releaseConnection();
1401         }
1402         // Clean up parent resources.
1403         for (String resourceId : allResourceIdsCreated) {
1404             // Note: Any non-success responses from the delete operation
1405             // below are ignored and not reported.
1406             ClientResponse<Response> res = client.delete(resourceId);
1407                 res.releaseConnection();
1408         }
1409     }
1410
1411     // ---------------------------------------------------------------
1412     // Utility methods used by tests above
1413     // ---------------------------------------------------------------
1414     /* (non-Javadoc)
1415      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1416      */
1417
1418     /**
1419      * Returns the root URL for the item service.
1420      *
1421      * This URL consists of a base URL for all services, followed by
1422      * a path component for the owning parent, followed by the
1423      * path component for the items.
1424      *
1425      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1426      * parent authority resource of the relevant item resource.
1427      *
1428      * @return The root URL for the item service.
1429      */
1430     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1431         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1432     }
1433
1434     /**
1435      * Returns the URL of a specific item resource managed by a service, and
1436      * designated by an identifier (such as a universally unique ID, or UUID).
1437      *
1438      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1439      * parent authority resource of the relevant item resource.
1440      *
1441      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1442      * item resource.
1443      *
1444      * @return The URL of a specific item resource managed by a service.
1445      */
1446     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1447         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1448     }
1449
1450
1451 }