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