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.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.LocationAuthorityClient;
41 import org.collectionspace.services.client.LocationAuthorityClientUtils;
42 import org.collectionspace.services.jaxb.AbstractCommonList;
43 import org.collectionspace.services.location.LocationauthoritiesCommon;
44 import org.collectionspace.services.location.LocationauthoritiesCommonList;
45 import org.collectionspace.services.location.LocationsCommon;
46 import org.collectionspace.services.location.LocationsCommonList;
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 * LocationAuthorityServiceTest, carries out tests against a
61 * deployed and running LocationAuthority Service.
63 * $LastChangedRevision: 753 $
64 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
66 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
69 private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
70 private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
73 public String getServicePathComponent() {
74 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
78 protected String getServiceName() {
79 return LocationAuthorityClient.SERVICE_NAME;
82 public String getItemServicePathComponent() {
83 return AuthorityClient.ITEMS;
86 // Instance variables specific to this test.
88 // /** The SERVICE path component. */
89 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
91 // /** The ITEM service path component. */
92 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
94 // /** The CONTACT service path component. */
95 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
97 final String TEST_NAME = "Shelf 1";
98 final String TEST_SHORTID = "shelf1";
99 final String TEST_CONDITION_NOTE = "Basically clean";
100 final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
101 final String TEST_SECURITY_NOTE = "Kind of safe";
102 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
103 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
104 // TODO Make loc type be a controlled vocab term.
105 final String TEST_LOCATION_TYPE = "Shelf";
106 // TODO Make status type be a controlled vocab term.
107 final String TEST_STATUS = "Approved";
109 /** The known resource id. */
110 private String knownResourceId = null;
111 private String knownResourceShortIdentifer = null;
112 private String knownResourceRefName = null;
113 private String knownLocationTypeRefName = null;
114 private String knownItemResourceId = null;
115 private String knownItemResourceShortIdentifer = null;
116 private String knownContactResourceId = null;
118 /** The n items to create in list. */
119 private int nItemsToCreateInList = 3;
121 /** The all resource ids created. */
122 private List<String> allResourceIdsCreated = new ArrayList<String>();
124 /** The all item resource ids created. */
125 private Map<String, String> allItemResourceIdsCreated =
126 new HashMap<String, String>();
128 protected void setKnownResource( String id, String shortIdentifer,
130 knownResourceId = id;
131 knownResourceShortIdentifer = shortIdentifer;
132 knownResourceRefName = refName;
135 protected void setKnownItemResource( String id, String shortIdentifer ) {
136 knownItemResourceId = id;
137 knownItemResourceShortIdentifer = shortIdentifer;
141 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
144 protected CollectionSpaceClient getClientInstance() {
145 return new LocationAuthorityClient();
149 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
152 protected AbstractCommonList getAbstractCommonList(
153 ClientResponse<AbstractCommonList> response) {
154 return response.getEntity(LocationsCommonList.class);
158 protected PoxPayloadOut createInstance(String identifier) {
159 LocationAuthorityClient client = new LocationAuthorityClient();
160 String shortId = identifier;
161 String displayName = "displayName-" + shortId;
163 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
164 PoxPayloadOut multipart =
165 LocationAuthorityClientUtils.createLocationAuthorityInstance(
166 displayName, shortId, client.getCommonPartName());
170 // ---------------------------------------------------------------
171 // CRUD tests : CREATE tests
172 // ---------------------------------------------------------------
175 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
178 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
180 public void create(String testName) throws Exception {
182 if (logger.isDebugEnabled()) {
183 logger.debug(testBanner(testName, CLASS_NAME));
185 // Perform setup, such as initializing the type of service request
186 // (e.g. CREATE, DELETE), its valid and expected status codes, and
187 // its associated HTTP method name (e.g. POST, DELETE).
190 // Submit the request to the service and store the response.
191 LocationAuthorityClient client = new LocationAuthorityClient();
192 String shortId = createIdentifier();
193 String displayName = "displayName-" + shortId;
195 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
197 PoxPayloadOut multipart =
198 LocationAuthorityClientUtils.createLocationAuthorityInstance(
199 displayName, shortId, client.getCommonPartName());
201 ClientResponse<Response> res = client.create(multipart);
203 int statusCode = res.getStatus();
205 // Check the status code of the response: does it match
206 // the expected response(s)?
209 // Does it fall within the set of valid status codes?
210 // Does it exactly match the expected status code?
211 if(logger.isDebugEnabled()){
212 logger.debug(testName + ": status = " + statusCode);
214 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
215 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
216 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
218 newID = LocationAuthorityClientUtils.extractId(res);
220 res.releaseConnection();
222 // Store the ID returned from the first resource created
223 // for additional tests below.
224 if (knownResourceId == null){
225 setKnownResource( newID, shortId, baseRefName );
226 if (logger.isDebugEnabled()) {
227 logger.debug(testName + ": knownResourceId=" + knownResourceId);
230 // Store the IDs from every resource created by tests,
231 // so they can be deleted after tests have been run.
232 allResourceIdsCreated.add(newID);
238 * @param testName the test name
240 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
241 groups = {"create"}, dependsOnMethods = {"create"})
242 public void createItem(String testName) {
243 if(logger.isDebugEnabled()){
244 logger.debug(testBanner(testName, CLASS_NAME));
247 createItemInAuthority(knownResourceId, knownResourceRefName);
251 * Creates the item in authority.
253 * @param vcsid the vcsid
254 * @param authRefName the auth ref name
257 private String createItemInAuthority(String vcsid, String authRefName) {
259 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
260 if(logger.isDebugEnabled()){
261 logger.debug(testBanner(testName, CLASS_NAME));
264 // Submit the request to the service and store the response.
265 LocationAuthorityClient client = new LocationAuthorityClient();
266 Map<String, String> shelf1Map = new HashMap<String,String>();
267 // TODO Make loc type and status be controlled vocabs.
268 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
269 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
270 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
271 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
272 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
273 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
274 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
275 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
276 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
278 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
279 authRefName, shelf1Map, client );
281 // Store the ID returned from the first item resource created
282 // for additional tests below.
283 if (knownItemResourceId == null){
284 setKnownItemResource(newID, TEST_SHORTID);
285 if (logger.isDebugEnabled()) {
286 logger.debug(testName + ": knownItemResourceId=" + newID);
290 // Store the IDs from any item resources created
291 // by tests, along with the IDs of their parents, so these items
292 // can be deleted after all tests have been run.
293 allItemResourceIdsCreated.put(newID, vcsid);
302 // Placeholders until the three tests below can be uncommented.
303 // See Issue CSPACE-401.
305 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
308 public void createWithEmptyEntityBody(String testName) throws Exception {
312 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
315 public void createWithMalformedXml(String testName) throws Exception {
319 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
322 public void createWithWrongXmlSchema(String testName) throws Exception {
326 // ---------------------------------------------------------------
327 // CRUD tests : CREATE LIST tests
328 // ---------------------------------------------------------------
331 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
334 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
335 groups = {"createList"}, dependsOnGroups = {"create"})
336 public void createList(String testName) throws Exception {
337 for (int i = 0; i < nItemsToCreateInList; i++) {
343 * Creates the item list.
345 * @param testName the test name
346 * @throws Exception the exception
348 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
349 groups = {"createList"}, dependsOnMethods = {"createList"})
350 public void createItemList(String testName) throws Exception {
351 // Add items to the initially-created, known parent record.
352 for (int j = 0; j < nItemsToCreateInList; j++) {
353 createItem(testName);
357 // ---------------------------------------------------------------
358 // CRUD tests : READ tests
359 // ---------------------------------------------------------------
362 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
365 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
366 groups = {"read"}, dependsOnGroups = {"create"})
367 public void read(String testName) throws Exception {
369 if (logger.isDebugEnabled()) {
370 logger.debug(testBanner(testName, CLASS_NAME));
375 // Submit the request to the service and store the response.
376 LocationAuthorityClient client = new LocationAuthorityClient();
378 ClientResponse<String> res = client.read(knownResourceId);
380 int statusCode = res.getStatus();
382 // Check the status code of the response: does it match
383 // the expected response(s)?
384 if(logger.isDebugEnabled()){
385 logger.debug(testName + ": status = " + statusCode);
387 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
388 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
389 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
390 //FIXME: remove the following try catch once Aron fixes signatures
392 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
393 LocationauthoritiesCommon locationAuthority =
394 (LocationauthoritiesCommon) extractPart(input,
395 client.getCommonPartName(), LocationauthoritiesCommon.class);
396 Assert.assertNotNull(locationAuthority);
397 Assert.assertNotNull(locationAuthority.getDisplayName());
398 Assert.assertNotNull(locationAuthority.getShortIdentifier());
399 Assert.assertNotNull(locationAuthority.getRefName());
400 } catch (Exception e) {
401 throw new RuntimeException(e);
404 res.releaseConnection();
411 * @param testName the test name
412 * @throws Exception the exception
414 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
415 groups = {"read"}, dependsOnGroups = {"create"})
416 public void readByName(String testName) throws Exception {
418 if (logger.isDebugEnabled()) {
419 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
424 // Submit the request to the service and store the response.
425 LocationAuthorityClient client = new LocationAuthorityClient();
426 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
428 int statusCode = res.getStatus();
430 // Check the status code of the response: does it match
431 // the expected response(s)?
432 if(logger.isDebugEnabled()){
433 logger.debug(testName + ": status = " + statusCode);
435 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
436 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
437 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
438 //FIXME: remove the following try catch once Aron fixes signatures
440 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
441 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
442 client.getCommonPartName(), LocationauthoritiesCommon.class);
443 Assert.assertNotNull(locationAuthority);
444 } catch (Exception e) {
445 throw new RuntimeException(e);
448 res.releaseConnection();
456 * @param testName the test name
457 * @throws Exception the exception
459 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
460 groups = {"read"}, dependsOnMethods = {"read"})
461 public void readItem(String testName) throws Exception {
463 if (logger.isDebugEnabled()) {
464 logger.debug(testBanner(testName, CLASS_NAME));
469 // Submit the request to the service and store the response.
470 LocationAuthorityClient client = new LocationAuthorityClient();
471 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
473 int statusCode = res.getStatus();
475 // Check the status code of the response: does it match
476 // the expected response(s)?
477 if(logger.isDebugEnabled()){
478 logger.debug(testName + ": status = " + statusCode);
480 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
481 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
482 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 // Check whether we've received a location.
485 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
486 LocationsCommon location = (LocationsCommon) extractPart(input,
487 client.getItemCommonPartName(), LocationsCommon.class);
488 Assert.assertNotNull(location);
489 boolean showFull = true;
490 if(showFull && logger.isDebugEnabled()){
491 logger.debug(testName + ": returned payload:");
492 logger.debug(objectAsXmlString(location, LocationsCommon.class));
494 Assert.assertEquals(location.getInAuthority(), knownResourceId);
496 res.releaseConnection();
502 * Verify item display name.
504 * @param testName the test name
505 * @throws Exception the exception
507 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
508 dependsOnMethods = {"readItem", "updateItem"})
509 public void verifyItemDisplayName(String testName) throws Exception {
511 if (logger.isDebugEnabled()) {
512 logger.debug(testBanner(testName, CLASS_NAME));
517 // Submit the request to the service and store the response.
518 LocationAuthorityClient client = new LocationAuthorityClient();
519 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
521 int statusCode = res.getStatus();
523 // Check the status code of the response: does it match
524 // the expected response(s)?
525 if(logger.isDebugEnabled()){
526 logger.debug(testName + ": status = " + statusCode);
528 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
529 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
530 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
532 // Check whether location has expected displayName.
533 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
534 LocationsCommon location = (LocationsCommon) extractPart(input,
535 client.getItemCommonPartName(), LocationsCommon.class);
536 Assert.assertNotNull(location);
537 String displayName = location.getDisplayName();
538 // Make sure displayName matches computed form
539 String expectedDisplayName =
540 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
541 Assert.assertNotNull(displayName, expectedDisplayName);
543 // Update the shortName and verify the computed name is updated.
544 location.setCsid(null);
545 location.setDisplayNameComputed(true);
546 location.setName("updated-" + TEST_NAME);
547 expectedDisplayName =
548 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
550 // Submit the updated resource to the service and store the response.
551 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
552 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
553 commonPart.setLabel(client.getItemCommonPartName());
554 res.releaseConnection();
555 res = client.updateItem(knownResourceId, knownItemResourceId, output);
556 statusCode = res.getStatus();
558 // Check the status code of the response: does it match the expected response(s)?
559 if(logger.isDebugEnabled()){
560 logger.debug("updateItem: status = " + statusCode);
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
566 // Retrieve the updated resource and verify that its contents exist.
567 input = new PoxPayloadIn(res.getEntity());
568 LocationsCommon updatedLocation =
569 (LocationsCommon) extractPart(input,
570 client.getItemCommonPartName(), LocationsCommon.class);
571 Assert.assertNotNull(updatedLocation);
573 // Verify that the updated resource received the correct data.
574 Assert.assertEquals(updatedLocation.getName(), location.getName(),
575 "Updated ForeName in Location did not match submitted data.");
576 // Verify that the updated resource computes the right displayName.
577 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
578 "Updated ForeName in Location not reflected in computed DisplayName.");
580 // Now Update the displayName, not computed and verify the computed name is overriden.
581 location.setDisplayNameComputed(false);
582 expectedDisplayName = "TestName";
583 location.setDisplayName(expectedDisplayName);
585 // Submit the updated resource to the service and store the response.
586 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
587 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
588 commonPart.setLabel(client.getItemCommonPartName());
589 res.releaseConnection();
590 res = client.updateItem(knownResourceId, knownItemResourceId, output);
591 statusCode = res.getStatus();
593 // Check the status code of the response: does it match the expected response(s)?
594 if(logger.isDebugEnabled()){
595 logger.debug("updateItem: status = " + statusCode);
597 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
598 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
599 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
601 // Retrieve the updated resource and verify that its contents exist.
602 input = new PoxPayloadIn(res.getEntity());
604 (LocationsCommon) extractPart(input,
605 client.getItemCommonPartName(), LocationsCommon.class);
606 Assert.assertNotNull(updatedLocation);
608 // Verify that the updated resource received the correct data.
609 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
610 "Updated displayNameComputed in Location did not match submitted data.");
611 // Verify that the updated resource computes the right displayName.
612 Assert.assertEquals(updatedLocation.getDisplayName(),
614 "Updated DisplayName (not computed) in Location not stored.");
616 res.releaseConnection();
621 * Verify illegal item display name.
623 * @param testName the test name
624 * @throws Exception the exception
626 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
627 dependsOnMethods = {"verifyItemDisplayName"})
628 public void verifyIllegalItemDisplayName(String testName) throws Exception {
630 if (logger.isDebugEnabled()) {
631 logger.debug(testBanner(testName, CLASS_NAME));
634 // FIXME: create a setup configuration for this operation.
635 setupUpdateWithWrongXmlSchema();
637 // Submit the request to the service and store the response.
638 LocationAuthorityClient client = new LocationAuthorityClient();
639 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
652 // Check whether Location has expected displayName.
653 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
654 LocationsCommon location = (LocationsCommon) extractPart(input,
655 client.getItemCommonPartName(), LocationsCommon.class);
656 Assert.assertNotNull(location);
657 // Try to Update with computed false and no displayName
658 location.setDisplayNameComputed(false);
659 location.setDisplayName(null);
661 // Submit the updated resource to the service and store the response.
662 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
663 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
664 commonPart.setLabel(client.getItemCommonPartName());
665 res.releaseConnection();
666 res = client.updateItem(knownResourceId, knownItemResourceId, output);
667 statusCode = res.getStatus();
669 // Check the status code of the response: does it match the expected response(s)?
670 if(logger.isDebugEnabled()){
671 logger.debug("updateItem: status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 res.releaseConnection();
684 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
687 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
688 groups = {"read"}, dependsOnMethods = {"read"})
689 public void readNonExistent(String testName) {
691 if (logger.isDebugEnabled()) {
692 logger.debug(testBanner(testName, CLASS_NAME));
695 setupReadNonExistent();
697 // Submit the request to the service and store the response.
698 LocationAuthorityClient client = new LocationAuthorityClient();
699 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
701 int statusCode = res.getStatus();
703 // Check the status code of the response: does it match
704 // the expected response(s)?
705 if(logger.isDebugEnabled()){
706 logger.debug(testName + ": status = " + statusCode);
708 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
709 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
710 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
712 res.releaseConnection();
717 * Read item non existent.
719 * @param testName the test name
721 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
722 groups = {"read"}, dependsOnMethods = {"readItem"})
723 public void readItemNonExistent(String testName) {
725 if (logger.isDebugEnabled()) {
726 logger.debug(testBanner(testName, CLASS_NAME));
729 setupReadNonExistent();
731 // Submit the request to the service and store the response.
732 LocationAuthorityClient client = new LocationAuthorityClient();
733 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
735 int statusCode = res.getStatus();
737 // Check the status code of the response: does it match
738 // the expected response(s)?
739 if(logger.isDebugEnabled()){
740 logger.debug(testName + ": status = " + statusCode);
742 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
743 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
744 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
746 res.releaseConnection();
751 // ---------------------------------------------------------------
752 // CRUD tests : READ_LIST tests
753 // ---------------------------------------------------------------
757 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
760 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
761 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
762 public void readList(String testName) throws Exception {
764 if (logger.isDebugEnabled()) {
765 logger.debug(testBanner(testName, CLASS_NAME));
770 // Submit the request to the service and store the response.
771 LocationAuthorityClient client = new LocationAuthorityClient();
772 ClientResponse<LocationauthoritiesCommonList> res = client.readList();
774 LocationauthoritiesCommonList list = res.getEntity();
775 int statusCode = res.getStatus();
777 // Check the status code of the response: does it match
778 // the expected response(s)?
779 if(logger.isDebugEnabled()){
780 logger.debug(testName + ": status = " + statusCode);
782 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
783 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
784 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
786 // Optionally output additional data about list members for debugging.
787 boolean iterateThroughList = false;
788 if (iterateThroughList && logger.isDebugEnabled()) {
789 List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
790 list.getLocationauthorityListItem();
792 for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
793 String csid = item.getCsid();
794 logger.debug(testName + ": list-item[" + i + "] csid=" +
796 logger.debug(testName + ": list-item[" + i + "] displayName=" +
797 item.getDisplayName());
798 logger.debug(testName + ": list-item[" + i + "] URI=" +
800 readItemList(csid, null);
805 res.releaseConnection();
812 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
813 public void readItemList() {
814 String testName = "readItemList";
815 if (logger.isDebugEnabled()) {
816 logger.debug(testBanner(testName, CLASS_NAME));
818 readItemList(knownResourceId, null);
822 * Read item list by authority name.
824 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
825 public void readItemListByAuthorityName() {
826 String testName = "readItemListByAuthorityName";
827 if (logger.isDebugEnabled()) {
828 logger.debug(testBanner(testName, CLASS_NAME));
830 readItemList(null, knownResourceShortIdentifer);
836 * @param vcsid the vcsid
837 * @param name the name
839 private void readItemList(String vcsid, String shortId) {
841 String testName = "readItemList";
846 // Submit the request to the service and store the response.
847 LocationAuthorityClient client = new LocationAuthorityClient();
848 ClientResponse<LocationsCommonList> res = null;
850 res = client.readItemList(vcsid, null, null);
851 } else if(shortId!= null) {
852 res = client.readItemListForNamedAuthority(shortId, null, null);
854 Assert.fail("readItemList passed null csid and name!");
857 LocationsCommonList list = res.getEntity();
858 int statusCode = res.getStatus();
860 // Check the status code of the response: does it match
861 // the expected response(s)?
862 if(logger.isDebugEnabled()){
863 logger.debug(testName + ": status = " + statusCode);
865 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
866 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
867 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
869 List<LocationsCommonList.LocationListItem> items =
870 list.getLocationListItem();
871 int nItemsReturned = items.size();
872 // There will be one item created, associated with a
873 // known parent resource, by the createItem test.
875 // In addition, there will be 'nItemsToCreateInList'
876 // additional items created by the createItemList test,
877 // all associated with the same parent resource.
878 int nExpectedItems = nItemsToCreateInList + 1;
879 if(logger.isDebugEnabled()){
880 logger.debug(testName + ": Expected "
881 + nExpectedItems +" items; got: "+nItemsReturned);
883 Assert.assertEquals(nItemsReturned, nExpectedItems);
886 for (LocationsCommonList.LocationListItem item : items) {
887 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
888 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
889 // Optionally output additional data about list members for debugging.
890 boolean showDetails = true;
891 if (showDetails && logger.isDebugEnabled()) {
892 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
894 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
896 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
897 item.getDisplayName());
898 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
904 res.releaseConnection();
912 // ---------------------------------------------------------------
913 // CRUD tests : UPDATE tests
914 // ---------------------------------------------------------------
917 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
920 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
921 groups = {"update"}, dependsOnGroups = {"read", "readList"})
922 public void update(String testName) throws Exception {
924 if (logger.isDebugEnabled()) {
925 logger.debug(testBanner(testName, CLASS_NAME));
930 // Retrieve the contents of a resource to update.
931 LocationAuthorityClient client = new LocationAuthorityClient();
932 ClientResponse<String> res = client.read(knownResourceId);
934 if(logger.isDebugEnabled()){
935 logger.debug(testName + ": read status = " + res.getStatus());
937 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
939 if(logger.isDebugEnabled()){
940 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
942 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
943 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
944 client.getCommonPartName(), LocationauthoritiesCommon.class);
945 Assert.assertNotNull(locationAuthority);
947 // Update the contents of this resource.
948 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
949 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
950 if(logger.isDebugEnabled()){
951 logger.debug("to be updated LocationAuthority");
952 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
955 // Submit the updated resource to the service and store the response.
956 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
957 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
958 commonPart.setLabel(client.getCommonPartName());
959 res.releaseConnection();
960 res = client.update(knownResourceId, output);
961 int statusCode = res.getStatus();
963 // Check the status code of the response: does it match the expected response(s)?
964 if(logger.isDebugEnabled()){
965 logger.debug(testName + ": status = " + statusCode);
967 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
968 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
969 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
971 // Retrieve the updated resource and verify that its contents exist.
972 input = new PoxPayloadIn(res.getEntity());
973 LocationauthoritiesCommon updatedLocationAuthority =
974 (LocationauthoritiesCommon) extractPart(input,
975 client.getCommonPartName(), LocationauthoritiesCommon.class);
976 Assert.assertNotNull(updatedLocationAuthority);
978 // Verify that the updated resource received the correct data.
979 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
980 locationAuthority.getDisplayName(),
981 "Data in updated object did not match submitted data.");
983 res.releaseConnection();
990 * @param testName the test name
991 * @throws Exception the exception
993 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
994 groups = {"update"}, dependsOnMethods = {"update"})
995 public void updateItem(String testName) throws Exception {
997 if (logger.isDebugEnabled()) {
998 logger.debug(testBanner(testName, CLASS_NAME));
1003 // Retrieve the contents of a resource to update.
1004 LocationAuthorityClient client = new LocationAuthorityClient();
1005 ClientResponse<String> res =
1006 client.readItem(knownResourceId, knownItemResourceId);
1008 if(logger.isDebugEnabled()){
1009 logger.debug(testName + ": read status = " + res.getStatus());
1011 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1013 if(logger.isDebugEnabled()){
1014 logger.debug("got Location to update with ID: " +
1015 knownItemResourceId +
1016 " in LocationAuthority: " + knownResourceId );
1018 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1019 LocationsCommon location = (LocationsCommon) extractPart(input,
1020 client.getItemCommonPartName(), LocationsCommon.class);
1021 Assert.assertNotNull(location);
1023 // Update the contents of this resource.
1024 location.setCsid(null);
1025 location.setName("updated-" + location.getName());
1026 if(logger.isDebugEnabled()){
1027 logger.debug("to be updated Location");
1028 logger.debug(objectAsXmlString(location,
1029 LocationsCommon.class));
1032 // Submit the updated resource to the service and store the response.
1033 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1034 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1035 commonPart.setLabel(client.getItemCommonPartName());
1036 res.releaseConnection();
1037 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1038 int statusCode = res.getStatus();
1040 // Check the status code of the response: does it match the expected response(s)?
1041 if(logger.isDebugEnabled()){
1042 logger.debug(testName + ": status = " + statusCode);
1044 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1045 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1046 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1048 // Retrieve the updated resource and verify that its contents exist.
1049 input = new PoxPayloadIn(res.getEntity());
1050 LocationsCommon updatedLocation =
1051 (LocationsCommon) extractPart(input,
1052 client.getItemCommonPartName(), LocationsCommon.class);
1053 Assert.assertNotNull(updatedLocation);
1055 // Verify that the updated resource received the correct data.
1056 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1057 "Data in updated Location did not match submitted data.");
1059 res.releaseConnection();
1064 // Placeholders until the three tests below can be uncommented.
1065 // See Issue CSPACE-401.
1067 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1070 public void updateWithEmptyEntityBody(String testName) throws Exception {
1074 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1077 public void updateWithMalformedXml(String testName) throws Exception {
1081 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1084 public void updateWithWrongXmlSchema(String testName) throws Exception {
1089 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1092 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1093 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1094 public void updateNonExistent(String testName) throws Exception {
1096 if (logger.isDebugEnabled()) {
1097 logger.debug(testBanner(testName, CLASS_NAME));
1100 setupUpdateNonExistent();
1102 // Submit the request to the service and store the response.
1103 // Note: The ID(s) used when creating the request payload may be arbitrary.
1104 // The only relevant ID may be the one used in update(), below.
1105 LocationAuthorityClient client = new LocationAuthorityClient();
1106 String displayName = "displayName-NON_EXISTENT_ID";
1107 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1108 displayName, "nonEx", client.getCommonPartName());
1109 ClientResponse<String> res =
1110 client.update(NON_EXISTENT_ID, multipart);
1112 int statusCode = res.getStatus();
1114 // Check the status code of the response: does it match
1115 // the expected response(s)?
1116 if(logger.isDebugEnabled()){
1117 logger.debug(testName + ": status = " + statusCode);
1119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1123 res.releaseConnection();
1128 * Update non existent item.
1130 * @param testName the test name
1131 * @throws Exception the exception
1133 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1134 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1135 public void updateNonExistentItem(String testName) throws Exception {
1137 if (logger.isDebugEnabled()) {
1138 logger.debug(testBanner(testName, CLASS_NAME));
1141 setupUpdateNonExistent();
1143 // Submit the request to the service and store the response.
1144 // Note: The ID used in this 'create' call may be arbitrary.
1145 // The only relevant ID may be the one used in update(), below.
1146 LocationAuthorityClient client = new LocationAuthorityClient();
1147 Map<String, String> nonexMap = new HashMap<String,String>();
1148 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1149 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1150 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1151 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1152 PoxPayloadOut multipart =
1153 LocationAuthorityClientUtils.createLocationInstance(
1154 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1155 nonexMap, client.getItemCommonPartName() );
1156 ClientResponse<String> res =
1157 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1159 int statusCode = res.getStatus();
1161 // Check the status code of the response: does it match
1162 // the expected response(s)?
1163 if(logger.isDebugEnabled()){
1164 logger.debug(testName + ": status = " + statusCode);
1166 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1167 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1168 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1170 res.releaseConnection();
1174 // ---------------------------------------------------------------
1175 // CRUD tests : DELETE tests
1176 // ---------------------------------------------------------------
1179 // Note: delete sub-resources in ascending hierarchical order,
1180 // before deleting their parents.
1185 * @param testName the test name
1186 * @throws Exception the exception
1188 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1189 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1190 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1191 public void deleteItem(String testName) throws Exception {
1193 if (logger.isDebugEnabled()) {
1194 logger.debug(testBanner(testName, CLASS_NAME));
1199 if(logger.isDebugEnabled()){
1200 logger.debug("parentcsid =" + knownResourceId +
1201 " itemcsid = " + knownItemResourceId);
1204 // Submit the request to the service and store the response.
1205 LocationAuthorityClient client = new LocationAuthorityClient();
1206 ClientResponse<Response> res =
1207 client.deleteItem(knownResourceId, knownItemResourceId);
1209 int statusCode = res.getStatus();
1211 // Check the status code of the response: does it match
1212 // the expected response(s)?
1213 if(logger.isDebugEnabled()){
1214 logger.debug(testName + ": status = " + statusCode);
1216 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1217 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1218 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1220 res.releaseConnection();
1225 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1228 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1229 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1230 public void delete(String testName) throws Exception {
1232 if (logger.isDebugEnabled()) {
1233 logger.debug(testBanner(testName, CLASS_NAME));
1238 if(logger.isDebugEnabled()){
1239 logger.debug("parentcsid =" + knownResourceId);
1242 // Submit the request to the service and store the response.
1243 LocationAuthorityClient client = new LocationAuthorityClient();
1244 ClientResponse<Response> res = client.delete(knownResourceId);
1246 int statusCode = res.getStatus();
1248 // Check the status code of the response: does it match
1249 // the expected response(s)?
1250 if(logger.isDebugEnabled()){
1251 logger.debug(testName + ": status = " + statusCode);
1253 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1254 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1255 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1257 res.releaseConnection();
1263 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1266 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1267 groups = {"delete"}, dependsOnMethods = {"delete"})
1268 public void deleteNonExistent(String testName) throws Exception {
1270 if (logger.isDebugEnabled()) {
1271 logger.debug(testBanner(testName, CLASS_NAME));
1274 setupDeleteNonExistent();
1276 // Submit the request to the service and store the response.
1277 LocationAuthorityClient client = new LocationAuthorityClient();
1278 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1280 int statusCode = res.getStatus();
1282 // Check the status code of the response: does it match
1283 // the expected response(s)?
1284 if(logger.isDebugEnabled()){
1285 logger.debug(testName + ": status = " + statusCode);
1287 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1288 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1289 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1291 res.releaseConnection();
1296 * Delete non existent item.
1298 * @param testName the test name
1300 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1301 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1302 public void deleteNonExistentItem(String testName) {
1304 if (logger.isDebugEnabled()) {
1305 logger.debug(testBanner(testName, CLASS_NAME));
1308 setupDeleteNonExistent();
1310 // Submit the request to the service and store the response.
1311 LocationAuthorityClient client = new LocationAuthorityClient();
1312 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1314 int statusCode = res.getStatus();
1316 // Check the status code of the response: does it match
1317 // the expected response(s)?
1318 if(logger.isDebugEnabled()){
1319 logger.debug(testName + ": status = " + statusCode);
1321 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1322 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1323 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1325 res.releaseConnection();
1329 // ---------------------------------------------------------------
1330 // Utility tests : tests of code used in tests above
1331 // ---------------------------------------------------------------
1333 * Tests the code for manually submitting data that is used by several
1334 * of the methods above.
1336 @Test(dependsOnMethods = {"create", "read"})
1337 public void testSubmitRequest() {
1339 // Expected status code: 200 OK
1340 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1342 // Submit the request to the service and store the response.
1343 String method = ServiceRequestType.READ.httpMethodName();
1344 String url = getResourceURL(knownResourceId);
1345 int statusCode = submitRequest(method, url);
1347 // Check the status code of the response: does it match
1348 // the expected response(s)?
1349 if(logger.isDebugEnabled()){
1350 logger.debug("testSubmitRequest: url=" + url +
1351 " status=" + statusCode);
1353 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1358 * Test item submit request.
1360 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1361 public void testItemSubmitRequest() {
1363 // Expected status code: 200 OK
1364 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1366 // Submit the request to the service and store the response.
1367 String method = ServiceRequestType.READ.httpMethodName();
1368 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1369 int statusCode = submitRequest(method, url);
1371 // Check the status code of the response: does it match
1372 // the expected response(s)?
1373 if(logger.isDebugEnabled()){
1374 logger.debug("testItemSubmitRequest: url=" + url +
1375 " status=" + statusCode);
1377 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1381 // ---------------------------------------------------------------
1382 // Cleanup of resources created during testing
1383 // ---------------------------------------------------------------
1386 * Deletes all resources created by tests, after all tests have been run.
1388 * This cleanup method will always be run, even if one or more tests fail.
1389 * For this reason, it attempts to remove all resources created
1390 * at any point during testing, even if some of those resources
1391 * may be expected to be deleted by certain tests.
1394 @AfterClass(alwaysRun=true)
1395 public void cleanUp() {
1396 String noTest = System.getProperty("noTestCleanup");
1397 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1398 if (logger.isDebugEnabled()) {
1399 logger.debug("Skipping Cleanup phase ...");
1403 if (logger.isDebugEnabled()) {
1404 logger.debug("Cleaning up temporary resources created for testing ...");
1406 String parentResourceId;
1407 String itemResourceId;
1408 // Clean up contact resources.
1409 LocationAuthorityClient client = new LocationAuthorityClient();
1410 parentResourceId = knownResourceId;
1411 // Clean up item resources.
1412 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1413 itemResourceId = entry.getKey();
1414 parentResourceId = entry.getValue();
1415 // Note: Any non-success responses from the delete operation
1416 // below are ignored and not reported.
1417 ClientResponse<Response> res =
1418 client.deleteItem(parentResourceId, itemResourceId);
1419 res.releaseConnection();
1421 // Clean up parent resources.
1422 for (String resourceId : allResourceIdsCreated) {
1423 // Note: Any non-success responses from the delete operation
1424 // below are ignored and not reported.
1425 ClientResponse<Response> res = client.delete(resourceId);
1426 res.releaseConnection();
1430 // ---------------------------------------------------------------
1431 // Utility methods used by tests above
1432 // ---------------------------------------------------------------
1434 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1438 * Returns the root URL for the item service.
1440 * This URL consists of a base URL for all services, followed by
1441 * a path component for the owning parent, followed by the
1442 * path component for the items.
1444 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1445 * parent authority resource of the relevant item resource.
1447 * @return The root URL for the item service.
1449 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1450 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1454 * Returns the URL of a specific item resource managed by a service, and
1455 * designated by an identifier (such as a universally unique ID, or UUID).
1457 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1458 * parent authority resource of the relevant item resource.
1460 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1463 * @return The URL of a specific item resource managed by a service.
1465 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1466 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;