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