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