]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
4ed239c7f130a555c93064787ebec1e0537d34db
[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             assertStatusCode(res, testName);
374             //FIXME: remove the following try catch once Aron fixes signatures
375             try {
376                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
377                 TaxonomyauthorityCommon taxonomyAuthority =
378                         (TaxonomyauthorityCommon) extractPart(input,
379                         client.getCommonPartName(), TaxonomyauthorityCommon.class);
380                 Assert.assertNotNull(taxonomyAuthority);
381             } catch (Exception e) {
382                 throw new RuntimeException(e);
383             }
384         } finally {
385             res.releaseConnection();
386         }
387     }
388
389     /**
390      * Read by name.
391      *
392      * @param testName the test name
393      * @throws Exception the exception
394      */
395     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
396     groups = {"read"}, dependsOnGroups = {"create"})
397     public void readByName(String testName) throws Exception {
398
399         if (logger.isDebugEnabled()) {
400             logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
401         }
402         // Perform setup.
403         setupRead();
404
405         // Submit the request to the service and store the response.
406         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
407         ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
408         try {
409             assertStatusCode(res, testName);
410             //FIXME: remove the following try catch once Aron fixes signatures
411             try {
412                 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
413                 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
414                         client.getCommonPartName(), TaxonomyauthorityCommon.class);
415                 Assert.assertNotNull(taxonomyAuthority);
416             } catch (Exception e) {
417                 throw new RuntimeException(e);
418             }
419         } finally {
420             res.releaseConnection();
421         }
422     }
423
424     /**
425      * Read item.
426      *
427      * @param testName the test name
428      * @throws Exception the exception
429      */
430     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
431     groups = {"read"}, dependsOnMethods = {"read"})
432     public void readItem(String testName) throws Exception {
433
434         if (logger.isDebugEnabled()) {
435             logger.debug(testBanner(testName, CLASS_NAME));
436         }
437         // Perform setup.
438         setupRead();
439
440         // Submit the request to the service and store the response.
441         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
442         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
443         try {
444             assertStatusCode(res, testName);
445             // Check whether we've received an authority item record.
446             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
447             TaxonCommon taxon = (TaxonCommon) extractPart(input,
448                     client.getItemCommonPartName(), TaxonCommon.class);
449             Assert.assertNotNull(taxon);
450             boolean showFull = true;
451             if (showFull && logger.isDebugEnabled()) {
452                 logger.debug(testName + ": returned payload:");
453                 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
454             }
455
456             // Check that this authority item record has the correct identifier
457             // pointing to its parent authority record.
458             Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null.");
459             Assert.assertEquals(taxon.getInAuthority(), knownResourceId,
460                     "Value of item's inAuthority field does not contain the correct identifier "
461                     + "pointing to its parent authority record.");
462
463             // Check individual fields in the authority item record.
464             Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null.");
465             Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME,
466                     "Field value " + taxon.getTaxonFullName()
467                     + "does not match expected value " + TEST_TAXON_FULL_NAME);
468         } finally {
469             res.releaseConnection();
470         }
471     }
472
473     /**
474      * Verify item display name.
475      *
476      * @param testName the test name
477      * @throws Exception the exception
478      */
479     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
480     dependsOnMethods = {"readItem", "updateItem"})
481     public void verifyItemDisplayName(String testName) throws Exception {
482
483         if (logger.isDebugEnabled()) {
484             logger.debug(testBanner(testName, CLASS_NAME));
485         }
486         // Perform setup.
487         setupUpdate();
488
489         // Submit the request to the service and store the response.
490         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
491         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
492         try {
493             assertStatusCode(res, testName);
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_TAXON_FULL_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_TAXON_FULL_NAME);
509             expectedDisplayName =
510                     TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_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             assertStatusCode(res, testName);
519             // Retrieve the updated resource and verify that its contents exist.
520             input = new PoxPayloadIn(res.getEntity());
521             TaxonCommon updatedTaxon =
522                     (TaxonCommon) extractPart(input,
523                     client.getItemCommonPartName(), TaxonCommon.class);
524             Assert.assertNotNull(updatedTaxon);
525
526             // Verify that the updated resource received the correct data.
527             Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
528                     "Updated ForeName in Taxonomy did not match submitted data.");
529             // Verify that the updated resource computes the right displayName.
530             Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
531                     "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
532
533             // Now Update the displayName, not computed and verify the computed name is overriden.
534             taxon.setDisplayNameComputed(false);
535             expectedDisplayName = "TestName";
536             taxon.setDisplayName(expectedDisplayName);
537
538             // Submit the updated resource to the service and store the response.
539             output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
540             commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
541             commonPart.setLabel(client.getItemCommonPartName());
542             res.releaseConnection();
543             res = client.updateItem(knownResourceId, knownItemResourceId, output);
544             assertStatusCode(res, testName);
545             // Retrieve the updated resource and verify that its contents exist.
546             input = new PoxPayloadIn(res.getEntity());
547             updatedTaxon =
548                     (TaxonCommon) extractPart(input,
549                     client.getItemCommonPartName(), TaxonCommon.class);
550             Assert.assertNotNull(updatedTaxon);
551
552             // Verify that the updated resource received the correct data.
553             Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
554                     "Updated displayNameComputed in Taxonomy did not match submitted data.");
555             // Verify that the updated resource computes the right displayName.
556             Assert.assertEquals(updatedTaxon.getDisplayName(),
557                     expectedDisplayName,
558                     "Updated DisplayName (not computed) in Taxonomy not stored.");
559         } finally {
560             res.releaseConnection();
561         }
562     }
563
564     /**
565      * Verify illegal item display name.
566      *
567      * @param testName the test name
568      * @throws Exception the exception
569      */
570     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
571     dependsOnMethods = {"verifyItemDisplayName"})
572     public void verifyIllegalItemDisplayName(String testName) throws Exception {
573
574         if (logger.isDebugEnabled()) {
575             logger.debug(testBanner(testName, CLASS_NAME));
576         }
577
578         // Perform setup for read.
579         setupRead();
580
581         // Submit the request to the service and store the response.
582         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
583         ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
584         assertStatusCode(res, testName);
585         
586         // Perform setup for update.
587         testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
588         
589         try {
590             // Check whether Taxonomy has expected displayName.
591             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
592             TaxonCommon taxon = (TaxonCommon) extractPart(input,
593                     client.getItemCommonPartName(), TaxonCommon.class);
594             Assert.assertNotNull(taxon);
595             // Try to Update with computed false and no displayName
596             taxon.setDisplayNameComputed(false);
597             taxon.setDisplayName(null);
598
599             // Submit the updated resource to the service and store the response.
600             PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
601             PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
602             commonPart.setLabel(client.getItemCommonPartName());
603             res.releaseConnection();
604             res = client.updateItem(knownResourceId, knownItemResourceId, output);
605             assertStatusCode(res, testName);
606         } finally {
607             res.releaseConnection();
608         }
609     }
610
611     // Failure outcomes
612     /* (non-Javadoc)
613      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
614      */
615     @Override
616     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
617     groups = {"read"}, dependsOnMethods = {"read"})
618     public void readNonExistent(String testName) {
619
620         if (logger.isDebugEnabled()) {
621             logger.debug(testBanner(testName, CLASS_NAME));
622         }
623         // Perform setup.
624         setupReadNonExistent();
625
626         // Submit the request to the service and store the response.
627         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
628         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
629         try {
630             int statusCode = res.getStatus();
631
632             // Check the status code of the response: does it match
633             // the expected response(s)?
634             if (logger.isDebugEnabled()) {
635                 logger.debug(testName + ": status = " + statusCode);
636             }
637             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
638                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
639             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
640         } finally {
641             res.releaseConnection();
642         }
643     }
644
645     /**
646      * Read item non existent.
647      *
648      * @param testName the test name
649      */
650     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
651     groups = {"read"}, dependsOnMethods = {"readItem"})
652     public void readItemNonExistent(String testName) {
653
654         if (logger.isDebugEnabled()) {
655             logger.debug(testBanner(testName, CLASS_NAME));
656         }
657         // Perform setup.
658         setupReadNonExistent();
659
660         // Submit the request to the service and store the response.
661         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
662         ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
663         try {
664             int statusCode = res.getStatus();
665
666             // Check the status code of the response: does it match
667             // the expected response(s)?
668             if (logger.isDebugEnabled()) {
669                 logger.debug(testName + ": status = " + statusCode);
670             }
671             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
672                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
673             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
674         } finally {
675             res.releaseConnection();
676         }
677     }
678
679     // ---------------------------------------------------------------
680     // CRUD tests : READ_LIST tests
681     // ---------------------------------------------------------------
682     // Success outcomes
683
684     /* (non-Javadoc)
685      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
686      */
687     @Override
688     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
689     groups = {"readList"}, dependsOnGroups = {"createList", "read"})
690     public void readList(String testName) throws Exception {
691
692         if (logger.isDebugEnabled()) {
693             logger.debug(testBanner(testName, CLASS_NAME));
694         }
695         // Perform setup.
696         setupReadList();
697
698         // Submit the request to the service and store the response.
699         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
700         ClientResponse<AbstractCommonList> res = client.readList();
701         try {
702             assertStatusCode(res, testName);
703                 AbstractCommonList list = res.getEntity();
704             // Optionally output additional data about list members for debugging.
705             if(logger.isTraceEnabled()){
706                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
707             }
708         } finally {
709             res.releaseConnection();
710         }
711     }
712
713     /**
714      * Read item list.
715      */
716     @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
717     public void readItemList() {
718         String testName = "readItemList";
719         if (logger.isDebugEnabled()) {
720             logger.debug(testBanner(testName, CLASS_NAME));
721         }
722         readItemList(knownResourceId, null);
723     }
724
725     /**
726      * Read item list by authority name.
727      */
728     @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
729     public void readItemListByAuthorityName() {
730         String testName = "readItemListByAuthorityName";
731         if (logger.isDebugEnabled()) {
732             logger.debug(testBanner(testName, CLASS_NAME));
733         }
734         readItemList(null, knownResourceShortIdentifer);
735     }
736
737     /**
738      * Read item list.
739      *
740      * @param vcsid the vcsid
741      * @param name the name
742      */
743     private void readItemList(String vcsid, String shortId) {
744
745         String testName = "readItemList";
746
747         // Perform setup.
748         setupReadList();
749
750         // Submit the request to the service and store the response.
751         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
752         ClientResponse<AbstractCommonList> res = null;
753         if (vcsid != null) {
754             res = client.readItemList(vcsid, null, null);
755         } else if (shortId != null) {
756             res = client.readItemListForNamedAuthority(shortId, null, null);
757         } else {
758             Assert.fail("readItemList passed null csid and name!");
759         }
760         try {
761             assertStatusCode(res, testName);
762                 AbstractCommonList list = res.getEntity();
763             List<AbstractCommonList.ListItem> items =
764                     list.getListItem();
765             int nItemsReturned = items.size();
766             // There will be one item created, associated with a
767             // known parent resource, by the createItem test.
768             //
769             // In addition, there will be 'nItemsToCreateInList'
770             // additional items created by the createItemList test,
771             // all associated with the same parent resource.
772             int nExpectedItems = nItemsToCreateInList + 1;
773             if (logger.isDebugEnabled()) {
774                 logger.debug(testName + ": Expected "
775                         + nExpectedItems + " items; got: " + nItemsReturned);
776             }
777             Assert.assertEquals(nItemsReturned, nExpectedItems);
778
779             for (AbstractCommonList.ListItem item : items) {
780                 String value = 
781                         AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
782                 Assert.assertTrue((null != value), "Item refName is null!");
783                 value = 
784                         AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
785                 Assert.assertTrue((null != value), "Item displayName is null!");
786             }
787             if(logger.isTraceEnabled()){
788                 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
789             }
790         } finally {
791             res.releaseConnection();
792         }
793     }
794
795     // Failure outcomes
796     // None at present.
797     // ---------------------------------------------------------------
798     // CRUD tests : UPDATE tests
799     // ---------------------------------------------------------------
800     // Success outcomes
801     /* (non-Javadoc)
802      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
803      */
804     @Override
805     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
806     groups = {"update"}, dependsOnGroups = {"read", "readList"})
807     public void update(String testName) throws Exception {
808
809         if (logger.isDebugEnabled()) {
810             logger.debug(testBanner(testName, CLASS_NAME));
811         }
812         // Perform setup.
813         setupUpdate();
814
815         // Retrieve the contents of a resource to update.
816         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
817         ClientResponse<String> res = client.read(knownResourceId);
818         try {
819             if (logger.isDebugEnabled()) {
820                 logger.debug(testName + ": read status = " + res.getStatus());
821             }
822             Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
823
824             if (logger.isDebugEnabled()) {
825                 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
826             }
827             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
828             TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
829                     client.getCommonPartName(), TaxonomyauthorityCommon.class);
830             Assert.assertNotNull(taxonomyAuthority);
831
832             // Update the contents of this resource.
833             taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
834             taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
835             if (logger.isDebugEnabled()) {
836                 logger.debug("to be updated TaxonomyAuthority");
837                 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
838             }
839
840             // Submit the updated resource to the service and store the response.
841             PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
842             PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
843             commonPart.setLabel(client.getCommonPartName());
844             res.releaseConnection();
845             res = client.update(knownResourceId, output);
846             int statusCode = res.getStatus();
847
848             // Check the status code of the response: does it match the expected response(s)?
849             if (logger.isDebugEnabled()) {
850                 logger.debug(testName + ": status = " + statusCode);
851             }
852             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
855
856             // Retrieve the updated resource and verify that its contents exist.
857             input = new PoxPayloadIn(res.getEntity());
858             TaxonomyauthorityCommon updatedTaxonomyAuthority =
859                     (TaxonomyauthorityCommon) extractPart(input,
860                     client.getCommonPartName(), TaxonomyauthorityCommon.class);
861             Assert.assertNotNull(updatedTaxonomyAuthority);
862
863             // Verify that the updated resource received the correct data.
864             Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
865                     taxonomyAuthority.getDisplayName(),
866                     "Data in updated object did not match submitted data.");
867         } finally {
868             res.releaseConnection();
869         }
870     }
871
872     /**
873      * Update item.
874      *
875      * @param testName the test name
876      * @throws Exception the exception
877      */
878     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
879     groups = {"update"}, dependsOnMethods = {"update"})
880     public void updateItem(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 =
891                 client.readItem(knownResourceId, knownItemResourceId);
892         try {
893             assertStatusCode(res, testName);
894             if (logger.isDebugEnabled()) {
895                 logger.debug("got Taxonomy to update with ID: "
896                         + knownItemResourceId
897                         + " in TaxonomyAuthority: " + knownResourceId);
898             }
899             PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
900             TaxonCommon taxon = (TaxonCommon) extractPart(input,
901                     client.getItemCommonPartName(), TaxonCommon.class);
902             Assert.assertNotNull(taxon);
903
904             // Update the contents of this resource.
905             taxon.setCsid(null);
906             taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
907             if (logger.isDebugEnabled()) {
908                 logger.debug("to be updated Taxonomy");
909                 logger.debug(objectAsXmlString(taxon,
910                         TaxonCommon.class));
911             }
912
913             // Submit the updated resource to the service and store the response.
914             PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
915             PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
916             commonPart.setLabel(client.getItemCommonPartName());
917             res.releaseConnection();
918             res = client.updateItem(knownResourceId, knownItemResourceId, output);
919             assertStatusCode(res, testName);
920
921             // Retrieve the updated resource and verify that its contents exist.
922             input = new PoxPayloadIn(res.getEntity());
923             TaxonCommon updatedTaxon =
924                     (TaxonCommon) extractPart(input,
925                     client.getItemCommonPartName(), TaxonCommon.class);
926             Assert.assertNotNull(updatedTaxon);
927
928             // Verify that the updated resource received the correct data.
929             Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
930                     "Data in updated Taxon did not match submitted data.");
931         } finally {
932             res.releaseConnection();
933         }
934     }
935
936     // Failure outcomes
937     // Placeholders until the three tests below can be uncommented.
938     // See Issue CSPACE-401.
939     /* (non-Javadoc)
940      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
941      */
942     @Override
943     public void updateWithEmptyEntityBody(String testName) throws Exception {
944     }
945
946     /* (non-Javadoc)
947      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
948      */
949     @Override
950     public void updateWithMalformedXml(String testName) throws Exception {
951     }
952
953     /* (non-Javadoc)
954      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
955      */
956     @Override
957     public void updateWithWrongXmlSchema(String testName) throws Exception {
958     }
959
960
961     /* (non-Javadoc)
962      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
963      */
964     @Override
965     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
966     groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
967     public void updateNonExistent(String testName) throws Exception {
968
969         if (logger.isDebugEnabled()) {
970             logger.debug(testBanner(testName, CLASS_NAME));
971         }
972         // Perform setup.
973         setupUpdateNonExistent();
974
975         // Submit the request to the service and store the response.
976         // Note: The ID(s) used when creating the request payload may be arbitrary.
977         // The only relevant ID may be the one used in update(), below.
978         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
979         String displayName = "displayName-NON_EXISTENT_ID";
980         PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
981                 displayName, "nonEx", client.getCommonPartName());
982         ClientResponse<String> res =
983                 client.update(NON_EXISTENT_ID, multipart);
984         try {
985             int statusCode = res.getStatus();
986
987             // Check the status code of the response: does it match
988             // the expected response(s)?
989             if (logger.isDebugEnabled()) {
990                 logger.debug(testName + ": status = " + statusCode);
991             }
992             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
993                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
994             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
995         } finally {
996             res.releaseConnection();
997         }
998     }
999
1000     /**
1001      * Update non existent item.
1002      *
1003      * @param testName the test name
1004      * @throws Exception the exception
1005      */
1006     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1007     groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1008     public void updateNonExistentItem(String testName) throws Exception {
1009
1010         if (logger.isDebugEnabled()) {
1011             logger.debug(testBanner(testName, CLASS_NAME));
1012         }
1013         // Perform setup.
1014         setupUpdateNonExistent();
1015
1016         // Submit the request to the service and store the response.
1017         // Note: The ID used in this 'create' call may be arbitrary.
1018         // The only relevant ID may be the one used in update(), below.
1019         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1020         Map<String, String> nonexMap = new HashMap<String, String>();
1021         nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
1022         nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1023         nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
1024         // PoxPayloadOut multipart =
1025         //        TaxonomyAuthorityClientUtils.createTaxonInstance(
1026         //        TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1027         //        nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST,
1028         //        client.getItemCommonPartName());
1029         final String EMPTY_REFNAME = "";
1030         PoxPayloadOut multipart =
1031                 TaxonomyAuthorityClientUtils.createTaxonInstance(EMPTY_REFNAME,
1032                 nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST,
1033                 client.getItemCommonPartName());
1034         ClientResponse<String> res =
1035                 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1036         try {
1037             int statusCode = res.getStatus();
1038
1039             // Check the status code of the response: does it match
1040             // the expected response(s)?
1041             if (logger.isDebugEnabled()) {
1042                 logger.debug(testName + ": status = " + statusCode);
1043             }
1044             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1045                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1046             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1047         } finally {
1048             res.releaseConnection();
1049         }
1050     }
1051
1052     // ---------------------------------------------------------------
1053     // CRUD tests : DELETE tests
1054     // ---------------------------------------------------------------
1055     // Success outcomes
1056     // Note: delete sub-resources in ascending hierarchical order,
1057     // before deleting their parents.
1058     /**
1059      * Delete item.
1060      *
1061      * @param testName the test name
1062      * @throws Exception the exception
1063      */
1064     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1065     //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1066     groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1067     public void deleteItem(String testName) throws Exception {
1068
1069         if (logger.isDebugEnabled()) {
1070             logger.debug(testBanner(testName, CLASS_NAME));
1071         }
1072         // Perform setup.
1073         setupDelete();
1074
1075         if (logger.isDebugEnabled()) {
1076             logger.debug("parentcsid =" + knownResourceId
1077                     + " itemcsid = " + knownItemResourceId);
1078         }
1079
1080         // Submit the request to the service and store the response.
1081         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1082         ClientResponse<Response> res =
1083                 client.deleteItem(knownResourceId, knownItemResourceId);
1084         try {
1085             int statusCode = res.getStatus();
1086
1087             // Check the status code of the response: does it match
1088             // the expected response(s)?
1089             if (logger.isDebugEnabled()) {
1090                 logger.debug(testName + ": status = " + statusCode);
1091             }
1092             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1093                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1094             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1095         } finally {
1096             res.releaseConnection();
1097         }
1098     }
1099
1100     /* (non-Javadoc)
1101      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1102      */
1103     @Override
1104     // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1105     // groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1106     public void delete(String testName) throws Exception {
1107
1108         if (logger.isDebugEnabled()) {
1109             logger.debug(testBanner(testName, CLASS_NAME));
1110         }
1111         // Perform setup.
1112         setupDelete();
1113
1114         if (logger.isDebugEnabled()) {
1115             logger.debug("parentcsid =" + knownResourceId);
1116         }
1117
1118         // Submit the request to the service and store the response.
1119         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1120         ClientResponse<Response> res = client.delete(knownResourceId);
1121         try {
1122             int statusCode = res.getStatus();
1123
1124             // Check the status code of the response: does it match
1125             // the expected response(s)?
1126             if (logger.isDebugEnabled()) {
1127                 logger.debug(testName + ": status = " + statusCode);
1128             }
1129             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1130                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1131             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1132         } finally {
1133             res.releaseConnection();
1134         }
1135     }
1136
1137     // Failure outcomes
1138     /* (non-Javadoc)
1139      * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1140      */
1141     @Override
1142     // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1143     // groups = {"delete"}, dependsOnMethods = {"delete"})
1144     public void deleteNonExistent(String testName) throws Exception {
1145
1146         if (logger.isDebugEnabled()) {
1147             logger.debug(testBanner(testName, CLASS_NAME));
1148         }
1149         // Perform setup.
1150         setupDeleteNonExistent();
1151
1152         // Submit the request to the service and store the response.
1153         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1154         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1155         try {
1156             int statusCode = res.getStatus();
1157
1158             // Check the status code of the response: does it match
1159             // the expected response(s)?
1160             if (logger.isDebugEnabled()) {
1161                 logger.debug(testName + ": status = " + statusCode);
1162             }
1163             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1164                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1165             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1166         } finally {
1167             res.releaseConnection();
1168         }
1169     }
1170
1171     /**
1172      * Delete non existent item.
1173      *
1174      * @param testName the test name
1175      */
1176     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1177     groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1178     public void deleteNonExistentItem(String testName) {
1179
1180         if (logger.isDebugEnabled()) {
1181             logger.debug(testBanner(testName, CLASS_NAME));
1182         }
1183         // Perform setup.
1184         setupDeleteNonExistent();
1185
1186         // Submit the request to the service and store the response.
1187         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1188         ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1189         try {
1190             int statusCode = res.getStatus();
1191
1192             // Check the status code of the response: does it match
1193             // the expected response(s)?
1194             if (logger.isDebugEnabled()) {
1195                 logger.debug(testName + ": status = " + statusCode);
1196             }
1197             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1198                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1199             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1200         } finally {
1201             res.releaseConnection();
1202         }
1203     }
1204
1205     // ---------------------------------------------------------------
1206     // Utility tests : tests of code used in tests above
1207     // ---------------------------------------------------------------
1208     /**
1209      * Tests the code for manually submitting data that is used by several
1210      * of the methods above.
1211      */
1212     @Test(dependsOnMethods = {"create", "read"})
1213     public void testSubmitRequest() {
1214
1215         // Expected status code: 200 OK
1216         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1217
1218         // Submit the request to the service and store the response.
1219         String method = ServiceRequestType.READ.httpMethodName();
1220         String url = getResourceURL(knownResourceId);
1221         int statusCode = submitRequest(method, url);
1222
1223         // Check the status code of the response: does it match
1224         // the expected response(s)?
1225         if (logger.isDebugEnabled()) {
1226             logger.debug("testSubmitRequest: url=" + url
1227                     + " status=" + statusCode);
1228         }
1229         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1230
1231     }
1232
1233     /**
1234      * Test item submit request.
1235      */
1236     @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1237     public void testItemSubmitRequest() {
1238
1239         // Expected status code: 200 OK
1240         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1241
1242         // Submit the request to the service and store the response.
1243         String method = ServiceRequestType.READ.httpMethodName();
1244         String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1245         int statusCode = submitRequest(method, url);
1246
1247         // Check the status code of the response: does it match
1248         // the expected response(s)?
1249         if (logger.isDebugEnabled()) {
1250             logger.debug("testItemSubmitRequest: url=" + url
1251                     + " status=" + statusCode);
1252         }
1253         Assert.assertEquals(statusCode, EXPECTED_STATUS);
1254
1255     }
1256
1257     // ---------------------------------------------------------------
1258     // Cleanup of resources created during testing
1259     // ---------------------------------------------------------------
1260     /**
1261      * Deletes all resources created by tests, after all tests have been run.
1262      *
1263      * This cleanup method will always be run, even if one or more tests fail.
1264      * For this reason, it attempts to remove all resources created
1265      * at any point during testing, even if some of those resources
1266      * may be expected to be deleted by certain tests.
1267      */
1268     @AfterClass(alwaysRun = true)
1269     public void cleanUp() {
1270         String noTest = System.getProperty("noTestCleanup");
1271         if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1272             if (logger.isDebugEnabled()) {
1273                 logger.debug("Skipping Cleanup phase ...");
1274             }
1275             return;
1276         }
1277         if (logger.isDebugEnabled()) {
1278             logger.debug("Cleaning up temporary resources created for testing ...");
1279         }
1280         String parentResourceId;
1281         String itemResourceId;
1282         // Clean up contact resources.
1283         TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1284         parentResourceId = knownResourceId;
1285         // Clean up item resources.
1286         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1287             itemResourceId = entry.getKey();
1288             parentResourceId = entry.getValue();
1289             // Note: Any non-success responses from the delete operation
1290             // below are ignored and not reported.
1291             ClientResponse<Response> res =
1292                     client.deleteItem(parentResourceId, itemResourceId);
1293             res.releaseConnection();
1294         }
1295         // Clean up parent resources.
1296         for (String resourceId : allResourceIdsCreated) {
1297             // Note: Any non-success responses from the delete operation
1298             // below are ignored and not reported.
1299             ClientResponse<Response> res = client.delete(resourceId);
1300             res.releaseConnection();
1301         }
1302     }
1303
1304     // ---------------------------------------------------------------
1305     // Utility methods used by tests above
1306     // ---------------------------------------------------------------
1307     /* (non-Javadoc)
1308      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1309      */
1310     /**
1311      * Returns the root URL for the item service.
1312      *
1313      * This URL consists of a base URL for all services, followed by
1314      * a path component for the owning parent, followed by the
1315      * path component for the items.
1316      *
1317      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1318      * parent authority resource of the relevant item resource.
1319      *
1320      * @return The root URL for the item service.
1321      */
1322     protected String getItemServiceRootURL(String parentResourceIdentifier) {
1323         return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1324     }
1325
1326     /**
1327      * Returns the URL of a specific item resource managed by a service, and
1328      * designated by an identifier (such as a universally unique ID, or UUID).
1329      *
1330      * @param  parentResourceIdentifier  An identifier (such as a UUID) for the
1331      * parent authority resource of the relevant item resource.
1332      *
1333      * @param  itemResourceIdentifier  An identifier (such as a UUID) for an
1334      * item resource.
1335      *
1336      * @return The URL of a specific item resource managed by a service.
1337      */
1338     protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1339         return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
1340     }
1341 }