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.common.AbstractCommonListUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.taxonomy.TaxonAuthorGroup;
41 import org.collectionspace.services.taxonomy.TaxonAuthorGroupList;
42 import org.collectionspace.services.taxonomy.TaxonCitationList;
43 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
44 import org.collectionspace.services.taxonomy.TaxonCommon;
46 import javax.ws.rs.core.MediaType;
47 import javax.ws.rs.core.Response;
48 import org.jboss.resteasy.client.ClientResponse;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
53 import org.testng.Assert;
54 import org.testng.annotations.AfterClass;
55 import org.testng.annotations.Test;
58 * TaxonomyAuthorityServiceTest, carries out tests against a
59 * deployed and running TaxonomyAuthority Service.
61 * $LastChangedRevision$
64 public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class!
67 private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName();
68 private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class);
69 private final String REFNAME = "refName";
70 private final String DISPLAYNAME = "displayName";
73 public String getServicePathComponent() {
74 return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
78 protected String getServiceName() {
79 return TaxonomyAuthorityClient.SERVICE_NAME;
82 public String getItemServicePathComponent() {
83 return AuthorityClient.ITEMS;
85 final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
86 final String TEST_TERM_STATUS = "accepted";
87 final String TEST_TAXON_FULL_NAME = "Centaurus pleurexanthemus Green 1832";
88 // TODO Re-implement the Taxon Rank field so as to provide an orderable
89 // ranking value, as well as a display name.
90 final String TEST_TAXON_RANK = "species";
91 final String TEST_TAXON_AUTHOR = "J. Green";
92 final String TEST_TAXON_AUTHOR_TYPE = "ascribed";
93 final String TEST_TAXON_CITATION = "A Monograph of the Trilobites of North America";
94 final String TEST_TAXON_CURRENCY = "current";
95 final String TEST_TAXON_YEAR = "1832";
96 final String TEST_TAXONOMIC_STATUS = "valid";
97 final String TEST_TAXON_IS_NAMED_HYBRID = "false";
98 final TaxonAuthorGroupList NULL_TAXON_AUTHOR_GROUP_LIST = null;
99 final TaxonCitationList NULL_TAXON_CITATION_LIST = null;
100 /** The known resource id. */
101 private String knownResourceId = null;
102 private String knownResourceShortIdentifer = null;
103 private String knownResourceRefName = null;
104 private String knownTaxonomyTypeRefName = null;
105 private String knownItemResourceId = null;
106 private String knownItemResourceShortIdentifer = null;
107 /** The n items to create in list. */
108 private int nItemsToCreateInList = 3;
109 /** The all resource ids created. */
110 private List<String> allResourceIdsCreated = new ArrayList<String>();
111 /** The all item resource ids created. */
112 private Map<String, String> allItemResourceIdsCreated =
113 new HashMap<String, String>();
115 protected void setKnownResource(String id, String shortIdentifer,
117 knownResourceId = id;
118 knownResourceShortIdentifer = shortIdentifer;
119 knownResourceRefName = refName;
122 protected void setKnownItemResource(String id, String shortIdentifer) {
123 knownItemResourceId = id;
124 knownItemResourceShortIdentifer = shortIdentifer;
128 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
131 protected CollectionSpaceClient getClientInstance() {
132 return new TaxonomyAuthorityClient();
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);
257 taxonMap.put(TaxonJAXBSchema.TAXON_IS_NAMED_HYBRID, TEST_TAXON_IS_NAMED_HYBRID);
259 TaxonCitationList taxonCitationList = new TaxonCitationList();
260 List<String> taxonCitations = taxonCitationList.getTaxonCitation();
261 taxonCitations.add(TEST_TAXON_CITATION);
263 TaxonAuthorGroupList taxonAuthorGroupList = new TaxonAuthorGroupList();
264 List<TaxonAuthorGroup> taxonAuthorGroups = taxonAuthorGroupList.getTaxonAuthorGroup();
265 TaxonAuthorGroup taxonAuthorGroup = new TaxonAuthorGroup();
266 taxonAuthorGroup.setTaxonAuthor(TEST_TAXON_AUTHOR);
267 taxonAuthorGroup.setTaxonAuthorType(TEST_TAXON_AUTHOR_TYPE);
268 taxonAuthorGroups.add(taxonAuthorGroup);
270 // FIXME: Add additional fields in the Taxon record here,
271 // including at least one each of:
272 // * a Boolean field (when implemented)
273 // * an authref field (when implemented)
275 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
276 authRefName, taxonMap, taxonAuthorGroupList, taxonCitationList, client);
278 // Store the ID returned from the first item resource created
279 // for additional tests below.
280 if (knownItemResourceId == null) {
281 setKnownItemResource(newID, TEST_SHORTID);
282 if (logger.isDebugEnabled()) {
283 logger.debug(testName + ": knownItemResourceId=" + newID + " inAuthority=" + vcsid);
287 // Store the IDs from any item resources created
288 // by tests, along with the IDs of their parents, so these items
289 // can be deleted after all tests have been run.
290 allItemResourceIdsCreated.put(newID, vcsid);
296 // Placeholders until the three tests below can be uncommented.
297 // See Issue CSPACE-401.
299 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
302 public void createWithEmptyEntityBody(String testName) throws Exception {
306 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
309 public void createWithMalformedXml(String testName) throws Exception {
313 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
316 public void createWithWrongXmlSchema(String testName) throws Exception {
319 // ---------------------------------------------------------------
320 // CRUD tests : CREATE LIST tests
321 // ---------------------------------------------------------------
324 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
327 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
328 groups = {"createList"}, dependsOnGroups = {"create"})
329 public void createList(String testName) throws Exception {
330 for (int i = 0; i < nItemsToCreateInList; i++) {
336 * Creates the item list.
338 * @param testName the test name
339 * @throws Exception the exception
341 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
342 groups = {"createList"}, dependsOnMethods = {"createList"})
343 public void createItemList(String testName) throws Exception {
344 // Add items to the initially-created, known parent record.
345 for (int j = 0; j < nItemsToCreateInList; j++) {
346 createItem(testName);
350 // ---------------------------------------------------------------
351 // CRUD tests : READ tests
352 // ---------------------------------------------------------------
355 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
358 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
359 groups = {"read"}, dependsOnGroups = {"create"})
360 public void read(String testName) throws Exception {
362 if (logger.isDebugEnabled()) {
363 logger.debug(testBanner(testName, CLASS_NAME));
368 // Submit the request to the service and store the response.
369 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
371 ClientResponse<String> res = client.read(knownResourceId);
373 int statusCode = res.getStatus();
375 // Check the status code of the response: does it match
376 // the expected response(s)?
377 if (logger.isDebugEnabled()) {
378 logger.debug(testName + ": status = " + statusCode);
380 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
381 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
382 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
383 //FIXME: remove the following try catch once Aron fixes signatures
385 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
386 TaxonomyauthorityCommon taxonomyAuthority =
387 (TaxonomyauthorityCommon) extractPart(input,
388 client.getCommonPartName(), TaxonomyauthorityCommon.class);
389 Assert.assertNotNull(taxonomyAuthority);
390 } catch (Exception e) {
391 throw new RuntimeException(e);
394 res.releaseConnection();
401 * @param testName the test name
402 * @throws Exception the exception
404 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
405 groups = {"read"}, dependsOnGroups = {"create"})
406 public void readByName(String testName) throws Exception {
408 if (logger.isDebugEnabled()) {
409 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
414 // Submit the request to the service and store the response.
415 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
416 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
418 int statusCode = res.getStatus();
420 // Check the status code of the response: does it match
421 // the expected response(s)?
422 if (logger.isDebugEnabled()) {
423 logger.debug(testName + ": status = " + statusCode);
425 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
426 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
427 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
428 //FIXME: remove the following try catch once Aron fixes signatures
430 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
431 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
432 client.getCommonPartName(), TaxonomyauthorityCommon.class);
433 Assert.assertNotNull(taxonomyAuthority);
434 } catch (Exception e) {
435 throw new RuntimeException(e);
438 res.releaseConnection();
445 * @param testName the test name
446 * @throws Exception the exception
448 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
449 groups = {"read"}, dependsOnMethods = {"read"})
450 public void readItem(String testName) throws Exception {
452 if (logger.isDebugEnabled()) {
453 logger.debug(testBanner(testName, CLASS_NAME));
458 // Submit the request to the service and store the response.
459 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
460 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
462 int statusCode = res.getStatus();
464 // Check the status code of the response: does it match
465 // the expected response(s)?
466 if (logger.isDebugEnabled()) {
467 logger.debug(testName + ": status = " + statusCode);
469 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
470 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
471 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
473 // Check whether we've received an authority item record.
474 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
475 TaxonCommon taxon = (TaxonCommon) extractPart(input,
476 client.getItemCommonPartName(), TaxonCommon.class);
477 Assert.assertNotNull(taxon);
478 boolean showFull = true;
479 if (showFull && logger.isDebugEnabled()) {
480 logger.debug(testName + ": returned payload:");
481 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
484 // Check that this authority item record has the correct identifier
485 // pointing to its parent authority record.
486 Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null.");
487 Assert.assertEquals(taxon.getInAuthority(), knownResourceId,
488 "Value of item's inAuthority field does not contain the correct identifier "
489 + "pointing to its parent authority record.");
491 // Check individual fields in the authority item record.
492 Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null.");
493 Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME,
494 "Field value " + taxon.getTaxonFullName()
495 + "does not match expected value " + TEST_TAXON_FULL_NAME);
497 res.releaseConnection();
502 * Verify item display name.
504 * @param testName the test name
505 * @throws Exception the exception
507 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
508 dependsOnMethods = {"readItem", "updateItem"})
509 public void verifyItemDisplayName(String testName) throws Exception {
511 if (logger.isDebugEnabled()) {
512 logger.debug(testBanner(testName, CLASS_NAME));
517 // Submit the request to the service and store the response.
518 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
519 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
521 int statusCode = res.getStatus();
523 // Check the status code of the response: does it match
524 // the expected response(s)?
525 if (logger.isDebugEnabled()) {
526 logger.debug(testName + ": status = " + statusCode);
528 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
529 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
530 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
532 // Check whether taxon has expected displayName.
533 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
534 TaxonCommon taxon = (TaxonCommon) extractPart(input,
535 client.getItemCommonPartName(), TaxonCommon.class);
536 Assert.assertNotNull(taxon);
537 String displayName = taxon.getDisplayName();
538 // Make sure displayName matches computed form
539 String expectedDisplayName =
540 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_TAXON_FULL_NAME);
541 Assert.assertNotNull(displayName, expectedDisplayName);
543 // Update the shortName and verify the computed name is updated.
545 taxon.setDisplayNameComputed(true);
546 taxon.setTaxonFullName("updated-" + TEST_TAXON_FULL_NAME);
547 expectedDisplayName =
548 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_NAME);
550 // Submit the updated resource to the service and store the response.
551 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
552 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
553 commonPart.setLabel(client.getItemCommonPartName());
554 res.releaseConnection();
555 res = client.updateItem(knownResourceId, knownItemResourceId, output);
556 statusCode = res.getStatus();
558 // Check the status code of the response: does it match the expected response(s)?
559 if (logger.isDebugEnabled()) {
560 logger.debug("updateItem: status = " + statusCode);
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
566 // Retrieve the updated resource and verify that its contents exist.
567 input = new PoxPayloadIn(res.getEntity());
568 TaxonCommon updatedTaxon =
569 (TaxonCommon) extractPart(input,
570 client.getItemCommonPartName(), TaxonCommon.class);
571 Assert.assertNotNull(updatedTaxon);
573 // Verify that the updated resource received the correct data.
574 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
575 "Updated ForeName in Taxonomy did not match submitted data.");
576 // Verify that the updated resource computes the right displayName.
577 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
578 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
580 // Now Update the displayName, not computed and verify the computed name is overriden.
581 taxon.setDisplayNameComputed(false);
582 expectedDisplayName = "TestName";
583 taxon.setDisplayName(expectedDisplayName);
585 // Submit the updated resource to the service and store the response.
586 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
587 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
588 commonPart.setLabel(client.getItemCommonPartName());
589 res.releaseConnection();
590 res = client.updateItem(knownResourceId, knownItemResourceId, output);
591 statusCode = res.getStatus();
593 // Check the status code of the response: does it match the expected response(s)?
594 if (logger.isDebugEnabled()) {
595 logger.debug("updateItem: status = " + statusCode);
597 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
598 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
599 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601 // Retrieve the updated resource and verify that its contents exist.
602 input = new PoxPayloadIn(res.getEntity());
604 (TaxonCommon) extractPart(input,
605 client.getItemCommonPartName(), TaxonCommon.class);
606 Assert.assertNotNull(updatedTaxon);
608 // Verify that the updated resource received the correct data.
609 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
610 "Updated displayNameComputed in Taxonomy did not match submitted data.");
611 // Verify that the updated resource computes the right displayName.
612 Assert.assertEquals(updatedTaxon.getDisplayName(),
614 "Updated DisplayName (not computed) in Taxonomy not stored.");
616 res.releaseConnection();
621 * Verify illegal item display name.
623 * @param testName the test name
624 * @throws Exception the exception
626 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
627 dependsOnMethods = {"verifyItemDisplayName"})
628 public void verifyIllegalItemDisplayName(String testName) throws Exception {
630 if (logger.isDebugEnabled()) {
631 logger.debug(testBanner(testName, CLASS_NAME));
634 // FIXME: create a setup configuration for this operation.
635 setupUpdateWithWrongXmlSchema();
637 // Submit the request to the service and store the response.
638 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
639 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if (logger.isDebugEnabled()) {
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
652 // Check whether Taxonomy has expected displayName.
653 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
654 TaxonCommon taxon = (TaxonCommon) extractPart(input,
655 client.getItemCommonPartName(), TaxonCommon.class);
656 Assert.assertNotNull(taxon);
657 // Try to Update with computed false and no displayName
658 taxon.setDisplayNameComputed(false);
659 taxon.setDisplayName(null);
661 // Submit the updated resource to the service and store the response.
662 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
663 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
664 commonPart.setLabel(client.getItemCommonPartName());
665 res.releaseConnection();
666 res = client.updateItem(knownResourceId, knownItemResourceId, output);
667 statusCode = res.getStatus();
669 // Check the status code of the response: does it match the expected response(s)?
670 if (logger.isDebugEnabled()) {
671 logger.debug("updateItem: status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 res.releaseConnection();
683 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
686 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
687 groups = {"read"}, dependsOnMethods = {"read"})
688 public void readNonExistent(String testName) {
690 if (logger.isDebugEnabled()) {
691 logger.debug(testBanner(testName, CLASS_NAME));
694 setupReadNonExistent();
696 // Submit the request to the service and store the response.
697 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
698 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
700 int statusCode = res.getStatus();
702 // Check the status code of the response: does it match
703 // the expected response(s)?
704 if (logger.isDebugEnabled()) {
705 logger.debug(testName + ": status = " + statusCode);
707 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
708 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
709 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
711 res.releaseConnection();
716 * Read item non existent.
718 * @param testName the test name
720 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
721 groups = {"read"}, dependsOnMethods = {"readItem"})
722 public void readItemNonExistent(String testName) {
724 if (logger.isDebugEnabled()) {
725 logger.debug(testBanner(testName, CLASS_NAME));
728 setupReadNonExistent();
730 // Submit the request to the service and store the response.
731 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
732 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
734 int statusCode = res.getStatus();
736 // Check the status code of the response: does it match
737 // the expected response(s)?
738 if (logger.isDebugEnabled()) {
739 logger.debug(testName + ": status = " + statusCode);
741 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
742 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
743 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
745 res.releaseConnection();
749 // ---------------------------------------------------------------
750 // CRUD tests : READ_LIST tests
751 // ---------------------------------------------------------------
755 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
758 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
759 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
760 public void readList(String testName) throws Exception {
762 if (logger.isDebugEnabled()) {
763 logger.debug(testBanner(testName, CLASS_NAME));
768 // Submit the request to the service and store the response.
769 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
770 ClientResponse<AbstractCommonList> res = client.readList();
772 AbstractCommonList list = res.getEntity();
773 int statusCode = res.getStatus();
775 // Check the status code of the response: does it match
776 // the expected response(s)?
777 if (logger.isDebugEnabled()) {
778 logger.debug(testName + ": status = " + statusCode);
780 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
781 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
782 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
784 // Optionally output additional data about list members for debugging.
785 if(logger.isTraceEnabled()){
786 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
789 res.releaseConnection();
796 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
797 public void readItemList() {
798 String testName = "readItemList";
799 if (logger.isDebugEnabled()) {
800 logger.debug(testBanner(testName, CLASS_NAME));
802 readItemList(knownResourceId, null);
806 * Read item list by authority name.
808 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
809 public void readItemListByAuthorityName() {
810 String testName = "readItemListByAuthorityName";
811 if (logger.isDebugEnabled()) {
812 logger.debug(testBanner(testName, CLASS_NAME));
814 readItemList(null, knownResourceShortIdentifer);
820 * @param vcsid the vcsid
821 * @param name the name
823 private void readItemList(String vcsid, String shortId) {
825 String testName = "readItemList";
830 // Submit the request to the service and store the response.
831 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
832 ClientResponse<AbstractCommonList> res = null;
834 res = client.readItemList(vcsid, null, null);
835 } else if (shortId != null) {
836 res = client.readItemListForNamedAuthority(shortId, null, null);
838 Assert.fail("readItemList passed null csid and name!");
841 AbstractCommonList list = res.getEntity();
842 int statusCode = res.getStatus();
844 // Check the status code of the response: does it match
845 // the expected response(s)?
846 if (logger.isDebugEnabled()) {
847 logger.debug(testName + ": status = " + statusCode);
849 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
850 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
851 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
853 List<AbstractCommonList.ListItem> items =
855 int nItemsReturned = items.size();
856 // There will be one item created, associated with a
857 // known parent resource, by the createItem test.
859 // In addition, there will be 'nItemsToCreateInList'
860 // additional items created by the createItemList test,
861 // all associated with the same parent resource.
862 int nExpectedItems = nItemsToCreateInList + 1;
863 if (logger.isDebugEnabled()) {
864 logger.debug(testName + ": Expected "
865 + nExpectedItems + " items; got: " + nItemsReturned);
867 Assert.assertEquals(nItemsReturned, nExpectedItems);
869 for (AbstractCommonList.ListItem item : items) {
871 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
872 Assert.assertTrue((null != value), "Item refName is null!");
874 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
875 Assert.assertTrue((null != value), "Item displayName is null!");
877 if(logger.isTraceEnabled()){
878 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
881 res.releaseConnection();
887 // ---------------------------------------------------------------
888 // CRUD tests : UPDATE tests
889 // ---------------------------------------------------------------
892 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
895 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
896 groups = {"update"}, dependsOnGroups = {"read", "readList"})
897 public void update(String testName) throws Exception {
899 if (logger.isDebugEnabled()) {
900 logger.debug(testBanner(testName, CLASS_NAME));
905 // Retrieve the contents of a resource to update.
906 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
907 ClientResponse<String> res = client.read(knownResourceId);
909 if (logger.isDebugEnabled()) {
910 logger.debug(testName + ": read status = " + res.getStatus());
912 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
914 if (logger.isDebugEnabled()) {
915 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
917 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
918 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
919 client.getCommonPartName(), TaxonomyauthorityCommon.class);
920 Assert.assertNotNull(taxonomyAuthority);
922 // Update the contents of this resource.
923 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
924 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
925 if (logger.isDebugEnabled()) {
926 logger.debug("to be updated TaxonomyAuthority");
927 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
930 // Submit the updated resource to the service and store the response.
931 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
932 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
933 commonPart.setLabel(client.getCommonPartName());
934 res.releaseConnection();
935 res = client.update(knownResourceId, output);
936 int statusCode = res.getStatus();
938 // Check the status code of the response: does it match the expected response(s)?
939 if (logger.isDebugEnabled()) {
940 logger.debug(testName + ": status = " + statusCode);
942 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
943 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
944 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
946 // Retrieve the updated resource and verify that its contents exist.
947 input = new PoxPayloadIn(res.getEntity());
948 TaxonomyauthorityCommon updatedTaxonomyAuthority =
949 (TaxonomyauthorityCommon) extractPart(input,
950 client.getCommonPartName(), TaxonomyauthorityCommon.class);
951 Assert.assertNotNull(updatedTaxonomyAuthority);
953 // Verify that the updated resource received the correct data.
954 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
955 taxonomyAuthority.getDisplayName(),
956 "Data in updated object did not match submitted data.");
958 res.releaseConnection();
965 * @param testName the test name
966 * @throws Exception the exception
968 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
969 groups = {"update"}, dependsOnMethods = {"update"})
970 public void updateItem(String testName) throws Exception {
972 if (logger.isDebugEnabled()) {
973 logger.debug(testBanner(testName, CLASS_NAME));
978 // Retrieve the contents of a resource to update.
979 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
980 ClientResponse<String> res =
981 client.readItem(knownResourceId, knownItemResourceId);
983 if (logger.isDebugEnabled()) {
984 logger.debug(testName + ": read status = " + res.getStatus());
986 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
988 if (logger.isDebugEnabled()) {
989 logger.debug("got Taxonomy to update with ID: "
990 + knownItemResourceId
991 + " in TaxonomyAuthority: " + knownResourceId);
993 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
994 TaxonCommon taxon = (TaxonCommon) extractPart(input,
995 client.getItemCommonPartName(), TaxonCommon.class);
996 Assert.assertNotNull(taxon);
998 // Update the contents of this resource.
1000 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
1001 if (logger.isDebugEnabled()) {
1002 logger.debug("to be updated Taxonomy");
1003 logger.debug(objectAsXmlString(taxon,
1004 TaxonCommon.class));
1007 // Submit the updated resource to the service and store the response.
1008 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1009 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
1010 commonPart.setLabel(client.getItemCommonPartName());
1011 res.releaseConnection();
1012 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1013 int statusCode = res.getStatus();
1015 // Check the status code of the response: does it match the expected response(s)?
1016 if (logger.isDebugEnabled()) {
1017 logger.debug(testName + ": status = " + statusCode);
1019 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1020 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1021 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1023 // Retrieve the updated resource and verify that its contents exist.
1024 input = new PoxPayloadIn(res.getEntity());
1025 TaxonCommon updatedTaxon =
1026 (TaxonCommon) extractPart(input,
1027 client.getItemCommonPartName(), TaxonCommon.class);
1028 Assert.assertNotNull(updatedTaxon);
1030 // Verify that the updated resource received the correct data.
1031 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1032 "Data in updated Taxon did not match submitted data.");
1034 res.releaseConnection();
1039 // Placeholders until the three tests below can be uncommented.
1040 // See Issue CSPACE-401.
1042 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1045 public void updateWithEmptyEntityBody(String testName) throws Exception {
1049 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1052 public void updateWithMalformedXml(String testName) throws Exception {
1056 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1059 public void updateWithWrongXmlSchema(String testName) throws Exception {
1064 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1067 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1068 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1069 public void updateNonExistent(String testName) throws Exception {
1071 if (logger.isDebugEnabled()) {
1072 logger.debug(testBanner(testName, CLASS_NAME));
1075 setupUpdateNonExistent();
1077 // Submit the request to the service and store the response.
1078 // Note: The ID(s) used when creating the request payload may be arbitrary.
1079 // The only relevant ID may be the one used in update(), below.
1080 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1081 String displayName = "displayName-NON_EXISTENT_ID";
1082 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1083 displayName, "nonEx", client.getCommonPartName());
1084 ClientResponse<String> res =
1085 client.update(NON_EXISTENT_ID, multipart);
1087 int statusCode = res.getStatus();
1089 // Check the status code of the response: does it match
1090 // the expected response(s)?
1091 if (logger.isDebugEnabled()) {
1092 logger.debug(testName + ": status = " + statusCode);
1094 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1095 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1096 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1098 res.releaseConnection();
1103 * Update non existent item.
1105 * @param testName the test name
1106 * @throws Exception the exception
1108 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1109 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1110 public void updateNonExistentItem(String testName) throws Exception {
1112 if (logger.isDebugEnabled()) {
1113 logger.debug(testBanner(testName, CLASS_NAME));
1116 setupUpdateNonExistent();
1118 // Submit the request to the service and store the response.
1119 // Note: The ID used in this 'create' call may be arbitrary.
1120 // The only relevant ID may be the one used in update(), below.
1121 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1122 Map<String, String> nonexMap = new HashMap<String, String>();
1123 nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
1124 nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1125 nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
1126 PoxPayloadOut multipart =
1127 TaxonomyAuthorityClientUtils.createTaxonInstance(
1128 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1129 nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST,
1130 client.getItemCommonPartName());
1131 ClientResponse<String> res =
1132 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1134 int statusCode = res.getStatus();
1136 // Check the status code of the response: does it match
1137 // the expected response(s)?
1138 if (logger.isDebugEnabled()) {
1139 logger.debug(testName + ": status = " + statusCode);
1141 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1142 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1143 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1145 res.releaseConnection();
1149 // ---------------------------------------------------------------
1150 // CRUD tests : DELETE tests
1151 // ---------------------------------------------------------------
1153 // Note: delete sub-resources in ascending hierarchical order,
1154 // before deleting their parents.
1158 * @param testName the test name
1159 * @throws Exception the exception
1161 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1162 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1163 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1164 public void deleteItem(String testName) throws Exception {
1166 if (logger.isDebugEnabled()) {
1167 logger.debug(testBanner(testName, CLASS_NAME));
1172 if (logger.isDebugEnabled()) {
1173 logger.debug("parentcsid =" + knownResourceId
1174 + " itemcsid = " + knownItemResourceId);
1177 // Submit the request to the service and store the response.
1178 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1179 ClientResponse<Response> res =
1180 client.deleteItem(knownResourceId, knownItemResourceId);
1182 int statusCode = res.getStatus();
1184 // Check the status code of the response: does it match
1185 // the expected response(s)?
1186 if (logger.isDebugEnabled()) {
1187 logger.debug(testName + ": status = " + statusCode);
1189 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1190 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1191 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1193 res.releaseConnection();
1198 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1201 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1202 // groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1203 public void delete(String testName) throws Exception {
1205 if (logger.isDebugEnabled()) {
1206 logger.debug(testBanner(testName, CLASS_NAME));
1211 if (logger.isDebugEnabled()) {
1212 logger.debug("parentcsid =" + knownResourceId);
1215 // Submit the request to the service and store the response.
1216 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1217 ClientResponse<Response> res = client.delete(knownResourceId);
1219 int statusCode = res.getStatus();
1221 // Check the status code of the response: does it match
1222 // the expected response(s)?
1223 if (logger.isDebugEnabled()) {
1224 logger.debug(testName + ": status = " + statusCode);
1226 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1227 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1228 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1230 res.releaseConnection();
1236 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1239 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1240 // groups = {"delete"}, dependsOnMethods = {"delete"})
1241 public void deleteNonExistent(String testName) throws Exception {
1243 if (logger.isDebugEnabled()) {
1244 logger.debug(testBanner(testName, CLASS_NAME));
1247 setupDeleteNonExistent();
1249 // Submit the request to the service and store the response.
1250 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1251 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1253 int statusCode = res.getStatus();
1255 // Check the status code of the response: does it match
1256 // the expected response(s)?
1257 if (logger.isDebugEnabled()) {
1258 logger.debug(testName + ": status = " + statusCode);
1260 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1261 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1262 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1264 res.releaseConnection();
1269 * Delete non existent item.
1271 * @param testName the test name
1273 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1274 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1275 public void deleteNonExistentItem(String testName) {
1277 if (logger.isDebugEnabled()) {
1278 logger.debug(testBanner(testName, CLASS_NAME));
1281 setupDeleteNonExistent();
1283 // Submit the request to the service and store the response.
1284 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1285 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1287 int statusCode = res.getStatus();
1289 // Check the status code of the response: does it match
1290 // the expected response(s)?
1291 if (logger.isDebugEnabled()) {
1292 logger.debug(testName + ": status = " + statusCode);
1294 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1295 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1296 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1298 res.releaseConnection();
1302 // ---------------------------------------------------------------
1303 // Utility tests : tests of code used in tests above
1304 // ---------------------------------------------------------------
1306 * Tests the code for manually submitting data that is used by several
1307 * of the methods above.
1309 @Test(dependsOnMethods = {"create", "read"})
1310 public void testSubmitRequest() {
1312 // Expected status code: 200 OK
1313 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1315 // Submit the request to the service and store the response.
1316 String method = ServiceRequestType.READ.httpMethodName();
1317 String url = getResourceURL(knownResourceId);
1318 int statusCode = submitRequest(method, url);
1320 // Check the status code of the response: does it match
1321 // the expected response(s)?
1322 if (logger.isDebugEnabled()) {
1323 logger.debug("testSubmitRequest: url=" + url
1324 + " status=" + statusCode);
1326 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1331 * Test item submit request.
1333 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1334 public void testItemSubmitRequest() {
1336 // Expected status code: 200 OK
1337 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1339 // Submit the request to the service and store the response.
1340 String method = ServiceRequestType.READ.httpMethodName();
1341 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1342 int statusCode = submitRequest(method, url);
1344 // Check the status code of the response: does it match
1345 // the expected response(s)?
1346 if (logger.isDebugEnabled()) {
1347 logger.debug("testItemSubmitRequest: url=" + url
1348 + " status=" + statusCode);
1350 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1354 // ---------------------------------------------------------------
1355 // Cleanup of resources created during testing
1356 // ---------------------------------------------------------------
1358 * Deletes all resources created by tests, after all tests have been run.
1360 * This cleanup method will always be run, even if one or more tests fail.
1361 * For this reason, it attempts to remove all resources created
1362 * at any point during testing, even if some of those resources
1363 * may be expected to be deleted by certain tests.
1365 @AfterClass(alwaysRun = true)
1366 public void cleanUp() {
1367 String noTest = System.getProperty("noTestCleanup");
1368 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1369 if (logger.isDebugEnabled()) {
1370 logger.debug("Skipping Cleanup phase ...");
1374 if (logger.isDebugEnabled()) {
1375 logger.debug("Cleaning up temporary resources created for testing ...");
1377 String parentResourceId;
1378 String itemResourceId;
1379 // Clean up contact resources.
1380 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1381 parentResourceId = knownResourceId;
1382 // Clean up item resources.
1383 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1384 itemResourceId = entry.getKey();
1385 parentResourceId = entry.getValue();
1386 // Note: Any non-success responses from the delete operation
1387 // below are ignored and not reported.
1388 ClientResponse<Response> res =
1389 client.deleteItem(parentResourceId, itemResourceId);
1390 res.releaseConnection();
1392 // Clean up parent resources.
1393 for (String resourceId : allResourceIdsCreated) {
1394 // Note: Any non-success responses from the delete operation
1395 // below are ignored and not reported.
1396 ClientResponse<Response> res = client.delete(resourceId);
1397 res.releaseConnection();
1401 // ---------------------------------------------------------------
1402 // Utility methods used by tests above
1403 // ---------------------------------------------------------------
1405 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1408 * Returns the root URL for the item service.
1410 * This URL consists of a base URL for all services, followed by
1411 * a path component for the owning parent, followed by the
1412 * path component for the items.
1414 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1415 * parent authority resource of the relevant item resource.
1417 * @return The root URL for the item service.
1419 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1420 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1424 * Returns the URL of a specific item resource managed by a service, and
1425 * designated by an identifier (such as a universally unique ID, or UUID).
1427 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1428 * parent authority resource of the relevant item resource.
1430 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1433 * @return The URL of a specific item resource managed by a service.
1435 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1436 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;