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