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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
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;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46 import org.jboss.resteasy.client.ClientResponse;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.AfterClass;
53 import org.testng.annotations.Test;
56 * TaxonomyAuthorityServiceTest, carries out tests against a
57 * deployed and running TaxonomyAuthority Service.
59 * $LastChangedRevision$
62 public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class!
65 private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName();
66 private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class);
69 public String getServicePathComponent() {
70 return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
74 protected String getServiceName() {
75 return TaxonomyAuthorityClient.SERVICE_NAME;
78 public String getItemServicePathComponent() {
79 return AuthorityClient.ITEMS;
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>();
103 protected void setKnownResource(String id, String shortIdentifer,
105 knownResourceId = id;
106 knownResourceShortIdentifer = shortIdentifer;
107 knownResourceRefName = refName;
110 protected void setKnownItemResource(String id, String shortIdentifer) {
111 knownItemResourceId = id;
112 knownItemResourceShortIdentifer = shortIdentifer;
116 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
119 protected CollectionSpaceClient getClientInstance() {
120 return new TaxonomyAuthorityClient();
124 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
127 protected AbstractCommonList getAbstractCommonList(
128 ClientResponse<AbstractCommonList> response) {
129 return response.getEntity(TaxonCommonList.class);
133 protected PoxPayloadOut createInstance(String identifier) {
134 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
135 String shortId = identifier;
136 String displayName = "displayName-" + shortId;
138 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
139 PoxPayloadOut multipart =
140 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
141 displayName, shortId, client.getCommonPartName());
145 // ---------------------------------------------------------------
146 // CRUD tests : CREATE tests
147 // ---------------------------------------------------------------
150 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
153 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
155 public void create(String testName) throws Exception {
157 if (logger.isDebugEnabled()) {
158 logger.debug(testBanner(testName, CLASS_NAME));
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).
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;
170 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
172 PoxPayloadOut multipart =
173 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
174 displayName, shortId, client.getCommonPartName());
176 ClientResponse<Response> res = client.create(multipart);
178 int statusCode = res.getStatus();
180 // Check the status code of the response: does it match
181 // the expected response(s)?
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);
189 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
190 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
191 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
193 newID = TaxonomyAuthorityClientUtils.extractId(res);
195 res.releaseConnection();
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);
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);
213 * @param testName the test name
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));
222 createItemInAuthority(knownResourceId, knownResourceRefName);
226 * Creates the item in authority.
228 * @param vcsid the vcsid
229 * @param authRefName the auth ref name
232 private String createItemInAuthority(String vcsid, String authRefName) {
234 final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")";
235 if (logger.isDebugEnabled()) {
236 logger.debug(testBanner(testName, CLASS_NAME));
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.
249 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
250 authRefName, taxonMap, client);
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);
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);
270 // Placeholders until the three tests below can be uncommented.
271 // See Issue CSPACE-401.
273 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
276 public void createWithEmptyEntityBody(String testName) throws Exception {
280 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
283 public void createWithMalformedXml(String testName) throws Exception {
287 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
290 public void createWithWrongXmlSchema(String testName) throws Exception {
293 // ---------------------------------------------------------------
294 // CRUD tests : CREATE LIST tests
295 // ---------------------------------------------------------------
298 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
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++) {
310 * Creates the item list.
312 * @param testName the test name
313 * @throws Exception the exception
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);
324 // ---------------------------------------------------------------
325 // CRUD tests : READ tests
326 // ---------------------------------------------------------------
329 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
332 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
333 groups = {"read"}, dependsOnGroups = {"create"})
334 public void read(String testName) throws Exception {
336 if (logger.isDebugEnabled()) {
337 logger.debug(testBanner(testName, CLASS_NAME));
342 // Submit the request to the service and store the response.
343 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
345 ClientResponse<String> res = client.read(knownResourceId);
347 int statusCode = res.getStatus();
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);
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
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);
368 res.releaseConnection();
375 * @param testName the test name
376 * @throws Exception the exception
378 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
379 groups = {"read"}, dependsOnGroups = {"create"})
380 public void readByName(String testName) throws Exception {
382 if (logger.isDebugEnabled()) {
383 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
388 // Submit the request to the service and store the response.
389 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
390 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
392 int statusCode = res.getStatus();
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);
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
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);
412 res.releaseConnection();
419 * @param testName the test name
420 * @throws Exception the exception
422 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
423 groups = {"read"}, dependsOnMethods = {"read"})
424 public void readItem(String testName) throws Exception {
426 if (logger.isDebugEnabled()) {
427 logger.debug(testBanner(testName, CLASS_NAME));
432 // Submit the request to the service and store the response.
433 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
434 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
436 int statusCode = res.getStatus();
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);
443 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
444 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
445 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447 // Check whether we've received a taxon.
448 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
449 TaxonCommon taxon = (TaxonCommon) extractPart(input,
450 client.getItemCommonPartName(), TaxonCommon.class);
451 Assert.assertNotNull(taxon);
452 boolean showFull = true;
453 if (showFull && logger.isDebugEnabled()) {
454 logger.debug(testName + ": returned payload:");
455 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
457 Assert.assertEquals(taxon.getInAuthority(), knownResourceId);
459 res.releaseConnection();
464 * Verify item display name.
466 * @param testName the test name
467 * @throws Exception the exception
469 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
470 dependsOnMethods = {"readItem", "updateItem"})
471 public void verifyItemDisplayName(String testName) throws Exception {
473 if (logger.isDebugEnabled()) {
474 logger.debug(testBanner(testName, CLASS_NAME));
479 // Submit the request to the service and store the response.
480 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
481 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
483 int statusCode = res.getStatus();
485 // Check the status code of the response: does it match
486 // the expected response(s)?
487 if (logger.isDebugEnabled()) {
488 logger.debug(testName + ": status = " + statusCode);
490 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
491 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
492 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
494 // Check whether taxon has expected displayName.
495 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
496 TaxonCommon taxon = (TaxonCommon) extractPart(input,
497 client.getItemCommonPartName(), TaxonCommon.class);
498 Assert.assertNotNull(taxon);
499 String displayName = taxon.getDisplayName();
500 // Make sure displayName matches computed form
501 String expectedDisplayName =
502 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
503 Assert.assertNotNull(displayName, expectedDisplayName);
505 // Update the shortName and verify the computed name is updated.
507 taxon.setDisplayNameComputed(true);
508 taxon.setTaxonFullName("updated-" + TEST_NAME);
509 expectedDisplayName =
510 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
512 // Submit the updated resource to the service and store the response.
513 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
514 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
515 commonPart.setLabel(client.getItemCommonPartName());
516 res.releaseConnection();
517 res = client.updateItem(knownResourceId, knownItemResourceId, output);
518 statusCode = res.getStatus();
520 // Check the status code of the response: does it match the expected response(s)?
521 if (logger.isDebugEnabled()) {
522 logger.debug("updateItem: status = " + statusCode);
524 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
528 // Retrieve the updated resource and verify that its contents exist.
529 input = new PoxPayloadIn(res.getEntity());
530 TaxonCommon updatedTaxon =
531 (TaxonCommon) extractPart(input,
532 client.getItemCommonPartName(), TaxonCommon.class);
533 Assert.assertNotNull(updatedTaxon);
535 // Verify that the updated resource received the correct data.
536 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
537 "Updated ForeName in Taxonomy did not match submitted data.");
538 // Verify that the updated resource computes the right displayName.
539 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
540 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
542 // Now Update the displayName, not computed and verify the computed name is overriden.
543 taxon.setDisplayNameComputed(false);
544 expectedDisplayName = "TestName";
545 taxon.setDisplayName(expectedDisplayName);
547 // Submit the updated resource to the service and store the response.
548 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
549 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
550 commonPart.setLabel(client.getItemCommonPartName());
551 res.releaseConnection();
552 res = client.updateItem(knownResourceId, knownItemResourceId, output);
553 statusCode = res.getStatus();
555 // Check the status code of the response: does it match the expected response(s)?
556 if (logger.isDebugEnabled()) {
557 logger.debug("updateItem: status = " + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
563 // Retrieve the updated resource and verify that its contents exist.
564 input = new PoxPayloadIn(res.getEntity());
566 (TaxonCommon) extractPart(input,
567 client.getItemCommonPartName(), TaxonCommon.class);
568 Assert.assertNotNull(updatedTaxon);
570 // Verify that the updated resource received the correct data.
571 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
572 "Updated displayNameComputed in Taxonomy did not match submitted data.");
573 // Verify that the updated resource computes the right displayName.
574 Assert.assertEquals(updatedTaxon.getDisplayName(),
576 "Updated DisplayName (not computed) in Taxonomy not stored.");
578 res.releaseConnection();
583 * Verify illegal item display name.
585 * @param testName the test name
586 * @throws Exception the exception
588 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
589 dependsOnMethods = {"verifyItemDisplayName"})
590 public void verifyIllegalItemDisplayName(String testName) throws Exception {
592 if (logger.isDebugEnabled()) {
593 logger.debug(testBanner(testName, CLASS_NAME));
596 // FIXME: create a setup configuration for this operation.
597 setupUpdateWithWrongXmlSchema();
599 // Submit the request to the service and store the response.
600 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
601 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
603 int statusCode = res.getStatus();
605 // Check the status code of the response: does it match
606 // the expected response(s)?
607 if (logger.isDebugEnabled()) {
608 logger.debug(testName + ": status = " + statusCode);
610 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
614 // Check whether Taxonomy has expected displayName.
615 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
616 TaxonCommon taxon = (TaxonCommon) extractPart(input,
617 client.getItemCommonPartName(), TaxonCommon.class);
618 Assert.assertNotNull(taxon);
619 // Try to Update with computed false and no displayName
620 taxon.setDisplayNameComputed(false);
621 taxon.setDisplayName(null);
623 // Submit the updated resource to the service and store the response.
624 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
625 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
626 commonPart.setLabel(client.getItemCommonPartName());
627 res.releaseConnection();
628 res = client.updateItem(knownResourceId, knownItemResourceId, output);
629 statusCode = res.getStatus();
631 // Check the status code of the response: does it match the expected response(s)?
632 if (logger.isDebugEnabled()) {
633 logger.debug("updateItem: status = " + statusCode);
635 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
636 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
637 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
639 res.releaseConnection();
645 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
648 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
649 groups = {"read"}, dependsOnMethods = {"read"})
650 public void readNonExistent(String testName) {
652 if (logger.isDebugEnabled()) {
653 logger.debug(testBanner(testName, CLASS_NAME));
656 setupReadNonExistent();
658 // Submit the request to the service and store the response.
659 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
660 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
662 int statusCode = res.getStatus();
664 // Check the status code of the response: does it match
665 // the expected response(s)?
666 if (logger.isDebugEnabled()) {
667 logger.debug(testName + ": status = " + statusCode);
669 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
673 res.releaseConnection();
678 * Read item non existent.
680 * @param testName the test name
682 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
683 groups = {"read"}, dependsOnMethods = {"readItem"})
684 public void readItemNonExistent(String testName) {
686 if (logger.isDebugEnabled()) {
687 logger.debug(testBanner(testName, CLASS_NAME));
690 setupReadNonExistent();
692 // Submit the request to the service and store the response.
693 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
694 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
696 int statusCode = res.getStatus();
698 // Check the status code of the response: does it match
699 // the expected response(s)?
700 if (logger.isDebugEnabled()) {
701 logger.debug(testName + ": status = " + statusCode);
703 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
704 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
705 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
707 res.releaseConnection();
711 // ---------------------------------------------------------------
712 // CRUD tests : READ_LIST tests
713 // ---------------------------------------------------------------
717 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
720 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
721 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
722 public void readList(String testName) throws Exception {
724 if (logger.isDebugEnabled()) {
725 logger.debug(testBanner(testName, CLASS_NAME));
730 // Submit the request to the service and store the response.
731 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
732 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
734 TaxonomyauthorityCommonList list = res.getEntity();
735 int statusCode = res.getStatus();
737 // Check the status code of the response: does it match
738 // the expected response(s)?
739 if (logger.isDebugEnabled()) {
740 logger.debug(testName + ": status = " + statusCode);
742 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
743 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
744 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
746 // Optionally output additional data about list members for debugging.
747 boolean iterateThroughList = false;
748 if (iterateThroughList && logger.isDebugEnabled()) {
749 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
750 list.getTaxonomyauthorityListItem();
752 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
753 String csid = item.getCsid();
754 logger.debug(testName + ": list-item[" + i + "] csid="
756 logger.debug(testName + ": list-item[" + i + "] displayName="
757 + item.getDisplayName());
758 logger.debug(testName + ": list-item[" + i + "] URI="
760 readItemList(csid, null);
765 res.releaseConnection();
772 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
773 public void readItemList() {
774 String testName = "readItemList";
775 if (logger.isDebugEnabled()) {
776 logger.debug(testBanner(testName, CLASS_NAME));
778 readItemList(knownResourceId, null);
782 * Read item list by authority name.
784 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
785 public void readItemListByAuthorityName() {
786 String testName = "readItemListByAuthorityName";
787 if (logger.isDebugEnabled()) {
788 logger.debug(testBanner(testName, CLASS_NAME));
790 readItemList(null, knownResourceShortIdentifer);
796 * @param vcsid the vcsid
797 * @param name the name
799 private void readItemList(String vcsid, String shortId) {
801 String testName = "readItemList";
806 // Submit the request to the service and store the response.
807 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
808 ClientResponse<TaxonCommonList> res = null;
810 res = client.readItemList(vcsid, null, null);
811 } else if (shortId != null) {
812 res = client.readItemListForNamedAuthority(shortId, null, null);
814 Assert.fail("readItemList passed null csid and name!");
817 TaxonCommonList list = res.getEntity();
818 int statusCode = res.getStatus();
820 // Check the status code of the response: does it match
821 // the expected response(s)?
822 if (logger.isDebugEnabled()) {
823 logger.debug(testName + ": status = " + statusCode);
825 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
826 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
827 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
829 List<TaxonCommonList.TaxonListItem> items =
830 list.getTaxonListItem();
831 int nItemsReturned = items.size();
832 // There will be one item created, associated with a
833 // known parent resource, by the createItem test.
835 // In addition, there will be 'nItemsToCreateInList'
836 // additional items created by the createItemList test,
837 // all associated with the same parent resource.
838 int nExpectedItems = nItemsToCreateInList + 1;
839 if (logger.isDebugEnabled()) {
840 logger.debug(testName + ": Expected "
841 + nExpectedItems + " items; got: " + nItemsReturned);
843 Assert.assertEquals(nItemsReturned, nExpectedItems);
846 for (TaxonCommonList.TaxonListItem item : items) {
847 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
848 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
849 // Optionally output additional data about list members for debugging.
850 boolean showDetails = true;
851 if (showDetails && logger.isDebugEnabled()) {
852 logger.debug(" " + testName + ": list-item[" + i + "] csid="
854 logger.debug(" " + testName + ": list-item[" + i + "] refName="
855 + item.getRefName());
856 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
857 + item.getDisplayName());
858 logger.debug(" " + testName + ": list-item[" + i + "] URI="
864 res.releaseConnection();
870 // ---------------------------------------------------------------
871 // CRUD tests : UPDATE tests
872 // ---------------------------------------------------------------
875 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
878 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
879 groups = {"update"}, dependsOnGroups = {"read", "readList"})
880 public void update(String testName) throws Exception {
882 if (logger.isDebugEnabled()) {
883 logger.debug(testBanner(testName, CLASS_NAME));
888 // Retrieve the contents of a resource to update.
889 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
890 ClientResponse<String> res = client.read(knownResourceId);
892 if (logger.isDebugEnabled()) {
893 logger.debug(testName + ": read status = " + res.getStatus());
895 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
897 if (logger.isDebugEnabled()) {
898 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
900 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
901 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
902 client.getCommonPartName(), TaxonomyauthorityCommon.class);
903 Assert.assertNotNull(taxonomyAuthority);
905 // Update the contents of this resource.
906 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
907 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
908 if (logger.isDebugEnabled()) {
909 logger.debug("to be updated TaxonomyAuthority");
910 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
913 // Submit the updated resource to the service and store the response.
914 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
915 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
916 commonPart.setLabel(client.getCommonPartName());
917 res.releaseConnection();
918 res = client.update(knownResourceId, output);
919 int statusCode = res.getStatus();
921 // Check the status code of the response: does it match the expected response(s)?
922 if (logger.isDebugEnabled()) {
923 logger.debug(testName + ": status = " + statusCode);
925 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
926 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
927 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
929 // Retrieve the updated resource and verify that its contents exist.
930 input = new PoxPayloadIn(res.getEntity());
931 TaxonomyauthorityCommon updatedTaxonomyAuthority =
932 (TaxonomyauthorityCommon) extractPart(input,
933 client.getCommonPartName(), TaxonomyauthorityCommon.class);
934 Assert.assertNotNull(updatedTaxonomyAuthority);
936 // Verify that the updated resource received the correct data.
937 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
938 taxonomyAuthority.getDisplayName(),
939 "Data in updated object did not match submitted data.");
941 res.releaseConnection();
948 * @param testName the test name
949 * @throws Exception the exception
951 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
952 groups = {"update"}, dependsOnMethods = {"update"})
953 public void updateItem(String testName) throws Exception {
955 if (logger.isDebugEnabled()) {
956 logger.debug(testBanner(testName, CLASS_NAME));
961 // Retrieve the contents of a resource to update.
962 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
963 ClientResponse<String> res =
964 client.readItem(knownResourceId, knownItemResourceId);
966 if (logger.isDebugEnabled()) {
967 logger.debug(testName + ": read status = " + res.getStatus());
969 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
971 if (logger.isDebugEnabled()) {
972 logger.debug("got Taxonomy to update with ID: "
973 + knownItemResourceId
974 + " in TaxonomyAuthority: " + knownResourceId);
976 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
977 TaxonCommon taxon = (TaxonCommon) extractPart(input,
978 client.getItemCommonPartName(), TaxonCommon.class);
979 Assert.assertNotNull(taxon);
981 // Update the contents of this resource.
983 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
984 if (logger.isDebugEnabled()) {
985 logger.debug("to be updated Taxonomy");
986 logger.debug(objectAsXmlString(taxon,
990 // Submit the updated resource to the service and store the response.
991 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
992 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
993 commonPart.setLabel(client.getItemCommonPartName());
994 res.releaseConnection();
995 res = client.updateItem(knownResourceId, knownItemResourceId, output);
996 int statusCode = res.getStatus();
998 // Check the status code of the response: does it match the expected response(s)?
999 if (logger.isDebugEnabled()) {
1000 logger.debug(testName + ": status = " + statusCode);
1002 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1003 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1004 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1006 // Retrieve the updated resource and verify that its contents exist.
1007 input = new PoxPayloadIn(res.getEntity());
1008 TaxonCommon updatedTaxon =
1009 (TaxonCommon) extractPart(input,
1010 client.getItemCommonPartName(), TaxonCommon.class);
1011 Assert.assertNotNull(updatedTaxon);
1013 // Verify that the updated resource received the correct data.
1014 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1015 "Data in updated Taxonomy did not match submitted data.");
1017 res.releaseConnection();
1022 // Placeholders until the three tests below can be uncommented.
1023 // See Issue CSPACE-401.
1025 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1028 public void updateWithEmptyEntityBody(String testName) throws Exception {
1032 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1035 public void updateWithMalformedXml(String testName) throws Exception {
1039 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1042 public void updateWithWrongXmlSchema(String testName) throws Exception {
1047 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1050 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1051 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1052 public void updateNonExistent(String testName) throws Exception {
1054 if (logger.isDebugEnabled()) {
1055 logger.debug(testBanner(testName, CLASS_NAME));
1058 setupUpdateNonExistent();
1060 // Submit the request to the service and store the response.
1061 // Note: The ID(s) used when creating the request payload may be arbitrary.
1062 // The only relevant ID may be the one used in update(), below.
1063 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1064 String displayName = "displayName-NON_EXISTENT_ID";
1065 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1066 displayName, "nonEx", client.getCommonPartName());
1067 ClientResponse<String> res =
1068 client.update(NON_EXISTENT_ID, multipart);
1070 int statusCode = res.getStatus();
1072 // Check the status code of the response: does it match
1073 // the expected response(s)?
1074 if (logger.isDebugEnabled()) {
1075 logger.debug(testName + ": status = " + statusCode);
1077 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1078 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1079 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1081 res.releaseConnection();
1086 * Update non existent item.
1088 * @param testName the test name
1089 * @throws Exception the exception
1091 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1092 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1093 public void updateNonExistentItem(String testName) throws Exception {
1095 if (logger.isDebugEnabled()) {
1096 logger.debug(testBanner(testName, CLASS_NAME));
1099 setupUpdateNonExistent();
1101 // Submit the request to the service and store the response.
1102 // Note: The ID used in this 'create' call may be arbitrary.
1103 // The only relevant ID may be the one used in update(), below.
1104 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1105 Map<String, String> nonexMap = new HashMap<String, String>();
1106 nonexMap.put(TaxonJAXBSchema.NAME, TEST_NAME);
1107 nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1108 nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_STATUS);
1109 PoxPayloadOut multipart =
1110 TaxonomyAuthorityClientUtils.createTaxonInstance(
1111 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1112 nonexMap, client.getItemCommonPartName());
1113 ClientResponse<String> res =
1114 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1116 int statusCode = res.getStatus();
1118 // Check the status code of the response: does it match
1119 // the expected response(s)?
1120 if (logger.isDebugEnabled()) {
1121 logger.debug(testName + ": status = " + statusCode);
1123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1127 res.releaseConnection();
1131 // ---------------------------------------------------------------
1132 // CRUD tests : DELETE tests
1133 // ---------------------------------------------------------------
1135 // Note: delete sub-resources in ascending hierarchical order,
1136 // before deleting their parents.
1140 * @param testName the test name
1141 * @throws Exception the exception
1143 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1144 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1145 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1146 public void deleteItem(String testName) throws Exception {
1148 if (logger.isDebugEnabled()) {
1149 logger.debug(testBanner(testName, CLASS_NAME));
1154 if (logger.isDebugEnabled()) {
1155 logger.debug("parentcsid =" + knownResourceId
1156 + " itemcsid = " + knownItemResourceId);
1159 // Submit the request to the service and store the response.
1160 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1161 ClientResponse<Response> res =
1162 client.deleteItem(knownResourceId, knownItemResourceId);
1164 int statusCode = res.getStatus();
1166 // Check the status code of the response: does it match
1167 // the expected response(s)?
1168 if (logger.isDebugEnabled()) {
1169 logger.debug(testName + ": status = " + statusCode);
1171 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1172 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1173 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1175 res.releaseConnection();
1180 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1183 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1184 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1185 public void delete(String testName) throws Exception {
1187 if (logger.isDebugEnabled()) {
1188 logger.debug(testBanner(testName, CLASS_NAME));
1193 if (logger.isDebugEnabled()) {
1194 logger.debug("parentcsid =" + knownResourceId);
1197 // Submit the request to the service and store the response.
1198 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1199 ClientResponse<Response> res = client.delete(knownResourceId);
1201 int statusCode = res.getStatus();
1203 // Check the status code of the response: does it match
1204 // the expected response(s)?
1205 if (logger.isDebugEnabled()) {
1206 logger.debug(testName + ": status = " + statusCode);
1208 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1209 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1210 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1212 res.releaseConnection();
1218 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1221 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1222 groups = {"delete"}, dependsOnMethods = {"delete"})
1223 public void deleteNonExistent(String testName) throws Exception {
1225 if (logger.isDebugEnabled()) {
1226 logger.debug(testBanner(testName, CLASS_NAME));
1229 setupDeleteNonExistent();
1231 // Submit the request to the service and store the response.
1232 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1233 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1235 int statusCode = res.getStatus();
1237 // Check the status code of the response: does it match
1238 // the expected response(s)?
1239 if (logger.isDebugEnabled()) {
1240 logger.debug(testName + ": status = " + statusCode);
1242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1244 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1246 res.releaseConnection();
1251 * Delete non existent item.
1253 * @param testName the test name
1255 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1256 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1257 public void deleteNonExistentItem(String testName) {
1259 if (logger.isDebugEnabled()) {
1260 logger.debug(testBanner(testName, CLASS_NAME));
1263 setupDeleteNonExistent();
1265 // Submit the request to the service and store the response.
1266 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1267 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1269 int statusCode = res.getStatus();
1271 // Check the status code of the response: does it match
1272 // the expected response(s)?
1273 if (logger.isDebugEnabled()) {
1274 logger.debug(testName + ": status = " + statusCode);
1276 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1277 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1278 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1280 res.releaseConnection();
1284 // ---------------------------------------------------------------
1285 // Utility tests : tests of code used in tests above
1286 // ---------------------------------------------------------------
1288 * Tests the code for manually submitting data that is used by several
1289 * of the methods above.
1291 @Test(dependsOnMethods = {"create", "read"})
1292 public void testSubmitRequest() {
1294 // Expected status code: 200 OK
1295 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1297 // Submit the request to the service and store the response.
1298 String method = ServiceRequestType.READ.httpMethodName();
1299 String url = getResourceURL(knownResourceId);
1300 int statusCode = submitRequest(method, url);
1302 // Check the status code of the response: does it match
1303 // the expected response(s)?
1304 if (logger.isDebugEnabled()) {
1305 logger.debug("testSubmitRequest: url=" + url
1306 + " status=" + statusCode);
1308 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1313 * Test item submit request.
1315 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1316 public void testItemSubmitRequest() {
1318 // Expected status code: 200 OK
1319 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1321 // Submit the request to the service and store the response.
1322 String method = ServiceRequestType.READ.httpMethodName();
1323 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1324 int statusCode = submitRequest(method, url);
1326 // Check the status code of the response: does it match
1327 // the expected response(s)?
1328 if (logger.isDebugEnabled()) {
1329 logger.debug("testItemSubmitRequest: url=" + url
1330 + " status=" + statusCode);
1332 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1336 // ---------------------------------------------------------------
1337 // Cleanup of resources created during testing
1338 // ---------------------------------------------------------------
1340 * Deletes all resources created by tests, after all tests have been run.
1342 * This cleanup method will always be run, even if one or more tests fail.
1343 * For this reason, it attempts to remove all resources created
1344 * at any point during testing, even if some of those resources
1345 * may be expected to be deleted by certain tests.
1347 @AfterClass(alwaysRun = true)
1348 public void cleanUp() {
1349 String noTest = System.getProperty("noTestCleanup");
1350 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1351 if (logger.isDebugEnabled()) {
1352 logger.debug("Skipping Cleanup phase ...");
1356 if (logger.isDebugEnabled()) {
1357 logger.debug("Cleaning up temporary resources created for testing ...");
1359 String parentResourceId;
1360 String itemResourceId;
1361 // Clean up contact resources.
1362 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1363 parentResourceId = knownResourceId;
1364 // Clean up item resources.
1365 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1366 itemResourceId = entry.getKey();
1367 parentResourceId = entry.getValue();
1368 // Note: Any non-success responses from the delete operation
1369 // below are ignored and not reported.
1370 ClientResponse<Response> res =
1371 client.deleteItem(parentResourceId, itemResourceId);
1372 res.releaseConnection();
1374 // Clean up parent resources.
1375 for (String resourceId : allResourceIdsCreated) {
1376 // Note: Any non-success responses from the delete operation
1377 // below are ignored and not reported.
1378 ClientResponse<Response> res = client.delete(resourceId);
1379 res.releaseConnection();
1383 // ---------------------------------------------------------------
1384 // Utility methods used by tests above
1385 // ---------------------------------------------------------------
1387 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1390 * Returns the root URL for the item service.
1392 * This URL consists of a base URL for all services, followed by
1393 * a path component for the owning parent, followed by the
1394 * path component for the items.
1396 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1397 * parent authority resource of the relevant item resource.
1399 * @return The root URL for the item service.
1401 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1402 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1406 * Returns the URL of a specific item resource managed by a service, and
1407 * designated by an identifier (such as a universally unique ID, or UUID).
1409 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1410 * parent authority resource of the relevant item resource.
1412 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1415 * @return The URL of a specific item resource managed by a service.
1417 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1418 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;