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