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