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_SHORTID = "CentauruspleurexanthemusGreen1832";
82 final String TEST_TERM_STATUS = "accepted";
83 final String TEST_TAXON_FULL_NAME = "Centaurus pleurexanthemus Green 1832";
84 // TODO Re-implement the Taxon Rank field so as to provide an orderable
85 // ranking value, as well as a display name.
86 final String TEST_TAXON_RANK = "species";
87 final String TEST_TAXON_CURRENCY = "current";
88 final String TEST_TAXON_YEAR = "1832";
89 final String TEST_TAXONOMIC_STATUS = "valid";
90 final boolean TEST_TAXON_IS_NAMED_HYBRID = false;
91 /** The known resource id. */
92 private String knownResourceId = null;
93 private String knownResourceShortIdentifer = null;
94 private String knownResourceRefName = null;
95 private String knownTaxonomyTypeRefName = null;
96 private String knownItemResourceId = null;
97 private String knownItemResourceShortIdentifer = null;
98 /** The n items to create in list. */
99 private int nItemsToCreateInList = 3;
100 /** The all resource ids created. */
101 private List<String> allResourceIdsCreated = new ArrayList<String>();
102 /** The all item resource ids created. */
103 private Map<String, String> allItemResourceIdsCreated =
104 new HashMap<String, String>();
106 protected void setKnownResource(String id, String shortIdentifer,
108 knownResourceId = id;
109 knownResourceShortIdentifer = shortIdentifer;
110 knownResourceRefName = refName;
113 protected void setKnownItemResource(String id, String shortIdentifer) {
114 knownItemResourceId = id;
115 knownItemResourceShortIdentifer = shortIdentifer;
119 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
122 protected CollectionSpaceClient getClientInstance() {
123 return new TaxonomyAuthorityClient();
127 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
130 protected AbstractCommonList getAbstractCommonList(
131 ClientResponse<AbstractCommonList> response) {
132 return response.getEntity(TaxonCommonList.class);
136 protected PoxPayloadOut createInstance(String identifier) {
137 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
138 String shortId = identifier;
139 String displayName = "displayName-" + shortId;
141 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
142 PoxPayloadOut multipart =
143 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
144 displayName, shortId, client.getCommonPartName());
148 // ---------------------------------------------------------------
149 // CRUD tests : CREATE tests
150 // ---------------------------------------------------------------
153 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
156 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
158 public void create(String testName) throws Exception {
160 if (logger.isDebugEnabled()) {
161 logger.debug(testBanner(testName, CLASS_NAME));
163 // Perform setup, such as initializing the type of service request
164 // (e.g. CREATE, DELETE), its valid and expected status codes, and
165 // its associated HTTP method name (e.g. POST, DELETE).
168 // Submit the request to the service and store the response.
169 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
170 String shortId = createIdentifier();
171 String displayName = "displayName-" + shortId;
173 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
175 PoxPayloadOut multipart =
176 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
177 displayName, shortId, client.getCommonPartName());
179 ClientResponse<Response> res = client.create(multipart);
181 int statusCode = res.getStatus();
183 // Check the status code of the response: does it match
184 // the expected response(s)?
187 // Does it fall within the set of valid status codes?
188 // Does it exactly match the expected status code?
189 if (logger.isDebugEnabled()) {
190 logger.debug(testName + ": status = " + statusCode);
192 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
193 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
194 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
196 newID = TaxonomyAuthorityClientUtils.extractId(res);
198 res.releaseConnection();
200 // Store the ID returned from the first resource created
201 // for additional tests below.
202 if (knownResourceId == null) {
203 setKnownResource(newID, shortId, baseRefName);
204 if (logger.isDebugEnabled()) {
205 logger.debug(testName + ": knownResourceId=" + knownResourceId);
208 // Store the IDs from every resource created by tests,
209 // so they can be deleted after tests have been run.
210 allResourceIdsCreated.add(newID);
216 * @param testName the test name
218 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
219 groups = {"create"}, dependsOnMethods = {"create"})
220 public void createItem(String testName) {
221 if (logger.isDebugEnabled()) {
222 logger.debug(testBanner(testName, CLASS_NAME));
225 createItemInAuthority(knownResourceId, knownResourceRefName);
229 * Creates the item in authority.
231 * @param vcsid the vcsid
232 * @param authRefName the auth ref name
235 private String createItemInAuthority(String vcsid, String authRefName) {
237 final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")";
238 if (logger.isDebugEnabled()) {
239 logger.debug(testBanner(testName, CLASS_NAME));
242 // Submit the request to the service and store the response.
243 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
244 Map<String, String> taxonMap = new HashMap<String, String>();
246 // Fields present in all authority records.
247 taxonMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
248 // TODO Make term status be controlled vocab.
249 taxonMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
251 // Fields specific to this specific authority record type.
252 taxonMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
253 taxonMap.put(TaxonJAXBSchema.TAXON_RANK, TEST_TAXON_RANK);
254 taxonMap.put(TaxonJAXBSchema.TAXON_CURRENCY, TEST_TAXON_CURRENCY);
255 taxonMap.put(TaxonJAXBSchema.TAXON_YEAR, TEST_TAXON_YEAR);
256 taxonMap.put(TaxonJAXBSchema.TAXONOMIC_STATUS, TEST_TAXONOMIC_STATUS);
258 // FIXME: Add additional fields in the Taxon record here,
259 // including at least one each of:
260 // * a repeatable field
261 // * a repeatable group of fields
263 // * an authref field (when implemented)
265 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
266 authRefName, taxonMap, client);
268 // Store the ID returned from the first item resource created
269 // for additional tests below.
270 if (knownItemResourceId == null) {
271 setKnownItemResource(newID, TEST_SHORTID);
272 if (logger.isDebugEnabled()) {
273 logger.debug(testName + ": knownItemResourceId=" + newID + " inAuthority=" + vcsid);
277 // Store the IDs from any item resources created
278 // by tests, along with the IDs of their parents, so these items
279 // can be deleted after all tests have been run.
280 allItemResourceIdsCreated.put(newID, vcsid);
286 // Placeholders until the three tests below can be uncommented.
287 // See Issue CSPACE-401.
289 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
292 public void createWithEmptyEntityBody(String testName) throws Exception {
296 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
299 public void createWithMalformedXml(String testName) throws Exception {
303 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
306 public void createWithWrongXmlSchema(String testName) throws Exception {
309 // ---------------------------------------------------------------
310 // CRUD tests : CREATE LIST tests
311 // ---------------------------------------------------------------
314 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
317 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
318 groups = {"createList"}, dependsOnGroups = {"create"})
319 public void createList(String testName) throws Exception {
320 for (int i = 0; i < nItemsToCreateInList; i++) {
326 * Creates the item list.
328 * @param testName the test name
329 * @throws Exception the exception
331 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
332 groups = {"createList"}, dependsOnMethods = {"createList"})
333 public void createItemList(String testName) throws Exception {
334 // Add items to the initially-created, known parent record.
335 for (int j = 0; j < nItemsToCreateInList; j++) {
336 createItem(testName);
340 // ---------------------------------------------------------------
341 // CRUD tests : READ tests
342 // ---------------------------------------------------------------
345 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
348 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
349 groups = {"read"}, dependsOnGroups = {"create"})
350 public void read(String testName) throws Exception {
352 if (logger.isDebugEnabled()) {
353 logger.debug(testBanner(testName, CLASS_NAME));
358 // Submit the request to the service and store the response.
359 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
361 ClientResponse<String> res = client.read(knownResourceId);
363 int statusCode = res.getStatus();
365 // Check the status code of the response: does it match
366 // the expected response(s)?
367 if (logger.isDebugEnabled()) {
368 logger.debug(testName + ": status = " + statusCode);
370 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
371 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
372 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
373 //FIXME: remove the following try catch once Aron fixes signatures
375 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
376 TaxonomyauthorityCommon taxonomyAuthority =
377 (TaxonomyauthorityCommon) extractPart(input,
378 client.getCommonPartName(), TaxonomyauthorityCommon.class);
379 Assert.assertNotNull(taxonomyAuthority);
380 } catch (Exception e) {
381 throw new RuntimeException(e);
384 res.releaseConnection();
391 * @param testName the test name
392 * @throws Exception the exception
394 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
395 groups = {"read"}, dependsOnGroups = {"create"})
396 public void readByName(String testName) throws Exception {
398 if (logger.isDebugEnabled()) {
399 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
404 // Submit the request to the service and store the response.
405 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
406 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
408 int statusCode = res.getStatus();
410 // Check the status code of the response: does it match
411 // the expected response(s)?
412 if (logger.isDebugEnabled()) {
413 logger.debug(testName + ": status = " + statusCode);
415 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
416 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
417 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
418 //FIXME: remove the following try catch once Aron fixes signatures
420 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
421 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
422 client.getCommonPartName(), TaxonomyauthorityCommon.class);
423 Assert.assertNotNull(taxonomyAuthority);
424 } catch (Exception e) {
425 throw new RuntimeException(e);
428 res.releaseConnection();
435 * @param testName the test name
436 * @throws Exception the exception
438 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
439 groups = {"read"}, dependsOnMethods = {"read"})
440 public void readItem(String testName) throws Exception {
442 if (logger.isDebugEnabled()) {
443 logger.debug(testBanner(testName, CLASS_NAME));
448 // Submit the request to the service and store the response.
449 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
450 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
452 int statusCode = res.getStatus();
454 // Check the status code of the response: does it match
455 // the expected response(s)?
456 if (logger.isDebugEnabled()) {
457 logger.debug(testName + ": status = " + statusCode);
459 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
460 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
461 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
463 // Check whether we've received an authority item record.
464 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
465 TaxonCommon taxon = (TaxonCommon) extractPart(input,
466 client.getItemCommonPartName(), TaxonCommon.class);
467 Assert.assertNotNull(taxon);
468 boolean showFull = true;
469 if (showFull && logger.isDebugEnabled()) {
470 logger.debug(testName + ": returned payload:");
471 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
474 // Check that this authority item record has the correct identifier
475 // pointing to its parent authority record.
476 Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null.");
477 Assert.assertEquals(taxon.getInAuthority(), knownResourceId,
478 "Value of item's inAuthority field does not contain the correct identifier "
479 + "pointing to its parent authority record.");
481 // Check individual fields in the authority item record.
482 Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null.");
483 Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME,
484 "Field value " + taxon.getTaxonFullName()
485 + "does not match expected value " + TEST_TAXON_FULL_NAME);
487 res.releaseConnection();
492 * Verify item display name.
494 * @param testName the test name
495 * @throws Exception the exception
497 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
498 dependsOnMethods = {"readItem", "updateItem"})
499 public void verifyItemDisplayName(String testName) throws Exception {
501 if (logger.isDebugEnabled()) {
502 logger.debug(testBanner(testName, CLASS_NAME));
507 // Submit the request to the service and store the response.
508 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
509 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
511 int statusCode = res.getStatus();
513 // Check the status code of the response: does it match
514 // the expected response(s)?
515 if (logger.isDebugEnabled()) {
516 logger.debug(testName + ": status = " + statusCode);
518 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
519 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
520 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
522 // Check whether taxon has expected displayName.
523 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
524 TaxonCommon taxon = (TaxonCommon) extractPart(input,
525 client.getItemCommonPartName(), TaxonCommon.class);
526 Assert.assertNotNull(taxon);
527 String displayName = taxon.getDisplayName();
528 // Make sure displayName matches computed form
529 String expectedDisplayName =
530 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_TAXON_FULL_NAME);
531 Assert.assertNotNull(displayName, expectedDisplayName);
533 // Update the shortName and verify the computed name is updated.
535 taxon.setDisplayNameComputed(true);
536 taxon.setTaxonFullName("updated-" + TEST_TAXON_FULL_NAME);
537 expectedDisplayName =
538 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_NAME);
540 // Submit the updated resource to the service and store the response.
541 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
542 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
543 commonPart.setLabel(client.getItemCommonPartName());
544 res.releaseConnection();
545 res = client.updateItem(knownResourceId, knownItemResourceId, output);
546 statusCode = res.getStatus();
548 // Check the status code of the response: does it match the expected response(s)?
549 if (logger.isDebugEnabled()) {
550 logger.debug("updateItem: status = " + statusCode);
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556 // Retrieve the updated resource and verify that its contents exist.
557 input = new PoxPayloadIn(res.getEntity());
558 TaxonCommon updatedTaxon =
559 (TaxonCommon) extractPart(input,
560 client.getItemCommonPartName(), TaxonCommon.class);
561 Assert.assertNotNull(updatedTaxon);
563 // Verify that the updated resource received the correct data.
564 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
565 "Updated ForeName in Taxonomy did not match submitted data.");
566 // Verify that the updated resource computes the right displayName.
567 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
568 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
570 // Now Update the displayName, not computed and verify the computed name is overriden.
571 taxon.setDisplayNameComputed(false);
572 expectedDisplayName = "TestName";
573 taxon.setDisplayName(expectedDisplayName);
575 // Submit the updated resource to the service and store the response.
576 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
577 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
578 commonPart.setLabel(client.getItemCommonPartName());
579 res.releaseConnection();
580 res = client.updateItem(knownResourceId, knownItemResourceId, output);
581 statusCode = res.getStatus();
583 // Check the status code of the response: does it match the expected response(s)?
584 if (logger.isDebugEnabled()) {
585 logger.debug("updateItem: status = " + statusCode);
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 // Retrieve the updated resource and verify that its contents exist.
592 input = new PoxPayloadIn(res.getEntity());
594 (TaxonCommon) extractPart(input,
595 client.getItemCommonPartName(), TaxonCommon.class);
596 Assert.assertNotNull(updatedTaxon);
598 // Verify that the updated resource received the correct data.
599 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
600 "Updated displayNameComputed in Taxonomy did not match submitted data.");
601 // Verify that the updated resource computes the right displayName.
602 Assert.assertEquals(updatedTaxon.getDisplayName(),
604 "Updated DisplayName (not computed) in Taxonomy not stored.");
606 res.releaseConnection();
611 * Verify illegal item display name.
613 * @param testName the test name
614 * @throws Exception the exception
616 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
617 dependsOnMethods = {"verifyItemDisplayName"})
618 public void verifyIllegalItemDisplayName(String testName) throws Exception {
620 if (logger.isDebugEnabled()) {
621 logger.debug(testBanner(testName, CLASS_NAME));
624 // FIXME: create a setup configuration for this operation.
625 setupUpdateWithWrongXmlSchema();
627 // Submit the request to the service and store the response.
628 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
629 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
631 int statusCode = res.getStatus();
633 // Check the status code of the response: does it match
634 // the expected response(s)?
635 if (logger.isDebugEnabled()) {
636 logger.debug(testName + ": status = " + statusCode);
638 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
642 // Check whether Taxonomy has expected displayName.
643 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
644 TaxonCommon taxon = (TaxonCommon) extractPart(input,
645 client.getItemCommonPartName(), TaxonCommon.class);
646 Assert.assertNotNull(taxon);
647 // Try to Update with computed false and no displayName
648 taxon.setDisplayNameComputed(false);
649 taxon.setDisplayName(null);
651 // Submit the updated resource to the service and store the response.
652 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
653 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
654 commonPart.setLabel(client.getItemCommonPartName());
655 res.releaseConnection();
656 res = client.updateItem(knownResourceId, knownItemResourceId, output);
657 statusCode = res.getStatus();
659 // Check the status code of the response: does it match the expected response(s)?
660 if (logger.isDebugEnabled()) {
661 logger.debug("updateItem: status = " + statusCode);
663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667 res.releaseConnection();
673 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
676 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
677 groups = {"read"}, dependsOnMethods = {"read"})
678 public void readNonExistent(String testName) {
680 if (logger.isDebugEnabled()) {
681 logger.debug(testBanner(testName, CLASS_NAME));
684 setupReadNonExistent();
686 // Submit the request to the service and store the response.
687 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
688 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
690 int statusCode = res.getStatus();
692 // Check the status code of the response: does it match
693 // the expected response(s)?
694 if (logger.isDebugEnabled()) {
695 logger.debug(testName + ": status = " + statusCode);
697 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
698 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
699 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
701 res.releaseConnection();
706 * Read item non existent.
708 * @param testName the test name
710 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
711 groups = {"read"}, dependsOnMethods = {"readItem"})
712 public void readItemNonExistent(String testName) {
714 if (logger.isDebugEnabled()) {
715 logger.debug(testBanner(testName, CLASS_NAME));
718 setupReadNonExistent();
720 // Submit the request to the service and store the response.
721 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
722 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
724 int statusCode = res.getStatus();
726 // Check the status code of the response: does it match
727 // the expected response(s)?
728 if (logger.isDebugEnabled()) {
729 logger.debug(testName + ": status = " + statusCode);
731 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
732 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
733 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
735 res.releaseConnection();
739 // ---------------------------------------------------------------
740 // CRUD tests : READ_LIST tests
741 // ---------------------------------------------------------------
745 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
748 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
749 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
750 public void readList(String testName) throws Exception {
752 if (logger.isDebugEnabled()) {
753 logger.debug(testBanner(testName, CLASS_NAME));
758 // Submit the request to the service and store the response.
759 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
760 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
762 TaxonomyauthorityCommonList list = res.getEntity();
763 int statusCode = res.getStatus();
765 // Check the status code of the response: does it match
766 // the expected response(s)?
767 if (logger.isDebugEnabled()) {
768 logger.debug(testName + ": status = " + statusCode);
770 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
774 // Optionally output additional data about list members for debugging.
775 boolean iterateThroughList = false;
776 if (iterateThroughList && logger.isDebugEnabled()) {
777 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
778 list.getTaxonomyauthorityListItem();
780 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
781 String csid = item.getCsid();
782 logger.debug(testName + ": list-item[" + i + "] csid="
784 logger.debug(testName + ": list-item[" + i + "] displayName="
785 + item.getDisplayName());
786 logger.debug(testName + ": list-item[" + i + "] URI="
788 readItemList(csid, null);
793 res.releaseConnection();
800 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
801 public void readItemList() {
802 String testName = "readItemList";
803 if (logger.isDebugEnabled()) {
804 logger.debug(testBanner(testName, CLASS_NAME));
806 readItemList(knownResourceId, null);
810 * Read item list by authority name.
812 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
813 public void readItemListByAuthorityName() {
814 String testName = "readItemListByAuthorityName";
815 if (logger.isDebugEnabled()) {
816 logger.debug(testBanner(testName, CLASS_NAME));
818 readItemList(null, knownResourceShortIdentifer);
824 * @param vcsid the vcsid
825 * @param name the name
827 private void readItemList(String vcsid, String shortId) {
829 String testName = "readItemList";
834 // Submit the request to the service and store the response.
835 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
836 ClientResponse<TaxonCommonList> res = null;
838 res = client.readItemList(vcsid, null, null);
839 } else if (shortId != null) {
840 res = client.readItemListForNamedAuthority(shortId, null, null);
842 Assert.fail("readItemList passed null csid and name!");
845 TaxonCommonList list = res.getEntity();
846 int statusCode = res.getStatus();
848 // Check the status code of the response: does it match
849 // the expected response(s)?
850 if (logger.isDebugEnabled()) {
851 logger.debug(testName + ": status = " + statusCode);
853 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
854 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
855 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
857 List<TaxonCommonList.TaxonListItem> items =
858 list.getTaxonListItem();
859 int nItemsReturned = items.size();
860 // There will be one item created, associated with a
861 // known parent resource, by the createItem test.
863 // In addition, there will be 'nItemsToCreateInList'
864 // additional items created by the createItemList test,
865 // all associated with the same parent resource.
866 int nExpectedItems = nItemsToCreateInList + 1;
867 if (logger.isDebugEnabled()) {
868 logger.debug(testName + ": Expected "
869 + nExpectedItems + " items; got: " + nItemsReturned);
871 Assert.assertEquals(nItemsReturned, nExpectedItems);
874 for (TaxonCommonList.TaxonListItem item : items) {
875 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
876 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
877 // Optionally output additional data about list members for debugging.
878 boolean showDetails = true;
879 if (showDetails && logger.isDebugEnabled()) {
880 logger.debug(" " + testName + ": list-item[" + i + "] csid="
882 logger.debug(" " + testName + ": list-item[" + i + "] refName="
883 + item.getRefName());
884 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
885 + item.getDisplayName());
886 logger.debug(" " + testName + ": list-item[" + i + "] URI="
892 res.releaseConnection();
898 // ---------------------------------------------------------------
899 // CRUD tests : UPDATE tests
900 // ---------------------------------------------------------------
903 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
906 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
907 groups = {"update"}, dependsOnGroups = {"read", "readList"})
908 public void update(String testName) throws Exception {
910 if (logger.isDebugEnabled()) {
911 logger.debug(testBanner(testName, CLASS_NAME));
916 // Retrieve the contents of a resource to update.
917 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
918 ClientResponse<String> res = client.read(knownResourceId);
920 if (logger.isDebugEnabled()) {
921 logger.debug(testName + ": read status = " + res.getStatus());
923 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
925 if (logger.isDebugEnabled()) {
926 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
928 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
929 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
930 client.getCommonPartName(), TaxonomyauthorityCommon.class);
931 Assert.assertNotNull(taxonomyAuthority);
933 // Update the contents of this resource.
934 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
935 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
936 if (logger.isDebugEnabled()) {
937 logger.debug("to be updated TaxonomyAuthority");
938 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
941 // Submit the updated resource to the service and store the response.
942 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
943 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
944 commonPart.setLabel(client.getCommonPartName());
945 res.releaseConnection();
946 res = client.update(knownResourceId, output);
947 int statusCode = res.getStatus();
949 // Check the status code of the response: does it match the expected response(s)?
950 if (logger.isDebugEnabled()) {
951 logger.debug(testName + ": status = " + statusCode);
953 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
954 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
955 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
957 // Retrieve the updated resource and verify that its contents exist.
958 input = new PoxPayloadIn(res.getEntity());
959 TaxonomyauthorityCommon updatedTaxonomyAuthority =
960 (TaxonomyauthorityCommon) extractPart(input,
961 client.getCommonPartName(), TaxonomyauthorityCommon.class);
962 Assert.assertNotNull(updatedTaxonomyAuthority);
964 // Verify that the updated resource received the correct data.
965 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
966 taxonomyAuthority.getDisplayName(),
967 "Data in updated object did not match submitted data.");
969 res.releaseConnection();
976 * @param testName the test name
977 * @throws Exception the exception
979 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
980 groups = {"update"}, dependsOnMethods = {"update"})
981 public void updateItem(String testName) throws Exception {
983 if (logger.isDebugEnabled()) {
984 logger.debug(testBanner(testName, CLASS_NAME));
989 // Retrieve the contents of a resource to update.
990 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
991 ClientResponse<String> res =
992 client.readItem(knownResourceId, knownItemResourceId);
994 if (logger.isDebugEnabled()) {
995 logger.debug(testName + ": read status = " + res.getStatus());
997 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
999 if (logger.isDebugEnabled()) {
1000 logger.debug("got Taxonomy to update with ID: "
1001 + knownItemResourceId
1002 + " in TaxonomyAuthority: " + knownResourceId);
1004 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1005 TaxonCommon taxon = (TaxonCommon) extractPart(input,
1006 client.getItemCommonPartName(), TaxonCommon.class);
1007 Assert.assertNotNull(taxon);
1009 // Update the contents of this resource.
1010 taxon.setCsid(null);
1011 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
1012 if (logger.isDebugEnabled()) {
1013 logger.debug("to be updated Taxonomy");
1014 logger.debug(objectAsXmlString(taxon,
1015 TaxonCommon.class));
1018 // Submit the updated resource to the service and store the response.
1019 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1020 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
1021 commonPart.setLabel(client.getItemCommonPartName());
1022 res.releaseConnection();
1023 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1024 int statusCode = res.getStatus();
1026 // Check the status code of the response: does it match the expected response(s)?
1027 if (logger.isDebugEnabled()) {
1028 logger.debug(testName + ": status = " + statusCode);
1030 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1034 // Retrieve the updated resource and verify that its contents exist.
1035 input = new PoxPayloadIn(res.getEntity());
1036 TaxonCommon updatedTaxon =
1037 (TaxonCommon) extractPart(input,
1038 client.getItemCommonPartName(), TaxonCommon.class);
1039 Assert.assertNotNull(updatedTaxon);
1041 // Verify that the updated resource received the correct data.
1042 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1043 "Data in updated Taxon did not match submitted data.");
1045 res.releaseConnection();
1050 // Placeholders until the three tests below can be uncommented.
1051 // See Issue CSPACE-401.
1053 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1056 public void updateWithEmptyEntityBody(String testName) throws Exception {
1060 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1063 public void updateWithMalformedXml(String testName) throws Exception {
1067 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1070 public void updateWithWrongXmlSchema(String testName) throws Exception {
1075 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1078 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1079 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1080 public void updateNonExistent(String testName) throws Exception {
1082 if (logger.isDebugEnabled()) {
1083 logger.debug(testBanner(testName, CLASS_NAME));
1086 setupUpdateNonExistent();
1088 // Submit the request to the service and store the response.
1089 // Note: The ID(s) used when creating the request payload may be arbitrary.
1090 // The only relevant ID may be the one used in update(), below.
1091 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1092 String displayName = "displayName-NON_EXISTENT_ID";
1093 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1094 displayName, "nonEx", client.getCommonPartName());
1095 ClientResponse<String> res =
1096 client.update(NON_EXISTENT_ID, multipart);
1098 int statusCode = res.getStatus();
1100 // Check the status code of the response: does it match
1101 // the expected response(s)?
1102 if (logger.isDebugEnabled()) {
1103 logger.debug(testName + ": status = " + statusCode);
1105 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1106 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1107 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1109 res.releaseConnection();
1114 * Update non existent item.
1116 * @param testName the test name
1117 * @throws Exception the exception
1119 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1120 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1121 public void updateNonExistentItem(String testName) throws Exception {
1123 if (logger.isDebugEnabled()) {
1124 logger.debug(testBanner(testName, CLASS_NAME));
1127 setupUpdateNonExistent();
1129 // Submit the request to the service and store the response.
1130 // Note: The ID used in this 'create' call may be arbitrary.
1131 // The only relevant ID may be the one used in update(), below.
1132 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1133 Map<String, String> nonexMap = new HashMap<String, String>();
1134 nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
1135 nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1136 nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
1137 PoxPayloadOut multipart =
1138 TaxonomyAuthorityClientUtils.createTaxonInstance(
1139 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1140 nonexMap, client.getItemCommonPartName());
1141 ClientResponse<String> res =
1142 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1144 int statusCode = res.getStatus();
1146 // Check the status code of the response: does it match
1147 // the expected response(s)?
1148 if (logger.isDebugEnabled()) {
1149 logger.debug(testName + ": status = " + statusCode);
1151 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1152 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1153 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1155 res.releaseConnection();
1159 // ---------------------------------------------------------------
1160 // CRUD tests : DELETE tests
1161 // ---------------------------------------------------------------
1163 // Note: delete sub-resources in ascending hierarchical order,
1164 // before deleting their parents.
1168 * @param testName the test name
1169 * @throws Exception the exception
1171 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1172 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1173 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1174 public void deleteItem(String testName) throws Exception {
1176 if (logger.isDebugEnabled()) {
1177 logger.debug(testBanner(testName, CLASS_NAME));
1182 if (logger.isDebugEnabled()) {
1183 logger.debug("parentcsid =" + knownResourceId
1184 + " itemcsid = " + knownItemResourceId);
1187 // Submit the request to the service and store the response.
1188 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1189 ClientResponse<Response> res =
1190 client.deleteItem(knownResourceId, knownItemResourceId);
1192 int statusCode = res.getStatus();
1194 // Check the status code of the response: does it match
1195 // the expected response(s)?
1196 if (logger.isDebugEnabled()) {
1197 logger.debug(testName + ": status = " + statusCode);
1199 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1200 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1201 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1203 res.releaseConnection();
1208 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1211 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1212 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1213 public void delete(String testName) throws Exception {
1215 if (logger.isDebugEnabled()) {
1216 logger.debug(testBanner(testName, CLASS_NAME));
1221 if (logger.isDebugEnabled()) {
1222 logger.debug("parentcsid =" + knownResourceId);
1225 // Submit the request to the service and store the response.
1226 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1227 ClientResponse<Response> res = client.delete(knownResourceId);
1229 int statusCode = res.getStatus();
1231 // Check the status code of the response: does it match
1232 // the expected response(s)?
1233 if (logger.isDebugEnabled()) {
1234 logger.debug(testName + ": status = " + statusCode);
1236 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1237 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1238 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1240 res.releaseConnection();
1246 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1249 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1250 groups = {"delete"}, dependsOnMethods = {"delete"})
1251 public void deleteNonExistent(String testName) throws Exception {
1253 if (logger.isDebugEnabled()) {
1254 logger.debug(testBanner(testName, CLASS_NAME));
1257 setupDeleteNonExistent();
1259 // Submit the request to the service and store the response.
1260 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1261 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1263 int statusCode = res.getStatus();
1265 // Check the status code of the response: does it match
1266 // the expected response(s)?
1267 if (logger.isDebugEnabled()) {
1268 logger.debug(testName + ": status = " + statusCode);
1270 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1271 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1272 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1274 res.releaseConnection();
1279 * Delete non existent item.
1281 * @param testName the test name
1283 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1284 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1285 public void deleteNonExistentItem(String testName) {
1287 if (logger.isDebugEnabled()) {
1288 logger.debug(testBanner(testName, CLASS_NAME));
1291 setupDeleteNonExistent();
1293 // Submit the request to the service and store the response.
1294 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1295 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1297 int statusCode = res.getStatus();
1299 // Check the status code of the response: does it match
1300 // the expected response(s)?
1301 if (logger.isDebugEnabled()) {
1302 logger.debug(testName + ": status = " + statusCode);
1304 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1305 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1306 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1308 res.releaseConnection();
1312 // ---------------------------------------------------------------
1313 // Utility tests : tests of code used in tests above
1314 // ---------------------------------------------------------------
1316 * Tests the code for manually submitting data that is used by several
1317 * of the methods above.
1319 @Test(dependsOnMethods = {"create", "read"})
1320 public void testSubmitRequest() {
1322 // Expected status code: 200 OK
1323 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1325 // Submit the request to the service and store the response.
1326 String method = ServiceRequestType.READ.httpMethodName();
1327 String url = getResourceURL(knownResourceId);
1328 int statusCode = submitRequest(method, url);
1330 // Check the status code of the response: does it match
1331 // the expected response(s)?
1332 if (logger.isDebugEnabled()) {
1333 logger.debug("testSubmitRequest: url=" + url
1334 + " status=" + statusCode);
1336 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1341 * Test item submit request.
1343 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1344 public void testItemSubmitRequest() {
1346 // Expected status code: 200 OK
1347 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1349 // Submit the request to the service and store the response.
1350 String method = ServiceRequestType.READ.httpMethodName();
1351 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1352 int statusCode = submitRequest(method, url);
1354 // Check the status code of the response: does it match
1355 // the expected response(s)?
1356 if (logger.isDebugEnabled()) {
1357 logger.debug("testItemSubmitRequest: url=" + url
1358 + " status=" + statusCode);
1360 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1364 // ---------------------------------------------------------------
1365 // Cleanup of resources created during testing
1366 // ---------------------------------------------------------------
1368 * Deletes all resources created by tests, after all tests have been run.
1370 * This cleanup method will always be run, even if one or more tests fail.
1371 * For this reason, it attempts to remove all resources created
1372 * at any point during testing, even if some of those resources
1373 * may be expected to be deleted by certain tests.
1375 @AfterClass(alwaysRun = true)
1376 public void cleanUp() {
1377 String noTest = System.getProperty("noTestCleanup");
1378 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1379 if (logger.isDebugEnabled()) {
1380 logger.debug("Skipping Cleanup phase ...");
1384 if (logger.isDebugEnabled()) {
1385 logger.debug("Cleaning up temporary resources created for testing ...");
1387 String parentResourceId;
1388 String itemResourceId;
1389 // Clean up contact resources.
1390 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1391 parentResourceId = knownResourceId;
1392 // Clean up item resources.
1393 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1394 itemResourceId = entry.getKey();
1395 parentResourceId = entry.getValue();
1396 // Note: Any non-success responses from the delete operation
1397 // below are ignored and not reported.
1398 ClientResponse<Response> res =
1399 client.deleteItem(parentResourceId, itemResourceId);
1400 res.releaseConnection();
1402 // Clean up parent resources.
1403 for (String resourceId : allResourceIdsCreated) {
1404 // Note: Any non-success responses from the delete operation
1405 // below are ignored and not reported.
1406 ClientResponse<Response> res = client.delete(resourceId);
1407 res.releaseConnection();
1411 // ---------------------------------------------------------------
1412 // Utility methods used by tests above
1413 // ---------------------------------------------------------------
1415 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1418 * Returns the root URL for the item service.
1420 * This URL consists of a base URL for all services, followed by
1421 * a path component for the owning parent, followed by the
1422 * path component for the items.
1424 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1425 * parent authority resource of the relevant item resource.
1427 * @return The root URL for the item service.
1429 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1430 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1434 * Returns the URL of a specific item resource managed by a service, and
1435 * designated by an identifier (such as a universally unique ID, or UUID).
1437 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1438 * parent authority resource of the relevant item resource.
1440 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1443 * @return The URL of a specific item resource managed by a service.
1445 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1446 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;