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