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.TaxonomyJAXBSchema;
31 import org.collectionspace.services.client.AuthorityClient;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.client.PayloadOutputPart;
36 import org.collectionspace.services.client.PoxPayloadIn;
37 import org.collectionspace.services.client.PoxPayloadOut;
38 import org.collectionspace.services.contact.ContactsCommon;
39 import org.collectionspace.services.contact.ContactsCommonList;
40 import org.collectionspace.services.client.TaxonomyAuthorityClient;
41 import org.collectionspace.services.client.TaxonomyAuthorityClientUtils;
42 import org.collectionspace.services.jaxb.AbstractCommonList;
43 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommon;
44 import org.collectionspace.services.taxonomy.TaxonomyauthorityCommonList;
45 import org.collectionspace.services.taxonomy.TaxonomyCommon;
46 import org.collectionspace.services.taxonomy.TaxonomyCommonList;
48 import javax.ws.rs.core.MediaType;
49 import javax.ws.rs.core.Response;
50 import org.jboss.resteasy.client.ClientResponse;
52 import org.slf4j.Logger;
53 import org.slf4j.LoggerFactory;
55 import org.testng.Assert;
56 import org.testng.annotations.AfterClass;
57 import org.testng.annotations.Test;
60 * TaxonomyAuthorityServiceTest, carries out tests against a
61 * deployed and running TaxonomyAuthority Service.
63 * $LastChangedRevision$
66 public class TaxonomyAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Taxonomy should have a base class!
69 private final String CLASS_NAME = TaxonomyAuthorityServiceTest.class.getName();
70 private final Logger logger = LoggerFactory.getLogger(TaxonomyAuthorityServiceTest.class);
73 public String getServicePathComponent() {
74 return TaxonomyAuthorityClient.SERVICE_PATH_COMPONENT;
78 protected String getServiceName() {
79 return TaxonomyAuthorityClient.SERVICE_NAME;
82 public String getItemServicePathComponent() {
83 return AuthorityClient.ITEMS;
86 final String TEST_FULL_NAME = "Centaurus pleurexanthemus Green 1832-";
87 final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
88 // TODO Make rank be a controlled vocab term, assuming that's how we'll implement it.
89 final String TEST_RANK = "5";
90 // TODO Make status type be a controlled vocab term.
91 final String TEST_STATUS = "Approved";
93 /** The known resource id. */
94 private String knownResourceId = null;
95 private String knownResourceShortIdentifer = null;
96 private String knownResourceRefName = null;
97 private String knownTaxonomyTypeRefName = null;
98 private String knownItemResourceId = null;
99 private String knownItemResourceShortIdentifer = null;
100 private String knownContactResourceId = null;
102 /** The n items to create in list. */
103 private int nItemsToCreateInList = 3;
105 /** The all resource ids created. */
106 private List<String> allResourceIdsCreated = new ArrayList<String>();
108 /** The all item resource ids created. */
109 private Map<String, String> allItemResourceIdsCreated =
110 new HashMap<String, String>();
112 protected void setKnownResource( String id, String shortIdentifer,
114 knownResourceId = id;
115 knownResourceShortIdentifer = shortIdentifer;
116 knownResourceRefName = refName;
119 protected void setKnownItemResource( String id, String shortIdentifer ) {
120 knownItemResourceId = id;
121 knownItemResourceShortIdentifer = shortIdentifer;
125 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
128 protected CollectionSpaceClient getClientInstance() {
129 return new TaxonomyAuthorityClient();
133 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
136 protected AbstractCommonList getAbstractCommonList(
137 ClientResponse<AbstractCommonList> response) {
138 return response.getEntity(TaxonomyCommonList.class);
142 protected PoxPayloadOut createInstance(String identifier) {
143 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
144 String shortId = identifier;
145 String displayName = "displayName-" + shortId;
147 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
148 PoxPayloadOut multipart =
149 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
150 displayName, shortId, client.getCommonPartName());
154 // ---------------------------------------------------------------
155 // CRUD tests : CREATE tests
156 // ---------------------------------------------------------------
159 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
162 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
164 public void create(String testName) throws Exception {
166 if (logger.isDebugEnabled()) {
167 logger.debug(testBanner(testName, CLASS_NAME));
169 // Perform setup, such as initializing the type of service request
170 // (e.g. CREATE, DELETE), its valid and expected status codes, and
171 // its associated HTTP method name (e.g. POST, DELETE).
174 // Submit the request to the service and store the response.
175 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
176 String shortId = createIdentifier();
177 String displayName = "displayName-" + shortId;
179 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
181 PoxPayloadOut multipart =
182 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
183 displayName, shortId, client.getCommonPartName());
185 ClientResponse<Response> res = client.create(multipart);
187 int statusCode = res.getStatus();
189 // Check the status code of the response: does it match
190 // the expected response(s)?
193 // Does it fall within the set of valid status codes?
194 // Does it exactly match the expected status code?
195 if(logger.isDebugEnabled()){
196 logger.debug(testName + ": status = " + statusCode);
198 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
199 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
200 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
202 newID = TaxonomyAuthorityClientUtils.extractId(res);
204 res.releaseConnection();
206 // Store the ID returned from the first resource created
207 // for additional tests below.
208 if (knownResourceId == null){
209 setKnownResource( newID, shortId, baseRefName );
210 if (logger.isDebugEnabled()) {
211 logger.debug(testName + ": knownResourceId=" + knownResourceId);
214 // Store the IDs from every resource created by tests,
215 // so they can be deleted after tests have been run.
216 allResourceIdsCreated.add(newID);
222 * @param testName the test name
224 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
225 groups = {"create"}, dependsOnMethods = {"create"})
226 public void createItem(String testName) {
227 if(logger.isDebugEnabled()){
228 logger.debug(testBanner(testName, CLASS_NAME));
231 createItemInAuthority(knownResourceId, knownResourceRefName);
235 * Creates the item in authority.
237 * @param vcsid the vcsid
238 * @param authRefName the auth ref name
241 private String createItemInAuthority(String vcsid, String authRefName) {
243 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
244 if(logger.isDebugEnabled()){
245 logger.debug(testBanner(testName, CLASS_NAME));
248 // Submit the request to the service and store the response.
249 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
250 Map<String, String> shelf1Map = new HashMap<String,String>();
251 // TODO Make loc type and status be controlled vocabs.
252 shelf1Map.put(TaxonomyJAXBSchema.FULL_NAME, TEST_FULL_NAME);
253 shelf1Map.put(TaxonomyJAXBSchema.TAXON_RANK, TEST_RANK);
254 shelf1Map.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
256 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
257 authRefName, shelf1Map, client );
259 // Store the ID returned from the first item resource created
260 // for additional tests below.
261 if (knownItemResourceId == null){
262 setKnownItemResource(newID, TEST_SHORTID);
263 if (logger.isDebugEnabled()) {
264 logger.debug(testName + ": knownItemResourceId=" + newID);
268 // Store the IDs from any item resources created
269 // by tests, along with the IDs of their parents, so these items
270 // can be deleted after all tests have been run.
271 allItemResourceIdsCreated.put(newID, vcsid);
280 // Placeholders until the three tests below can be uncommented.
281 // See Issue CSPACE-401.
283 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
286 public void createWithEmptyEntityBody(String testName) throws Exception {
290 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
293 public void createWithMalformedXml(String testName) throws Exception {
297 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
300 public void createWithWrongXmlSchema(String testName) throws Exception {
304 // ---------------------------------------------------------------
305 // CRUD tests : CREATE LIST tests
306 // ---------------------------------------------------------------
309 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
312 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
313 groups = {"createList"}, dependsOnGroups = {"create"})
314 public void createList(String testName) throws Exception {
315 for (int i = 0; i < nItemsToCreateInList; i++) {
321 * Creates the item list.
323 * @param testName the test name
324 * @throws Exception the exception
326 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
327 groups = {"createList"}, dependsOnMethods = {"createList"})
328 public void createItemList(String testName) throws Exception {
329 // Add items to the initially-created, known parent record.
330 for (int j = 0; j < nItemsToCreateInList; j++) {
331 createItem(testName);
335 // ---------------------------------------------------------------
336 // CRUD tests : READ tests
337 // ---------------------------------------------------------------
340 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
343 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
344 groups = {"read"}, dependsOnGroups = {"create"})
345 public void read(String testName) throws Exception {
347 if (logger.isDebugEnabled()) {
348 logger.debug(testBanner(testName, CLASS_NAME));
353 // Submit the request to the service and store the response.
354 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
356 ClientResponse<String> res = client.read(knownResourceId);
358 int statusCode = res.getStatus();
360 // Check the status code of the response: does it match
361 // the expected response(s)?
362 if(logger.isDebugEnabled()){
363 logger.debug(testName + ": status = " + statusCode);
365 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
366 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
367 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
368 //FIXME: remove the following try catch once Aron fixes signatures
370 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
371 TaxonomyauthorityCommon taxonomyAuthority =
372 (TaxonomyauthorityCommon) extractPart(input,
373 client.getCommonPartName(), TaxonomyauthorityCommon.class);
374 Assert.assertNotNull(taxonomyAuthority);
375 } catch (Exception e) {
376 throw new RuntimeException(e);
379 res.releaseConnection();
386 * @param testName the test name
387 * @throws Exception the exception
389 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
390 groups = {"read"}, dependsOnGroups = {"create"})
391 public void readByName(String testName) throws Exception {
393 if (logger.isDebugEnabled()) {
394 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
399 // Submit the request to the service and store the response.
400 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
401 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
403 int statusCode = res.getStatus();
405 // Check the status code of the response: does it match
406 // the expected response(s)?
407 if(logger.isDebugEnabled()){
408 logger.debug(testName + ": status = " + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
413 //FIXME: remove the following try catch once Aron fixes signatures
415 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
416 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
417 client.getCommonPartName(), TaxonomyauthorityCommon.class);
418 Assert.assertNotNull(taxonomyAuthority);
419 } catch (Exception e) {
420 throw new RuntimeException(e);
423 res.releaseConnection();
431 * @param testName the test name
432 * @throws Exception the exception
434 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
435 groups = {"read"}, dependsOnMethods = {"read"})
436 public void readItem(String testName) throws Exception {
438 if (logger.isDebugEnabled()) {
439 logger.debug(testBanner(testName, CLASS_NAME));
444 // Submit the request to the service and store the response.
445 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
446 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
448 int statusCode = res.getStatus();
450 // Check the status code of the response: does it match
451 // the expected response(s)?
452 if(logger.isDebugEnabled()){
453 logger.debug(testName + ": status = " + statusCode);
455 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
456 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
457 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
459 // Check whether we've received a taxonomy.
460 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
461 TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input,
462 client.getItemCommonPartName(), TaxonomyCommon.class);
463 Assert.assertNotNull(taxonomy);
464 boolean showFull = true;
465 if(showFull && logger.isDebugEnabled()){
466 logger.debug(testName + ": returned payload:");
467 logger.debug(objectAsXmlString(taxonomy, TaxonomyCommon.class));
469 Assert.assertEquals(taxonomy.getInAuthority(), knownResourceId);
471 res.releaseConnection();
477 * Verify item display name.
479 * @param testName the test name
480 * @throws Exception the exception
482 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
483 dependsOnMethods = {"readItem", "updateItem"})
484 public void verifyItemDisplayName(String testName) throws Exception {
486 if (logger.isDebugEnabled()) {
487 logger.debug(testBanner(testName, CLASS_NAME));
492 // Submit the request to the service and store the response.
493 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
494 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
496 int statusCode = res.getStatus();
498 // Check the status code of the response: does it match
499 // the expected response(s)?
500 if(logger.isDebugEnabled()){
501 logger.debug(testName + ": status = " + statusCode);
503 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
504 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
505 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
507 // Check whether taxonomy has expected displayName.
508 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
509 TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input,
510 client.getItemCommonPartName(), TaxonomyCommon.class);
511 Assert.assertNotNull(taxonomy);
512 String displayName = taxonomy.getDisplayName();
513 // Make sure displayName matches computed form
514 String expectedDisplayName =
515 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_FULL_NAME);
516 Assert.assertNotNull(displayName, expectedDisplayName);
518 // Update the shortName and verify the computed name is updated.
519 taxonomy.setCsid(null);
520 taxonomy.setDisplayNameComputed(true);
521 taxonomy.setTaxonFullName("updated-" + TEST_FULL_NAME);
522 expectedDisplayName =
523 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_FULL_NAME);
525 // Submit the updated resource to the service and store the response.
526 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
527 PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
528 commonPart.setLabel(client.getItemCommonPartName());
529 res.releaseConnection();
530 res = client.updateItem(knownResourceId, knownItemResourceId, output);
531 statusCode = res.getStatus();
533 // Check the status code of the response: does it match the expected response(s)?
534 if(logger.isDebugEnabled()){
535 logger.debug("updateItem: status = " + statusCode);
537 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
538 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
539 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
541 // Retrieve the updated resource and verify that its contents exist.
542 input = new PoxPayloadIn(res.getEntity());
543 TaxonomyCommon updatedTaxonomy =
544 (TaxonomyCommon) extractPart(input,
545 client.getItemCommonPartName(), TaxonomyCommon.class);
546 Assert.assertNotNull(updatedTaxonomy);
548 // Verify that the updated resource received the correct data.
549 Assert.assertEquals(updatedTaxonomy.getTaxonFullName(), taxonomy.getTaxonFullName(),
550 "Updated ForeName in Taxonomy did not match submitted data.");
551 // Verify that the updated resource computes the right displayName.
552 Assert.assertEquals(updatedTaxonomy.getDisplayName(), expectedDisplayName,
553 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
555 // Now Update the displayName, not computed and verify the computed name is overriden.
556 taxonomy.setDisplayNameComputed(false);
557 expectedDisplayName = "TestName";
558 taxonomy.setDisplayName(expectedDisplayName);
560 // Submit the updated resource to the service and store the response.
561 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
562 commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
563 commonPart.setLabel(client.getItemCommonPartName());
564 res.releaseConnection();
565 res = client.updateItem(knownResourceId, knownItemResourceId, output);
566 statusCode = res.getStatus();
568 // Check the status code of the response: does it match the expected response(s)?
569 if(logger.isDebugEnabled()){
570 logger.debug("updateItem: status = " + statusCode);
572 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
573 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
574 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
576 // Retrieve the updated resource and verify that its contents exist.
577 input = new PoxPayloadIn(res.getEntity());
579 (TaxonomyCommon) extractPart(input,
580 client.getItemCommonPartName(), TaxonomyCommon.class);
581 Assert.assertNotNull(updatedTaxonomy);
583 // Verify that the updated resource received the correct data.
584 Assert.assertEquals(updatedTaxonomy.isDisplayNameComputed(), false,
585 "Updated displayNameComputed in Taxonomy did not match submitted data.");
586 // Verify that the updated resource computes the right displayName.
587 Assert.assertEquals(updatedTaxonomy.getDisplayName(),
589 "Updated DisplayName (not computed) in Taxonomy not stored.");
591 res.releaseConnection();
596 * Verify illegal item display name.
598 * @param testName the test name
599 * @throws Exception the exception
601 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
602 dependsOnMethods = {"verifyItemDisplayName"})
603 public void verifyIllegalItemDisplayName(String testName) throws Exception {
605 if (logger.isDebugEnabled()) {
606 logger.debug(testBanner(testName, CLASS_NAME));
609 // FIXME: create a setup configuration for this operation.
610 setupUpdateWithWrongXmlSchema();
612 // Submit the request to the service and store the response.
613 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
614 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
616 int statusCode = res.getStatus();
618 // Check the status code of the response: does it match
619 // the expected response(s)?
620 if(logger.isDebugEnabled()){
621 logger.debug(testName + ": status = " + statusCode);
623 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
624 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
625 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
627 // Check whether Taxonomy has expected displayName.
628 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
629 TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input,
630 client.getItemCommonPartName(), TaxonomyCommon.class);
631 Assert.assertNotNull(taxonomy);
632 // Try to Update with computed false and no displayName
633 taxonomy.setDisplayNameComputed(false);
634 taxonomy.setDisplayName(null);
636 // Submit the updated resource to the service and store the response.
637 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
638 PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
639 commonPart.setLabel(client.getItemCommonPartName());
640 res.releaseConnection();
641 res = client.updateItem(knownResourceId, knownItemResourceId, output);
642 statusCode = res.getStatus();
644 // Check the status code of the response: does it match the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug("updateItem: status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
652 res.releaseConnection();
659 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
662 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
663 groups = {"read"}, dependsOnMethods = {"read"})
664 public void readNonExistent(String testName) {
666 if (logger.isDebugEnabled()) {
667 logger.debug(testBanner(testName, CLASS_NAME));
670 setupReadNonExistent();
672 // Submit the request to the service and store the response.
673 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
674 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
676 int statusCode = res.getStatus();
678 // Check the status code of the response: does it match
679 // the expected response(s)?
680 if(logger.isDebugEnabled()){
681 logger.debug(testName + ": status = " + statusCode);
683 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
684 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
685 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
687 res.releaseConnection();
692 * Read item non existent.
694 * @param testName the test name
696 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
697 groups = {"read"}, dependsOnMethods = {"readItem"})
698 public void readItemNonExistent(String testName) {
700 if (logger.isDebugEnabled()) {
701 logger.debug(testBanner(testName, CLASS_NAME));
704 setupReadNonExistent();
706 // Submit the request to the service and store the response.
707 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
708 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
710 int statusCode = res.getStatus();
712 // Check the status code of the response: does it match
713 // the expected response(s)?
714 if(logger.isDebugEnabled()){
715 logger.debug(testName + ": status = " + statusCode);
717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
721 res.releaseConnection();
726 // ---------------------------------------------------------------
727 // CRUD tests : READ_LIST tests
728 // ---------------------------------------------------------------
732 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
735 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
736 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
737 public void readList(String testName) throws Exception {
739 if (logger.isDebugEnabled()) {
740 logger.debug(testBanner(testName, CLASS_NAME));
745 // Submit the request to the service and store the response.
746 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
747 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
749 TaxonomyauthorityCommonList list = res.getEntity();
750 int statusCode = res.getStatus();
752 // Check the status code of the response: does it match
753 // the expected response(s)?
754 if(logger.isDebugEnabled()){
755 logger.debug(testName + ": status = " + statusCode);
757 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
758 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
759 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
761 // Optionally output additional data about list members for debugging.
762 boolean iterateThroughList = false;
763 if (iterateThroughList && logger.isDebugEnabled()) {
764 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
765 list.getTaxonomyauthorityListItem();
767 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
768 String csid = item.getCsid();
769 logger.debug(testName + ": list-item[" + i + "] csid=" +
771 logger.debug(testName + ": list-item[" + i + "] displayName=" +
772 item.getDisplayName());
773 logger.debug(testName + ": list-item[" + i + "] URI=" +
775 readItemList(csid, null);
780 res.releaseConnection();
787 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
788 public void readItemList() {
789 String testName = "readItemList";
790 if (logger.isDebugEnabled()) {
791 logger.debug(testBanner(testName, CLASS_NAME));
793 readItemList(knownResourceId, null);
797 * Read item list by authority name.
799 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
800 public void readItemListByAuthorityName() {
801 String testName = "readItemListByAuthorityName";
802 if (logger.isDebugEnabled()) {
803 logger.debug(testBanner(testName, CLASS_NAME));
805 readItemList(null, knownResourceShortIdentifer);
811 * @param vcsid the vcsid
812 * @param name the name
814 private void readItemList(String vcsid, String shortId) {
816 String testName = "readItemList";
821 // Submit the request to the service and store the response.
822 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
823 ClientResponse<TaxonomyCommonList> res = null;
825 res = client.readItemList(vcsid, null, null);
826 } else if(shortId!= null) {
827 res = client.readItemListForNamedAuthority(shortId, null, null);
829 Assert.fail("readItemList passed null csid and name!");
832 TaxonomyCommonList list = res.getEntity();
833 int statusCode = res.getStatus();
835 // Check the status code of the response: does it match
836 // the expected response(s)?
837 if(logger.isDebugEnabled()){
838 logger.debug(testName + ": status = " + statusCode);
840 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
841 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
842 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
844 List<TaxonomyCommonList.TaxonomyListItem> items =
845 list.getTaxonomyListItem();
846 int nItemsReturned = items.size();
847 // There will be one item created, associated with a
848 // known parent resource, by the createItem test.
850 // In addition, there will be 'nItemsToCreateInList'
851 // additional items created by the createItemList test,
852 // all associated with the same parent resource.
853 int nExpectedItems = nItemsToCreateInList + 1;
854 if(logger.isDebugEnabled()){
855 logger.debug(testName + ": Expected "
856 + nExpectedItems +" items; got: "+nItemsReturned);
858 Assert.assertEquals(nItemsReturned, nExpectedItems);
861 for (TaxonomyCommonList.TaxonomyListItem item : items) {
862 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
863 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
864 // Optionally output additional data about list members for debugging.
865 boolean showDetails = true;
866 if (showDetails && logger.isDebugEnabled()) {
867 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
869 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
871 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
872 item.getDisplayName());
873 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
879 res.releaseConnection();
887 // ---------------------------------------------------------------
888 // CRUD tests : UPDATE tests
889 // ---------------------------------------------------------------
892 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
895 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
896 groups = {"update"}, dependsOnGroups = {"read", "readList"})
897 public void update(String testName) throws Exception {
899 if (logger.isDebugEnabled()) {
900 logger.debug(testBanner(testName, CLASS_NAME));
905 // Retrieve the contents of a resource to update.
906 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
907 ClientResponse<String> res = client.read(knownResourceId);
909 if(logger.isDebugEnabled()){
910 logger.debug(testName + ": read status = " + res.getStatus());
912 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
914 if(logger.isDebugEnabled()){
915 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
917 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
918 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
919 client.getCommonPartName(), TaxonomyauthorityCommon.class);
920 Assert.assertNotNull(taxonomyAuthority);
922 // Update the contents of this resource.
923 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
924 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
925 if(logger.isDebugEnabled()){
926 logger.debug("to be updated TaxonomyAuthority");
927 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
930 // Submit the updated resource to the service and store the response.
931 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
932 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
933 commonPart.setLabel(client.getCommonPartName());
934 res.releaseConnection();
935 res = client.update(knownResourceId, output);
936 int statusCode = res.getStatus();
938 // Check the status code of the response: does it match the expected response(s)?
939 if(logger.isDebugEnabled()){
940 logger.debug(testName + ": status = " + statusCode);
942 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
943 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
944 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
946 // Retrieve the updated resource and verify that its contents exist.
947 input = new PoxPayloadIn(res.getEntity());
948 TaxonomyauthorityCommon updatedTaxonomyAuthority =
949 (TaxonomyauthorityCommon) extractPart(input,
950 client.getCommonPartName(), TaxonomyauthorityCommon.class);
951 Assert.assertNotNull(updatedTaxonomyAuthority);
953 // Verify that the updated resource received the correct data.
954 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
955 taxonomyAuthority.getDisplayName(),
956 "Data in updated object did not match submitted data.");
958 res.releaseConnection();
965 * @param testName the test name
966 * @throws Exception the exception
968 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
969 groups = {"update"}, dependsOnMethods = {"update"})
970 public void updateItem(String testName) throws Exception {
972 if (logger.isDebugEnabled()) {
973 logger.debug(testBanner(testName, CLASS_NAME));
978 // Retrieve the contents of a resource to update.
979 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
980 ClientResponse<String> res =
981 client.readItem(knownResourceId, knownItemResourceId);
983 if(logger.isDebugEnabled()){
984 logger.debug(testName + ": read status = " + res.getStatus());
986 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
988 if(logger.isDebugEnabled()){
989 logger.debug("got Taxonomy to update with ID: " +
990 knownItemResourceId +
991 " in TaxonomyAuthority: " + knownResourceId );
993 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
994 TaxonomyCommon taxonomy = (TaxonomyCommon) extractPart(input,
995 client.getItemCommonPartName(), TaxonomyCommon.class);
996 Assert.assertNotNull(taxonomy);
998 // Update the contents of this resource.
999 taxonomy.setCsid(null);
1000 taxonomy.setTaxonFullName("updated-" + taxonomy.getTaxonFullName());
1001 if(logger.isDebugEnabled()){
1002 logger.debug("to be updated Taxonomy");
1003 logger.debug(objectAsXmlString(taxonomy,
1004 TaxonomyCommon.class));
1007 // Submit the updated resource to the service and store the response.
1008 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1009 PayloadOutputPart commonPart = output.addPart(taxonomy, MediaType.APPLICATION_XML_TYPE);
1010 commonPart.setLabel(client.getItemCommonPartName());
1011 res.releaseConnection();
1012 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1013 int statusCode = res.getStatus();
1015 // Check the status code of the response: does it match the expected response(s)?
1016 if(logger.isDebugEnabled()){
1017 logger.debug(testName + ": status = " + statusCode);
1019 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1020 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1021 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1023 // Retrieve the updated resource and verify that its contents exist.
1024 input = new PoxPayloadIn(res.getEntity());
1025 TaxonomyCommon updatedTaxonomy =
1026 (TaxonomyCommon) extractPart(input,
1027 client.getItemCommonPartName(), TaxonomyCommon.class);
1028 Assert.assertNotNull(updatedTaxonomy);
1030 // Verify that the updated resource received the correct data.
1031 Assert.assertEquals(updatedTaxonomy.getTaxonFullName(), taxonomy.getTaxonFullName(),
1032 "Data in updated Taxonomy did not match submitted data.");
1034 res.releaseConnection();
1039 // Placeholders until the three tests below can be uncommented.
1040 // See Issue CSPACE-401.
1042 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1045 public void updateWithEmptyEntityBody(String testName) throws Exception {
1049 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1052 public void updateWithMalformedXml(String testName) throws Exception {
1056 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1059 public void updateWithWrongXmlSchema(String testName) throws Exception {
1064 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1067 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1068 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1069 public void updateNonExistent(String testName) throws Exception {
1071 if (logger.isDebugEnabled()) {
1072 logger.debug(testBanner(testName, CLASS_NAME));
1075 setupUpdateNonExistent();
1077 // Submit the request to the service and store the response.
1078 // Note: The ID(s) used when creating the request payload may be arbitrary.
1079 // The only relevant ID may be the one used in update(), below.
1080 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1081 String displayName = "displayName-NON_EXISTENT_ID";
1082 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1083 displayName, "nonEx", client.getCommonPartName());
1084 ClientResponse<String> res =
1085 client.update(NON_EXISTENT_ID, multipart);
1087 int statusCode = res.getStatus();
1089 // Check the status code of the response: does it match
1090 // the expected response(s)?
1091 if(logger.isDebugEnabled()){
1092 logger.debug(testName + ": status = " + statusCode);
1094 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1095 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1096 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1098 res.releaseConnection();
1103 * Update non existent item.
1105 * @param testName the test name
1106 * @throws Exception the exception
1108 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1109 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1110 public void updateNonExistentItem(String testName) throws Exception {
1112 if (logger.isDebugEnabled()) {
1113 logger.debug(testBanner(testName, CLASS_NAME));
1116 setupUpdateNonExistent();
1118 // Submit the request to the service and store the response.
1119 // Note: The ID used in this 'create' call may be arbitrary.
1120 // The only relevant ID may be the one used in update(), below.
1121 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1122 Map<String, String> nonexMap = new HashMap<String,String>();
1123 nonexMap.put(TaxonomyJAXBSchema.FULL_NAME, TEST_FULL_NAME);
1124 nonexMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1125 nonexMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
1126 PoxPayloadOut multipart =
1127 TaxonomyAuthorityClientUtils.createTaxonomyInstance(
1128 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1129 nonexMap, client.getItemCommonPartName() );
1130 ClientResponse<String> res =
1131 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1133 int statusCode = res.getStatus();
1135 // Check the status code of the response: does it match
1136 // the expected response(s)?
1137 if(logger.isDebugEnabled()){
1138 logger.debug(testName + ": status = " + statusCode);
1140 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1141 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1142 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1144 res.releaseConnection();
1148 // ---------------------------------------------------------------
1149 // CRUD tests : DELETE tests
1150 // ---------------------------------------------------------------
1153 // Note: delete sub-resources in ascending hierarchical order,
1154 // before deleting their parents.
1159 * @param testName the test name
1160 * @throws Exception the exception
1162 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1163 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1164 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1165 public void deleteItem(String testName) throws Exception {
1167 if (logger.isDebugEnabled()) {
1168 logger.debug(testBanner(testName, CLASS_NAME));
1173 if(logger.isDebugEnabled()){
1174 logger.debug("parentcsid =" + knownResourceId +
1175 " itemcsid = " + knownItemResourceId);
1178 // Submit the request to the service and store the response.
1179 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1180 ClientResponse<Response> res =
1181 client.deleteItem(knownResourceId, knownItemResourceId);
1183 int statusCode = res.getStatus();
1185 // Check the status code of the response: does it match
1186 // the expected response(s)?
1187 if(logger.isDebugEnabled()){
1188 logger.debug(testName + ": status = " + statusCode);
1190 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1191 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1192 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1194 res.releaseConnection();
1199 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1202 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1203 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1204 public void delete(String testName) throws Exception {
1206 if (logger.isDebugEnabled()) {
1207 logger.debug(testBanner(testName, CLASS_NAME));
1212 if(logger.isDebugEnabled()){
1213 logger.debug("parentcsid =" + knownResourceId);
1216 // Submit the request to the service and store the response.
1217 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1218 ClientResponse<Response> res = client.delete(knownResourceId);
1220 int statusCode = res.getStatus();
1222 // Check the status code of the response: does it match
1223 // the expected response(s)?
1224 if(logger.isDebugEnabled()){
1225 logger.debug(testName + ": status = " + statusCode);
1227 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1228 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1229 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1231 res.releaseConnection();
1237 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1240 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1241 groups = {"delete"}, dependsOnMethods = {"delete"})
1242 public void deleteNonExistent(String testName) throws Exception {
1244 if (logger.isDebugEnabled()) {
1245 logger.debug(testBanner(testName, CLASS_NAME));
1248 setupDeleteNonExistent();
1250 // Submit the request to the service and store the response.
1251 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1252 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1254 int statusCode = res.getStatus();
1256 // Check the status code of the response: does it match
1257 // the expected response(s)?
1258 if(logger.isDebugEnabled()){
1259 logger.debug(testName + ": status = " + statusCode);
1261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1263 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1265 res.releaseConnection();
1270 * Delete non existent item.
1272 * @param testName the test name
1274 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1275 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1276 public void deleteNonExistentItem(String testName) {
1278 if (logger.isDebugEnabled()) {
1279 logger.debug(testBanner(testName, CLASS_NAME));
1282 setupDeleteNonExistent();
1284 // Submit the request to the service and store the response.
1285 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1286 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1288 int statusCode = res.getStatus();
1290 // Check the status code of the response: does it match
1291 // the expected response(s)?
1292 if(logger.isDebugEnabled()){
1293 logger.debug(testName + ": status = " + statusCode);
1295 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1296 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1297 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1299 res.releaseConnection();
1303 // ---------------------------------------------------------------
1304 // Utility tests : tests of code used in tests above
1305 // ---------------------------------------------------------------
1307 * Tests the code for manually submitting data that is used by several
1308 * of the methods above.
1310 @Test(dependsOnMethods = {"create", "read"})
1311 public void testSubmitRequest() {
1313 // Expected status code: 200 OK
1314 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1316 // Submit the request to the service and store the response.
1317 String method = ServiceRequestType.READ.httpMethodName();
1318 String url = getResourceURL(knownResourceId);
1319 int statusCode = submitRequest(method, url);
1321 // Check the status code of the response: does it match
1322 // the expected response(s)?
1323 if(logger.isDebugEnabled()){
1324 logger.debug("testSubmitRequest: url=" + url +
1325 " status=" + statusCode);
1327 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1332 * Test item submit request.
1334 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1335 public void testItemSubmitRequest() {
1337 // Expected status code: 200 OK
1338 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1340 // Submit the request to the service and store the response.
1341 String method = ServiceRequestType.READ.httpMethodName();
1342 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1343 int statusCode = submitRequest(method, url);
1345 // Check the status code of the response: does it match
1346 // the expected response(s)?
1347 if(logger.isDebugEnabled()){
1348 logger.debug("testItemSubmitRequest: url=" + url +
1349 " status=" + statusCode);
1351 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1355 // ---------------------------------------------------------------
1356 // Cleanup of resources created during testing
1357 // ---------------------------------------------------------------
1360 * Deletes all resources created by tests, after all tests have been run.
1362 * This cleanup method will always be run, even if one or more tests fail.
1363 * For this reason, it attempts to remove all resources created
1364 * at any point during testing, even if some of those resources
1365 * may be expected to be deleted by certain tests.
1368 @AfterClass(alwaysRun=true)
1369 public void cleanUp() {
1370 String noTest = System.getProperty("noTestCleanup");
1371 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1372 if (logger.isDebugEnabled()) {
1373 logger.debug("Skipping Cleanup phase ...");
1377 if (logger.isDebugEnabled()) {
1378 logger.debug("Cleaning up temporary resources created for testing ...");
1380 String parentResourceId;
1381 String itemResourceId;
1382 // Clean up contact resources.
1383 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1384 parentResourceId = knownResourceId;
1385 // Clean up item resources.
1386 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1387 itemResourceId = entry.getKey();
1388 parentResourceId = entry.getValue();
1389 // Note: Any non-success responses from the delete operation
1390 // below are ignored and not reported.
1391 ClientResponse<Response> res =
1392 client.deleteItem(parentResourceId, itemResourceId);
1393 res.releaseConnection();
1395 // Clean up parent resources.
1396 for (String resourceId : allResourceIdsCreated) {
1397 // Note: Any non-success responses from the delete operation
1398 // below are ignored and not reported.
1399 ClientResponse<Response> res = client.delete(resourceId);
1400 res.releaseConnection();
1404 // ---------------------------------------------------------------
1405 // Utility methods used by tests above
1406 // ---------------------------------------------------------------
1408 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1412 * Returns the root URL for the item service.
1414 * This URL consists of a base URL for all services, followed by
1415 * a path component for the owning parent, followed by the
1416 * path component for the items.
1418 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1419 * parent authority resource of the relevant item resource.
1421 * @return The root URL for the item service.
1423 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1424 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1428 * Returns the URL of a specific item resource managed by a service, and
1429 * designated by an identifier (such as a universally unique ID, or UUID).
1431 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1432 * parent authority resource of the relevant item resource.
1434 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1437 * @return The URL of a specific item resource managed by a service.
1439 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1440 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;