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 String xml = input.getXmlPayload(); // for debugging
450 if (logger.isDebugEnabled()) { // for debugging
451 logger.debug(testName + "#########" + xml);
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));
462 Assert.assertEquals(taxon.getInAuthority(), knownResourceId);
464 res.releaseConnection();
469 * Verify item display name.
471 * @param testName the test name
472 * @throws Exception the exception
474 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
475 dependsOnMethods = {"readItem", "updateItem"})
476 public void verifyItemDisplayName(String testName) throws Exception {
478 if (logger.isDebugEnabled()) {
479 logger.debug(testBanner(testName, CLASS_NAME));
484 // Submit the request to the service and store the response.
485 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
486 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
488 int statusCode = res.getStatus();
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);
495 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
496 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
497 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
510 // Update the shortName and verify the computed name is updated.
512 taxon.setDisplayNameComputed(true);
513 taxon.setTaxonFullName("updated-" + TEST_NAME);
514 expectedDisplayName =
515 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
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();
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);
529 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
530 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
531 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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.");
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);
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();
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);
564 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
565 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
566 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
568 // Retrieve the updated resource and verify that its contents exist.
569 input = new PoxPayloadIn(res.getEntity());
571 (TaxonCommon) extractPart(input,
572 client.getItemCommonPartName(), TaxonCommon.class);
573 Assert.assertNotNull(updatedTaxon);
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(),
581 "Updated DisplayName (not computed) in Taxonomy not stored.");
583 res.releaseConnection();
588 * Verify illegal item display name.
590 * @param testName the test name
591 * @throws Exception the exception
593 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
594 dependsOnMethods = {"verifyItemDisplayName"})
595 public void verifyIllegalItemDisplayName(String testName) throws Exception {
597 if (logger.isDebugEnabled()) {
598 logger.debug(testBanner(testName, CLASS_NAME));
601 // FIXME: create a setup configuration for this operation.
602 setupUpdateWithWrongXmlSchema();
604 // Submit the request to the service and store the response.
605 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
606 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
608 int statusCode = res.getStatus();
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);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
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);
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();
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);
640 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
644 res.releaseConnection();
650 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
653 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
654 groups = {"read"}, dependsOnMethods = {"read"})
655 public void readNonExistent(String testName) {
657 if (logger.isDebugEnabled()) {
658 logger.debug(testBanner(testName, CLASS_NAME));
661 setupReadNonExistent();
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);
667 int statusCode = res.getStatus();
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);
674 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 res.releaseConnection();
683 * Read item non existent.
685 * @param testName the test name
687 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
688 groups = {"read"}, dependsOnMethods = {"readItem"})
689 public void readItemNonExistent(String testName) {
691 if (logger.isDebugEnabled()) {
692 logger.debug(testBanner(testName, CLASS_NAME));
695 setupReadNonExistent();
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);
701 int statusCode = res.getStatus();
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);
708 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
709 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
710 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 res.releaseConnection();
716 // ---------------------------------------------------------------
717 // CRUD tests : READ_LIST tests
718 // ---------------------------------------------------------------
722 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
725 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
726 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
727 public void readList(String testName) throws Exception {
729 if (logger.isDebugEnabled()) {
730 logger.debug(testBanner(testName, CLASS_NAME));
735 // Submit the request to the service and store the response.
736 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
737 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
739 TaxonomyauthorityCommonList list = res.getEntity();
740 int statusCode = res.getStatus();
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);
747 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
748 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
749 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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();
757 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
758 String csid = item.getCsid();
759 logger.debug(testName + ": list-item[" + i + "] csid="
761 logger.debug(testName + ": list-item[" + i + "] displayName="
762 + item.getDisplayName());
763 logger.debug(testName + ": list-item[" + i + "] URI="
765 readItemList(csid, null);
770 res.releaseConnection();
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));
783 readItemList(knownResourceId, null);
787 * Read item list by authority name.
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));
795 readItemList(null, knownResourceShortIdentifer);
801 * @param vcsid the vcsid
802 * @param name the name
804 private void readItemList(String vcsid, String shortId) {
806 String testName = "readItemList";
811 // Submit the request to the service and store the response.
812 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
813 ClientResponse<TaxonCommonList> res = null;
815 res = client.readItemList(vcsid, null, null);
816 } else if (shortId != null) {
817 res = client.readItemListForNamedAuthority(shortId, null, null);
819 Assert.fail("readItemList passed null csid and name!");
822 TaxonCommonList list = res.getEntity();
823 int statusCode = res.getStatus();
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);
830 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
831 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
832 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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.
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);
848 Assert.assertEquals(nItemsReturned, nExpectedItems);
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="
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="
869 res.releaseConnection();
875 // ---------------------------------------------------------------
876 // CRUD tests : UPDATE tests
877 // ---------------------------------------------------------------
880 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
883 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
884 groups = {"update"}, dependsOnGroups = {"read", "readList"})
885 public void update(String testName) throws Exception {
887 if (logger.isDebugEnabled()) {
888 logger.debug(testBanner(testName, CLASS_NAME));
893 // Retrieve the contents of a resource to update.
894 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
895 ClientResponse<String> res = client.read(knownResourceId);
897 if (logger.isDebugEnabled()) {
898 logger.debug(testName + ": read status = " + res.getStatus());
900 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
902 if (logger.isDebugEnabled()) {
903 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
905 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
906 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
907 client.getCommonPartName(), TaxonomyauthorityCommon.class);
908 Assert.assertNotNull(taxonomyAuthority);
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));
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();
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);
930 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
931 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
932 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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.");
946 res.releaseConnection();
953 * @param testName the test name
954 * @throws Exception the exception
956 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
957 groups = {"update"}, dependsOnMethods = {"update"})
958 public void updateItem(String testName) throws Exception {
960 if (logger.isDebugEnabled()) {
961 logger.debug(testBanner(testName, CLASS_NAME));
966 // Retrieve the contents of a resource to update.
967 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
968 ClientResponse<String> res =
969 client.readItem(knownResourceId, knownItemResourceId);
971 if (logger.isDebugEnabled()) {
972 logger.debug(testName + ": read status = " + res.getStatus());
974 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
976 if (logger.isDebugEnabled()) {
977 logger.debug("got Taxonomy to update with ID: "
978 + knownItemResourceId
979 + " in TaxonomyAuthority: " + knownResourceId);
981 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
982 TaxonCommon taxon = (TaxonCommon) extractPart(input,
983 client.getItemCommonPartName(), TaxonCommon.class);
984 Assert.assertNotNull(taxon);
986 // Update the contents of this resource.
988 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
989 if (logger.isDebugEnabled()) {
990 logger.debug("to be updated Taxonomy");
991 logger.debug(objectAsXmlString(taxon,
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();
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);
1007 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1008 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1009 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
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);
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.");
1022 res.releaseConnection();
1027 // Placeholders until the three tests below can be uncommented.
1028 // See Issue CSPACE-401.
1030 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1033 public void updateWithEmptyEntityBody(String testName) throws Exception {
1037 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1040 public void updateWithMalformedXml(String testName) throws Exception {
1044 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1047 public void updateWithWrongXmlSchema(String testName) throws Exception {
1052 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1055 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1056 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1057 public void updateNonExistent(String testName) throws Exception {
1059 if (logger.isDebugEnabled()) {
1060 logger.debug(testBanner(testName, CLASS_NAME));
1063 setupUpdateNonExistent();
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);
1075 int statusCode = res.getStatus();
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);
1082 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1083 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1084 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1086 res.releaseConnection();
1091 * Update non existent item.
1093 * @param testName the test name
1094 * @throws Exception the exception
1096 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1097 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1098 public void updateNonExistentItem(String testName) throws Exception {
1100 if (logger.isDebugEnabled()) {
1101 logger.debug(testBanner(testName, CLASS_NAME));
1104 setupUpdateNonExistent();
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);
1121 int statusCode = res.getStatus();
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);
1128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1130 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1132 res.releaseConnection();
1136 // ---------------------------------------------------------------
1137 // CRUD tests : DELETE tests
1138 // ---------------------------------------------------------------
1140 // Note: delete sub-resources in ascending hierarchical order,
1141 // before deleting their parents.
1145 * @param testName the test name
1146 * @throws Exception the exception
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 {
1153 if (logger.isDebugEnabled()) {
1154 logger.debug(testBanner(testName, CLASS_NAME));
1159 if (logger.isDebugEnabled()) {
1160 logger.debug("parentcsid =" + knownResourceId
1161 + " itemcsid = " + knownItemResourceId);
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);
1169 int statusCode = res.getStatus();
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);
1176 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1177 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1178 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1180 res.releaseConnection();
1185 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1188 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1189 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1190 public void delete(String testName) throws Exception {
1192 if (logger.isDebugEnabled()) {
1193 logger.debug(testBanner(testName, CLASS_NAME));
1198 if (logger.isDebugEnabled()) {
1199 logger.debug("parentcsid =" + knownResourceId);
1202 // Submit the request to the service and store the response.
1203 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1204 ClientResponse<Response> res = client.delete(knownResourceId);
1206 int statusCode = res.getStatus();
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);
1213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1217 res.releaseConnection();
1223 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1226 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1227 groups = {"delete"}, dependsOnMethods = {"delete"})
1228 public void deleteNonExistent(String testName) throws Exception {
1230 if (logger.isDebugEnabled()) {
1231 logger.debug(testBanner(testName, CLASS_NAME));
1234 setupDeleteNonExistent();
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);
1240 int statusCode = res.getStatus();
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);
1247 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1248 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1249 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1251 res.releaseConnection();
1256 * Delete non existent item.
1258 * @param testName the test name
1260 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1261 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1262 public void deleteNonExistentItem(String testName) {
1264 if (logger.isDebugEnabled()) {
1265 logger.debug(testBanner(testName, CLASS_NAME));
1268 setupDeleteNonExistent();
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);
1274 int statusCode = res.getStatus();
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);
1281 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1282 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1283 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1285 res.releaseConnection();
1289 // ---------------------------------------------------------------
1290 // Utility tests : tests of code used in tests above
1291 // ---------------------------------------------------------------
1293 * Tests the code for manually submitting data that is used by several
1294 * of the methods above.
1296 @Test(dependsOnMethods = {"create", "read"})
1297 public void testSubmitRequest() {
1299 // Expected status code: 200 OK
1300 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
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);
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);
1313 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1318 * Test item submit request.
1320 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1321 public void testItemSubmitRequest() {
1323 // Expected status code: 200 OK
1324 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
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);
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);
1337 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1341 // ---------------------------------------------------------------
1342 // Cleanup of resources created during testing
1343 // ---------------------------------------------------------------
1345 * Deletes all resources created by tests, after all tests have been run.
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.
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 ...");
1361 if (logger.isDebugEnabled()) {
1362 logger.debug("Cleaning up temporary resources created for testing ...");
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();
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();
1388 // ---------------------------------------------------------------
1389 // Utility methods used by tests above
1390 // ---------------------------------------------------------------
1392 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1395 * Returns the root URL for the item service.
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.
1401 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1402 * parent authority resource of the relevant item resource.
1404 * @return The root URL for the item service.
1406 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1407 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
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).
1414 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1415 * parent authority resource of the relevant item resource.
1417 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1420 * @return The URL of a specific item resource managed by a service.
1422 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1423 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;