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.LocationJAXBSchema;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.ContactClient;
33 import org.collectionspace.services.client.ContactClientUtils;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.contact.ContactsCommon;
38 import org.collectionspace.services.contact.ContactsCommonList;
39 import org.collectionspace.services.client.LocationAuthorityClient;
40 import org.collectionspace.services.client.LocationAuthorityClientUtils;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.location.LocationauthoritiesCommon;
43 import org.collectionspace.services.location.LocationauthoritiesCommonList;
44 import org.collectionspace.services.location.LocationsCommon;
45 import org.collectionspace.services.location.LocationsCommonList;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import org.jboss.resteasy.client.ClientResponse;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
59 * LocationAuthorityServiceTest, carries out tests against a
60 * deployed and running LocationAuthority Service.
62 * $LastChangedRevision: 753 $
63 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
65 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
68 private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
69 private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
72 public String getServicePathComponent() {
73 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
77 protected String getServiceName() {
78 return LocationAuthorityClient.SERVICE_NAME;
81 public String getItemServicePathComponent() {
82 return LocationAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
85 // Instance variables specific to this test.
87 // /** The SERVICE path component. */
88 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
90 // /** The ITEM service path component. */
91 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
93 // /** The CONTACT service path component. */
94 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
96 final String TEST_NAME = "Shelf 1";
97 final String TEST_SHORTID = "shelf1";
98 final String TEST_CONDITION_NOTE = "Basically clean";
99 final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
100 final String TEST_SECURITY_NOTE = "Kind of safe";
101 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
102 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
103 // TODO Make loc type be a controlled vocab term.
104 final String TEST_LOCATION_TYPE = "Shelf";
105 // TODO Make status type be a controlled vocab term.
106 final String TEST_STATUS = "Approved";
108 /** The known resource id. */
109 private String knownResourceId = null;
110 private String knownResourceShortIdentifer = null;
111 private String knownResourceRefName = null;
112 private String knownLocationTypeRefName = null;
113 private String knownItemResourceId = null;
114 private String knownItemResourceShortIdentifer = null;
115 private String knownContactResourceId = null;
117 /** The n items to create in list. */
118 private int nItemsToCreateInList = 3;
120 /** The all resource ids created. */
121 private List<String> allResourceIdsCreated = new ArrayList<String>();
123 /** The all item resource ids created. */
124 private Map<String, String> allItemResourceIdsCreated =
125 new HashMap<String, String>();
127 protected void setKnownResource( String id, String shortIdentifer,
129 knownResourceId = id;
130 knownResourceShortIdentifer = shortIdentifer;
131 knownResourceRefName = refName;
134 protected void setKnownItemResource( String id, String shortIdentifer ) {
135 knownItemResourceId = id;
136 knownItemResourceShortIdentifer = shortIdentifer;
140 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
143 protected CollectionSpaceClient getClientInstance() {
144 return new LocationAuthorityClient();
148 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
151 protected AbstractCommonList getAbstractCommonList(
152 ClientResponse<AbstractCommonList> response) {
153 return response.getEntity(LocationsCommonList.class);
157 protected PoxPayloadOut createInstance(String identifier) {
158 LocationAuthorityClient client = new LocationAuthorityClient();
159 String shortId = createIdentifier();
160 String displayName = "displayName-" + shortId;
161 String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
162 PoxPayloadOut multipart =
163 LocationAuthorityClientUtils.createLocationAuthorityInstance(
164 displayName, shortId, client.getCommonPartName());
168 // ---------------------------------------------------------------
169 // CRUD tests : CREATE tests
170 // ---------------------------------------------------------------
173 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
176 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
178 public void create(String testName) throws Exception {
180 if (logger.isDebugEnabled()) {
181 logger.debug(testBanner(testName, CLASS_NAME));
183 // Perform setup, such as initializing the type of service request
184 // (e.g. CREATE, DELETE), its valid and expected status codes, and
185 // its associated HTTP method name (e.g. POST, DELETE).
188 // Submit the request to the service and store the response.
189 LocationAuthorityClient client = new LocationAuthorityClient();
190 String shortId = createIdentifier();
191 String displayName = "displayName-" + shortId;
192 String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
193 PoxPayloadOut multipart =
194 LocationAuthorityClientUtils.createLocationAuthorityInstance(
195 displayName, shortId, client.getCommonPartName());
197 ClientResponse<Response> res = client.create(multipart);
199 int statusCode = res.getStatus();
201 // Check the status code of the response: does it match
202 // the expected response(s)?
205 // Does it fall within the set of valid status codes?
206 // Does it exactly match the expected status code?
207 if(logger.isDebugEnabled()){
208 logger.debug(testName + ": status = " + statusCode);
210 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
211 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
212 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
214 newID = LocationAuthorityClientUtils.extractId(res);
216 res.releaseConnection();
218 // Store the ID returned from the first resource created
219 // for additional tests below.
220 if (knownResourceId == null){
221 setKnownResource( newID, shortId, baseRefName );
222 if (logger.isDebugEnabled()) {
223 logger.debug(testName + ": knownResourceId=" + knownResourceId);
226 // Store the IDs from every resource created by tests,
227 // so they can be deleted after tests have been run.
228 allResourceIdsCreated.add(newID);
234 * @param testName the test name
236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
237 groups = {"create"}, dependsOnMethods = {"create"})
238 public void createItem(String testName) {
239 if(logger.isDebugEnabled()){
240 logger.debug(testBanner(testName, CLASS_NAME));
243 createItemInAuthority(knownResourceId, knownResourceRefName);
247 * Creates the item in authority.
249 * @param vcsid the vcsid
250 * @param authRefName the auth ref name
253 private String createItemInAuthority(String vcsid, String authRefName) {
255 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
256 if(logger.isDebugEnabled()){
257 logger.debug(testBanner(testName, CLASS_NAME));
260 // Submit the request to the service and store the response.
261 LocationAuthorityClient client = new LocationAuthorityClient();
262 Map<String, String> shelf1Map = new HashMap<String,String>();
263 // TODO Make loc type and status be controlled vocabs.
264 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
265 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
266 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
267 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
268 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
269 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
270 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
271 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
272 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
274 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
275 authRefName, shelf1Map, client );
277 // Store the ID returned from the first item resource created
278 // for additional tests below.
279 if (knownItemResourceId == null){
280 setKnownItemResource(newID, TEST_SHORTID);
281 if (logger.isDebugEnabled()) {
282 logger.debug(testName + ": knownItemResourceId=" + newID);
286 // Store the IDs from any item resources created
287 // by tests, along with the IDs of their parents, so these items
288 // can be deleted after all tests have been run.
289 allItemResourceIdsCreated.put(newID, vcsid);
298 // Placeholders until the three tests below can be uncommented.
299 // See Issue CSPACE-401.
301 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
304 public void createWithEmptyEntityBody(String testName) throws Exception {
308 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
311 public void createWithMalformedXml(String testName) throws Exception {
315 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
318 public void createWithWrongXmlSchema(String testName) throws Exception {
322 // ---------------------------------------------------------------
323 // CRUD tests : CREATE LIST tests
324 // ---------------------------------------------------------------
327 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
330 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
331 groups = {"createList"}, dependsOnGroups = {"create"})
332 public void createList(String testName) throws Exception {
333 for (int i = 0; i < nItemsToCreateInList; i++) {
339 * Creates the item list.
341 * @param testName the test name
342 * @throws Exception the exception
344 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
345 groups = {"createList"}, dependsOnMethods = {"createList"})
346 public void createItemList(String testName) throws Exception {
347 // Add items to the initially-created, known parent record.
348 for (int j = 0; j < nItemsToCreateInList; j++) {
349 createItem(testName);
353 // ---------------------------------------------------------------
354 // CRUD tests : READ tests
355 // ---------------------------------------------------------------
358 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
361 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
362 groups = {"read"}, dependsOnGroups = {"create"})
363 public void read(String testName) throws Exception {
365 if (logger.isDebugEnabled()) {
366 logger.debug(testBanner(testName, CLASS_NAME));
371 // Submit the request to the service and store the response.
372 LocationAuthorityClient client = new LocationAuthorityClient();
374 ClientResponse<String> res = client.read(knownResourceId);
376 int statusCode = res.getStatus();
378 // Check the status code of the response: does it match
379 // the expected response(s)?
380 if(logger.isDebugEnabled()){
381 logger.debug(testName + ": status = " + statusCode);
383 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
384 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
385 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
386 //FIXME: remove the following try catch once Aron fixes signatures
388 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
389 LocationauthoritiesCommon locationAuthority =
390 (LocationauthoritiesCommon) extractPart(input,
391 client.getCommonPartName(), LocationauthoritiesCommon.class);
392 Assert.assertNotNull(locationAuthority);
393 } catch (Exception e) {
394 throw new RuntimeException(e);
397 res.releaseConnection();
404 * @param testName the test name
405 * @throws Exception the exception
407 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
408 groups = {"read"}, dependsOnGroups = {"create"})
409 public void readByName(String testName) throws Exception {
411 if (logger.isDebugEnabled()) {
412 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
417 // Submit the request to the service and store the response.
418 LocationAuthorityClient client = new LocationAuthorityClient();
419 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
421 int statusCode = res.getStatus();
423 // Check the status code of the response: does it match
424 // the expected response(s)?
425 if(logger.isDebugEnabled()){
426 logger.debug(testName + ": status = " + statusCode);
428 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
429 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
430 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
431 //FIXME: remove the following try catch once Aron fixes signatures
433 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
434 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
435 client.getCommonPartName(), LocationauthoritiesCommon.class);
436 Assert.assertNotNull(locationAuthority);
437 } catch (Exception e) {
438 throw new RuntimeException(e);
441 res.releaseConnection();
449 * @param testName the test name
450 * @throws Exception the exception
452 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
453 groups = {"read"}, dependsOnMethods = {"read"})
454 public void readItem(String testName) throws Exception {
456 if (logger.isDebugEnabled()) {
457 logger.debug(testBanner(testName, CLASS_NAME));
462 // Submit the request to the service and store the response.
463 LocationAuthorityClient client = new LocationAuthorityClient();
464 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
466 int statusCode = res.getStatus();
468 // Check the status code of the response: does it match
469 // the expected response(s)?
470 if(logger.isDebugEnabled()){
471 logger.debug(testName + ": status = " + statusCode);
473 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
474 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
475 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
477 // Check whether we've received a location.
478 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
479 LocationsCommon location = (LocationsCommon) extractPart(input,
480 client.getItemCommonPartName(), LocationsCommon.class);
481 Assert.assertNotNull(location);
482 boolean showFull = true;
483 if(showFull && logger.isDebugEnabled()){
484 logger.debug(testName + ": returned payload:");
485 logger.debug(objectAsXmlString(location, LocationsCommon.class));
487 Assert.assertEquals(location.getInAuthority(), knownResourceId);
489 res.releaseConnection();
495 * Verify item display name.
497 * @param testName the test name
498 * @throws Exception the exception
500 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
501 dependsOnMethods = {"readItem", "updateItem"})
502 public void verifyItemDisplayName(String testName) throws Exception {
504 if (logger.isDebugEnabled()) {
505 logger.debug(testBanner(testName, CLASS_NAME));
510 // Submit the request to the service and store the response.
511 LocationAuthorityClient client = new LocationAuthorityClient();
512 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
514 int statusCode = res.getStatus();
516 // Check the status code of the response: does it match
517 // the expected response(s)?
518 if(logger.isDebugEnabled()){
519 logger.debug(testName + ": status = " + statusCode);
521 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
522 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
523 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
525 // Check whether location has expected displayName.
526 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
527 LocationsCommon location = (LocationsCommon) extractPart(input,
528 client.getItemCommonPartName(), LocationsCommon.class);
529 Assert.assertNotNull(location);
530 String displayName = location.getDisplayName();
531 // Make sure displayName matches computed form
532 String expectedDisplayName =
533 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
534 Assert.assertNotNull(displayName, expectedDisplayName);
536 // Update the shortName and verify the computed name is updated.
537 location.setCsid(null);
538 location.setDisplayNameComputed(true);
539 location.setName("updated-" + TEST_NAME);
540 expectedDisplayName =
541 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
543 // Submit the updated resource to the service and store the response.
544 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
545 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
546 commonPart.setLabel(client.getItemCommonPartName());
547 res.releaseConnection();
548 res = client.updateItem(knownResourceId, knownItemResourceId, output);
549 statusCode = res.getStatus();
551 // Check the status code of the response: does it match the expected response(s)?
552 if(logger.isDebugEnabled()){
553 logger.debug("updateItem: status = " + statusCode);
555 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
556 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
557 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
559 // Retrieve the updated resource and verify that its contents exist.
560 input = new PoxPayloadIn(res.getEntity());
561 LocationsCommon updatedLocation =
562 (LocationsCommon) extractPart(input,
563 client.getItemCommonPartName(), LocationsCommon.class);
564 Assert.assertNotNull(updatedLocation);
566 // Verify that the updated resource received the correct data.
567 Assert.assertEquals(updatedLocation.getName(), location.getName(),
568 "Updated ForeName in Location did not match submitted data.");
569 // Verify that the updated resource computes the right displayName.
570 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
571 "Updated ForeName in Location not reflected in computed DisplayName.");
573 // Now Update the displayName, not computed and verify the computed name is overriden.
574 location.setDisplayNameComputed(false);
575 expectedDisplayName = "TestName";
576 location.setDisplayName(expectedDisplayName);
578 // Submit the updated resource to the service and store the response.
579 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
580 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
581 commonPart.setLabel(client.getItemCommonPartName());
582 res.releaseConnection();
583 res = client.updateItem(knownResourceId, knownItemResourceId, output);
584 statusCode = res.getStatus();
586 // Check the status code of the response: does it match the expected response(s)?
587 if(logger.isDebugEnabled()){
588 logger.debug("updateItem: status = " + statusCode);
590 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
591 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
592 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
594 // Retrieve the updated resource and verify that its contents exist.
595 input = new PoxPayloadIn(res.getEntity());
597 (LocationsCommon) extractPart(input,
598 client.getItemCommonPartName(), LocationsCommon.class);
599 Assert.assertNotNull(updatedLocation);
601 // Verify that the updated resource received the correct data.
602 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
603 "Updated displayNameComputed in Location did not match submitted data.");
604 // Verify that the updated resource computes the right displayName.
605 Assert.assertEquals(updatedLocation.getDisplayName(),
607 "Updated DisplayName (not computed) in Location not stored.");
609 res.releaseConnection();
614 * Verify illegal item display name.
616 * @param testName the test name
617 * @throws Exception the exception
619 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
620 dependsOnMethods = {"verifyItemDisplayName"})
621 public void verifyIllegalItemDisplayName(String testName) throws Exception {
623 if (logger.isDebugEnabled()) {
624 logger.debug(testBanner(testName, CLASS_NAME));
627 // FIXME: create a setup configuration for this operation.
628 setupUpdateWithWrongXmlSchema();
630 // Submit the request to the service and store the response.
631 LocationAuthorityClient client = new LocationAuthorityClient();
632 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
634 int statusCode = res.getStatus();
636 // Check the status code of the response: does it match
637 // the expected response(s)?
638 if(logger.isDebugEnabled()){
639 logger.debug(testName + ": status = " + statusCode);
641 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
642 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
643 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
645 // Check whether Location has expected displayName.
646 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
647 LocationsCommon location = (LocationsCommon) extractPart(input,
648 client.getItemCommonPartName(), LocationsCommon.class);
649 Assert.assertNotNull(location);
650 // Try to Update with computed false and no displayName
651 location.setDisplayNameComputed(false);
652 location.setDisplayName(null);
654 // Submit the updated resource to the service and store the response.
655 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
656 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
657 commonPart.setLabel(client.getItemCommonPartName());
658 res.releaseConnection();
659 res = client.updateItem(knownResourceId, knownItemResourceId, output);
660 statusCode = res.getStatus();
662 // Check the status code of the response: does it match the expected response(s)?
663 if(logger.isDebugEnabled()){
664 logger.debug("updateItem: status = " + statusCode);
666 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
667 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
668 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
670 res.releaseConnection();
677 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
680 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
681 groups = {"read"}, dependsOnMethods = {"read"})
682 public void readNonExistent(String testName) {
684 if (logger.isDebugEnabled()) {
685 logger.debug(testBanner(testName, CLASS_NAME));
688 setupReadNonExistent();
690 // Submit the request to the service and store the response.
691 LocationAuthorityClient client = new LocationAuthorityClient();
692 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
694 int statusCode = res.getStatus();
696 // Check the status code of the response: does it match
697 // the expected response(s)?
698 if(logger.isDebugEnabled()){
699 logger.debug(testName + ": status = " + statusCode);
701 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
702 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
703 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
705 res.releaseConnection();
710 * Read item non existent.
712 * @param testName the test name
714 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
715 groups = {"read"}, dependsOnMethods = {"readItem"})
716 public void readItemNonExistent(String testName) {
718 if (logger.isDebugEnabled()) {
719 logger.debug(testBanner(testName, CLASS_NAME));
722 setupReadNonExistent();
724 // Submit the request to the service and store the response.
725 LocationAuthorityClient client = new LocationAuthorityClient();
726 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
728 int statusCode = res.getStatus();
730 // Check the status code of the response: does it match
731 // the expected response(s)?
732 if(logger.isDebugEnabled()){
733 logger.debug(testName + ": status = " + statusCode);
735 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
736 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
737 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
739 res.releaseConnection();
744 // ---------------------------------------------------------------
745 // CRUD tests : READ_LIST tests
746 // ---------------------------------------------------------------
750 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
753 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
755 public void readList(String testName) throws Exception {
757 if (logger.isDebugEnabled()) {
758 logger.debug(testBanner(testName, CLASS_NAME));
763 // Submit the request to the service and store the response.
764 LocationAuthorityClient client = new LocationAuthorityClient();
765 ClientResponse<LocationauthoritiesCommonList> res = client.readList();
767 LocationauthoritiesCommonList list = res.getEntity();
768 int statusCode = res.getStatus();
770 // Check the status code of the response: does it match
771 // the expected response(s)?
772 if(logger.isDebugEnabled()){
773 logger.debug(testName + ": status = " + statusCode);
775 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
776 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
777 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
779 // Optionally output additional data about list members for debugging.
780 boolean iterateThroughList = false;
781 if (iterateThroughList && logger.isDebugEnabled()) {
782 List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
783 list.getLocationauthorityListItem();
785 for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
786 String csid = item.getCsid();
787 logger.debug(testName + ": list-item[" + i + "] csid=" +
789 logger.debug(testName + ": list-item[" + i + "] displayName=" +
790 item.getDisplayName());
791 logger.debug(testName + ": list-item[" + i + "] URI=" +
793 readItemList(csid, null);
798 res.releaseConnection();
805 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
806 public void readItemList() {
807 String testName = "readItemList";
808 if (logger.isDebugEnabled()) {
809 logger.debug(testBanner(testName, CLASS_NAME));
811 readItemList(knownResourceId, null);
815 * Read item list by authority name.
817 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
818 public void readItemListByAuthorityName() {
819 String testName = "readItemListByAuthorityName";
820 if (logger.isDebugEnabled()) {
821 logger.debug(testBanner(testName, CLASS_NAME));
823 readItemList(null, knownResourceShortIdentifer);
829 * @param vcsid the vcsid
830 * @param name the name
832 private void readItemList(String vcsid, String shortId) {
834 String testName = "readItemList";
839 // Submit the request to the service and store the response.
840 LocationAuthorityClient client = new LocationAuthorityClient();
841 ClientResponse<LocationsCommonList> res = null;
843 res = client.readItemList(vcsid, null, null);
844 } else if(shortId!= null) {
845 res = client.readItemListForNamedAuthority(shortId, null, null);
847 Assert.fail("readItemList passed null csid and name!");
850 LocationsCommonList list = res.getEntity();
851 int statusCode = res.getStatus();
853 // Check the status code of the response: does it match
854 // the expected response(s)?
855 if(logger.isDebugEnabled()){
856 logger.debug(testName + ": status = " + statusCode);
858 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
859 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
860 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
862 List<LocationsCommonList.LocationListItem> items =
863 list.getLocationListItem();
864 int nItemsReturned = items.size();
865 // There will be one item created, associated with a
866 // known parent resource, by the createItem test.
868 // In addition, there will be 'nItemsToCreateInList'
869 // additional items created by the createItemList test,
870 // all associated with the same parent resource.
871 int nExpectedItems = nItemsToCreateInList + 1;
872 if(logger.isDebugEnabled()){
873 logger.debug(testName + ": Expected "
874 + nExpectedItems +" items; got: "+nItemsReturned);
876 Assert.assertEquals(nItemsReturned, nExpectedItems);
879 for (LocationsCommonList.LocationListItem item : items) {
880 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
881 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
882 // Optionally output additional data about list members for debugging.
883 boolean showDetails = true;
884 if (showDetails && logger.isDebugEnabled()) {
885 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
887 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
889 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
890 item.getDisplayName());
891 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
897 res.releaseConnection();
905 // ---------------------------------------------------------------
906 // CRUD tests : UPDATE tests
907 // ---------------------------------------------------------------
910 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
913 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
914 groups = {"update"}, dependsOnGroups = {"read", "readList"})
915 public void update(String testName) throws Exception {
917 if (logger.isDebugEnabled()) {
918 logger.debug(testBanner(testName, CLASS_NAME));
923 // Retrieve the contents of a resource to update.
924 LocationAuthorityClient client = new LocationAuthorityClient();
925 ClientResponse<String> res = client.read(knownResourceId);
927 if(logger.isDebugEnabled()){
928 logger.debug(testName + ": read status = " + res.getStatus());
930 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
932 if(logger.isDebugEnabled()){
933 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
935 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
936 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
937 client.getCommonPartName(), LocationauthoritiesCommon.class);
938 Assert.assertNotNull(locationAuthority);
940 // Update the contents of this resource.
941 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
942 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
943 if(logger.isDebugEnabled()){
944 logger.debug("to be updated LocationAuthority");
945 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
948 // Submit the updated resource to the service and store the response.
949 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
950 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
951 commonPart.setLabel(client.getCommonPartName());
952 res.releaseConnection();
953 res = client.update(knownResourceId, output);
954 int statusCode = res.getStatus();
956 // Check the status code of the response: does it match the expected response(s)?
957 if(logger.isDebugEnabled()){
958 logger.debug(testName + ": status = " + statusCode);
960 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
961 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
962 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
964 // Retrieve the updated resource and verify that its contents exist.
965 input = new PoxPayloadIn(res.getEntity());
966 LocationauthoritiesCommon updatedLocationAuthority =
967 (LocationauthoritiesCommon) extractPart(input,
968 client.getCommonPartName(), LocationauthoritiesCommon.class);
969 Assert.assertNotNull(updatedLocationAuthority);
971 // Verify that the updated resource received the correct data.
972 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
973 locationAuthority.getDisplayName(),
974 "Data in updated object did not match submitted data.");
976 res.releaseConnection();
983 * @param testName the test name
984 * @throws Exception the exception
986 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
987 groups = {"update"}, dependsOnMethods = {"update"})
988 public void updateItem(String testName) throws Exception {
990 if (logger.isDebugEnabled()) {
991 logger.debug(testBanner(testName, CLASS_NAME));
996 // Retrieve the contents of a resource to update.
997 LocationAuthorityClient client = new LocationAuthorityClient();
998 ClientResponse<String> res =
999 client.readItem(knownResourceId, knownItemResourceId);
1001 if(logger.isDebugEnabled()){
1002 logger.debug(testName + ": read status = " + res.getStatus());
1004 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1006 if(logger.isDebugEnabled()){
1007 logger.debug("got Location to update with ID: " +
1008 knownItemResourceId +
1009 " in LocationAuthority: " + knownResourceId );
1011 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1012 LocationsCommon location = (LocationsCommon) extractPart(input,
1013 client.getItemCommonPartName(), LocationsCommon.class);
1014 Assert.assertNotNull(location);
1016 // Update the contents of this resource.
1017 location.setCsid(null);
1018 location.setName("updated-" + location.getName());
1019 if(logger.isDebugEnabled()){
1020 logger.debug("to be updated Location");
1021 logger.debug(objectAsXmlString(location,
1022 LocationsCommon.class));
1025 // Submit the updated resource to the service and store the response.
1026 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1027 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1028 commonPart.setLabel(client.getItemCommonPartName());
1029 res.releaseConnection();
1030 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1031 int statusCode = res.getStatus();
1033 // Check the status code of the response: does it match the expected response(s)?
1034 if(logger.isDebugEnabled()){
1035 logger.debug(testName + ": status = " + statusCode);
1037 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1038 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1039 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1041 // Retrieve the updated resource and verify that its contents exist.
1042 input = new PoxPayloadIn(res.getEntity());
1043 LocationsCommon updatedLocation =
1044 (LocationsCommon) extractPart(input,
1045 client.getItemCommonPartName(), LocationsCommon.class);
1046 Assert.assertNotNull(updatedLocation);
1048 // Verify that the updated resource received the correct data.
1049 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1050 "Data in updated Location did not match submitted data.");
1052 res.releaseConnection();
1057 // Placeholders until the three tests below can be uncommented.
1058 // See Issue CSPACE-401.
1060 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1063 public void updateWithEmptyEntityBody(String testName) throws Exception {
1067 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1070 public void updateWithMalformedXml(String testName) throws Exception {
1074 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1077 public void updateWithWrongXmlSchema(String testName) throws Exception {
1082 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1085 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1086 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1087 public void updateNonExistent(String testName) throws Exception {
1089 if (logger.isDebugEnabled()) {
1090 logger.debug(testBanner(testName, CLASS_NAME));
1093 setupUpdateNonExistent();
1095 // Submit the request to the service and store the response.
1096 // Note: The ID(s) used when creating the request payload may be arbitrary.
1097 // The only relevant ID may be the one used in update(), below.
1098 LocationAuthorityClient client = new LocationAuthorityClient();
1099 String displayName = "displayName-NON_EXISTENT_ID";
1100 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1101 displayName, "nonEx", client.getCommonPartName());
1102 ClientResponse<String> res =
1103 client.update(NON_EXISTENT_ID, multipart);
1105 int statusCode = res.getStatus();
1107 // Check the status code of the response: does it match
1108 // the expected response(s)?
1109 if(logger.isDebugEnabled()){
1110 logger.debug(testName + ": status = " + statusCode);
1112 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1113 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1114 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1116 res.releaseConnection();
1121 * Update non existent item.
1123 * @param testName the test name
1124 * @throws Exception the exception
1126 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1127 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1128 public void updateNonExistentItem(String testName) throws Exception {
1130 if (logger.isDebugEnabled()) {
1131 logger.debug(testBanner(testName, CLASS_NAME));
1134 setupUpdateNonExistent();
1136 // Submit the request to the service and store the response.
1137 // Note: The ID used in this 'create' call may be arbitrary.
1138 // The only relevant ID may be the one used in update(), below.
1139 LocationAuthorityClient client = new LocationAuthorityClient();
1140 Map<String, String> nonexMap = new HashMap<String,String>();
1141 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1142 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1143 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1144 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1145 PoxPayloadOut multipart =
1146 LocationAuthorityClientUtils.createLocationInstance(
1147 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1148 nonexMap, client.getItemCommonPartName() );
1149 ClientResponse<String> res =
1150 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1152 int statusCode = res.getStatus();
1154 // Check the status code of the response: does it match
1155 // the expected response(s)?
1156 if(logger.isDebugEnabled()){
1157 logger.debug(testName + ": status = " + statusCode);
1159 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1160 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1161 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1163 res.releaseConnection();
1167 // ---------------------------------------------------------------
1168 // CRUD tests : DELETE tests
1169 // ---------------------------------------------------------------
1172 // Note: delete sub-resources in ascending hierarchical order,
1173 // before deleting their parents.
1178 * @param testName the test name
1179 * @throws Exception the exception
1181 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1182 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1183 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1184 public void deleteItem(String testName) throws Exception {
1186 if (logger.isDebugEnabled()) {
1187 logger.debug(testBanner(testName, CLASS_NAME));
1192 if(logger.isDebugEnabled()){
1193 logger.debug("parentcsid =" + knownResourceId +
1194 " itemcsid = " + knownItemResourceId);
1197 // Submit the request to the service and store the response.
1198 LocationAuthorityClient client = new LocationAuthorityClient();
1199 ClientResponse<Response> res =
1200 client.deleteItem(knownResourceId, knownItemResourceId);
1202 int statusCode = res.getStatus();
1204 // Check the status code of the response: does it match
1205 // the expected response(s)?
1206 if(logger.isDebugEnabled()){
1207 logger.debug(testName + ": status = " + statusCode);
1209 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1210 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1211 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1213 res.releaseConnection();
1218 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1221 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1222 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1223 public void delete(String testName) throws Exception {
1225 if (logger.isDebugEnabled()) {
1226 logger.debug(testBanner(testName, CLASS_NAME));
1231 if(logger.isDebugEnabled()){
1232 logger.debug("parentcsid =" + knownResourceId);
1235 // Submit the request to the service and store the response.
1236 LocationAuthorityClient client = new LocationAuthorityClient();
1237 ClientResponse<Response> res = client.delete(knownResourceId);
1239 int statusCode = res.getStatus();
1241 // Check the status code of the response: does it match
1242 // the expected response(s)?
1243 if(logger.isDebugEnabled()){
1244 logger.debug(testName + ": status = " + statusCode);
1246 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1247 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1248 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1250 res.releaseConnection();
1256 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1259 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1260 groups = {"delete"}, dependsOnMethods = {"delete"})
1261 public void deleteNonExistent(String testName) throws Exception {
1263 if (logger.isDebugEnabled()) {
1264 logger.debug(testBanner(testName, CLASS_NAME));
1267 setupDeleteNonExistent();
1269 // Submit the request to the service and store the response.
1270 LocationAuthorityClient client = new LocationAuthorityClient();
1271 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1273 int statusCode = res.getStatus();
1275 // Check the status code of the response: does it match
1276 // the expected response(s)?
1277 if(logger.isDebugEnabled()){
1278 logger.debug(testName + ": status = " + statusCode);
1280 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1281 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1282 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1284 res.releaseConnection();
1289 * Delete non existent item.
1291 * @param testName the test name
1293 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1294 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1295 public void deleteNonExistentItem(String testName) {
1297 if (logger.isDebugEnabled()) {
1298 logger.debug(testBanner(testName, CLASS_NAME));
1301 setupDeleteNonExistent();
1303 // Submit the request to the service and store the response.
1304 LocationAuthorityClient client = new LocationAuthorityClient();
1305 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1307 int statusCode = res.getStatus();
1309 // Check the status code of the response: does it match
1310 // the expected response(s)?
1311 if(logger.isDebugEnabled()){
1312 logger.debug(testName + ": status = " + statusCode);
1314 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1315 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1316 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1318 res.releaseConnection();
1322 // ---------------------------------------------------------------
1323 // Utility tests : tests of code used in tests above
1324 // ---------------------------------------------------------------
1326 * Tests the code for manually submitting data that is used by several
1327 * of the methods above.
1329 @Test(dependsOnMethods = {"create", "read"})
1330 public void testSubmitRequest() {
1332 // Expected status code: 200 OK
1333 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1335 // Submit the request to the service and store the response.
1336 String method = ServiceRequestType.READ.httpMethodName();
1337 String url = getResourceURL(knownResourceId);
1338 int statusCode = submitRequest(method, url);
1340 // Check the status code of the response: does it match
1341 // the expected response(s)?
1342 if(logger.isDebugEnabled()){
1343 logger.debug("testSubmitRequest: url=" + url +
1344 " status=" + statusCode);
1346 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1351 * Test item submit request.
1353 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1354 public void testItemSubmitRequest() {
1356 // Expected status code: 200 OK
1357 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1359 // Submit the request to the service and store the response.
1360 String method = ServiceRequestType.READ.httpMethodName();
1361 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1362 int statusCode = submitRequest(method, url);
1364 // Check the status code of the response: does it match
1365 // the expected response(s)?
1366 if(logger.isDebugEnabled()){
1367 logger.debug("testItemSubmitRequest: url=" + url +
1368 " status=" + statusCode);
1370 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1374 // ---------------------------------------------------------------
1375 // Cleanup of resources created during testing
1376 // ---------------------------------------------------------------
1379 * Deletes all resources created by tests, after all tests have been run.
1381 * This cleanup method will always be run, even if one or more tests fail.
1382 * For this reason, it attempts to remove all resources created
1383 * at any point during testing, even if some of those resources
1384 * may be expected to be deleted by certain tests.
1387 @AfterClass(alwaysRun=true)
1388 public void cleanUp() {
1389 String noTest = System.getProperty("noTestCleanup");
1390 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1391 if (logger.isDebugEnabled()) {
1392 logger.debug("Skipping Cleanup phase ...");
1396 if (logger.isDebugEnabled()) {
1397 logger.debug("Cleaning up temporary resources created for testing ...");
1399 String parentResourceId;
1400 String itemResourceId;
1401 // Clean up contact resources.
1402 LocationAuthorityClient client = new LocationAuthorityClient();
1403 parentResourceId = knownResourceId;
1404 // Clean up item resources.
1405 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1406 itemResourceId = entry.getKey();
1407 parentResourceId = entry.getValue();
1408 // Note: Any non-success responses from the delete operation
1409 // below are ignored and not reported.
1410 ClientResponse<Response> res =
1411 client.deleteItem(parentResourceId, itemResourceId);
1412 res.releaseConnection();
1414 // Clean up parent resources.
1415 for (String resourceId : allResourceIdsCreated) {
1416 // Note: Any non-success responses from the delete operation
1417 // below are ignored and not reported.
1418 ClientResponse<Response> res = client.delete(resourceId);
1419 res.releaseConnection();
1423 // ---------------------------------------------------------------
1424 // Utility methods used by tests above
1425 // ---------------------------------------------------------------
1427 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1431 * Returns the root URL for the item service.
1433 * This URL consists of a base URL for all services, followed by
1434 * a path component for the owning parent, followed by the
1435 * path component for the items.
1437 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1438 * parent authority resource of the relevant item resource.
1440 * @return The root URL for the item service.
1442 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1443 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1447 * Returns the URL of a specific item resource managed by a service, and
1448 * designated by an identifier (such as a universally unique ID, or UUID).
1450 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1451 * parent authority resource of the relevant item resource.
1453 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1456 * @return The URL of a specific item resource managed by a service.
1458 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1459 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;