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.TaxonCommon;
46 import org.collectionspace.services.taxonomy.TaxonCommonList;
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;
85 final String TEST_NAME = "Centaurus pleurexanthemus Green 1832-";
86 final String TEST_SHORTID = "CentauruspleurexanthemusGreen1832";
87 // TODO Make rank be a controlled vocab term, assuming that's how we'll implement it.
88 final String TEST_RANK = "5";
89 // TODO Make status type be a controlled vocab term.
90 final String TEST_STATUS = "Approved";
91 /** The known resource id. */
92 private String knownResourceId = null;
93 private String knownResourceShortIdentifer = null;
94 private String knownResourceRefName = null;
95 private String knownTaxonomyTypeRefName = null;
96 private String knownItemResourceId = null;
97 private String knownItemResourceShortIdentifer = null;
98 private String knownContactResourceId = null;
99 /** The n items to create in list. */
100 private int nItemsToCreateInList = 3;
101 /** The all resource ids created. */
102 private List<String> allResourceIdsCreated = new ArrayList<String>();
103 /** The all item resource ids created. */
104 private Map<String, String> allItemResourceIdsCreated =
105 new HashMap<String, String>();
107 protected void setKnownResource(String id, String shortIdentifer,
109 knownResourceId = id;
110 knownResourceShortIdentifer = shortIdentifer;
111 knownResourceRefName = refName;
114 protected void setKnownItemResource(String id, String shortIdentifer) {
115 knownItemResourceId = id;
116 knownItemResourceShortIdentifer = shortIdentifer;
120 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
123 protected CollectionSpaceClient getClientInstance() {
124 return new TaxonomyAuthorityClient();
128 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
131 protected AbstractCommonList getAbstractCommonList(
132 ClientResponse<AbstractCommonList> response) {
133 return response.getEntity(TaxonCommonList.class);
137 protected PoxPayloadOut createInstance(String identifier) {
138 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
139 String shortId = identifier;
140 String displayName = "displayName-" + shortId;
142 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
143 PoxPayloadOut multipart =
144 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
145 displayName, shortId, client.getCommonPartName());
149 // ---------------------------------------------------------------
150 // CRUD tests : CREATE tests
151 // ---------------------------------------------------------------
154 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
157 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
159 public void create(String testName) throws Exception {
161 if (logger.isDebugEnabled()) {
162 logger.debug(testBanner(testName, CLASS_NAME));
164 // Perform setup, such as initializing the type of service request
165 // (e.g. CREATE, DELETE), its valid and expected status codes, and
166 // its associated HTTP method name (e.g. POST, DELETE).
169 // Submit the request to the service and store the response.
170 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
171 String shortId = createIdentifier();
172 String displayName = "displayName-" + shortId;
174 TaxonomyAuthorityClientUtils.createTaxonomyAuthRefName(shortId, null);
176 PoxPayloadOut multipart =
177 TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
178 displayName, shortId, client.getCommonPartName());
180 ClientResponse<Response> res = client.create(multipart);
182 int statusCode = res.getStatus();
184 // Check the status code of the response: does it match
185 // the expected response(s)?
188 // Does it fall within the set of valid status codes?
189 // Does it exactly match the expected status code?
190 if (logger.isDebugEnabled()) {
191 logger.debug(testName + ": status = " + statusCode);
193 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
194 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
195 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
197 newID = TaxonomyAuthorityClientUtils.extractId(res);
199 res.releaseConnection();
201 // Store the ID returned from the first resource created
202 // for additional tests below.
203 if (knownResourceId == null) {
204 setKnownResource(newID, shortId, baseRefName);
205 if (logger.isDebugEnabled()) {
206 logger.debug(testName + ": knownResourceId=" + knownResourceId);
209 // Store the IDs from every resource created by tests,
210 // so they can be deleted after tests have been run.
211 allResourceIdsCreated.add(newID);
217 * @param testName the test name
219 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
220 groups = {"create"}, dependsOnMethods = {"create"})
221 public void createItem(String testName) {
222 if (logger.isDebugEnabled()) {
223 logger.debug(testBanner(testName, CLASS_NAME));
226 createItemInAuthority(knownResourceId, knownResourceRefName);
230 * Creates the item in authority.
232 * @param vcsid the vcsid
233 * @param authRefName the auth ref name
236 private String createItemInAuthority(String vcsid, String authRefName) {
238 final String testName = "createItemInAuthority(" + vcsid + "," + authRefName + ")";
239 if (logger.isDebugEnabled()) {
240 logger.debug(testBanner(testName, CLASS_NAME));
243 // Submit the request to the service and store the response.
244 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
245 Map<String, String> taxonMap = new HashMap<String, String>();
246 // TODO Make loc type and status be controlled vocabs.
247 taxonMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
248 taxonMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME);
249 taxonMap.put(TaxonomyJAXBSchema.RANK, TEST_RANK);
250 taxonMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
251 // FIXME: Add additional fields in the Taxon record here.
253 String newID = TaxonomyAuthorityClientUtils.createItemInAuthority(vcsid,
254 authRefName, taxonMap, client);
256 // Store the ID returned from the first item resource created
257 // for additional tests below.
258 if (knownItemResourceId == null) {
259 setKnownItemResource(newID, TEST_SHORTID);
260 if (logger.isDebugEnabled()) {
261 logger.debug(testName + ": knownItemResourceId=" + newID);
265 // Store the IDs from any item resources created
266 // by tests, along with the IDs of their parents, so these items
267 // can be deleted after all tests have been run.
268 allItemResourceIdsCreated.put(newID, vcsid);
274 // Placeholders until the three tests below can be uncommented.
275 // See Issue CSPACE-401.
277 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
280 public void createWithEmptyEntityBody(String testName) throws Exception {
284 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
287 public void createWithMalformedXml(String testName) throws Exception {
291 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
294 public void createWithWrongXmlSchema(String testName) throws Exception {
297 // ---------------------------------------------------------------
298 // CRUD tests : CREATE LIST tests
299 // ---------------------------------------------------------------
302 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
305 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
306 groups = {"createList"}, dependsOnGroups = {"create"})
307 public void createList(String testName) throws Exception {
308 for (int i = 0; i < nItemsToCreateInList; i++) {
314 * Creates the item list.
316 * @param testName the test name
317 * @throws Exception the exception
319 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
320 groups = {"createList"}, dependsOnMethods = {"createList"})
321 public void createItemList(String testName) throws Exception {
322 // Add items to the initially-created, known parent record.
323 for (int j = 0; j < nItemsToCreateInList; j++) {
324 createItem(testName);
328 // ---------------------------------------------------------------
329 // CRUD tests : READ tests
330 // ---------------------------------------------------------------
333 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
336 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
337 groups = {"read"}, dependsOnGroups = {"create"})
338 public void read(String testName) throws Exception {
340 if (logger.isDebugEnabled()) {
341 logger.debug(testBanner(testName, CLASS_NAME));
346 // Submit the request to the service and store the response.
347 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
349 ClientResponse<String> res = client.read(knownResourceId);
351 int statusCode = res.getStatus();
353 // Check the status code of the response: does it match
354 // the expected response(s)?
355 if (logger.isDebugEnabled()) {
356 logger.debug(testName + ": status = " + statusCode);
358 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
359 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
360 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
361 //FIXME: remove the following try catch once Aron fixes signatures
363 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
364 TaxonomyauthorityCommon taxonomyAuthority =
365 (TaxonomyauthorityCommon) extractPart(input,
366 client.getCommonPartName(), TaxonomyauthorityCommon.class);
367 Assert.assertNotNull(taxonomyAuthority);
368 } catch (Exception e) {
369 throw new RuntimeException(e);
372 res.releaseConnection();
379 * @param testName the test name
380 * @throws Exception the exception
382 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
383 groups = {"read"}, dependsOnGroups = {"create"})
384 public void readByName(String testName) throws Exception {
386 if (logger.isDebugEnabled()) {
387 logger.debug(testBanner(testName + "(" + knownResourceShortIdentifer + ")", CLASS_NAME));
392 // Submit the request to the service and store the response.
393 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
394 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
396 int statusCode = res.getStatus();
398 // Check the status code of the response: does it match
399 // the expected response(s)?
400 if (logger.isDebugEnabled()) {
401 logger.debug(testName + ": status = " + statusCode);
403 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
404 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
405 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
406 //FIXME: remove the following try catch once Aron fixes signatures
408 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
409 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
410 client.getCommonPartName(), TaxonomyauthorityCommon.class);
411 Assert.assertNotNull(taxonomyAuthority);
412 } catch (Exception e) {
413 throw new RuntimeException(e);
416 res.releaseConnection();
423 * @param testName the test name
424 * @throws Exception the exception
426 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
427 groups = {"read"}, dependsOnMethods = {"read"})
428 public void readItem(String testName) throws Exception {
430 if (logger.isDebugEnabled()) {
431 logger.debug(testBanner(testName, CLASS_NAME));
436 // Submit the request to the service and store the response.
437 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
438 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
440 int statusCode = res.getStatus();
442 // Check the status code of the response: does it match
443 // the expected response(s)?
444 if (logger.isDebugEnabled()) {
445 logger.debug(testName + ": status = " + statusCode);
447 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
448 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
449 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
451 // Check whether we've received a taxon.
452 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
453 String xml = input.getXmlPayload(); // for debugging
454 if (logger.isDebugEnabled()) { // for debugging
455 logger.debug(testName + "#########" + xml);
457 String cpn = client.getItemCommonPartName(); // for debugging
458 TaxonCommon taxon = (TaxonCommon) extractPart(input,
459 client.getItemCommonPartName(), TaxonCommon.class);
460 Assert.assertNotNull(taxon);
461 boolean showFull = true;
462 if (showFull && logger.isDebugEnabled()) {
463 logger.debug(testName + ": returned payload:");
464 logger.debug(objectAsXmlString(taxon, TaxonCommon.class));
466 Assert.assertEquals(taxon.getInAuthority(), knownResourceId);
468 res.releaseConnection();
473 * Verify item display name.
475 * @param testName the test name
476 * @throws Exception the exception
478 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
479 dependsOnMethods = {"readItem", "updateItem"})
480 public void verifyItemDisplayName(String testName) throws Exception {
482 if (logger.isDebugEnabled()) {
483 logger.debug(testBanner(testName, CLASS_NAME));
488 // Submit the request to the service and store the response.
489 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
490 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
492 int statusCode = res.getStatus();
494 // Check the status code of the response: does it match
495 // the expected response(s)?
496 if (logger.isDebugEnabled()) {
497 logger.debug(testName + ": status = " + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 // Check whether taxon has expected displayName.
504 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
505 TaxonCommon taxon = (TaxonCommon) extractPart(input,
506 client.getItemCommonPartName(), TaxonCommon.class);
507 Assert.assertNotNull(taxon);
508 String displayName = taxon.getDisplayName();
509 // Make sure displayName matches computed form
510 String expectedDisplayName =
511 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
512 Assert.assertNotNull(displayName, expectedDisplayName);
514 // Update the shortName and verify the computed name is updated.
516 taxon.setDisplayNameComputed(true);
517 taxon.setTaxonFullName("updated-" + TEST_NAME);
518 expectedDisplayName =
519 TaxonomyAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
521 // Submit the updated resource to the service and store the response.
522 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
523 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
524 commonPart.setLabel(client.getItemCommonPartName());
525 res.releaseConnection();
526 res = client.updateItem(knownResourceId, knownItemResourceId, output);
527 statusCode = res.getStatus();
529 // Check the status code of the response: does it match the expected response(s)?
530 if (logger.isDebugEnabled()) {
531 logger.debug("updateItem: status = " + statusCode);
533 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
534 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
535 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
537 // Retrieve the updated resource and verify that its contents exist.
538 input = new PoxPayloadIn(res.getEntity());
539 TaxonCommon updatedTaxon =
540 (TaxonCommon) extractPart(input,
541 client.getItemCommonPartName(), TaxonCommon.class);
542 Assert.assertNotNull(updatedTaxon);
544 // Verify that the updated resource received the correct data.
545 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
546 "Updated ForeName in Taxonomy did not match submitted data.");
547 // Verify that the updated resource computes the right displayName.
548 Assert.assertEquals(updatedTaxon.getDisplayName(), expectedDisplayName,
549 "Updated ForeName in Taxonomy not reflected in computed DisplayName.");
551 // Now Update the displayName, not computed and verify the computed name is overriden.
552 taxon.setDisplayNameComputed(false);
553 expectedDisplayName = "TestName";
554 taxon.setDisplayName(expectedDisplayName);
556 // Submit the updated resource to the service and store the response.
557 output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
558 commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
559 commonPart.setLabel(client.getItemCommonPartName());
560 res.releaseConnection();
561 res = client.updateItem(knownResourceId, knownItemResourceId, output);
562 statusCode = res.getStatus();
564 // Check the status code of the response: does it match the expected response(s)?
565 if (logger.isDebugEnabled()) {
566 logger.debug("updateItem: status = " + statusCode);
568 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
569 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
570 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
572 // Retrieve the updated resource and verify that its contents exist.
573 input = new PoxPayloadIn(res.getEntity());
575 (TaxonCommon) extractPart(input,
576 client.getItemCommonPartName(), TaxonCommon.class);
577 Assert.assertNotNull(updatedTaxon);
579 // Verify that the updated resource received the correct data.
580 Assert.assertEquals(updatedTaxon.isDisplayNameComputed(), false,
581 "Updated displayNameComputed in Taxonomy did not match submitted data.");
582 // Verify that the updated resource computes the right displayName.
583 Assert.assertEquals(updatedTaxon.getDisplayName(),
585 "Updated DisplayName (not computed) in Taxonomy not stored.");
587 res.releaseConnection();
592 * Verify illegal item display name.
594 * @param testName the test name
595 * @throws Exception the exception
597 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
598 dependsOnMethods = {"verifyItemDisplayName"})
599 public void verifyIllegalItemDisplayName(String testName) throws Exception {
601 if (logger.isDebugEnabled()) {
602 logger.debug(testBanner(testName, CLASS_NAME));
605 // FIXME: create a setup configuration for this operation.
606 setupUpdateWithWrongXmlSchema();
608 // Submit the request to the service and store the response.
609 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
610 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
612 int statusCode = res.getStatus();
614 // Check the status code of the response: does it match
615 // the expected response(s)?
616 if (logger.isDebugEnabled()) {
617 logger.debug(testName + ": status = " + statusCode);
619 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
620 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
621 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
623 // Check whether Taxonomy has expected displayName.
624 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
625 TaxonCommon taxon = (TaxonCommon) extractPart(input,
626 client.getItemCommonPartName(), TaxonCommon.class);
627 Assert.assertNotNull(taxon);
628 // Try to Update with computed false and no displayName
629 taxon.setDisplayNameComputed(false);
630 taxon.setDisplayName(null);
632 // Submit the updated resource to the service and store the response.
633 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
634 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
635 commonPart.setLabel(client.getItemCommonPartName());
636 res.releaseConnection();
637 res = client.updateItem(knownResourceId, knownItemResourceId, output);
638 statusCode = res.getStatus();
640 // Check the status code of the response: does it match the expected response(s)?
641 if (logger.isDebugEnabled()) {
642 logger.debug("updateItem: status = " + statusCode);
644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
648 res.releaseConnection();
654 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
657 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
658 groups = {"read"}, dependsOnMethods = {"read"})
659 public void readNonExistent(String testName) {
661 if (logger.isDebugEnabled()) {
662 logger.debug(testBanner(testName, CLASS_NAME));
665 setupReadNonExistent();
667 // Submit the request to the service and store the response.
668 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
669 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
671 int statusCode = res.getStatus();
673 // Check the status code of the response: does it match
674 // the expected response(s)?
675 if (logger.isDebugEnabled()) {
676 logger.debug(testName + ": status = " + statusCode);
678 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
679 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
680 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
682 res.releaseConnection();
687 * Read item non existent.
689 * @param testName the test name
691 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
692 groups = {"read"}, dependsOnMethods = {"readItem"})
693 public void readItemNonExistent(String testName) {
695 if (logger.isDebugEnabled()) {
696 logger.debug(testBanner(testName, CLASS_NAME));
699 setupReadNonExistent();
701 // Submit the request to the service and store the response.
702 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
703 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if (logger.isDebugEnabled()) {
710 logger.debug(testName + ": status = " + statusCode);
712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
716 res.releaseConnection();
720 // ---------------------------------------------------------------
721 // CRUD tests : READ_LIST tests
722 // ---------------------------------------------------------------
726 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
729 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
730 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
731 public void readList(String testName) throws Exception {
733 if (logger.isDebugEnabled()) {
734 logger.debug(testBanner(testName, CLASS_NAME));
739 // Submit the request to the service and store the response.
740 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
741 ClientResponse<TaxonomyauthorityCommonList> res = client.readList();
743 TaxonomyauthorityCommonList list = res.getEntity();
744 int statusCode = res.getStatus();
746 // Check the status code of the response: does it match
747 // the expected response(s)?
748 if (logger.isDebugEnabled()) {
749 logger.debug(testName + ": status = " + statusCode);
751 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
752 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
753 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
755 // Optionally output additional data about list members for debugging.
756 boolean iterateThroughList = false;
757 if (iterateThroughList && logger.isDebugEnabled()) {
758 List<TaxonomyauthorityCommonList.TaxonomyauthorityListItem> items =
759 list.getTaxonomyauthorityListItem();
761 for (TaxonomyauthorityCommonList.TaxonomyauthorityListItem item : items) {
762 String csid = item.getCsid();
763 logger.debug(testName + ": list-item[" + i + "] csid="
765 logger.debug(testName + ": list-item[" + i + "] displayName="
766 + item.getDisplayName());
767 logger.debug(testName + ": list-item[" + i + "] URI="
769 readItemList(csid, null);
774 res.releaseConnection();
781 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
782 public void readItemList() {
783 String testName = "readItemList";
784 if (logger.isDebugEnabled()) {
785 logger.debug(testBanner(testName, CLASS_NAME));
787 readItemList(knownResourceId, null);
791 * Read item list by authority name.
793 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
794 public void readItemListByAuthorityName() {
795 String testName = "readItemListByAuthorityName";
796 if (logger.isDebugEnabled()) {
797 logger.debug(testBanner(testName, CLASS_NAME));
799 readItemList(null, knownResourceShortIdentifer);
805 * @param vcsid the vcsid
806 * @param name the name
808 private void readItemList(String vcsid, String shortId) {
810 String testName = "readItemList";
815 // Submit the request to the service and store the response.
816 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
817 ClientResponse<TaxonCommonList> res = null;
819 res = client.readItemList(vcsid, null, null);
820 } else if (shortId != null) {
821 res = client.readItemListForNamedAuthority(shortId, null, null);
823 Assert.fail("readItemList passed null csid and name!");
826 TaxonCommonList list = res.getEntity();
827 int statusCode = res.getStatus();
829 // Check the status code of the response: does it match
830 // the expected response(s)?
831 if (logger.isDebugEnabled()) {
832 logger.debug(testName + ": status = " + statusCode);
834 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
835 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
836 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
838 List<TaxonCommonList.TaxonListItem> items =
839 list.getTaxonListItem();
840 int nItemsReturned = items.size();
841 // There will be one item created, associated with a
842 // known parent resource, by the createItem test.
844 // In addition, there will be 'nItemsToCreateInList'
845 // additional items created by the createItemList test,
846 // all associated with the same parent resource.
847 int nExpectedItems = nItemsToCreateInList + 1;
848 if (logger.isDebugEnabled()) {
849 logger.debug(testName + ": Expected "
850 + nExpectedItems + " items; got: " + nItemsReturned);
852 Assert.assertEquals(nItemsReturned, nExpectedItems);
855 for (TaxonCommonList.TaxonListItem item : items) {
856 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
857 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
858 // Optionally output additional data about list members for debugging.
859 boolean showDetails = true;
860 if (showDetails && logger.isDebugEnabled()) {
861 logger.debug(" " + testName + ": list-item[" + i + "] csid="
863 logger.debug(" " + testName + ": list-item[" + i + "] refName="
864 + item.getRefName());
865 logger.debug(" " + testName + ": list-item[" + i + "] displayName="
866 + item.getDisplayName());
867 logger.debug(" " + testName + ": list-item[" + i + "] URI="
873 res.releaseConnection();
879 // ---------------------------------------------------------------
880 // CRUD tests : UPDATE tests
881 // ---------------------------------------------------------------
884 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
887 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
888 groups = {"update"}, dependsOnGroups = {"read", "readList"})
889 public void update(String testName) throws Exception {
891 if (logger.isDebugEnabled()) {
892 logger.debug(testBanner(testName, CLASS_NAME));
897 // Retrieve the contents of a resource to update.
898 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
899 ClientResponse<String> res = client.read(knownResourceId);
901 if (logger.isDebugEnabled()) {
902 logger.debug(testName + ": read status = " + res.getStatus());
904 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
906 if (logger.isDebugEnabled()) {
907 logger.debug("got TaxonomyAuthority to update with ID: " + knownResourceId);
909 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
910 TaxonomyauthorityCommon taxonomyAuthority = (TaxonomyauthorityCommon) extractPart(input,
911 client.getCommonPartName(), TaxonomyauthorityCommon.class);
912 Assert.assertNotNull(taxonomyAuthority);
914 // Update the contents of this resource.
915 taxonomyAuthority.setDisplayName("updated-" + taxonomyAuthority.getDisplayName());
916 taxonomyAuthority.setVocabType("updated-" + taxonomyAuthority.getVocabType());
917 if (logger.isDebugEnabled()) {
918 logger.debug("to be updated TaxonomyAuthority");
919 logger.debug(objectAsXmlString(taxonomyAuthority, TaxonomyauthorityCommon.class));
922 // Submit the updated resource to the service and store the response.
923 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_PAYLOAD_NAME);
924 PayloadOutputPart commonPart = output.addPart(taxonomyAuthority, MediaType.APPLICATION_XML_TYPE);
925 commonPart.setLabel(client.getCommonPartName());
926 res.releaseConnection();
927 res = client.update(knownResourceId, output);
928 int statusCode = res.getStatus();
930 // Check the status code of the response: does it match the expected response(s)?
931 if (logger.isDebugEnabled()) {
932 logger.debug(testName + ": status = " + statusCode);
934 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
935 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
936 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
938 // Retrieve the updated resource and verify that its contents exist.
939 input = new PoxPayloadIn(res.getEntity());
940 TaxonomyauthorityCommon updatedTaxonomyAuthority =
941 (TaxonomyauthorityCommon) extractPart(input,
942 client.getCommonPartName(), TaxonomyauthorityCommon.class);
943 Assert.assertNotNull(updatedTaxonomyAuthority);
945 // Verify that the updated resource received the correct data.
946 Assert.assertEquals(updatedTaxonomyAuthority.getDisplayName(),
947 taxonomyAuthority.getDisplayName(),
948 "Data in updated object did not match submitted data.");
950 res.releaseConnection();
957 * @param testName the test name
958 * @throws Exception the exception
960 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
961 groups = {"update"}, dependsOnMethods = {"update"})
962 public void updateItem(String testName) throws Exception {
964 if (logger.isDebugEnabled()) {
965 logger.debug(testBanner(testName, CLASS_NAME));
970 // Retrieve the contents of a resource to update.
971 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
972 ClientResponse<String> res =
973 client.readItem(knownResourceId, knownItemResourceId);
975 if (logger.isDebugEnabled()) {
976 logger.debug(testName + ": read status = " + res.getStatus());
978 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
980 if (logger.isDebugEnabled()) {
981 logger.debug("got Taxonomy to update with ID: "
982 + knownItemResourceId
983 + " in TaxonomyAuthority: " + knownResourceId);
985 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
986 TaxonCommon taxon = (TaxonCommon) extractPart(input,
987 client.getItemCommonPartName(), TaxonCommon.class);
988 Assert.assertNotNull(taxon);
990 // Update the contents of this resource.
992 taxon.setTaxonFullName("updated-" + taxon.getTaxonFullName());
993 if (logger.isDebugEnabled()) {
994 logger.debug("to be updated Taxonomy");
995 logger.debug(objectAsXmlString(taxon,
999 // Submit the updated resource to the service and store the response.
1000 PoxPayloadOut output = new PoxPayloadOut(TaxonomyAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1001 PayloadOutputPart commonPart = output.addPart(taxon, MediaType.APPLICATION_XML_TYPE);
1002 commonPart.setLabel(client.getItemCommonPartName());
1003 res.releaseConnection();
1004 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1005 int statusCode = res.getStatus();
1007 // Check the status code of the response: does it match the expected response(s)?
1008 if (logger.isDebugEnabled()) {
1009 logger.debug(testName + ": status = " + statusCode);
1011 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1012 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1013 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1015 // Retrieve the updated resource and verify that its contents exist.
1016 input = new PoxPayloadIn(res.getEntity());
1017 TaxonCommon updatedTaxon =
1018 (TaxonCommon) extractPart(input,
1019 client.getItemCommonPartName(), TaxonCommon.class);
1020 Assert.assertNotNull(updatedTaxon);
1022 // Verify that the updated resource received the correct data.
1023 Assert.assertEquals(updatedTaxon.getTaxonFullName(), taxon.getTaxonFullName(),
1024 "Data in updated Taxonomy did not match submitted data.");
1026 res.releaseConnection();
1031 // Placeholders until the three tests below can be uncommented.
1032 // See Issue CSPACE-401.
1034 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1037 public void updateWithEmptyEntityBody(String testName) throws Exception {
1041 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1044 public void updateWithMalformedXml(String testName) throws Exception {
1048 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1051 public void updateWithWrongXmlSchema(String testName) throws Exception {
1056 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1059 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1060 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1061 public void updateNonExistent(String testName) throws Exception {
1063 if (logger.isDebugEnabled()) {
1064 logger.debug(testBanner(testName, CLASS_NAME));
1067 setupUpdateNonExistent();
1069 // Submit the request to the service and store the response.
1070 // Note: The ID(s) used when creating the request payload may be arbitrary.
1071 // The only relevant ID may be the one used in update(), below.
1072 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1073 String displayName = "displayName-NON_EXISTENT_ID";
1074 PoxPayloadOut multipart = TaxonomyAuthorityClientUtils.createTaxonomyAuthorityInstance(
1075 displayName, "nonEx", client.getCommonPartName());
1076 ClientResponse<String> res =
1077 client.update(NON_EXISTENT_ID, multipart);
1079 int statusCode = res.getStatus();
1081 // Check the status code of the response: does it match
1082 // the expected response(s)?
1083 if (logger.isDebugEnabled()) {
1084 logger.debug(testName + ": status = " + statusCode);
1086 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1087 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1088 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1090 res.releaseConnection();
1095 * Update non existent item.
1097 * @param testName the test name
1098 * @throws Exception the exception
1100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1101 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1102 public void updateNonExistentItem(String testName) throws Exception {
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testBanner(testName, CLASS_NAME));
1108 setupUpdateNonExistent();
1110 // Submit the request to the service and store the response.
1111 // Note: The ID used in this 'create' call may be arbitrary.
1112 // The only relevant ID may be the one used in update(), below.
1113 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1114 Map<String, String> nonexMap = new HashMap<String, String>();
1115 nonexMap.put(TaxonomyJAXBSchema.NAME, TEST_NAME);
1116 nonexMap.put(TaxonomyJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1117 nonexMap.put(TaxonomyJAXBSchema.TERM_STATUS, TEST_STATUS);
1118 PoxPayloadOut multipart =
1119 TaxonomyAuthorityClientUtils.createTaxonInstance(
1120 TaxonomyAuthorityClientUtils.createTaxonomyRefName(knownResourceRefName, "nonEx", "Non Existent"),
1121 nonexMap, client.getItemCommonPartName());
1122 ClientResponse<String> res =
1123 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1125 int statusCode = res.getStatus();
1127 // Check the status code of the response: does it match
1128 // the expected response(s)?
1129 if (logger.isDebugEnabled()) {
1130 logger.debug(testName + ": status = " + statusCode);
1132 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1133 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1134 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1136 res.releaseConnection();
1140 // ---------------------------------------------------------------
1141 // CRUD tests : DELETE tests
1142 // ---------------------------------------------------------------
1144 // Note: delete sub-resources in ascending hierarchical order,
1145 // before deleting their parents.
1149 * @param testName the test name
1150 * @throws Exception the exception
1152 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1153 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1154 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1155 public void deleteItem(String testName) throws Exception {
1157 if (logger.isDebugEnabled()) {
1158 logger.debug(testBanner(testName, CLASS_NAME));
1163 if (logger.isDebugEnabled()) {
1164 logger.debug("parentcsid =" + knownResourceId
1165 + " itemcsid = " + knownItemResourceId);
1168 // Submit the request to the service and store the response.
1169 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1170 ClientResponse<Response> res =
1171 client.deleteItem(knownResourceId, knownItemResourceId);
1173 int statusCode = res.getStatus();
1175 // Check the status code of the response: does it match
1176 // the expected response(s)?
1177 if (logger.isDebugEnabled()) {
1178 logger.debug(testName + ": status = " + statusCode);
1180 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1181 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1182 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1184 res.releaseConnection();
1189 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1192 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1193 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1194 public void delete(String testName) throws Exception {
1196 if (logger.isDebugEnabled()) {
1197 logger.debug(testBanner(testName, CLASS_NAME));
1202 if (logger.isDebugEnabled()) {
1203 logger.debug("parentcsid =" + knownResourceId);
1206 // Submit the request to the service and store the response.
1207 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1208 ClientResponse<Response> res = client.delete(knownResourceId);
1210 int statusCode = res.getStatus();
1212 // Check the status code of the response: does it match
1213 // the expected response(s)?
1214 if (logger.isDebugEnabled()) {
1215 logger.debug(testName + ": status = " + statusCode);
1217 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1218 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1219 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1221 res.releaseConnection();
1227 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1230 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1231 groups = {"delete"}, dependsOnMethods = {"delete"})
1232 public void deleteNonExistent(String testName) throws Exception {
1234 if (logger.isDebugEnabled()) {
1235 logger.debug(testBanner(testName, CLASS_NAME));
1238 setupDeleteNonExistent();
1240 // Submit the request to the service and store the response.
1241 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1242 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1244 int statusCode = res.getStatus();
1246 // Check the status code of the response: does it match
1247 // the expected response(s)?
1248 if (logger.isDebugEnabled()) {
1249 logger.debug(testName + ": status = " + statusCode);
1251 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1252 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1253 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1255 res.releaseConnection();
1260 * Delete non existent item.
1262 * @param testName the test name
1264 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1265 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1266 public void deleteNonExistentItem(String testName) {
1268 if (logger.isDebugEnabled()) {
1269 logger.debug(testBanner(testName, CLASS_NAME));
1272 setupDeleteNonExistent();
1274 // Submit the request to the service and store the response.
1275 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1276 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1278 int statusCode = res.getStatus();
1280 // Check the status code of the response: does it match
1281 // the expected response(s)?
1282 if (logger.isDebugEnabled()) {
1283 logger.debug(testName + ": status = " + statusCode);
1285 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1286 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1287 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1289 res.releaseConnection();
1293 // ---------------------------------------------------------------
1294 // Utility tests : tests of code used in tests above
1295 // ---------------------------------------------------------------
1297 * Tests the code for manually submitting data that is used by several
1298 * of the methods above.
1300 @Test(dependsOnMethods = {"create", "read"})
1301 public void testSubmitRequest() {
1303 // Expected status code: 200 OK
1304 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1306 // Submit the request to the service and store the response.
1307 String method = ServiceRequestType.READ.httpMethodName();
1308 String url = getResourceURL(knownResourceId);
1309 int statusCode = submitRequest(method, url);
1311 // Check the status code of the response: does it match
1312 // the expected response(s)?
1313 if (logger.isDebugEnabled()) {
1314 logger.debug("testSubmitRequest: url=" + url
1315 + " status=" + statusCode);
1317 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1322 * Test item submit request.
1324 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1325 public void testItemSubmitRequest() {
1327 // Expected status code: 200 OK
1328 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1330 // Submit the request to the service and store the response.
1331 String method = ServiceRequestType.READ.httpMethodName();
1332 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1333 int statusCode = submitRequest(method, url);
1335 // Check the status code of the response: does it match
1336 // the expected response(s)?
1337 if (logger.isDebugEnabled()) {
1338 logger.debug("testItemSubmitRequest: url=" + url
1339 + " status=" + statusCode);
1341 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1345 // ---------------------------------------------------------------
1346 // Cleanup of resources created during testing
1347 // ---------------------------------------------------------------
1349 * Deletes all resources created by tests, after all tests have been run.
1351 * This cleanup method will always be run, even if one or more tests fail.
1352 * For this reason, it attempts to remove all resources created
1353 * at any point during testing, even if some of those resources
1354 * may be expected to be deleted by certain tests.
1356 @AfterClass(alwaysRun = true)
1357 public void cleanUp() {
1358 String noTest = System.getProperty("noTestCleanup");
1359 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1360 if (logger.isDebugEnabled()) {
1361 logger.debug("Skipping Cleanup phase ...");
1365 if (logger.isDebugEnabled()) {
1366 logger.debug("Cleaning up temporary resources created for testing ...");
1368 String parentResourceId;
1369 String itemResourceId;
1370 // Clean up contact resources.
1371 TaxonomyAuthorityClient client = new TaxonomyAuthorityClient();
1372 parentResourceId = knownResourceId;
1373 // Clean up item resources.
1374 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1375 itemResourceId = entry.getKey();
1376 parentResourceId = entry.getValue();
1377 // Note: Any non-success responses from the delete operation
1378 // below are ignored and not reported.
1379 ClientResponse<Response> res =
1380 client.deleteItem(parentResourceId, itemResourceId);
1381 res.releaseConnection();
1383 // Clean up parent resources.
1384 for (String resourceId : allResourceIdsCreated) {
1385 // Note: Any non-success responses from the delete operation
1386 // below are ignored and not reported.
1387 ClientResponse<Response> res = client.delete(resourceId);
1388 res.releaseConnection();
1392 // ---------------------------------------------------------------
1393 // Utility methods used by tests above
1394 // ---------------------------------------------------------------
1396 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1399 * Returns the root URL for the item service.
1401 * This URL consists of a base URL for all services, followed by
1402 * a path component for the owning parent, followed by the
1403 * path component for the items.
1405 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1406 * parent authority resource of the relevant item resource.
1408 * @return The root URL for the item service.
1410 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1411 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1415 * Returns the URL of a specific item resource managed by a service, and
1416 * designated by an identifier (such as a universally unique ID, or UUID).
1418 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1419 * parent authority resource of the relevant item resource.
1421 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1424 * @return The URL of a specific item resource managed by a service.
1426 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1427 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;