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