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.TaxonAuthorGroup;
40 import org.collectionspace.services.taxonomy.TaxonAuthorGroupList;
41 import org.collectionspace.services.taxonomy.TaxonCitationList;
42 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
43 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList;
44 import org.collectionspace.services.taxonomy.TaxonCommon;
45 import org.collectionspace.services.taxonomy.TaxonCommonList;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import org.jboss.resteasy.client.ClientResponse;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
59 * TaxonomyAuthorityServiceTest, carries out tests against a
60 * deployed and running TaxonomyAuthority Service.
62 * $LastChangedRevision$
65 public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class!
68 private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName();
69 private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class);
72 public String getServicePathComponent() {
73 return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
77 protected String getServiceName() {
78 return TaxonomyAuthorityClient.SERVICE_NAME;
81 public String getItemServicePathComponent() {
82 return AuthorityClient.ITEMS;
84 final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
85 final String TEST_TERM_STATUS = "accepted";
86 final String TEST_TAXON_FULL_NAME = "Centaurus pleurexanthemus Green 1832";
87 // TODO Re-implement the Taxon Rank field so as to provide an orderable
88 // ranking value, as well as a display name.
89 final String TEST_TAXON_RANK = "species";
90 final String TEST_TAXON_AUTHOR = "J. Green";
91 final String TEST_TAXON_AUTHOR_TYPE = "ascribed";
92 final String TEST_TAXON_CITATION = "A Monograph of the Trilobites of North America";
93 final String TEST_TAXON_CURRENCY = "current";
94 final String TEST_TAXON_YEAR = "1832";
95 final String TEST_TAXONOMIC_STATUS = "valid";
96 final String TEST_TAXON_IS_NAMED_HYBRID = "false";
97 final TaxonAuthorGroupList NULL_TAXON_AUTHOR_GROUP_LIST = null;
98 final TaxonCitationList NULL_TAXON_CITATION_LIST = null;
99 /** The known resource id. */
100 private String knownResourceId = null;
101 private String knownResourceShortIdentifer = null;
102 private String knownResourceRefName = null;
103 private String knownTaxonomyTypeRefName = null;
104 private String knownItemResourceId = null;
105 private String knownItemResourceShortIdentifer = null;
106 /** The n items to create in list. */
107 private int nItemsToCreateInList = 3;
108 /** The all resource ids created. */
109 private List<String> allResourceIdsCreated = new ArrayList<String>();
110 /** The all item resource ids created. */
111 private Map<String, String> allItemResourceIdsCreated =
112 new HashMap<String, String>();
114 protected void setKnownResource(String id, String shortIdentifer,
116 knownResourceId = id;
117 knownResourceShortIdentifer = shortIdentifer;
118 knownResourceRefName = refName;
121 protected void setKnownItemResource(String id, String shortIdentifer) {
122 knownItemResourceId = id;
123 knownItemResourceShortIdentifer = shortIdentifer;
127 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
130 protected CollectionSpaceClient getClientInstance() {
131 return new TaxonomyAuthorityClient();
135 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
138 protected AbstractCommonList getAbstractCommonList(
139 ClientResponse<AbstractCommonList> response) {
140 return response.getEntity(TaxonCommonList.class);
144 protected PoxPayloadOut createInstance(String identifier) {
145 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
146 String shortId = identifier;
147 String displayName = "displayName-" + shortId;
149 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
150 PoxPayloadOut multipart =
151 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
152 displayName, shortId, client.getCommonPartName());
156 // ---------------------------------------------------------------
157 // CRUD tests : CREATE tests
158 // ---------------------------------------------------------------
161 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
164 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
166 public void create(String testName) throws Exception {
168 if (logger.isDebugEnabled()) {
169 logger.debug(testBanner(testName, CLASS_NAME));
171 // Perform setup, such as initializing the type of service request
172 // (e.g. CREATE, DELETE), its valid and expected status codes, and
173 // its associated HTTP method name (e.g. POST, DELETE).
176 // Submit the request to the service and store the response.
177 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
178 String shortId = createIdentifier();
179 String displayName = "displayName-" + shortId;
181 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
183 PoxPayloadOut multipart =
184 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
185 displayName, shortId, client.getCommonPartName());
187 ClientResponse<Response> res = client.create(multipart);
189 int statusCode = res.getStatus();
191 // Check the status code of the response: does it match
192 // the expected response(s)?
195 // Does it fall within the set of valid status codes?
196 // Does it exactly match the expected status code?
197 if (logger.isDebugEnabled()) {
198 logger.debug(testName + ": status = " + statusCode);
200 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
201 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
202 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
204 newID = TaxonomyAuthorityClientUtils.extractId(res);
206 res.releaseConnection();
208 // Store the ID returned from the first resource created
209 // for additional tests below.
210 if (knownResourceId == null) {
211 setKnownResource(newID, shortId, baseRefName);
212 if (logger.isDebugEnabled()) {
213 logger.debug(testName + ": knownResourceId=" + knownResourceId);
216 // Store the IDs from every resource created by tests,
217 // so they can be deleted after tests have been run.
218 allResourceIdsCreated.add(newID);
224 * @param testName the test name
226 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
227 groups = {"create"}, dependsOnMethods = {"create"})
228 public void createItem(String testName) {
229 if (logger.isDebugEnabled()) {
230 logger.debug(testBanner(testName, CLASS_NAME));
233 createItemInAuthority(knownResourceId, knownResourceRefName);
237 * Creates the item in authority.
239 * @param vcsid the vcsid
240 * @param authRefName the auth ref name
243 private String createItemInAuthority(String vcsid, String authRefName) {
245 final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")";
246 if (logger.isDebugEnabled()) {
247 logger.debug(testBanner(testName, CLASS_NAME));
250 // Submit the request to the service and store the response.
251 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
252 Map<String, String> taxonMap = new HashMap<String, String>();
254 // Fields present in all authority records.
255 taxonMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
256 // TODO Make term status be controlled vocab.
257 taxonMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
259 // Fields specific to this specific authority record type.
260 taxonMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
261 taxonMap.put(TaxonJAXBSchema.TAXON_RANK, TEST_TAXON_RANK);
262 taxonMap.put(TaxonJAXBSchema.TAXON_CURRENCY, TEST_TAXON_CURRENCY);
263 taxonMap.put(TaxonJAXBSchema.TAXON_YEAR, TEST_TAXON_YEAR);
264 taxonMap.put(TaxonJAXBSchema.TAXONOMIC_STATUS, TEST_TAXONOMIC_STATUS);
265 taxonMap.put(TaxonJAXBSchema.TAXON_IS_NAMED_HYBRID, TEST_TAXON_IS_NAMED_HYBRID);
267 TaxonCitationList taxonCitationList = new TaxonCitationList();
268 List<String> taxonCitations = taxonCitationList.getTaxonCitation();
269 taxonCitations.add(TEST_TAXON_CITATION);
271 TaxonAuthorGroupList taxonAuthorGroupList = new TaxonAuthorGroupList();
272 List<TaxonAuthorGroup> taxonAuthorGroups = taxonAuthorGroupList.getTaxonAuthorGroup();
273 TaxonAuthorGroup taxonAuthorGroup = new TaxonAuthorGroup();
274 taxonAuthorGroup.setTaxonAuthor(TEST_TAXON_AUTHOR);
275 taxonAuthorGroup.setTaxonAuthorType(TEST_TAXON_AUTHOR_TYPE);
276 taxonAuthorGroups.add(taxonAuthorGroup);
278 // FIXME: Add additional fields in the Taxon record here,
279 // including at least one each of:
280 // * a Boolean field (when implemented)
281 // * an authref field (when implemented)
283 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
284 authRefName, taxonMap, taxonAuthorGroupList, taxonCitationList, client);
286 // Store the ID returned from the first item resource created
287 // for additional tests below.
288 if (knownItemResourceId == null) {
289 setKnownItemResource(newID, TEST_SHORTID);
290 if (logger.isDebugEnabled()) {
291 logger.debug(testName + ": knownItemResourceId=" + newID + " inAuthority=" + vcsid);
295 // Store the IDs from any item resources created
296 // by tests, along with the IDs of their parents, so these items
297 // can be deleted after all tests have been run.
298 allItemResourceIdsCreated.put(newID, vcsid);
304 // Placeholders until the three tests below can be uncommented.
305 // See Issue CSPACE-401.
307 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
310 public void createWithEmptyEntityBody(String testName) throws Exception {
314 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
317 public void createWithMalformedXml(String testName) throws Exception {
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
324 public void createWithWrongXmlSchema(String testName) throws Exception {
327 // ---------------------------------------------------------------
328 // CRUD tests : CREATE LIST tests
329 // ---------------------------------------------------------------
332 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
335 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
336 groups = {"createList"}, dependsOnGroups = {"create"})
337 public void createList(String testName) throws Exception {
338 for (int i = 0; i < nItemsToCreateInList; i++) {
344 * Creates the item list.
346 * @param testName the test name
347 * @throws Exception the exception
349 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
350 groups = {"createList"}, dependsOnMethods = {"createList"})
351 public void createItemList(String testName) throws Exception {
352 // Add items to the initially-created, known parent record.
353 for (int j = 0; j < nItemsToCreateInList; j++) {
354 createItem(testName);
358 // ---------------------------------------------------------------
359 // CRUD tests : READ tests
360 // ---------------------------------------------------------------
363 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
366 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
367 groups = {"read"}, dependsOnGroups = {"create"})
368 public void read(String testName) throws Exception {
370 if (logger.isDebugEnabled()) {
371 logger.debug(testBanner(testName, CLASS_NAME));
376 // Submit the request to the service and store the response.
377 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
379 ClientResponse<String> res = client.read(knownResourceId);
381 int statusCode = res.getStatus();
383 // Check the status code of the response: does it match
384 // the expected response(s)?
385 if (logger.isDebugEnabled()) {
386 logger.debug(testName + ": status = " + statusCode);
388 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
389 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
390 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
391 //FIXME: remove the following try catch once Aron fixes signatures
393 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
394 TaxonomyauthorityCommon taxonomyAuthority =
395 (TaxonomyauthorityCommon) extractPart(input,
396 client.getCommonPartName(), TaxonomyauthorityCommon.class);
397 Assert.assertNotNull(taxonomyAuthority);
398 } catch (Exception e) {
399 throw new RuntimeException(e);
402 res.releaseConnection();
409 * @param testName the test name
410 * @throws Exception the exception
412 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
413 groups = {"read"}, dependsOnGroups = {"create"})
414 public void readByName(String testName) throws Exception {
416 if (logger.isDebugEnabled()) {
417 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
422 // Submit the request to the service and store the response.
423 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
424 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
426 int statusCode = res.getStatus();
428 // Check the status code of the response: does it match
429 // the expected response(s)?
430 if (logger.isDebugEnabled()) {
431 logger.debug(testName + ": status = " + statusCode);
433 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
434 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
435 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
436 //FIXME: remove the following try catch once Aron fixes signatures
438 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
439 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
440 client.getCommonPartName(), TaxonomyauthorityCommon.class);
441 Assert.assertNotNull(taxonomyAuthority);
442 } catch (Exception e) {
443 throw new RuntimeException(e);
446 res.releaseConnection();
453 * @param testName the test name
454 * @throws Exception the exception
456 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
457 groups = {"read"}, dependsOnMethods = {"read"})
458 public void readItem(String testName) throws Exception {
460 if (logger.isDebugEnabled()) {
461 logger.debug(testBanner(testName, CLASS_NAME));
466 // Submit the request to the service and store the response.
467 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
468 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
470 int statusCode = res.getStatus();
472 // Check the status code of the response: does it match
473 // the expected response(s)?
474 if (logger.isDebugEnabled()) {
475 logger.debug(testName + ": status = " + statusCode);
477 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
478 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
479 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
481 // Check whether we've received an authority item record.
482 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
483 TaxonCommon taxon = (TaxonCommon) extractPart(input,
484 client.getItemCommonPartName(), TaxonCommon.class);
485 Assert.assertNotNull(taxon);
486 boolean showFull = true;
487 if (showFull && logger.isDebugEnabled()) {
488 logger.debug(testName + ": returned payload:");
489 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
492 // Check that this authority item record has the correct identifier
493 // pointing to its parent authority record.
494 Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null.");
495 Assert.assertEquals(taxon.getInAuthority(), knownResourceId,
496 "Value of item's inAuthority field does not contain the correct identifier "
497 + "pointing to its parent authority record.");
499 // Check individual fields in the authority item record.
500 Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null.");
501 Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME,
502 "Field value " + taxon.getTaxonFullName()
503 + "does not match expected value " + TEST_TAXON_FULL_NAME);
505 res.releaseConnection();
510 * Verify item display name.
512 * @param testName the test name
513 * @throws Exception the exception
515 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
516 dependsOnMethods = {"readItem", "updateItem"})
517 public void verifyItemDisplayName(String testName) throws Exception {
519 if (logger.isDebugEnabled()) {
520 logger.debug(testBanner(testName, CLASS_NAME));
525 // Submit the request to the service and store the response.
526 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
527 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
529 int statusCode = res.getStatus();
531 // Check the status code of the response: does it match
532 // the expected response(s)?
533 if (logger.isDebugEnabled()) {
534 logger.debug(testName + ": status = " + statusCode);
536 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
537 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
538 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
540 // Check whether taxon has expected displayName.
541 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
542 TaxonCommon taxon = (TaxonCommon) extractPart(input,
543 client.getItemCommonPartName(), TaxonCommon.class);
544 Assert.assertNotNull(taxon);
545 String displayName = taxon.getDisplayName();
546 // Make sure displayName matches computed form
547 String expectedDisplayName =
548 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_TAXON_FULL_NAME);
549 Assert.assertNotNull(displayName, expectedDisplayName);
551 // Update the shortName and verify the computed name is updated.
553 taxon.setDisplayNameComputed(true);
554 taxon.setTaxonFullName("updated-" + TEST_TAXON_FULL_NAME);
555 expectedDisplayName =
556 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_NAME);
558 // Submit the updated resource to the service and store the response.
559 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
560 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
561 commonPart.setLabel(client.getItemCommonPartName());
562 res.releaseConnection();
563 res = client.updateItem(knownResourceId, knownItemResourceId, output);
564 statusCode = res.getStatus();
566 // Check the status code of the response: does it match the expected response(s)?
567 if (logger.isDebugEnabled()) {
568 logger.debug("updateItem: status = " + statusCode);
570 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
571 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
572 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
574 // Retrieve the updated resource and verify that its contents exist.
575 input = new PoxPayloadIn(res.getEntity());
576 TaxonCommon updatedTaxon =
577 (TaxonCommon) extractPart(input,
578 client.getItemCommonPartName(), TaxonCommon.class);
579 Assert.assertNotNull(updatedTaxon);
581 // Verify that the updated resource received the correct data.
582 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
583 "Updated ForeName in Taxonomy did not match submitted data.");
584 // Verify that the updated resource computes the right displayName.
585 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
586 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
588 // Now Update the displayName, not computed and verify the computed name is overriden.
589 taxon.setDisplayNameComputed(false);
590 expectedDisplayName = "TestName";
591 taxon.setDisplayName(expectedDisplayName);
593 // Submit the updated resource to the service and store the response.
594 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
595 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
596 commonPart.setLabel(client.getItemCommonPartName());
597 res.releaseConnection();
598 res = client.updateItem(knownResourceId, knownItemResourceId, output);
599 statusCode = res.getStatus();
601 // Check the status code of the response: does it match the expected response(s)?
602 if (logger.isDebugEnabled()) {
603 logger.debug("updateItem: status = " + statusCode);
605 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
606 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
607 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
609 // Retrieve the updated resource and verify that its contents exist.
610 input = new PoxPayloadIn(res.getEntity());
612 (TaxonCommon) extractPart(input,
613 client.getItemCommonPartName(), TaxonCommon.class);
614 Assert.assertNotNull(updatedTaxon);
616 // Verify that the updated resource received the correct data.
617 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
618 "Updated displayNameComputed in Taxonomy did not match submitted data.");
619 // Verify that the updated resource computes the right displayName.
620 Assert.assertEquals(updatedTaxon.getDisplayName(),
622 "Updated DisplayName (not computed) in Taxonomy not stored.");
624 res.releaseConnection();
629 * Verify illegal item display name.
631 * @param testName the test name
632 * @throws Exception the exception
634 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
635 dependsOnMethods = {"verifyItemDisplayName"})
636 public void verifyIllegalItemDisplayName(String testName) throws Exception {
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
642 // FIXME: create a setup configuration for this operation.
643 setupUpdateWithWrongXmlSchema();
645 // Submit the request to the service and store the response.
646 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
647 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
649 int statusCode = res.getStatus();
651 // Check the status code of the response: does it match
652 // the expected response(s)?
653 if (logger.isDebugEnabled()) {
654 logger.debug(testName + ": status = " + statusCode);
656 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
657 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
658 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
660 // Check whether Taxonomy has expected displayName.
661 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
662 TaxonCommon taxon = (TaxonCommon) extractPart(input,
663 client.getItemCommonPartName(), TaxonCommon.class);
664 Assert.assertNotNull(taxon);
665 // Try to Update with computed false and no displayName
666 taxon.setDisplayNameComputed(false);
667 taxon.setDisplayName(null);
669 // Submit the updated resource to the service and store the response.
670 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
671 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
672 commonPart.setLabel(client.getItemCommonPartName());
673 res.releaseConnection();
674 res = client.updateItem(knownResourceId, knownItemResourceId, output);
675 statusCode = res.getStatus();
677 // Check the status code of the response: does it match the expected response(s)?
678 if (logger.isDebugEnabled()) {
679 logger.debug("updateItem: status = " + statusCode);
681 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
683 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
685 res.releaseConnection();
691 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
694 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
695 groups = {"read"}, dependsOnMethods = {"read"})
696 public void readNonExistent(String testName) {
698 if (logger.isDebugEnabled()) {
699 logger.debug(testBanner(testName, CLASS_NAME));
702 setupReadNonExistent();
704 // Submit the request to the service and store the response.
705 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
706 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
708 int statusCode = res.getStatus();
710 // Check the status code of the response: does it match
711 // the expected response(s)?
712 if (logger.isDebugEnabled()) {
713 logger.debug(testName + ": status = " + statusCode);
715 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
716 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
717 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
719 res.releaseConnection();
724 * Read item non existent.
726 * @param testName the test name
728 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
729 groups = {"read"}, dependsOnMethods = {"readItem"})
730 public void readItemNonExistent(String testName) {
732 if (logger.isDebugEnabled()) {
733 logger.debug(testBanner(testName, CLASS_NAME));
736 setupReadNonExistent();
738 // Submit the request to the service and store the response.
739 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
740 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
742 int statusCode = res.getStatus();
744 // Check the status code of the response: does it match
745 // the expected response(s)?
746 if (logger.isDebugEnabled()) {
747 logger.debug(testName + ": status = " + statusCode);
749 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
750 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
751 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
753 res.releaseConnection();
757 // ---------------------------------------------------------------
758 // CRUD tests : READ_LIST tests
759 // ---------------------------------------------------------------
763 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
766 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
767 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
768 public void readList(String testName) throws Exception {
770 if (logger.isDebugEnabled()) {
771 logger.debug(testBanner(testName, CLASS_NAME));
776 // Submit the request to the service and store the response.
777 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
778 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
780 TaxonomyauthorityCommonList list = res.getEntity();
781 int statusCode = res.getStatus();
783 // Check the status code of the response: does it match
784 // the expected response(s)?
785 if (logger.isDebugEnabled()) {
786 logger.debug(testName + ": status = " + statusCode);
788 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
789 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
790 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
792 // Optionally output additional data about list members for debugging.
793 boolean iterateThroughList = false;
794 if (iterateThroughList && logger.isDebugEnabled()) {
795 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
796 list.getTaxonomyauthorityListItem();
798 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
799 String csid = item.getCsid();
800 logger.debug(testName + ": list-item[" + i + "] csid="
802 logger.debug(testName + ": list-item[" + i + "] displayName="
803 + item.getDisplayName());
804 logger.debug(testName + ": list-item[" + i + "] URI="
806 readItemList(csid, null);
811 res.releaseConnection();
818 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
819 public void readItemList() {
820 String testName = "readItemList";
821 if (logger.isDebugEnabled()) {
822 logger.debug(testBanner(testName, CLASS_NAME));
824 readItemList(knownResourceId, null);
828 * Read item list by authority name.
830 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
831 public void readItemListByAuthorityName() {
832 String testName = "readItemListByAuthorityName";
833 if (logger.isDebugEnabled()) {
834 logger.debug(testBanner(testName, CLASS_NAME));
836 readItemList(null, knownResourceShortIdentifer);
842 * @param vcsid the vcsid
843 * @param name the name
845 private void readItemList(String vcsid, String shortId) {
847 String testName = "readItemList";
852 // Submit the request to the service and store the response.
853 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
854 ClientResponse<TaxonCommonList> res = null;
856 res = client.readItemList(vcsid, null, null);
857 } else if (shortId != null) {
858 res = client.readItemListForNamedAuthority(shortId, null, null);
860 Assert.fail("readItemList passed null csid and name!");
863 TaxonCommonList list = res.getEntity();
864 int statusCode = res.getStatus();
866 // Check the status code of the response: does it match
867 // the expected response(s)?
868 if (logger.isDebugEnabled()) {
869 logger.debug(testName + ": status = " + statusCode);
871 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
872 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
873 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
875 List<TaxonCommonList.TaxonListItem> items =
876 list.getTaxonListItem();
877 int nItemsReturned = items.size();
878 // There will be one item created, associated with a
879 // known parent resource, by the createItem test.
881 // In addition, there will be 'nItemsToCreateInList'
882 // additional items created by the createItemList test,
883 // all associated with the same parent resource.
884 int nExpectedItems = nItemsToCreateInList + 1;
885 if (logger.isDebugEnabled()) {
886 logger.debug(testName + ": Expected "
887 + nExpectedItems + " items; got: " + nItemsReturned);
889 Assert.assertEquals(nItemsReturned, nExpectedItems);
892 for (TaxonCommonList.TaxonListItem item : items) {
893 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
894 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
895 // Optionally output additional data about list members for debugging.
896 boolean showDetails = true;
897 if (showDetails && logger.isDebugEnabled()) {
898 logger.debug(" " + testName + ": list-item[" + i + "] csid="
900 logger.debug(" " + testName + ": list-item[" + i + "] refName="
901 + item.getRefName());
902 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
903 + item.getDisplayName());
904 logger.debug(" " + testName + ": list-item[" + i + "] URI="
910 res.releaseConnection();
916 // ---------------------------------------------------------------
917 // CRUD tests : UPDATE tests
918 // ---------------------------------------------------------------
921 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
924 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
925 groups = {"update"}, dependsOnGroups = {"read", "readList"})
926 public void update(String testName) throws Exception {
928 if (logger.isDebugEnabled()) {
929 logger.debug(testBanner(testName, CLASS_NAME));
934 // Retrieve the contents of a resource to update.
935 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
936 ClientResponse<String> res = client.read(knownResourceId);
938 if (logger.isDebugEnabled()) {
939 logger.debug(testName + ": read status = " + res.getStatus());
941 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
943 if (logger.isDebugEnabled()) {
944 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
946 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
947 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
948 client.getCommonPartName(), TaxonomyauthorityCommon.class);
949 Assert.assertNotNull(taxonomyAuthority);
951 // Update the contents of this resource.
952 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
953 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
954 if (logger.isDebugEnabled()) {
955 logger.debug("to be updated TaxonomyAuthority");
956 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
959 // Submit the updated resource to the service and store the response.
960 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
961 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
962 commonPart.setLabel(client.getCommonPartName());
963 res.releaseConnection();
964 res = client.update(knownResourceId, output);
965 int statusCode = res.getStatus();
967 // Check the status code of the response: does it match the expected response(s)?
968 if (logger.isDebugEnabled()) {
969 logger.debug(testName + ": status = " + statusCode);
971 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
972 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
973 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
975 // Retrieve the updated resource and verify that its contents exist.
976 input = new PoxPayloadIn(res.getEntity());
977 TaxonomyauthorityCommon updatedTaxonomyAuthority =
978 (TaxonomyauthorityCommon) extractPart(input,
979 client.getCommonPartName(), TaxonomyauthorityCommon.class);
980 Assert.assertNotNull(updatedTaxonomyAuthority);
982 // Verify that the updated resource received the correct data.
983 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
984 taxonomyAuthority.getDisplayName(),
985 "Data in updated object did not match submitted data.");
987 res.releaseConnection();
994 * @param testName the test name
995 * @throws Exception the exception
997 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
998 groups = {"update"}, dependsOnMethods = {"update"})
999 public void updateItem(String testName) throws Exception {
1001 if (logger.isDebugEnabled()) {
1002 logger.debug(testBanner(testName, CLASS_NAME));
1007 // Retrieve the contents of a resource to update.
1008 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1009 ClientResponse<String> res =
1010 client.readItem(knownResourceId, knownItemResourceId);
1012 if (logger.isDebugEnabled()) {
1013 logger.debug(testName + ": read status = " + res.getStatus());
1015 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1017 if (logger.isDebugEnabled()) {
1018 logger.debug("got Taxonomy to update with ID: "
1019 + knownItemResourceId
1020 + " in TaxonomyAuthority: " + knownResourceId);
1022 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1023 TaxonCommon taxon = (TaxonCommon) extractPart(input,
1024 client.getItemCommonPartName(), TaxonCommon.class);
1025 Assert.assertNotNull(taxon);
1027 // Update the contents of this resource.
1028 taxon.setCsid(null);
1029 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
1030 if (logger.isDebugEnabled()) {
1031 logger.debug("to be updated Taxonomy");
1032 logger.debug(objectAsXmlString(taxon,
1033 TaxonCommon.class));
1036 // Submit the updated resource to the service and store the response.
1037 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1038 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
1039 commonPart.setLabel(client.getItemCommonPartName());
1040 res.releaseConnection();
1041 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1042 int statusCode = res.getStatus();
1044 // Check the status code of the response: does it match the expected response(s)?
1045 if (logger.isDebugEnabled()) {
1046 logger.debug(testName + ": status = " + statusCode);
1048 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1049 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1050 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1052 // Retrieve the updated resource and verify that its contents exist.
1053 input = new PoxPayloadIn(res.getEntity());
1054 TaxonCommon updatedTaxon =
1055 (TaxonCommon) extractPart(input,
1056 client.getItemCommonPartName(), TaxonCommon.class);
1057 Assert.assertNotNull(updatedTaxon);
1059 // Verify that the updated resource received the correct data.
1060 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1061 "Data in updated Taxon did not match submitted data.");
1063 res.releaseConnection();
1068 // Placeholders until the three tests below can be uncommented.
1069 // See Issue CSPACE-401.
1071 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1074 public void updateWithEmptyEntityBody(String testName) throws Exception {
1078 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1081 public void updateWithMalformedXml(String testName) throws Exception {
1085 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1088 public void updateWithWrongXmlSchema(String testName) throws Exception {
1093 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1096 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1097 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1098 public void updateNonExistent(String testName) throws Exception {
1100 if (logger.isDebugEnabled()) {
1101 logger.debug(testBanner(testName, CLASS_NAME));
1104 setupUpdateNonExistent();
1106 // Submit the request to the service and store the response.
1107 // Note: The ID(s) used when creating the request payload may be arbitrary.
1108 // The only relevant ID may be the one used in update(), below.
1109 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1110 String displayName = "displayName-NON_EXISTENT_ID";
1111 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1112 displayName, "nonEx", client.getCommonPartName());
1113 ClientResponse<String> res =
1114 client.update(NON_EXISTENT_ID, multipart);
1116 int statusCode = res.getStatus();
1118 // Check the status code of the response: does it match
1119 // the expected response(s)?
1120 if (logger.isDebugEnabled()) {
1121 logger.debug(testName + ": status = " + statusCode);
1123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1127 res.releaseConnection();
1132 * Update non existent item.
1134 * @param testName the test name
1135 * @throws Exception the exception
1137 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1138 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1139 public void updateNonExistentItem(String testName) throws Exception {
1141 if (logger.isDebugEnabled()) {
1142 logger.debug(testBanner(testName, CLASS_NAME));
1145 setupUpdateNonExistent();
1147 // Submit the request to the service and store the response.
1148 // Note: The ID used in this 'create' call may be arbitrary.
1149 // The only relevant ID may be the one used in update(), below.
1150 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1151 Map<String, String> nonexMap = new HashMap<String, String>();
1152 nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
1153 nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1154 nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
1155 PoxPayloadOut multipart =
1156 TaxonomyAuthorityClientUtils.createTaxonInstance(
1157 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1158 nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST,
1159 client.getItemCommonPartName());
1160 ClientResponse<String> res =
1161 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1163 int statusCode = res.getStatus();
1165 // Check the status code of the response: does it match
1166 // the expected response(s)?
1167 if (logger.isDebugEnabled()) {
1168 logger.debug(testName + ": status = " + statusCode);
1170 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1171 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1172 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1174 res.releaseConnection();
1178 // ---------------------------------------------------------------
1179 // CRUD tests : DELETE tests
1180 // ---------------------------------------------------------------
1182 // Note: delete sub-resources in ascending hierarchical order,
1183 // before deleting their parents.
1187 * @param testName the test name
1188 * @throws Exception the exception
1190 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1191 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1192 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1193 public void deleteItem(String testName) throws Exception {
1195 if (logger.isDebugEnabled()) {
1196 logger.debug(testBanner(testName, CLASS_NAME));
1201 if (logger.isDebugEnabled()) {
1202 logger.debug("parentcsid =" + knownResourceId
1203 + " itemcsid = " + knownItemResourceId);
1206 // Submit the request to the service and store the response.
1207 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1208 ClientResponse<Response> res =
1209 client.deleteItem(knownResourceId, knownItemResourceId);
1211 int statusCode = res.getStatus();
1213 // Check the status code of the response: does it match
1214 // the expected response(s)?
1215 if (logger.isDebugEnabled()) {
1216 logger.debug(testName + ": status = " + statusCode);
1218 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1219 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1220 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1222 res.releaseConnection();
1227 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1230 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1231 // groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1232 public void delete(String testName) throws Exception {
1234 if (logger.isDebugEnabled()) {
1235 logger.debug(testBanner(testName, CLASS_NAME));
1240 if (logger.isDebugEnabled()) {
1241 logger.debug("parentcsid =" + knownResourceId);
1244 // Submit the request to the service and store the response.
1245 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1246 ClientResponse<Response> res = client.delete(knownResourceId);
1248 int statusCode = res.getStatus();
1250 // Check the status code of the response: does it match
1251 // the expected response(s)?
1252 if (logger.isDebugEnabled()) {
1253 logger.debug(testName + ": status = " + statusCode);
1255 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1256 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1257 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1259 res.releaseConnection();
1265 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1268 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1269 // groups = {"delete"}, dependsOnMethods = {"delete"})
1270 public void deleteNonExistent(String testName) throws Exception {
1272 if (logger.isDebugEnabled()) {
1273 logger.debug(testBanner(testName, CLASS_NAME));
1276 setupDeleteNonExistent();
1278 // Submit the request to the service and store the response.
1279 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1280 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1282 int statusCode = res.getStatus();
1284 // Check the status code of the response: does it match
1285 // the expected response(s)?
1286 if (logger.isDebugEnabled()) {
1287 logger.debug(testName + ": status = " + statusCode);
1289 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1290 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1291 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1293 res.releaseConnection();
1298 * Delete non existent item.
1300 * @param testName the test name
1302 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1303 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1304 public void deleteNonExistentItem(String testName) {
1306 if (logger.isDebugEnabled()) {
1307 logger.debug(testBanner(testName, CLASS_NAME));
1310 setupDeleteNonExistent();
1312 // Submit the request to the service and store the response.
1313 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1314 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1316 int statusCode = res.getStatus();
1318 // Check the status code of the response: does it match
1319 // the expected response(s)?
1320 if (logger.isDebugEnabled()) {
1321 logger.debug(testName + ": status = " + statusCode);
1323 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1324 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1325 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1327 res.releaseConnection();
1331 // ---------------------------------------------------------------
1332 // Utility tests : tests of code used in tests above
1333 // ---------------------------------------------------------------
1335 * Tests the code for manually submitting data that is used by several
1336 * of the methods above.
1338 @Test(dependsOnMethods = {"create", "read"})
1339 public void testSubmitRequest() {
1341 // Expected status code: 200 OK
1342 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1344 // Submit the request to the service and store the response.
1345 String method = ServiceRequestType.READ.httpMethodName();
1346 String url = getResourceURL(knownResourceId);
1347 int statusCode = submitRequest(method, url);
1349 // Check the status code of the response: does it match
1350 // the expected response(s)?
1351 if (logger.isDebugEnabled()) {
1352 logger.debug("testSubmitRequest: url=" + url
1353 + " status=" + statusCode);
1355 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1360 * Test item submit request.
1362 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1363 public void testItemSubmitRequest() {
1365 // Expected status code: 200 OK
1366 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1368 // Submit the request to the service and store the response.
1369 String method = ServiceRequestType.READ.httpMethodName();
1370 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1371 int statusCode = submitRequest(method, url);
1373 // Check the status code of the response: does it match
1374 // the expected response(s)?
1375 if (logger.isDebugEnabled()) {
1376 logger.debug("testItemSubmitRequest: url=" + url
1377 + " status=" + statusCode);
1379 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1383 // ---------------------------------------------------------------
1384 // Cleanup of resources created during testing
1385 // ---------------------------------------------------------------
1387 * Deletes all resources created by tests, after all tests have been run.
1389 * This cleanup method will always be run, even if one or more tests fail.
1390 * For this reason, it attempts to remove all resources created
1391 * at any point during testing, even if some of those resources
1392 * may be expected to be deleted by certain tests.
1394 @AfterClass(alwaysRun = true)
1395 public void cleanUp() {
1396 String noTest = System.getProperty("noTestCleanup");
1397 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1398 if (logger.isDebugEnabled()) {
1399 logger.debug("Skipping Cleanup phase ...");
1403 if (logger.isDebugEnabled()) {
1404 logger.debug("Cleaning up temporary resources created for testing ...");
1406 String parentResourceId;
1407 String itemResourceId;
1408 // Clean up contact resources.
1409 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1410 parentResourceId = knownResourceId;
1411 // Clean up item resources.
1412 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1413 itemResourceId = entry.getKey();
1414 parentResourceId = entry.getValue();
1415 // Note: Any non-success responses from the delete operation
1416 // below are ignored and not reported.
1417 ClientResponse<Response> res =
1418 client.deleteItem(parentResourceId, itemResourceId);
1419 res.releaseConnection();
1421 // Clean up parent resources.
1422 for (String resourceId : allResourceIdsCreated) {
1423 // Note: Any non-success responses from the delete operation
1424 // below are ignored and not reported.
1425 ClientResponse<Response> res = client.delete(resourceId);
1426 res.releaseConnection();
1430 // ---------------------------------------------------------------
1431 // Utility methods used by tests above
1432 // ---------------------------------------------------------------
1434 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1437 * Returns the root URL for the item service.
1439 * This URL consists of a base URL for all services, followed by
1440 * a path component for the owning parent, followed by the
1441 * path component for the items.
1443 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1444 * parent authority resource of the relevant item resource.
1446 * @return The root URL for the item service.
1448 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1449 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1453 * Returns the URL of a specific item resource managed by a service, and
1454 * designated by an identifier (such as a universally unique ID, or UUID).
1456 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1457 * parent authority resource of the relevant item resource.
1459 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1462 * @return The URL of a specific item resource managed by a service.
1464 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1465 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;