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 = identifier;
160 String displayName = "displayName-" + shortId;
162 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
163 PoxPayloadOut multipart =
164 LocationAuthorityClientUtils.createLocationAuthorityInstance(
165 displayName, shortId, client.getCommonPartName());
169 // ---------------------------------------------------------------
170 // CRUD tests : CREATE tests
171 // ---------------------------------------------------------------
174 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
177 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
179 public void create(String testName) throws Exception {
181 if (logger.isDebugEnabled()) {
182 logger.debug(testBanner(testName, CLASS_NAME));
184 // Perform setup, such as initializing the type of service request
185 // (e.g. CREATE, DELETE), its valid and expected status codes, and
186 // its associated HTTP method name (e.g. POST, DELETE).
189 // Submit the request to the service and store the response.
190 LocationAuthorityClient client = new LocationAuthorityClient();
191 String shortId = createIdentifier();
192 String displayName = "displayName-" + shortId;
194 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
196 PoxPayloadOut multipart =
197 LocationAuthorityClientUtils.createLocationAuthorityInstance(
198 displayName, shortId, client.getCommonPartName());
200 ClientResponse<Response> res = client.create(multipart);
202 int statusCode = res.getStatus();
204 // Check the status code of the response: does it match
205 // the expected response(s)?
208 // Does it fall within the set of valid status codes?
209 // Does it exactly match the expected status code?
210 if(logger.isDebugEnabled()){
211 logger.debug(testName + ": status = " + statusCode);
213 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
217 newID = LocationAuthorityClientUtils.extractId(res);
219 res.releaseConnection();
221 // Store the ID returned from the first resource created
222 // for additional tests below.
223 if (knownResourceId == null){
224 setKnownResource( newID, shortId, baseRefName );
225 if (logger.isDebugEnabled()) {
226 logger.debug(testName + ": knownResourceId=" + knownResourceId);
229 // Store the IDs from every resource created by tests,
230 // so they can be deleted after tests have been run.
231 allResourceIdsCreated.add(newID);
237 * @param testName the test name
239 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
240 groups = {"create"}, dependsOnMethods = {"create"})
241 public void createItem(String testName) {
242 if(logger.isDebugEnabled()){
243 logger.debug(testBanner(testName, CLASS_NAME));
246 createItemInAuthority(knownResourceId, knownResourceRefName);
250 * Creates the item in authority.
252 * @param vcsid the vcsid
253 * @param authRefName the auth ref name
256 private String createItemInAuthority(String vcsid, String authRefName) {
258 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
259 if(logger.isDebugEnabled()){
260 logger.debug(testBanner(testName, CLASS_NAME));
263 // Submit the request to the service and store the response.
264 LocationAuthorityClient client = new LocationAuthorityClient();
265 Map<String, String> shelf1Map = new HashMap<String,String>();
266 // TODO Make loc type and status be controlled vocabs.
267 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
268 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
269 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
270 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
271 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
272 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
273 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
274 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
275 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
277 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
278 authRefName, shelf1Map, client );
280 // Store the ID returned from the first item resource created
281 // for additional tests below.
282 if (knownItemResourceId == null){
283 setKnownItemResource(newID, TEST_SHORTID);
284 if (logger.isDebugEnabled()) {
285 logger.debug(testName + ": knownItemResourceId=" + newID);
289 // Store the IDs from any item resources created
290 // by tests, along with the IDs of their parents, so these items
291 // can be deleted after all tests have been run.
292 allItemResourceIdsCreated.put(newID, vcsid);
301 // Placeholders until the three tests below can be uncommented.
302 // See Issue CSPACE-401.
304 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
307 public void createWithEmptyEntityBody(String testName) throws Exception {
311 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
314 public void createWithMalformedXml(String testName) throws Exception {
318 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
321 public void createWithWrongXmlSchema(String testName) throws Exception {
325 // ---------------------------------------------------------------
326 // CRUD tests : CREATE LIST tests
327 // ---------------------------------------------------------------
330 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
333 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
334 groups = {"createList"}, dependsOnGroups = {"create"})
335 public void createList(String testName) throws Exception {
336 for (int i = 0; i < nItemsToCreateInList; i++) {
342 * Creates the item list.
344 * @param testName the test name
345 * @throws Exception the exception
347 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
348 groups = {"createList"}, dependsOnMethods = {"createList"})
349 public void createItemList(String testName) throws Exception {
350 // Add items to the initially-created, known parent record.
351 for (int j = 0; j < nItemsToCreateInList; j++) {
352 createItem(testName);
356 // ---------------------------------------------------------------
357 // CRUD tests : READ tests
358 // ---------------------------------------------------------------
361 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
364 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
365 groups = {"read"}, dependsOnGroups = {"create"})
366 public void read(String testName) throws Exception {
368 if (logger.isDebugEnabled()) {
369 logger.debug(testBanner(testName, CLASS_NAME));
374 // Submit the request to the service and store the response.
375 LocationAuthorityClient client = new LocationAuthorityClient();
377 ClientResponse<String> res = client.read(knownResourceId);
379 int statusCode = res.getStatus();
381 // Check the status code of the response: does it match
382 // the expected response(s)?
383 if(logger.isDebugEnabled()){
384 logger.debug(testName + ": status = " + statusCode);
386 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
387 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
388 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
389 //FIXME: remove the following try catch once Aron fixes signatures
391 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
392 LocationauthoritiesCommon locationAuthority =
393 (LocationauthoritiesCommon) extractPart(input,
394 client.getCommonPartName(), LocationauthoritiesCommon.class);
395 Assert.assertNotNull(locationAuthority);
396 } catch (Exception e) {
397 throw new RuntimeException(e);
400 res.releaseConnection();
407 * @param testName the test name
408 * @throws Exception the exception
410 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
411 groups = {"read"}, dependsOnGroups = {"create"})
412 public void readByName(String testName) throws Exception {
414 if (logger.isDebugEnabled()) {
415 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
420 // Submit the request to the service and store the response.
421 LocationAuthorityClient client = new LocationAuthorityClient();
422 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
424 int statusCode = res.getStatus();
426 // Check the status code of the response: does it match
427 // the expected response(s)?
428 if(logger.isDebugEnabled()){
429 logger.debug(testName + ": status = " + statusCode);
431 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
432 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
433 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
434 //FIXME: remove the following try catch once Aron fixes signatures
436 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
437 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
438 client.getCommonPartName(), LocationauthoritiesCommon.class);
439 Assert.assertNotNull(locationAuthority);
440 } catch (Exception e) {
441 throw new RuntimeException(e);
444 res.releaseConnection();
452 * @param testName the test name
453 * @throws Exception the exception
455 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
456 groups = {"read"}, dependsOnMethods = {"read"})
457 public void readItem(String testName) throws Exception {
459 if (logger.isDebugEnabled()) {
460 logger.debug(testBanner(testName, CLASS_NAME));
465 // Submit the request to the service and store the response.
466 LocationAuthorityClient client = new LocationAuthorityClient();
467 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
469 int statusCode = res.getStatus();
471 // Check the status code of the response: does it match
472 // the expected response(s)?
473 if(logger.isDebugEnabled()){
474 logger.debug(testName + ": status = " + statusCode);
476 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
477 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
478 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
480 // Check whether we've received a location.
481 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
482 LocationsCommon location = (LocationsCommon) extractPart(input,
483 client.getItemCommonPartName(), LocationsCommon.class);
484 Assert.assertNotNull(location);
485 boolean showFull = true;
486 if(showFull && logger.isDebugEnabled()){
487 logger.debug(testName + ": returned payload:");
488 logger.debug(objectAsXmlString(location, LocationsCommon.class));
490 Assert.assertEquals(location.getInAuthority(), knownResourceId);
492 res.releaseConnection();
498 * Verify item display name.
500 * @param testName the test name
501 * @throws Exception the exception
503 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
504 dependsOnMethods = {"readItem", "updateItem"})
505 public void verifyItemDisplayName(String testName) throws Exception {
507 if (logger.isDebugEnabled()) {
508 logger.debug(testBanner(testName, CLASS_NAME));
513 // Submit the request to the service and store the response.
514 LocationAuthorityClient client = new LocationAuthorityClient();
515 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
517 int statusCode = res.getStatus();
519 // Check the status code of the response: does it match
520 // the expected response(s)?
521 if(logger.isDebugEnabled()){
522 logger.debug(testName + ": status = " + statusCode);
524 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
528 // Check whether location has expected displayName.
529 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
530 LocationsCommon location = (LocationsCommon) extractPart(input,
531 client.getItemCommonPartName(), LocationsCommon.class);
532 Assert.assertNotNull(location);
533 String displayName = location.getDisplayName();
534 // Make sure displayName matches computed form
535 String expectedDisplayName =
536 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
537 Assert.assertNotNull(displayName, expectedDisplayName);
539 // Update the shortName and verify the computed name is updated.
540 location.setCsid(null);
541 location.setDisplayNameComputed(true);
542 location.setName("updated-" + TEST_NAME);
543 expectedDisplayName =
544 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
546 // Submit the updated resource to the service and store the response.
547 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
548 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
549 commonPart.setLabel(client.getItemCommonPartName());
550 res.releaseConnection();
551 res = client.updateItem(knownResourceId, knownItemResourceId, output);
552 statusCode = res.getStatus();
554 // Check the status code of the response: does it match the expected response(s)?
555 if(logger.isDebugEnabled()){
556 logger.debug("updateItem: status = " + statusCode);
558 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
559 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
560 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
562 // Retrieve the updated resource and verify that its contents exist.
563 input = new PoxPayloadIn(res.getEntity());
564 LocationsCommon updatedLocation =
565 (LocationsCommon) extractPart(input,
566 client.getItemCommonPartName(), LocationsCommon.class);
567 Assert.assertNotNull(updatedLocation);
569 // Verify that the updated resource received the correct data.
570 Assert.assertEquals(updatedLocation.getName(), location.getName(),
571 "Updated ForeName in Location did not match submitted data.");
572 // Verify that the updated resource computes the right displayName.
573 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
574 "Updated ForeName in Location not reflected in computed DisplayName.");
576 // Now Update the displayName, not computed and verify the computed name is overriden.
577 location.setDisplayNameComputed(false);
578 expectedDisplayName = "TestName";
579 location.setDisplayName(expectedDisplayName);
581 // Submit the updated resource to the service and store the response.
582 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
583 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
584 commonPart.setLabel(client.getItemCommonPartName());
585 res.releaseConnection();
586 res = client.updateItem(knownResourceId, knownItemResourceId, output);
587 statusCode = res.getStatus();
589 // Check the status code of the response: does it match the expected response(s)?
590 if(logger.isDebugEnabled()){
591 logger.debug("updateItem: status = " + statusCode);
593 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
594 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
595 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
597 // Retrieve the updated resource and verify that its contents exist.
598 input = new PoxPayloadIn(res.getEntity());
600 (LocationsCommon) extractPart(input,
601 client.getItemCommonPartName(), LocationsCommon.class);
602 Assert.assertNotNull(updatedLocation);
604 // Verify that the updated resource received the correct data.
605 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
606 "Updated displayNameComputed in Location did not match submitted data.");
607 // Verify that the updated resource computes the right displayName.
608 Assert.assertEquals(updatedLocation.getDisplayName(),
610 "Updated DisplayName (not computed) in Location not stored.");
612 res.releaseConnection();
617 * Verify illegal item display name.
619 * @param testName the test name
620 * @throws Exception the exception
622 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
623 dependsOnMethods = {"verifyItemDisplayName"})
624 public void verifyIllegalItemDisplayName(String testName) throws Exception {
626 if (logger.isDebugEnabled()) {
627 logger.debug(testBanner(testName, CLASS_NAME));
630 // FIXME: create a setup configuration for this operation.
631 setupUpdateWithWrongXmlSchema();
633 // Submit the request to the service and store the response.
634 LocationAuthorityClient client = new LocationAuthorityClient();
635 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
637 int statusCode = res.getStatus();
639 // Check the status code of the response: does it match
640 // the expected response(s)?
641 if(logger.isDebugEnabled()){
642 logger.debug(testName + ": status = " + statusCode);
644 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
645 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
646 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
648 // Check whether Location has expected displayName.
649 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
650 LocationsCommon location = (LocationsCommon) extractPart(input,
651 client.getItemCommonPartName(), LocationsCommon.class);
652 Assert.assertNotNull(location);
653 // Try to Update with computed false and no displayName
654 location.setDisplayNameComputed(false);
655 location.setDisplayName(null);
657 // Submit the updated resource to the service and store the response.
658 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
659 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
660 commonPart.setLabel(client.getItemCommonPartName());
661 res.releaseConnection();
662 res = client.updateItem(knownResourceId, knownItemResourceId, output);
663 statusCode = res.getStatus();
665 // Check the status code of the response: does it match the expected response(s)?
666 if(logger.isDebugEnabled()){
667 logger.debug("updateItem: status = " + statusCode);
669 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
670 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
671 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
673 res.releaseConnection();
680 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
683 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684 groups = {"read"}, dependsOnMethods = {"read"})
685 public void readNonExistent(String testName) {
687 if (logger.isDebugEnabled()) {
688 logger.debug(testBanner(testName, CLASS_NAME));
691 setupReadNonExistent();
693 // Submit the request to the service and store the response.
694 LocationAuthorityClient client = new LocationAuthorityClient();
695 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
697 int statusCode = res.getStatus();
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if(logger.isDebugEnabled()){
702 logger.debug(testName + ": status = " + statusCode);
704 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
708 res.releaseConnection();
713 * Read item non existent.
715 * @param testName the test name
717 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
718 groups = {"read"}, dependsOnMethods = {"readItem"})
719 public void readItemNonExistent(String testName) {
721 if (logger.isDebugEnabled()) {
722 logger.debug(testBanner(testName, CLASS_NAME));
725 setupReadNonExistent();
727 // Submit the request to the service and store the response.
728 LocationAuthorityClient client = new LocationAuthorityClient();
729 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
731 int statusCode = res.getStatus();
733 // Check the status code of the response: does it match
734 // the expected response(s)?
735 if(logger.isDebugEnabled()){
736 logger.debug(testName + ": status = " + statusCode);
738 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
739 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
740 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
742 res.releaseConnection();
747 // ---------------------------------------------------------------
748 // CRUD tests : READ_LIST tests
749 // ---------------------------------------------------------------
753 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
756 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
757 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
758 public void readList(String testName) throws Exception {
760 if (logger.isDebugEnabled()) {
761 logger.debug(testBanner(testName, CLASS_NAME));
766 // Submit the request to the service and store the response.
767 LocationAuthorityClient client = new LocationAuthorityClient();
768 ClientResponse<LocationauthoritiesCommonList> res = client.readList();
770 LocationauthoritiesCommonList list = res.getEntity();
771 int statusCode = res.getStatus();
773 // Check the status code of the response: does it match
774 // the expected response(s)?
775 if(logger.isDebugEnabled()){
776 logger.debug(testName + ": status = " + statusCode);
778 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
779 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
780 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
782 // Optionally output additional data about list members for debugging.
783 boolean iterateThroughList = false;
784 if (iterateThroughList && logger.isDebugEnabled()) {
785 List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
786 list.getLocationauthorityListItem();
788 for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
789 String csid = item.getCsid();
790 logger.debug(testName + ": list-item[" + i + "] csid=" +
792 logger.debug(testName + ": list-item[" + i + "] displayName=" +
793 item.getDisplayName());
794 logger.debug(testName + ": list-item[" + i + "] URI=" +
796 readItemList(csid, null);
801 res.releaseConnection();
808 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
809 public void readItemList() {
810 String testName = "readItemList";
811 if (logger.isDebugEnabled()) {
812 logger.debug(testBanner(testName, CLASS_NAME));
814 readItemList(knownResourceId, null);
818 * Read item list by authority name.
820 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
821 public void readItemListByAuthorityName() {
822 String testName = "readItemListByAuthorityName";
823 if (logger.isDebugEnabled()) {
824 logger.debug(testBanner(testName, CLASS_NAME));
826 readItemList(null, knownResourceShortIdentifer);
832 * @param vcsid the vcsid
833 * @param name the name
835 private void readItemList(String vcsid, String shortId) {
837 String testName = "readItemList";
842 // Submit the request to the service and store the response.
843 LocationAuthorityClient client = new LocationAuthorityClient();
844 ClientResponse<LocationsCommonList> res = null;
846 res = client.readItemList(vcsid, null, null);
847 } else if(shortId!= null) {
848 res = client.readItemListForNamedAuthority(shortId, null, null);
850 Assert.fail("readItemList passed null csid and name!");
853 LocationsCommonList list = res.getEntity();
854 int statusCode = res.getStatus();
856 // Check the status code of the response: does it match
857 // the expected response(s)?
858 if(logger.isDebugEnabled()){
859 logger.debug(testName + ": status = " + statusCode);
861 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
862 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
863 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
865 List<LocationsCommonList.LocationListItem> items =
866 list.getLocationListItem();
867 int nItemsReturned = items.size();
868 // There will be one item created, associated with a
869 // known parent resource, by the createItem test.
871 // In addition, there will be 'nItemsToCreateInList'
872 // additional items created by the createItemList test,
873 // all associated with the same parent resource.
874 int nExpectedItems = nItemsToCreateInList + 1;
875 if(logger.isDebugEnabled()){
876 logger.debug(testName + ": Expected "
877 + nExpectedItems +" items; got: "+nItemsReturned);
879 Assert.assertEquals(nItemsReturned, nExpectedItems);
882 for (LocationsCommonList.LocationListItem item : items) {
883 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
884 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
885 // Optionally output additional data about list members for debugging.
886 boolean showDetails = true;
887 if (showDetails && logger.isDebugEnabled()) {
888 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
890 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
892 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
893 item.getDisplayName());
894 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
900 res.releaseConnection();
908 // ---------------------------------------------------------------
909 // CRUD tests : UPDATE tests
910 // ---------------------------------------------------------------
913 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
916 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
917 groups = {"update"}, dependsOnGroups = {"read", "readList"})
918 public void update(String testName) throws Exception {
920 if (logger.isDebugEnabled()) {
921 logger.debug(testBanner(testName, CLASS_NAME));
926 // Retrieve the contents of a resource to update.
927 LocationAuthorityClient client = new LocationAuthorityClient();
928 ClientResponse<String> res = client.read(knownResourceId);
930 if(logger.isDebugEnabled()){
931 logger.debug(testName + ": read status = " + res.getStatus());
933 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
935 if(logger.isDebugEnabled()){
936 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
938 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
939 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
940 client.getCommonPartName(), LocationauthoritiesCommon.class);
941 Assert.assertNotNull(locationAuthority);
943 // Update the contents of this resource.
944 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
945 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
946 if(logger.isDebugEnabled()){
947 logger.debug("to be updated LocationAuthority");
948 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
951 // Submit the updated resource to the service and store the response.
952 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
953 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
954 commonPart.setLabel(client.getCommonPartName());
955 res.releaseConnection();
956 res = client.update(knownResourceId, output);
957 int statusCode = res.getStatus();
959 // Check the status code of the response: does it match the expected response(s)?
960 if(logger.isDebugEnabled()){
961 logger.debug(testName + ": status = " + statusCode);
963 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
964 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
965 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
967 // Retrieve the updated resource and verify that its contents exist.
968 input = new PoxPayloadIn(res.getEntity());
969 LocationauthoritiesCommon updatedLocationAuthority =
970 (LocationauthoritiesCommon) extractPart(input,
971 client.getCommonPartName(), LocationauthoritiesCommon.class);
972 Assert.assertNotNull(updatedLocationAuthority);
974 // Verify that the updated resource received the correct data.
975 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
976 locationAuthority.getDisplayName(),
977 "Data in updated object did not match submitted data.");
979 res.releaseConnection();
986 * @param testName the test name
987 * @throws Exception the exception
989 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
990 groups = {"update"}, dependsOnMethods = {"update"})
991 public void updateItem(String testName) throws Exception {
993 if (logger.isDebugEnabled()) {
994 logger.debug(testBanner(testName, CLASS_NAME));
999 // Retrieve the contents of a resource to update.
1000 LocationAuthorityClient client = new LocationAuthorityClient();
1001 ClientResponse<String> res =
1002 client.readItem(knownResourceId, knownItemResourceId);
1004 if(logger.isDebugEnabled()){
1005 logger.debug(testName + ": read status = " + res.getStatus());
1007 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1009 if(logger.isDebugEnabled()){
1010 logger.debug("got Location to update with ID: " +
1011 knownItemResourceId +
1012 " in LocationAuthority: " + knownResourceId );
1014 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1015 LocationsCommon location = (LocationsCommon) extractPart(input,
1016 client.getItemCommonPartName(), LocationsCommon.class);
1017 Assert.assertNotNull(location);
1019 // Update the contents of this resource.
1020 location.setCsid(null);
1021 location.setName("updated-" + location.getName());
1022 if(logger.isDebugEnabled()){
1023 logger.debug("to be updated Location");
1024 logger.debug(objectAsXmlString(location,
1025 LocationsCommon.class));
1028 // Submit the updated resource to the service and store the response.
1029 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1030 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1031 commonPart.setLabel(client.getItemCommonPartName());
1032 res.releaseConnection();
1033 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1034 int statusCode = res.getStatus();
1036 // Check the status code of the response: does it match the expected response(s)?
1037 if(logger.isDebugEnabled()){
1038 logger.debug(testName + ": status = " + statusCode);
1040 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1041 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1042 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1044 // Retrieve the updated resource and verify that its contents exist.
1045 input = new PoxPayloadIn(res.getEntity());
1046 LocationsCommon updatedLocation =
1047 (LocationsCommon) extractPart(input,
1048 client.getItemCommonPartName(), LocationsCommon.class);
1049 Assert.assertNotNull(updatedLocation);
1051 // Verify that the updated resource received the correct data.
1052 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1053 "Data in updated Location did not match submitted data.");
1055 res.releaseConnection();
1060 // Placeholders until the three tests below can be uncommented.
1061 // See Issue CSPACE-401.
1063 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1066 public void updateWithEmptyEntityBody(String testName) throws Exception {
1070 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1073 public void updateWithMalformedXml(String testName) throws Exception {
1077 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1080 public void updateWithWrongXmlSchema(String testName) throws Exception {
1085 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1088 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1089 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1090 public void updateNonExistent(String testName) throws Exception {
1092 if (logger.isDebugEnabled()) {
1093 logger.debug(testBanner(testName, CLASS_NAME));
1096 setupUpdateNonExistent();
1098 // Submit the request to the service and store the response.
1099 // Note: The ID(s) used when creating the request payload may be arbitrary.
1100 // The only relevant ID may be the one used in update(), below.
1101 LocationAuthorityClient client = new LocationAuthorityClient();
1102 String displayName = "displayName-NON_EXISTENT_ID";
1103 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1104 displayName, "nonEx", client.getCommonPartName());
1105 ClientResponse<String> res =
1106 client.update(NON_EXISTENT_ID, multipart);
1108 int statusCode = res.getStatus();
1110 // Check the status code of the response: does it match
1111 // the expected response(s)?
1112 if(logger.isDebugEnabled()){
1113 logger.debug(testName + ": status = " + statusCode);
1115 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1116 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1117 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1119 res.releaseConnection();
1124 * Update non existent item.
1126 * @param testName the test name
1127 * @throws Exception the exception
1129 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1130 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1131 public void updateNonExistentItem(String testName) throws Exception {
1133 if (logger.isDebugEnabled()) {
1134 logger.debug(testBanner(testName, CLASS_NAME));
1137 setupUpdateNonExistent();
1139 // Submit the request to the service and store the response.
1140 // Note: The ID used in this 'create' call may be arbitrary.
1141 // The only relevant ID may be the one used in update(), below.
1142 LocationAuthorityClient client = new LocationAuthorityClient();
1143 Map<String, String> nonexMap = new HashMap<String,String>();
1144 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1145 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1146 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1147 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1148 PoxPayloadOut multipart =
1149 LocationAuthorityClientUtils.createLocationInstance(
1150 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1151 nonexMap, client.getItemCommonPartName() );
1152 ClientResponse<String> res =
1153 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1155 int statusCode = res.getStatus();
1157 // Check the status code of the response: does it match
1158 // the expected response(s)?
1159 if(logger.isDebugEnabled()){
1160 logger.debug(testName + ": status = " + statusCode);
1162 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1163 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1164 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1166 res.releaseConnection();
1170 // ---------------------------------------------------------------
1171 // CRUD tests : DELETE tests
1172 // ---------------------------------------------------------------
1175 // Note: delete sub-resources in ascending hierarchical order,
1176 // before deleting their parents.
1181 * @param testName the test name
1182 * @throws Exception the exception
1184 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1185 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1186 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1187 public void deleteItem(String testName) throws Exception {
1189 if (logger.isDebugEnabled()) {
1190 logger.debug(testBanner(testName, CLASS_NAME));
1195 if(logger.isDebugEnabled()){
1196 logger.debug("parentcsid =" + knownResourceId +
1197 " itemcsid = " + knownItemResourceId);
1200 // Submit the request to the service and store the response.
1201 LocationAuthorityClient client = new LocationAuthorityClient();
1202 ClientResponse<Response> res =
1203 client.deleteItem(knownResourceId, knownItemResourceId);
1205 int statusCode = res.getStatus();
1207 // Check the status code of the response: does it match
1208 // the expected response(s)?
1209 if(logger.isDebugEnabled()){
1210 logger.debug(testName + ": status = " + statusCode);
1212 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1213 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1214 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1216 res.releaseConnection();
1221 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1224 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1225 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1226 public void delete(String testName) throws Exception {
1228 if (logger.isDebugEnabled()) {
1229 logger.debug(testBanner(testName, CLASS_NAME));
1234 if(logger.isDebugEnabled()){
1235 logger.debug("parentcsid =" + knownResourceId);
1238 // Submit the request to the service and store the response.
1239 LocationAuthorityClient client = new LocationAuthorityClient();
1240 ClientResponse<Response> res = client.delete(knownResourceId);
1242 int statusCode = res.getStatus();
1244 // Check the status code of the response: does it match
1245 // the expected response(s)?
1246 if(logger.isDebugEnabled()){
1247 logger.debug(testName + ": status = " + statusCode);
1249 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1250 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1251 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1253 res.releaseConnection();
1259 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1262 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1263 groups = {"delete"}, dependsOnMethods = {"delete"})
1264 public void deleteNonExistent(String testName) throws Exception {
1266 if (logger.isDebugEnabled()) {
1267 logger.debug(testBanner(testName, CLASS_NAME));
1270 setupDeleteNonExistent();
1272 // Submit the request to the service and store the response.
1273 LocationAuthorityClient client = new LocationAuthorityClient();
1274 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1276 int statusCode = res.getStatus();
1278 // Check the status code of the response: does it match
1279 // the expected response(s)?
1280 if(logger.isDebugEnabled()){
1281 logger.debug(testName + ": status = " + statusCode);
1283 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1284 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1285 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1287 res.releaseConnection();
1292 * Delete non existent item.
1294 * @param testName the test name
1296 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1297 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1298 public void deleteNonExistentItem(String testName) {
1300 if (logger.isDebugEnabled()) {
1301 logger.debug(testBanner(testName, CLASS_NAME));
1304 setupDeleteNonExistent();
1306 // Submit the request to the service and store the response.
1307 LocationAuthorityClient client = new LocationAuthorityClient();
1308 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1310 int statusCode = res.getStatus();
1312 // Check the status code of the response: does it match
1313 // the expected response(s)?
1314 if(logger.isDebugEnabled()){
1315 logger.debug(testName + ": status = " + statusCode);
1317 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1318 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1319 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1321 res.releaseConnection();
1325 // ---------------------------------------------------------------
1326 // Utility tests : tests of code used in tests above
1327 // ---------------------------------------------------------------
1329 * Tests the code for manually submitting data that is used by several
1330 * of the methods above.
1332 @Test(dependsOnMethods = {"create", "read"})
1333 public void testSubmitRequest() {
1335 // Expected status code: 200 OK
1336 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1338 // Submit the request to the service and store the response.
1339 String method = ServiceRequestType.READ.httpMethodName();
1340 String url = getResourceURL(knownResourceId);
1341 int statusCode = submitRequest(method, url);
1343 // Check the status code of the response: does it match
1344 // the expected response(s)?
1345 if(logger.isDebugEnabled()){
1346 logger.debug("testSubmitRequest: url=" + url +
1347 " status=" + statusCode);
1349 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1354 * Test item submit request.
1356 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1357 public void testItemSubmitRequest() {
1359 // Expected status code: 200 OK
1360 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1362 // Submit the request to the service and store the response.
1363 String method = ServiceRequestType.READ.httpMethodName();
1364 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1365 int statusCode = submitRequest(method, url);
1367 // Check the status code of the response: does it match
1368 // the expected response(s)?
1369 if(logger.isDebugEnabled()){
1370 logger.debug("testItemSubmitRequest: url=" + url +
1371 " status=" + statusCode);
1373 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1377 // ---------------------------------------------------------------
1378 // Cleanup of resources created during testing
1379 // ---------------------------------------------------------------
1382 * Deletes all resources created by tests, after all tests have been run.
1384 * This cleanup method will always be run, even if one or more tests fail.
1385 * For this reason, it attempts to remove all resources created
1386 * at any point during testing, even if some of those resources
1387 * may be expected to be deleted by certain tests.
1390 @AfterClass(alwaysRun=true)
1391 public void cleanUp() {
1392 String noTest = System.getProperty("noTestCleanup");
1393 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1394 if (logger.isDebugEnabled()) {
1395 logger.debug("Skipping Cleanup phase ...");
1399 if (logger.isDebugEnabled()) {
1400 logger.debug("Cleaning up temporary resources created for testing ...");
1402 String parentResourceId;
1403 String itemResourceId;
1404 // Clean up contact resources.
1405 LocationAuthorityClient client = new LocationAuthorityClient();
1406 parentResourceId = knownResourceId;
1407 // Clean up item resources.
1408 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1409 itemResourceId = entry.getKey();
1410 parentResourceId = entry.getValue();
1411 // Note: Any non-success responses from the delete operation
1412 // below are ignored and not reported.
1413 ClientResponse<Response> res =
1414 client.deleteItem(parentResourceId, itemResourceId);
1415 res.releaseConnection();
1417 // Clean up parent resources.
1418 for (String resourceId : allResourceIdsCreated) {
1419 // Note: Any non-success responses from the delete operation
1420 // below are ignored and not reported.
1421 ClientResponse<Response> res = client.delete(resourceId);
1422 res.releaseConnection();
1426 // ---------------------------------------------------------------
1427 // Utility methods used by tests above
1428 // ---------------------------------------------------------------
1430 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1434 * Returns the root URL for the item service.
1436 * This URL consists of a base URL for all services, followed by
1437 * a path component for the owning parent, followed by the
1438 * path component for the items.
1440 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1441 * parent authority resource of the relevant item resource.
1443 * @return The root URL for the item service.
1445 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1446 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1450 * Returns the URL of a specific item resource managed by a service, and
1451 * designated by an identifier (such as a universally unique ID, or UUID).
1453 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1454 * parent authority resource of the relevant item resource.
1456 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1459 * @return The URL of a specific item resource managed by a service.
1461 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1462 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;