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 } catch (Exception e) {
398 throw new RuntimeException(e);
401 res.releaseConnection();
408 * @param testName the test name
409 * @throws Exception the exception
411 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
412 groups = {"read"}, dependsOnGroups = {"create"})
413 public void readByName(String testName) throws Exception {
415 if (logger.isDebugEnabled()) {
416 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
421 // Submit the request to the service and store the response.
422 LocationAuthorityClient client = new LocationAuthorityClient();
423 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
425 int statusCode = res.getStatus();
427 // Check the status code of the response: does it match
428 // the expected response(s)?
429 if(logger.isDebugEnabled()){
430 logger.debug(testName + ": status = " + statusCode);
432 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
433 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
434 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
435 //FIXME: remove the following try catch once Aron fixes signatures
437 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
438 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
439 client.getCommonPartName(), LocationauthoritiesCommon.class);
440 Assert.assertNotNull(locationAuthority);
441 } catch (Exception e) {
442 throw new RuntimeException(e);
445 res.releaseConnection();
453 * @param testName the test name
454 * @throws Exception the exception
456 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
457 groups = {"read"}, dependsOnMethods = {"read"})
458 public void readItem(String testName) throws Exception {
460 if (logger.isDebugEnabled()) {
461 logger.debug(testBanner(testName, CLASS_NAME));
466 // Submit the request to the service and store the response.
467 LocationAuthorityClient client = new LocationAuthorityClient();
468 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
470 int statusCode = res.getStatus();
472 // Check the status code of the response: does it match
473 // the expected response(s)?
474 if(logger.isDebugEnabled()){
475 logger.debug(testName + ": status = " + statusCode);
477 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
478 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
479 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
481 // Check whether we've received a location.
482 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
483 LocationsCommon location = (LocationsCommon) extractPart(input,
484 client.getItemCommonPartName(), LocationsCommon.class);
485 Assert.assertNotNull(location);
486 boolean showFull = true;
487 if(showFull && logger.isDebugEnabled()){
488 logger.debug(testName + ": returned payload:");
489 logger.debug(objectAsXmlString(location, LocationsCommon.class));
491 Assert.assertEquals(location.getInAuthority(), knownResourceId);
493 res.releaseConnection();
499 * Verify item display name.
501 * @param testName the test name
502 * @throws Exception the exception
504 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
505 dependsOnMethods = {"readItem", "updateItem"})
506 public void verifyItemDisplayName(String testName) throws Exception {
508 if (logger.isDebugEnabled()) {
509 logger.debug(testBanner(testName, CLASS_NAME));
514 // Submit the request to the service and store the response.
515 LocationAuthorityClient client = new LocationAuthorityClient();
516 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
518 int statusCode = res.getStatus();
520 // Check the status code of the response: does it match
521 // the expected response(s)?
522 if(logger.isDebugEnabled()){
523 logger.debug(testName + ": status = " + statusCode);
525 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
526 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
527 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
529 // Check whether location has expected displayName.
530 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
531 LocationsCommon location = (LocationsCommon) extractPart(input,
532 client.getItemCommonPartName(), LocationsCommon.class);
533 Assert.assertNotNull(location);
534 String displayName = location.getDisplayName();
535 // Make sure displayName matches computed form
536 String expectedDisplayName =
537 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
538 Assert.assertNotNull(displayName, expectedDisplayName);
540 // Update the shortName and verify the computed name is updated.
541 location.setCsid(null);
542 location.setDisplayNameComputed(true);
543 location.setName("updated-" + TEST_NAME);
544 expectedDisplayName =
545 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
547 // Submit the updated resource to the service and store the response.
548 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
549 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
550 commonPart.setLabel(client.getItemCommonPartName());
551 res.releaseConnection();
552 res = client.updateItem(knownResourceId, knownItemResourceId, output);
553 statusCode = res.getStatus();
555 // Check the status code of the response: does it match the expected response(s)?
556 if(logger.isDebugEnabled()){
557 logger.debug("updateItem: status = " + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
563 // Retrieve the updated resource and verify that its contents exist.
564 input = new PoxPayloadIn(res.getEntity());
565 LocationsCommon updatedLocation =
566 (LocationsCommon) extractPart(input,
567 client.getItemCommonPartName(), LocationsCommon.class);
568 Assert.assertNotNull(updatedLocation);
570 // Verify that the updated resource received the correct data.
571 Assert.assertEquals(updatedLocation.getName(), location.getName(),
572 "Updated ForeName in Location did not match submitted data.");
573 // Verify that the updated resource computes the right displayName.
574 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
575 "Updated ForeName in Location not reflected in computed DisplayName.");
577 // Now Update the displayName, not computed and verify the computed name is overriden.
578 location.setDisplayNameComputed(false);
579 expectedDisplayName = "TestName";
580 location.setDisplayName(expectedDisplayName);
582 // Submit the updated resource to the service and store the response.
583 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
584 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
585 commonPart.setLabel(client.getItemCommonPartName());
586 res.releaseConnection();
587 res = client.updateItem(knownResourceId, knownItemResourceId, output);
588 statusCode = res.getStatus();
590 // Check the status code of the response: does it match the expected response(s)?
591 if(logger.isDebugEnabled()){
592 logger.debug("updateItem: status = " + statusCode);
594 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
595 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
596 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
598 // Retrieve the updated resource and verify that its contents exist.
599 input = new PoxPayloadIn(res.getEntity());
601 (LocationsCommon) extractPart(input,
602 client.getItemCommonPartName(), LocationsCommon.class);
603 Assert.assertNotNull(updatedLocation);
605 // Verify that the updated resource received the correct data.
606 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
607 "Updated displayNameComputed in Location did not match submitted data.");
608 // Verify that the updated resource computes the right displayName.
609 Assert.assertEquals(updatedLocation.getDisplayName(),
611 "Updated DisplayName (not computed) in Location not stored.");
613 res.releaseConnection();
618 * Verify illegal item display name.
620 * @param testName the test name
621 * @throws Exception the exception
623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
624 dependsOnMethods = {"verifyItemDisplayName"})
625 public void verifyIllegalItemDisplayName(String testName) throws Exception {
627 if (logger.isDebugEnabled()) {
628 logger.debug(testBanner(testName, CLASS_NAME));
631 // FIXME: create a setup configuration for this operation.
632 setupUpdateWithWrongXmlSchema();
634 // Submit the request to the service and store the response.
635 LocationAuthorityClient client = new LocationAuthorityClient();
636 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
638 int statusCode = res.getStatus();
640 // Check the status code of the response: does it match
641 // the expected response(s)?
642 if(logger.isDebugEnabled()){
643 logger.debug(testName + ": status = " + statusCode);
645 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
646 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
647 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
649 // Check whether Location has expected displayName.
650 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
651 LocationsCommon location = (LocationsCommon) extractPart(input,
652 client.getItemCommonPartName(), LocationsCommon.class);
653 Assert.assertNotNull(location);
654 // Try to Update with computed false and no displayName
655 location.setDisplayNameComputed(false);
656 location.setDisplayName(null);
658 // Submit the updated resource to the service and store the response.
659 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
660 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
661 commonPart.setLabel(client.getItemCommonPartName());
662 res.releaseConnection();
663 res = client.updateItem(knownResourceId, knownItemResourceId, output);
664 statusCode = res.getStatus();
666 // Check the status code of the response: does it match the expected response(s)?
667 if(logger.isDebugEnabled()){
668 logger.debug("updateItem: status = " + statusCode);
670 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
671 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
672 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
674 res.releaseConnection();
681 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
684 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
685 groups = {"read"}, dependsOnMethods = {"read"})
686 public void readNonExistent(String testName) {
688 if (logger.isDebugEnabled()) {
689 logger.debug(testBanner(testName, CLASS_NAME));
692 setupReadNonExistent();
694 // Submit the request to the service and store the response.
695 LocationAuthorityClient client = new LocationAuthorityClient();
696 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
698 int statusCode = res.getStatus();
700 // Check the status code of the response: does it match
701 // the expected response(s)?
702 if(logger.isDebugEnabled()){
703 logger.debug(testName + ": status = " + statusCode);
705 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
706 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
707 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
709 res.releaseConnection();
714 * Read item non existent.
716 * @param testName the test name
718 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
719 groups = {"read"}, dependsOnMethods = {"readItem"})
720 public void readItemNonExistent(String testName) {
722 if (logger.isDebugEnabled()) {
723 logger.debug(testBanner(testName, CLASS_NAME));
726 setupReadNonExistent();
728 // Submit the request to the service and store the response.
729 LocationAuthorityClient client = new LocationAuthorityClient();
730 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
732 int statusCode = res.getStatus();
734 // Check the status code of the response: does it match
735 // the expected response(s)?
736 if(logger.isDebugEnabled()){
737 logger.debug(testName + ": status = " + statusCode);
739 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
740 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
741 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743 res.releaseConnection();
748 // ---------------------------------------------------------------
749 // CRUD tests : READ_LIST tests
750 // ---------------------------------------------------------------
754 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
757 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
758 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
759 public void readList(String testName) throws Exception {
761 if (logger.isDebugEnabled()) {
762 logger.debug(testBanner(testName, CLASS_NAME));
767 // Submit the request to the service and store the response.
768 LocationAuthorityClient client = new LocationAuthorityClient();
769 ClientResponse<LocationauthoritiesCommonList> res = client.readList();
771 LocationauthoritiesCommonList list = res.getEntity();
772 int statusCode = res.getStatus();
774 // Check the status code of the response: does it match
775 // the expected response(s)?
776 if(logger.isDebugEnabled()){
777 logger.debug(testName + ": status = " + statusCode);
779 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
780 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
781 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
783 // Optionally output additional data about list members for debugging.
784 boolean iterateThroughList = false;
785 if (iterateThroughList && logger.isDebugEnabled()) {
786 List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
787 list.getLocationauthorityListItem();
789 for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
790 String csid = item.getCsid();
791 logger.debug(testName + ": list-item[" + i + "] csid=" +
793 logger.debug(testName + ": list-item[" + i + "] displayName=" +
794 item.getDisplayName());
795 logger.debug(testName + ": list-item[" + i + "] URI=" +
797 readItemList(csid, null);
802 res.releaseConnection();
809 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
810 public void readItemList() {
811 String testName = "readItemList";
812 if (logger.isDebugEnabled()) {
813 logger.debug(testBanner(testName, CLASS_NAME));
815 readItemList(knownResourceId, null);
819 * Read item list by authority name.
821 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
822 public void readItemListByAuthorityName() {
823 String testName = "readItemListByAuthorityName";
824 if (logger.isDebugEnabled()) {
825 logger.debug(testBanner(testName, CLASS_NAME));
827 readItemList(null, knownResourceShortIdentifer);
833 * @param vcsid the vcsid
834 * @param name the name
836 private void readItemList(String vcsid, String shortId) {
838 String testName = "readItemList";
843 // Submit the request to the service and store the response.
844 LocationAuthorityClient client = new LocationAuthorityClient();
845 ClientResponse<LocationsCommonList> res = null;
847 res = client.readItemList(vcsid, null, null);
848 } else if(shortId!= null) {
849 res = client.readItemListForNamedAuthority(shortId, null, null);
851 Assert.fail("readItemList passed null csid and name!");
854 LocationsCommonList list = res.getEntity();
855 int statusCode = res.getStatus();
857 // Check the status code of the response: does it match
858 // the expected response(s)?
859 if(logger.isDebugEnabled()){
860 logger.debug(testName + ": status = " + statusCode);
862 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
863 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
864 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
866 List<LocationsCommonList.LocationListItem> items =
867 list.getLocationListItem();
868 int nItemsReturned = items.size();
869 // There will be one item created, associated with a
870 // known parent resource, by the createItem test.
872 // In addition, there will be 'nItemsToCreateInList'
873 // additional items created by the createItemList test,
874 // all associated with the same parent resource.
875 int nExpectedItems = nItemsToCreateInList + 1;
876 if(logger.isDebugEnabled()){
877 logger.debug(testName + ": Expected "
878 + nExpectedItems +" items; got: "+nItemsReturned);
880 Assert.assertEquals(nItemsReturned, nExpectedItems);
883 for (LocationsCommonList.LocationListItem item : items) {
884 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
885 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
886 // Optionally output additional data about list members for debugging.
887 boolean showDetails = true;
888 if (showDetails && logger.isDebugEnabled()) {
889 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
891 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
893 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
894 item.getDisplayName());
895 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
901 res.releaseConnection();
909 // ---------------------------------------------------------------
910 // CRUD tests : UPDATE tests
911 // ---------------------------------------------------------------
914 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
917 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
918 groups = {"update"}, dependsOnGroups = {"read", "readList"})
919 public void update(String testName) throws Exception {
921 if (logger.isDebugEnabled()) {
922 logger.debug(testBanner(testName, CLASS_NAME));
927 // Retrieve the contents of a resource to update.
928 LocationAuthorityClient client = new LocationAuthorityClient();
929 ClientResponse<String> res = client.read(knownResourceId);
931 if(logger.isDebugEnabled()){
932 logger.debug(testName + ": read status = " + res.getStatus());
934 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
936 if(logger.isDebugEnabled()){
937 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
939 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
940 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
941 client.getCommonPartName(), LocationauthoritiesCommon.class);
942 Assert.assertNotNull(locationAuthority);
944 // Update the contents of this resource.
945 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
946 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
947 if(logger.isDebugEnabled()){
948 logger.debug("to be updated LocationAuthority");
949 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
952 // Submit the updated resource to the service and store the response.
953 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
954 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
955 commonPart.setLabel(client.getCommonPartName());
956 res.releaseConnection();
957 res = client.update(knownResourceId, output);
958 int statusCode = res.getStatus();
960 // Check the status code of the response: does it match the expected response(s)?
961 if(logger.isDebugEnabled()){
962 logger.debug(testName + ": status = " + statusCode);
964 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
965 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
966 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
968 // Retrieve the updated resource and verify that its contents exist.
969 input = new PoxPayloadIn(res.getEntity());
970 LocationauthoritiesCommon updatedLocationAuthority =
971 (LocationauthoritiesCommon) extractPart(input,
972 client.getCommonPartName(), LocationauthoritiesCommon.class);
973 Assert.assertNotNull(updatedLocationAuthority);
975 // Verify that the updated resource received the correct data.
976 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
977 locationAuthority.getDisplayName(),
978 "Data in updated object did not match submitted data.");
980 res.releaseConnection();
987 * @param testName the test name
988 * @throws Exception the exception
990 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
991 groups = {"update"}, dependsOnMethods = {"update"})
992 public void updateItem(String testName) throws Exception {
994 if (logger.isDebugEnabled()) {
995 logger.debug(testBanner(testName, CLASS_NAME));
1000 // Retrieve the contents of a resource to update.
1001 LocationAuthorityClient client = new LocationAuthorityClient();
1002 ClientResponse<String> res =
1003 client.readItem(knownResourceId, knownItemResourceId);
1005 if(logger.isDebugEnabled()){
1006 logger.debug(testName + ": read status = " + res.getStatus());
1008 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1010 if(logger.isDebugEnabled()){
1011 logger.debug("got Location to update with ID: " +
1012 knownItemResourceId +
1013 " in LocationAuthority: " + knownResourceId );
1015 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1016 LocationsCommon location = (LocationsCommon) extractPart(input,
1017 client.getItemCommonPartName(), LocationsCommon.class);
1018 Assert.assertNotNull(location);
1020 // Update the contents of this resource.
1021 location.setCsid(null);
1022 location.setName("updated-" + location.getName());
1023 if(logger.isDebugEnabled()){
1024 logger.debug("to be updated Location");
1025 logger.debug(objectAsXmlString(location,
1026 LocationsCommon.class));
1029 // Submit the updated resource to the service and store the response.
1030 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1031 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1032 commonPart.setLabel(client.getItemCommonPartName());
1033 res.releaseConnection();
1034 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1035 int statusCode = res.getStatus();
1037 // Check the status code of the response: does it match the expected response(s)?
1038 if(logger.isDebugEnabled()){
1039 logger.debug(testName + ": status = " + statusCode);
1041 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1042 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1043 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1045 // Retrieve the updated resource and verify that its contents exist.
1046 input = new PoxPayloadIn(res.getEntity());
1047 LocationsCommon updatedLocation =
1048 (LocationsCommon) extractPart(input,
1049 client.getItemCommonPartName(), LocationsCommon.class);
1050 Assert.assertNotNull(updatedLocation);
1052 // Verify that the updated resource received the correct data.
1053 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1054 "Data in updated Location did not match submitted data.");
1056 res.releaseConnection();
1061 // Placeholders until the three tests below can be uncommented.
1062 // See Issue CSPACE-401.
1064 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1067 public void updateWithEmptyEntityBody(String testName) throws Exception {
1071 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1074 public void updateWithMalformedXml(String testName) throws Exception {
1078 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1081 public void updateWithWrongXmlSchema(String testName) throws Exception {
1086 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1089 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1090 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1091 public void updateNonExistent(String testName) throws Exception {
1093 if (logger.isDebugEnabled()) {
1094 logger.debug(testBanner(testName, CLASS_NAME));
1097 setupUpdateNonExistent();
1099 // Submit the request to the service and store the response.
1100 // Note: The ID(s) used when creating the request payload may be arbitrary.
1101 // The only relevant ID may be the one used in update(), below.
1102 LocationAuthorityClient client = new LocationAuthorityClient();
1103 String displayName = "displayName-NON_EXISTENT_ID";
1104 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1105 displayName, "nonEx", client.getCommonPartName());
1106 ClientResponse<String> res =
1107 client.update(NON_EXISTENT_ID, multipart);
1109 int statusCode = res.getStatus();
1111 // Check the status code of the response: does it match
1112 // the expected response(s)?
1113 if(logger.isDebugEnabled()){
1114 logger.debug(testName + ": status = " + statusCode);
1116 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1117 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1118 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1120 res.releaseConnection();
1125 * Update non existent item.
1127 * @param testName the test name
1128 * @throws Exception the exception
1130 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1131 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1132 public void updateNonExistentItem(String testName) throws Exception {
1134 if (logger.isDebugEnabled()) {
1135 logger.debug(testBanner(testName, CLASS_NAME));
1138 setupUpdateNonExistent();
1140 // Submit the request to the service and store the response.
1141 // Note: The ID used in this 'create' call may be arbitrary.
1142 // The only relevant ID may be the one used in update(), below.
1143 LocationAuthorityClient client = new LocationAuthorityClient();
1144 Map<String, String> nonexMap = new HashMap<String,String>();
1145 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1146 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1147 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1148 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1149 PoxPayloadOut multipart =
1150 LocationAuthorityClientUtils.createLocationInstance(
1151 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1152 nonexMap, client.getItemCommonPartName() );
1153 ClientResponse<String> res =
1154 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1156 int statusCode = res.getStatus();
1158 // Check the status code of the response: does it match
1159 // the expected response(s)?
1160 if(logger.isDebugEnabled()){
1161 logger.debug(testName + ": status = " + statusCode);
1163 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1164 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1165 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1167 res.releaseConnection();
1171 // ---------------------------------------------------------------
1172 // CRUD tests : DELETE tests
1173 // ---------------------------------------------------------------
1176 // Note: delete sub-resources in ascending hierarchical order,
1177 // before deleting their parents.
1182 * @param testName the test name
1183 * @throws Exception the exception
1185 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1186 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1187 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1188 public void deleteItem(String testName) throws Exception {
1190 if (logger.isDebugEnabled()) {
1191 logger.debug(testBanner(testName, CLASS_NAME));
1196 if(logger.isDebugEnabled()){
1197 logger.debug("parentcsid =" + knownResourceId +
1198 " itemcsid = " + knownItemResourceId);
1201 // Submit the request to the service and store the response.
1202 LocationAuthorityClient client = new LocationAuthorityClient();
1203 ClientResponse<Response> res =
1204 client.deleteItem(knownResourceId, knownItemResourceId);
1206 int statusCode = res.getStatus();
1208 // Check the status code of the response: does it match
1209 // the expected response(s)?
1210 if(logger.isDebugEnabled()){
1211 logger.debug(testName + ": status = " + statusCode);
1213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1217 res.releaseConnection();
1222 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1225 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1226 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1227 public void delete(String testName) throws Exception {
1229 if (logger.isDebugEnabled()) {
1230 logger.debug(testBanner(testName, CLASS_NAME));
1235 if(logger.isDebugEnabled()){
1236 logger.debug("parentcsid =" + knownResourceId);
1239 // Submit the request to the service and store the response.
1240 LocationAuthorityClient client = new LocationAuthorityClient();
1241 ClientResponse<Response> res = client.delete(knownResourceId);
1243 int statusCode = res.getStatus();
1245 // Check the status code of the response: does it match
1246 // the expected response(s)?
1247 if(logger.isDebugEnabled()){
1248 logger.debug(testName + ": status = " + statusCode);
1250 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1251 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1252 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1254 res.releaseConnection();
1260 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1263 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1264 groups = {"delete"}, dependsOnMethods = {"delete"})
1265 public void deleteNonExistent(String testName) throws Exception {
1267 if (logger.isDebugEnabled()) {
1268 logger.debug(testBanner(testName, CLASS_NAME));
1271 setupDeleteNonExistent();
1273 // Submit the request to the service and store the response.
1274 LocationAuthorityClient client = new LocationAuthorityClient();
1275 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1277 int statusCode = res.getStatus();
1279 // Check the status code of the response: does it match
1280 // the expected response(s)?
1281 if(logger.isDebugEnabled()){
1282 logger.debug(testName + ": status = " + statusCode);
1284 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1285 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1286 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1288 res.releaseConnection();
1293 * Delete non existent item.
1295 * @param testName the test name
1297 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1298 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1299 public void deleteNonExistentItem(String testName) {
1301 if (logger.isDebugEnabled()) {
1302 logger.debug(testBanner(testName, CLASS_NAME));
1305 setupDeleteNonExistent();
1307 // Submit the request to the service and store the response.
1308 LocationAuthorityClient client = new LocationAuthorityClient();
1309 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1311 int statusCode = res.getStatus();
1313 // Check the status code of the response: does it match
1314 // the expected response(s)?
1315 if(logger.isDebugEnabled()){
1316 logger.debug(testName + ": status = " + statusCode);
1318 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1319 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1320 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1322 res.releaseConnection();
1326 // ---------------------------------------------------------------
1327 // Utility tests : tests of code used in tests above
1328 // ---------------------------------------------------------------
1330 * Tests the code for manually submitting data that is used by several
1331 * of the methods above.
1333 @Test(dependsOnMethods = {"create", "read"})
1334 public void testSubmitRequest() {
1336 // Expected status code: 200 OK
1337 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1339 // Submit the request to the service and store the response.
1340 String method = ServiceRequestType.READ.httpMethodName();
1341 String url = getResourceURL(knownResourceId);
1342 int statusCode = submitRequest(method, url);
1344 // Check the status code of the response: does it match
1345 // the expected response(s)?
1346 if(logger.isDebugEnabled()){
1347 logger.debug("testSubmitRequest: url=" + url +
1348 " status=" + statusCode);
1350 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1355 * Test item submit request.
1357 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1358 public void testItemSubmitRequest() {
1360 // Expected status code: 200 OK
1361 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1363 // Submit the request to the service and store the response.
1364 String method = ServiceRequestType.READ.httpMethodName();
1365 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1366 int statusCode = submitRequest(method, url);
1368 // Check the status code of the response: does it match
1369 // the expected response(s)?
1370 if(logger.isDebugEnabled()){
1371 logger.debug("testItemSubmitRequest: url=" + url +
1372 " status=" + statusCode);
1374 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1378 // ---------------------------------------------------------------
1379 // Cleanup of resources created during testing
1380 // ---------------------------------------------------------------
1383 * Deletes all resources created by tests, after all tests have been run.
1385 * This cleanup method will always be run, even if one or more tests fail.
1386 * For this reason, it attempts to remove all resources created
1387 * at any point during testing, even if some of those resources
1388 * may be expected to be deleted by certain tests.
1391 @AfterClass(alwaysRun=true)
1392 public void cleanUp() {
1393 String noTest = System.getProperty("noTestCleanup");
1394 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1395 if (logger.isDebugEnabled()) {
1396 logger.debug("Skipping Cleanup phase ...");
1400 if (logger.isDebugEnabled()) {
1401 logger.debug("Cleaning up temporary resources created for testing ...");
1403 String parentResourceId;
1404 String itemResourceId;
1405 // Clean up contact resources.
1406 LocationAuthorityClient client = new LocationAuthorityClient();
1407 parentResourceId = knownResourceId;
1408 // Clean up item resources.
1409 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1410 itemResourceId = entry.getKey();
1411 parentResourceId = entry.getValue();
1412 // Note: Any non-success responses from the delete operation
1413 // below are ignored and not reported.
1414 ClientResponse<Response> res =
1415 client.deleteItem(parentResourceId, itemResourceId);
1416 res.releaseConnection();
1418 // Clean up parent resources.
1419 for (String resourceId : allResourceIdsCreated) {
1420 // Note: Any non-success responses from the delete operation
1421 // below are ignored and not reported.
1422 ClientResponse<Response> res = client.delete(resourceId);
1423 res.releaseConnection();
1427 // ---------------------------------------------------------------
1428 // Utility methods used by tests above
1429 // ---------------------------------------------------------------
1431 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1435 * Returns the root URL for the item service.
1437 * This URL consists of a base URL for all services, followed by
1438 * a path component for the owning parent, followed by the
1439 * path component for the items.
1441 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1442 * parent authority resource of the relevant item resource.
1444 * @return The root URL for the item service.
1446 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1447 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1451 * Returns the URL of a specific item resource managed by a service, and
1452 * designated by an identifier (such as a universally unique ID, or UUID).
1454 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1455 * parent authority resource of the relevant item resource.
1457 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1460 * @return The URL of a specific item resource managed by a service.
1462 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1463 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;