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 boolean 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);
266 TaxonCitationList taxonCitationList = new TaxonCitationList();
267 List<String> taxonCitations = taxonCitationList.getTaxonCitation();
268 taxonCitations.add(TEST_TAXON_CITATION);
270 TaxonAuthorGroupList taxonAuthorGroupList = new TaxonAuthorGroupList();
271 List<TaxonAuthorGroup> taxonAuthorGroups = taxonAuthorGroupList.getTaxonAuthorGroup();
272 TaxonAuthorGroup taxonAuthorGroup = new TaxonAuthorGroup();
273 taxonAuthorGroup.setTaxonAuthor(TEST_TAXON_AUTHOR);
274 taxonAuthorGroup.setTaxonAuthorType(TEST_TAXON_AUTHOR_TYPE);
275 taxonAuthorGroups.add(taxonAuthorGroup);
277 // FIXME: Add additional fields in the Taxon record here,
278 // including at least one each of:
279 // * a repeatable field
280 // * a repeatable group of fields
282 // * an authref field (when implemented)
284 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
285 authRefName, taxonMap, taxonAuthorGroupList, taxonCitationList, client);
287 // Store the ID returned from the first item resource created
288 // for additional tests below.
289 if (knownItemResourceId == null) {
290 setKnownItemResource(newID, TEST_SHORTID);
291 if (logger.isDebugEnabled()) {
292 logger.debug(testName + ": knownItemResourceId=" + newID + " inAuthority=" + vcsid);
296 // Store the IDs from any item resources created
297 // by tests, along with the IDs of their parents, so these items
298 // can be deleted after all tests have been run.
299 allItemResourceIdsCreated.put(newID, vcsid);
305 // Placeholders until the three tests below can be uncommented.
306 // See Issue CSPACE-401.
308 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
311 public void createWithEmptyEntityBody(String testName) throws Exception {
315 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
318 public void createWithMalformedXml(String testName) throws Exception {
322 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
325 public void createWithWrongXmlSchema(String testName) throws Exception {
328 // ---------------------------------------------------------------
329 // CRUD tests : CREATE LIST tests
330 // ---------------------------------------------------------------
333 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
336 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
337 groups = {"createList"}, dependsOnGroups = {"create"})
338 public void createList(String testName) throws Exception {
339 for (int i = 0; i < nItemsToCreateInList; i++) {
345 * Creates the item list.
347 * @param testName the test name
348 * @throws Exception the exception
350 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
351 groups = {"createList"}, dependsOnMethods = {"createList"})
352 public void createItemList(String testName) throws Exception {
353 // Add items to the initially-created, known parent record.
354 for (int j = 0; j < nItemsToCreateInList; j++) {
355 createItem(testName);
359 // ---------------------------------------------------------------
360 // CRUD tests : READ tests
361 // ---------------------------------------------------------------
364 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
367 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
368 groups = {"read"}, dependsOnGroups = {"create"})
369 public void read(String testName) throws Exception {
371 if (logger.isDebugEnabled()) {
372 logger.debug(testBanner(testName, CLASS_NAME));
377 // Submit the request to the service and store the response.
378 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
380 ClientResponse<String> res = client.read(knownResourceId);
382 int statusCode = res.getStatus();
384 // Check the status code of the response: does it match
385 // the expected response(s)?
386 if (logger.isDebugEnabled()) {
387 logger.debug(testName + ": status = " + statusCode);
389 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
390 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
391 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
392 //FIXME: remove the following try catch once Aron fixes signatures
394 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
395 TaxonomyauthorityCommon taxonomyAuthority =
396 (TaxonomyauthorityCommon) extractPart(input,
397 client.getCommonPartName(), TaxonomyauthorityCommon.class);
398 Assert.assertNotNull(taxonomyAuthority);
399 } catch (Exception e) {
400 throw new RuntimeException(e);
403 res.releaseConnection();
410 * @param testName the test name
411 * @throws Exception the exception
413 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
414 groups = {"read"}, dependsOnGroups = {"create"})
415 public void readByName(String testName) throws Exception {
417 if (logger.isDebugEnabled()) {
418 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
423 // Submit the request to the service and store the response.
424 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
425 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
427 int statusCode = res.getStatus();
429 // Check the status code of the response: does it match
430 // the expected response(s)?
431 if (logger.isDebugEnabled()) {
432 logger.debug(testName + ": status = " + statusCode);
434 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
435 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
436 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
437 //FIXME: remove the following try catch once Aron fixes signatures
439 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
440 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
441 client.getCommonPartName(), TaxonomyauthorityCommon.class);
442 Assert.assertNotNull(taxonomyAuthority);
443 } catch (Exception e) {
444 throw new RuntimeException(e);
447 res.releaseConnection();
454 * @param testName the test name
455 * @throws Exception the exception
457 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
458 groups = {"read"}, dependsOnMethods = {"read"})
459 public void readItem(String testName) throws Exception {
461 if (logger.isDebugEnabled()) {
462 logger.debug(testBanner(testName, CLASS_NAME));
467 // Submit the request to the service and store the response.
468 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
469 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
471 int statusCode = res.getStatus();
473 // Check the status code of the response: does it match
474 // the expected response(s)?
475 if (logger.isDebugEnabled()) {
476 logger.debug(testName + ": status = " + statusCode);
478 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
479 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
480 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
482 // Check whether we've received an authority item record.
483 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
484 TaxonCommon taxon = (TaxonCommon) extractPart(input,
485 client.getItemCommonPartName(), TaxonCommon.class);
486 Assert.assertNotNull(taxon);
487 boolean showFull = true;
488 if (showFull && logger.isDebugEnabled()) {
489 logger.debug(testName + ": returned payload:");
490 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
493 // Check that this authority item record has the correct identifier
494 // pointing to its parent authority record.
495 Assert.assertNotNull(taxon.getInAuthority(), "inAuthority field value is unexpectedly null.");
496 Assert.assertEquals(taxon.getInAuthority(), knownResourceId,
497 "Value of item's inAuthority field does not contain the correct identifier "
498 + "pointing to its parent authority record.");
500 // Check individual fields in the authority item record.
501 Assert.assertNotNull(taxon.getTaxonFullName(), "Field value is unexpectedly null.");
502 Assert.assertEquals(taxon.getTaxonFullName(), TEST_TAXON_FULL_NAME,
503 "Field value " + taxon.getTaxonFullName()
504 + "does not match expected value " + TEST_TAXON_FULL_NAME);
506 res.releaseConnection();
511 * Verify item display name.
513 * @param testName the test name
514 * @throws Exception the exception
516 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
517 dependsOnMethods = {"readItem", "updateItem"})
518 public void verifyItemDisplayName(String testName) throws Exception {
520 if (logger.isDebugEnabled()) {
521 logger.debug(testBanner(testName, CLASS_NAME));
526 // Submit the request to the service and store the response.
527 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
528 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
530 int statusCode = res.getStatus();
532 // Check the status code of the response: does it match
533 // the expected response(s)?
534 if (logger.isDebugEnabled()) {
535 logger.debug(testName + ": status = " + statusCode);
537 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
538 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
539 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
541 // Check whether taxon has expected displayName.
542 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
543 TaxonCommon taxon = (TaxonCommon) extractPart(input,
544 client.getItemCommonPartName(), TaxonCommon.class);
545 Assert.assertNotNull(taxon);
546 String displayName = taxon.getDisplayName();
547 // Make sure displayName matches computed form
548 String expectedDisplayName =
549 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_TAXON_FULL_NAME);
550 Assert.assertNotNull(displayName, expectedDisplayName);
552 // Update the shortName and verify the computed name is updated.
554 taxon.setDisplayNameComputed(true);
555 taxon.setTaxonFullName("updated-" + TEST_TAXON_FULL_NAME);
556 expectedDisplayName =
557 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_TAXON_FULL_NAME);
559 // Submit the updated resource to the service and store the response.
560 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
561 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
562 commonPart.setLabel(client.getItemCommonPartName());
563 res.releaseConnection();
564 res = client.updateItem(knownResourceId, knownItemResourceId, output);
565 statusCode = res.getStatus();
567 // Check the status code of the response: does it match the expected response(s)?
568 if (logger.isDebugEnabled()) {
569 logger.debug("updateItem: status = " + statusCode);
571 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
572 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
573 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
575 // Retrieve the updated resource and verify that its contents exist.
576 input = new PoxPayloadIn(res.getEntity());
577 TaxonCommon updatedTaxon =
578 (TaxonCommon) extractPart(input,
579 client.getItemCommonPartName(), TaxonCommon.class);
580 Assert.assertNotNull(updatedTaxon);
582 // Verify that the updated resource received the correct data.
583 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
584 "Updated ForeName in Taxonomy did not match submitted data.");
585 // Verify that the updated resource computes the right displayName.
586 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
587 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
589 // Now Update the displayName, not computed and verify the computed name is overriden.
590 taxon.setDisplayNameComputed(false);
591 expectedDisplayName = "TestName";
592 taxon.setDisplayName(expectedDisplayName);
594 // Submit the updated resource to the service and store the response.
595 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
596 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
597 commonPart.setLabel(client.getItemCommonPartName());
598 res.releaseConnection();
599 res = client.updateItem(knownResourceId, knownItemResourceId, output);
600 statusCode = res.getStatus();
602 // Check the status code of the response: does it match the expected response(s)?
603 if (logger.isDebugEnabled()) {
604 logger.debug("updateItem: status = " + statusCode);
606 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
607 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
608 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 // Retrieve the updated resource and verify that its contents exist.
611 input = new PoxPayloadIn(res.getEntity());
613 (TaxonCommon) extractPart(input,
614 client.getItemCommonPartName(), TaxonCommon.class);
615 Assert.assertNotNull(updatedTaxon);
617 // Verify that the updated resource received the correct data.
618 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
619 "Updated displayNameComputed in Taxonomy did not match submitted data.");
620 // Verify that the updated resource computes the right displayName.
621 Assert.assertEquals(updatedTaxon.getDisplayName(),
623 "Updated DisplayName (not computed) in Taxonomy not stored.");
625 res.releaseConnection();
630 * Verify illegal item display name.
632 * @param testName the test name
633 * @throws Exception the exception
635 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
636 dependsOnMethods = {"verifyItemDisplayName"})
637 public void verifyIllegalItemDisplayName(String testName) throws Exception {
639 if (logger.isDebugEnabled()) {
640 logger.debug(testBanner(testName, CLASS_NAME));
643 // FIXME: create a setup configuration for this operation.
644 setupUpdateWithWrongXmlSchema();
646 // Submit the request to the service and store the response.
647 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
648 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
650 int statusCode = res.getStatus();
652 // Check the status code of the response: does it match
653 // the expected response(s)?
654 if (logger.isDebugEnabled()) {
655 logger.debug(testName + ": status = " + statusCode);
657 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
658 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
659 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
661 // Check whether Taxonomy has expected displayName.
662 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
663 TaxonCommon taxon = (TaxonCommon) extractPart(input,
664 client.getItemCommonPartName(), TaxonCommon.class);
665 Assert.assertNotNull(taxon);
666 // Try to Update with computed false and no displayName
667 taxon.setDisplayNameComputed(false);
668 taxon.setDisplayName(null);
670 // Submit the updated resource to the service and store the response.
671 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
672 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
673 commonPart.setLabel(client.getItemCommonPartName());
674 res.releaseConnection();
675 res = client.updateItem(knownResourceId, knownItemResourceId, output);
676 statusCode = res.getStatus();
678 // Check the status code of the response: does it match the expected response(s)?
679 if (logger.isDebugEnabled()) {
680 logger.debug("updateItem: status = " + statusCode);
682 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
683 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
684 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
686 res.releaseConnection();
692 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
695 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
696 groups = {"read"}, dependsOnMethods = {"read"})
697 public void readNonExistent(String testName) {
699 if (logger.isDebugEnabled()) {
700 logger.debug(testBanner(testName, CLASS_NAME));
703 setupReadNonExistent();
705 // Submit the request to the service and store the response.
706 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
707 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
709 int statusCode = res.getStatus();
711 // Check the status code of the response: does it match
712 // the expected response(s)?
713 if (logger.isDebugEnabled()) {
714 logger.debug(testName + ": status = " + statusCode);
716 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
717 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
718 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
720 res.releaseConnection();
725 * Read item non existent.
727 * @param testName the test name
729 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
730 groups = {"read"}, dependsOnMethods = {"readItem"})
731 public void readItemNonExistent(String testName) {
733 if (logger.isDebugEnabled()) {
734 logger.debug(testBanner(testName, CLASS_NAME));
737 setupReadNonExistent();
739 // Submit the request to the service and store the response.
740 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
741 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
743 int statusCode = res.getStatus();
745 // Check the status code of the response: does it match
746 // the expected response(s)?
747 if (logger.isDebugEnabled()) {
748 logger.debug(testName + ": status = " + statusCode);
750 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
751 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
752 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 res.releaseConnection();
758 // ---------------------------------------------------------------
759 // CRUD tests : READ_LIST tests
760 // ---------------------------------------------------------------
764 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
767 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
768 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
769 public void readList(String testName) throws Exception {
771 if (logger.isDebugEnabled()) {
772 logger.debug(testBanner(testName, CLASS_NAME));
777 // Submit the request to the service and store the response.
778 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
779 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
781 TaxonomyauthorityCommonList list = res.getEntity();
782 int statusCode = res.getStatus();
784 // Check the status code of the response: does it match
785 // the expected response(s)?
786 if (logger.isDebugEnabled()) {
787 logger.debug(testName + ": status = " + statusCode);
789 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
793 // Optionally output additional data about list members for debugging.
794 boolean iterateThroughList = false;
795 if (iterateThroughList && logger.isDebugEnabled()) {
796 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
797 list.getTaxonomyauthorityListItem();
799 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
800 String csid = item.getCsid();
801 logger.debug(testName + ": list-item[" + i + "] csid="
803 logger.debug(testName + ": list-item[" + i + "] displayName="
804 + item.getDisplayName());
805 logger.debug(testName + ": list-item[" + i + "] URI="
807 readItemList(csid, null);
812 res.releaseConnection();
819 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
820 public void readItemList() {
821 String testName = "readItemList";
822 if (logger.isDebugEnabled()) {
823 logger.debug(testBanner(testName, CLASS_NAME));
825 readItemList(knownResourceId, null);
829 * Read item list by authority name.
831 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
832 public void readItemListByAuthorityName() {
833 String testName = "readItemListByAuthorityName";
834 if (logger.isDebugEnabled()) {
835 logger.debug(testBanner(testName, CLASS_NAME));
837 readItemList(null, knownResourceShortIdentifer);
843 * @param vcsid the vcsid
844 * @param name the name
846 private void readItemList(String vcsid, String shortId) {
848 String testName = "readItemList";
853 // Submit the request to the service and store the response.
854 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
855 ClientResponse<TaxonCommonList> res = null;
857 res = client.readItemList(vcsid, null, null);
858 } else if (shortId != null) {
859 res = client.readItemListForNamedAuthority(shortId, null, null);
861 Assert.fail("readItemList passed null csid and name!");
864 TaxonCommonList list = res.getEntity();
865 int statusCode = res.getStatus();
867 // Check the status code of the response: does it match
868 // the expected response(s)?
869 if (logger.isDebugEnabled()) {
870 logger.debug(testName + ": status = " + statusCode);
872 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
873 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
874 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
876 List<TaxonCommonList.TaxonListItem> items =
877 list.getTaxonListItem();
878 int nItemsReturned = items.size();
879 // There will be one item created, associated with a
880 // known parent resource, by the createItem test.
882 // In addition, there will be 'nItemsToCreateInList'
883 // additional items created by the createItemList test,
884 // all associated with the same parent resource.
885 int nExpectedItems = nItemsToCreateInList + 1;
886 if (logger.isDebugEnabled()) {
887 logger.debug(testName + ": Expected "
888 + nExpectedItems + " items; got: " + nItemsReturned);
890 Assert.assertEquals(nItemsReturned, nExpectedItems);
893 for (TaxonCommonList.TaxonListItem item : items) {
894 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
895 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
896 // Optionally output additional data about list members for debugging.
897 boolean showDetails = true;
898 if (showDetails && logger.isDebugEnabled()) {
899 logger.debug(" " + testName + ": list-item[" + i + "] csid="
901 logger.debug(" " + testName + ": list-item[" + i + "] refName="
902 + item.getRefName());
903 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
904 + item.getDisplayName());
905 logger.debug(" " + testName + ": list-item[" + i + "] URI="
911 res.releaseConnection();
917 // ---------------------------------------------------------------
918 // CRUD tests : UPDATE tests
919 // ---------------------------------------------------------------
922 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
925 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
926 groups = {"update"}, dependsOnGroups = {"read", "readList"})
927 public void update(String testName) throws Exception {
929 if (logger.isDebugEnabled()) {
930 logger.debug(testBanner(testName, CLASS_NAME));
935 // Retrieve the contents of a resource to update.
936 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
937 ClientResponse<String> res = client.read(knownResourceId);
939 if (logger.isDebugEnabled()) {
940 logger.debug(testName + ": read status = " + res.getStatus());
942 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
944 if (logger.isDebugEnabled()) {
945 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
947 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
948 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
949 client.getCommonPartName(), TaxonomyauthorityCommon.class);
950 Assert.assertNotNull(taxonomyAuthority);
952 // Update the contents of this resource.
953 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
954 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
955 if (logger.isDebugEnabled()) {
956 logger.debug("to be updated TaxonomyAuthority");
957 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
960 // Submit the updated resource to the service and store the response.
961 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
962 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
963 commonPart.setLabel(client.getCommonPartName());
964 res.releaseConnection();
965 res = client.update(knownResourceId, output);
966 int statusCode = res.getStatus();
968 // Check the status code of the response: does it match the expected response(s)?
969 if (logger.isDebugEnabled()) {
970 logger.debug(testName + ": status = " + statusCode);
972 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
973 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
974 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
976 // Retrieve the updated resource and verify that its contents exist.
977 input = new PoxPayloadIn(res.getEntity());
978 TaxonomyauthorityCommon updatedTaxonomyAuthority =
979 (TaxonomyauthorityCommon) extractPart(input,
980 client.getCommonPartName(), TaxonomyauthorityCommon.class);
981 Assert.assertNotNull(updatedTaxonomyAuthority);
983 // Verify that the updated resource received the correct data.
984 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
985 taxonomyAuthority.getDisplayName(),
986 "Data in updated object did not match submitted data.");
988 res.releaseConnection();
995 * @param testName the test name
996 * @throws Exception the exception
998 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
999 groups = {"update"}, dependsOnMethods = {"update"})
1000 public void updateItem(String testName) throws Exception {
1002 if (logger.isDebugEnabled()) {
1003 logger.debug(testBanner(testName, CLASS_NAME));
1008 // Retrieve the contents of a resource to update.
1009 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1010 ClientResponse<String> res =
1011 client.readItem(knownResourceId, knownItemResourceId);
1013 if (logger.isDebugEnabled()) {
1014 logger.debug(testName + ": read status = " + res.getStatus());
1016 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1018 if (logger.isDebugEnabled()) {
1019 logger.debug("got Taxonomy to update with ID: "
1020 + knownItemResourceId
1021 + " in TaxonomyAuthority: " + knownResourceId);
1023 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1024 TaxonCommon taxon = (TaxonCommon) extractPart(input,
1025 client.getItemCommonPartName(), TaxonCommon.class);
1026 Assert.assertNotNull(taxon);
1028 // Update the contents of this resource.
1029 taxon.setCsid(null);
1030 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
1031 if (logger.isDebugEnabled()) {
1032 logger.debug("to be updated Taxonomy");
1033 logger.debug(objectAsXmlString(taxon,
1034 TaxonCommon.class));
1037 // Submit the updated resource to the service and store the response.
1038 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1039 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
1040 commonPart.setLabel(client.getItemCommonPartName());
1041 res.releaseConnection();
1042 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1043 int statusCode = res.getStatus();
1045 // Check the status code of the response: does it match the expected response(s)?
1046 if (logger.isDebugEnabled()) {
1047 logger.debug(testName + ": status = " + statusCode);
1049 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1050 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1051 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1053 // Retrieve the updated resource and verify that its contents exist.
1054 input = new PoxPayloadIn(res.getEntity());
1055 TaxonCommon updatedTaxon =
1056 (TaxonCommon) extractPart(input,
1057 client.getItemCommonPartName(), TaxonCommon.class);
1058 Assert.assertNotNull(updatedTaxon);
1060 // Verify that the updated resource received the correct data.
1061 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1062 "Data in updated Taxon did not match submitted data.");
1064 res.releaseConnection();
1069 // Placeholders until the three tests below can be uncommented.
1070 // See Issue CSPACE-401.
1072 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1075 public void updateWithEmptyEntityBody(String testName) throws Exception {
1079 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1082 public void updateWithMalformedXml(String testName) throws Exception {
1086 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1089 public void updateWithWrongXmlSchema(String testName) throws Exception {
1094 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1097 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1098 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1099 public void updateNonExistent(String testName) throws Exception {
1101 if (logger.isDebugEnabled()) {
1102 logger.debug(testBanner(testName, CLASS_NAME));
1105 setupUpdateNonExistent();
1107 // Submit the request to the service and store the response.
1108 // Note: The ID(s) used when creating the request payload may be arbitrary.
1109 // The only relevant ID may be the one used in update(), below.
1110 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1111 String displayName = "displayName-NON_EXISTENT_ID";
1112 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1113 displayName, "nonEx", client.getCommonPartName());
1114 ClientResponse<String> res =
1115 client.update(NON_EXISTENT_ID, multipart);
1117 int statusCode = res.getStatus();
1119 // Check the status code of the response: does it match
1120 // the expected response(s)?
1121 if (logger.isDebugEnabled()) {
1122 logger.debug(testName + ": status = " + statusCode);
1124 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1125 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1126 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1128 res.releaseConnection();
1133 * Update non existent item.
1135 * @param testName the test name
1136 * @throws Exception the exception
1138 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1139 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1140 public void updateNonExistentItem(String testName) throws Exception {
1142 if (logger.isDebugEnabled()) {
1143 logger.debug(testBanner(testName, CLASS_NAME));
1146 setupUpdateNonExistent();
1148 // Submit the request to the service and store the response.
1149 // Note: The ID used in this 'create' call may be arbitrary.
1150 // The only relevant ID may be the one used in update(), below.
1151 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1152 Map<String, String> nonexMap = new HashMap<String, String>();
1153 nonexMap.put(TaxonJAXBSchema.NAME, TEST_TAXON_FULL_NAME);
1154 nonexMap.put(TaxonJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1155 nonexMap.put(TaxonJAXBSchema.TERM_STATUS, TEST_TERM_STATUS);
1156 PoxPayloadOut multipart =
1157 TaxonomyAuthorityClientUtils.createTaxonInstance(
1158 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1159 nonexMap, NULL_TAXON_AUTHOR_GROUP_LIST, NULL_TAXON_CITATION_LIST,
1160 client.getItemCommonPartName());
1161 ClientResponse<String> res =
1162 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1164 int statusCode = res.getStatus();
1166 // Check the status code of the response: does it match
1167 // the expected response(s)?
1168 if (logger.isDebugEnabled()) {
1169 logger.debug(testName + ": status = " + statusCode);
1171 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1172 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1173 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1175 res.releaseConnection();
1179 // ---------------------------------------------------------------
1180 // CRUD tests : DELETE tests
1181 // ---------------------------------------------------------------
1183 // Note: delete sub-resources in ascending hierarchical order,
1184 // before deleting their parents.
1188 * @param testName the test name
1189 * @throws Exception the exception
1191 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1192 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1193 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1194 public void deleteItem(String testName) throws Exception {
1196 if (logger.isDebugEnabled()) {
1197 logger.debug(testBanner(testName, CLASS_NAME));
1202 if (logger.isDebugEnabled()) {
1203 logger.debug("parentcsid =" + knownResourceId
1204 + " itemcsid = " + knownItemResourceId);
1207 // Submit the request to the service and store the response.
1208 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1209 ClientResponse<Response> res =
1210 client.deleteItem(knownResourceId, knownItemResourceId);
1212 int statusCode = res.getStatus();
1214 // Check the status code of the response: does it match
1215 // the expected response(s)?
1216 if (logger.isDebugEnabled()) {
1217 logger.debug(testName + ": status = " + statusCode);
1219 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1220 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1221 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1223 res.releaseConnection();
1228 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1231 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1232 // groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1233 public void delete(String testName) throws Exception {
1235 if (logger.isDebugEnabled()) {
1236 logger.debug(testBanner(testName, CLASS_NAME));
1241 if (logger.isDebugEnabled()) {
1242 logger.debug("parentcsid =" + knownResourceId);
1245 // Submit the request to the service and store the response.
1246 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1247 ClientResponse<Response> res = client.delete(knownResourceId);
1249 int statusCode = res.getStatus();
1251 // Check the status code of the response: does it match
1252 // the expected response(s)?
1253 if (logger.isDebugEnabled()) {
1254 logger.debug(testName + ": status = " + statusCode);
1256 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1257 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1258 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1260 res.releaseConnection();
1266 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1269 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1270 // groups = {"delete"}, dependsOnMethods = {"delete"})
1271 public void deleteNonExistent(String testName) throws Exception {
1273 if (logger.isDebugEnabled()) {
1274 logger.debug(testBanner(testName, CLASS_NAME));
1277 setupDeleteNonExistent();
1279 // Submit the request to the service and store the response.
1280 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1281 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1283 int statusCode = res.getStatus();
1285 // Check the status code of the response: does it match
1286 // the expected response(s)?
1287 if (logger.isDebugEnabled()) {
1288 logger.debug(testName + ": status = " + statusCode);
1290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1294 res.releaseConnection();
1299 * Delete non existent item.
1301 * @param testName the test name
1303 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1304 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1305 public void deleteNonExistentItem(String testName) {
1307 if (logger.isDebugEnabled()) {
1308 logger.debug(testBanner(testName, CLASS_NAME));
1311 setupDeleteNonExistent();
1313 // Submit the request to the service and store the response.
1314 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1315 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1317 int statusCode = res.getStatus();
1319 // Check the status code of the response: does it match
1320 // the expected response(s)?
1321 if (logger.isDebugEnabled()) {
1322 logger.debug(testName + ": status = " + statusCode);
1324 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1325 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1326 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1328 res.releaseConnection();
1332 // ---------------------------------------------------------------
1333 // Utility tests : tests of code used in tests above
1334 // ---------------------------------------------------------------
1336 * Tests the code for manually submitting data that is used by several
1337 * of the methods above.
1339 @Test(dependsOnMethods = {"create", "read"})
1340 public void testSubmitRequest() {
1342 // Expected status code: 200 OK
1343 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1345 // Submit the request to the service and store the response.
1346 String method = ServiceRequestType.READ.httpMethodName();
1347 String url = getResourceURL(knownResourceId);
1348 int statusCode = submitRequest(method, url);
1350 // Check the status code of the response: does it match
1351 // the expected response(s)?
1352 if (logger.isDebugEnabled()) {
1353 logger.debug("testSubmitRequest: url=" + url
1354 + " status=" + statusCode);
1356 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1361 * Test item submit request.
1363 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1364 public void testItemSubmitRequest() {
1366 // Expected status code: 200 OK
1367 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1369 // Submit the request to the service and store the response.
1370 String method = ServiceRequestType.READ.httpMethodName();
1371 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1372 int statusCode = submitRequest(method, url);
1374 // Check the status code of the response: does it match
1375 // the expected response(s)?
1376 if (logger.isDebugEnabled()) {
1377 logger.debug("testItemSubmitRequest: url=" + url
1378 + " status=" + statusCode);
1380 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1384 // ---------------------------------------------------------------
1385 // Cleanup of resources created during testing
1386 // ---------------------------------------------------------------
1388 * Deletes all resources created by tests, after all tests have been run.
1390 * This cleanup method will always be run, even if one or more tests fail.
1391 * For this reason, it attempts to remove all resources created
1392 * at any point during testing, even if some of those resources
1393 * may be expected to be deleted by certain tests.
1395 @AfterClass(alwaysRun = true)
1396 public void cleanUp() {
1397 String noTest = System.getProperty("noTestCleanup");
1398 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1399 if (logger.isDebugEnabled()) {
1400 logger.debug("Skipping Cleanup phase ...");
1404 if (logger.isDebugEnabled()) {
1405 logger.debug("Cleaning up temporary resources created for testing ...");
1407 String parentResourceId;
1408 String itemResourceId;
1409 // Clean up contact resources.
1410 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1411 parentResourceId = knownResourceId;
1412 // Clean up item resources.
1413 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1414 itemResourceId = entry.getKey();
1415 parentResourceId = entry.getValue();
1416 // Note: Any non-success responses from the delete operation
1417 // below are ignored and not reported.
1418 ClientResponse<Response> res =
1419 client.deleteItem(parentResourceId, itemResourceId);
1420 res.releaseConnection();
1422 // Clean up parent resources.
1423 for (String resourceId : allResourceIdsCreated) {
1424 // Note: Any non-success responses from the delete operation
1425 // below are ignored and not reported.
1426 ClientResponse<Response> res = client.delete(resourceId);
1427 res.releaseConnection();
1431 // ---------------------------------------------------------------
1432 // Utility methods used by tests above
1433 // ---------------------------------------------------------------
1435 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1438 * Returns the root URL for the item service.
1440 * This URL consists of a base URL for all services, followed by
1441 * a path component for the owning parent, followed by the
1442 * path component for the items.
1444 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1445 * parent authority resource of the relevant item resource.
1447 * @return The root URL for the item service.
1449 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1450 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1454 * Returns the URL of a specific item resource managed by a service, and
1455 * designated by an identifier (such as a universally unique ID, or UUID).
1457 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1458 * parent authority resource of the relevant item resource.
1460 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1463 * @return The URL of a specific item resource managed by a service.
1465 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1466 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;