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