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