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