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