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.HashMap;
26 import java.util.List;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.PersonJAXBSchema;
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.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonauthoritiesCommon;
41 import org.collectionspace.services.person.PersonauthoritiesCommonList;
42 import org.collectionspace.services.person.PersonsCommon;
43 import org.collectionspace.services.person.PersonsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
55 * PersonAuthorityServiceTest, carries out tests against a
56 * deployed and running PersonAuthority Service.
58 * $LastChangedRevision: 753 $
59 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
61 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
64 private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
65 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
67 // Instance variables specific to this test.
68 /** The service path component. */
69 final String SERVICE_PATH_COMPONENT = "personauthorities";
71 /** The item service path component. */
72 final String ITEM_SERVICE_PATH_COMPONENT = "items";
74 /** The contact service path component. */
75 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
77 /** The test forename. */
78 final String TEST_FORE_NAME = "John";
80 /** The test middle name. */
81 final String TEST_MIDDLE_NAME = null;
83 /** The test surname. */
84 final String TEST_SUR_NAME = "Wayne";
86 /** The test birthdate. */
87 final String TEST_BIRTH_DATE = "May 26, 1907";
89 /** The test death date. */
90 final String TEST_DEATH_DATE = "June 11, 1979";
92 // Hold some values for a recently created item to verify upon read.
93 private String knownResourceId = null;
94 private String knownResourceShortIdentifer = null;
95 private String knownResourceRefName = null;
96 private String knownItemResourceId = null;
97 private String knownItemResourceShortIdentifer = null;
99 // The resource ID of an item resource used for partial term matching tests.
100 private String knownItemPartialTermResourceId = null;
102 /** The known contact resource id. */
103 private String knownContactResourceId = null;
105 /** The n items to create in list. */
106 private int nItemsToCreateInList = 3;
108 /** The all item resource ids created. */
109 private Map<String, String> allItemResourceIdsCreated =
110 new HashMap<String, String>();
112 /** The all contact resource ids created. */
113 private Map<String, String> allContactResourceIdsCreated =
114 new HashMap<String, String>();
116 protected void setKnownResource( String id, String shortIdentifer,
118 knownResourceId = id;
119 knownResourceShortIdentifer = shortIdentifer;
120 knownResourceRefName = refName;
123 protected void setKnownItemResource( String id, String shortIdentifer ) {
124 knownItemResourceId = id;
125 knownItemResourceShortIdentifer = shortIdentifer;
130 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
133 protected CollectionSpaceClient getClientInstance() {
134 return new PersonAuthorityClient();
138 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
141 protected AbstractCommonList getAbstractCommonList(
142 ClientResponse<AbstractCommonList> response) {
143 return response.getEntity(PersonsCommonList.class);
146 // ---------------------------------------------------------------
147 // CRUD tests : CREATE tests
148 // ---------------------------------------------------------------
151 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
154 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
156 public void create(String testName) throws Exception {
158 if (logger.isDebugEnabled()) {
159 logger.debug(testBanner(testName, CLASS_NAME));
161 // Perform setup, such as initializing the type of service request
162 // (e.g. CREATE, DELETE), its valid and expected status codes, and
163 // its associated HTTP method name (e.g. POST, DELETE).
166 // Submit the request to the service and store the response.
167 PersonAuthorityClient client = new PersonAuthorityClient();
168 String shortId = createIdentifier();
169 String displayName = "displayName-" + shortId;
170 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
171 MultipartOutput multipart =
172 PersonAuthorityClientUtils.createPersonAuthorityInstance(
173 displayName, shortId, client.getCommonPartName());
176 ClientResponse<Response> res = client.create(multipart);
178 int statusCode = res.getStatus();
180 // Check the status code of the response: does it match
181 // the expected response(s)?
184 // Does it fall within the set of valid status codes?
185 // Does it exactly match the expected status code?
186 if(logger.isDebugEnabled()){
187 logger.debug(testName + ": status = " + statusCode);
189 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
190 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
191 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
193 newID = PersonAuthorityClientUtils.extractId(res);
195 res.releaseConnection();
197 // Save values for additional tests
198 if (knownResourceId == null){
199 setKnownResource( newID, shortId, baseRefName );
200 if (logger.isDebugEnabled()) {
201 logger.debug(testName + ": knownResourceId=" + knownResourceId);
204 // Store the IDs from every resource created by tests,
205 // so they can be deleted after tests have been run.
206 allResourceIdsCreated.add(newID);
212 * @param testName the test name
214 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
215 groups = {"create"}, dependsOnMethods = {"create"})
216 public void createItem(String testName) {
217 if (logger.isDebugEnabled()) {
218 logger.debug(testBanner(testName, CLASS_NAME));
221 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
225 * Creates the item in authority.
227 * @param vcsid the vcsid
228 * @param authRefName the auth ref name
231 private String createItemInAuthority(String vcsid, String authRefName) {
233 final String testName = "createItemInAuthority";
234 if(logger.isDebugEnabled()){
235 logger.debug(testName + ":...");
238 // Submit the request to the service and store the response.
239 PersonAuthorityClient client = new PersonAuthorityClient();
241 Map<String, String> johnWayneMap = new HashMap<String,String>();
243 // Fill the property map
245 String shortId = "johnWayneActor";
246 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
247 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
248 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
250 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
251 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
252 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
253 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
254 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
255 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
256 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
257 "known by his stage name John Wayne, was an American film actor, director " +
258 "and producer. He epitomized rugged masculinity and has become an enduring " +
259 "American icon. He is famous for his distinctive voice, walk and height. " +
260 "He was also known for his conservative political views and his support in " +
261 "the 1950s for anti-communist positions.");
262 MultipartOutput multipart =
263 PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
264 client.getItemCommonPartName() );
267 ClientResponse<Response> res = client.createItem(vcsid, multipart);
269 int statusCode = res.getStatus();
270 // Check the status code of the response: does it match
271 // the expected response(s)?
272 if(logger.isDebugEnabled()){
273 logger.debug(testName + ": status = " + statusCode);
275 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
276 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
277 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
279 newID = PersonAuthorityClientUtils.extractId(res);
281 res.releaseConnection();
284 // Store the ID returned from the first item resource created
285 // for additional tests below.
286 if (knownItemResourceId == null){
287 setKnownItemResource(newID, shortId);
288 if (logger.isDebugEnabled()) {
289 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
293 // Store the IDs from any item resources created
294 // by tests, along with the IDs of their parents, so these items
295 // can be deleted after all tests have been run.
296 allItemResourceIdsCreated.put(newID, vcsid);
302 * Creates the contact.
304 * @param testName the test name
306 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
307 groups = {"create"}, dependsOnMethods = {"createItem"})
308 public void createContact(String testName) {
309 if (logger.isDebugEnabled()) {
310 logger.debug(testBanner(testName, CLASS_NAME));
313 String newID = createContactInItem(knownResourceId, knownItemResourceId);
317 * Creates the contact in item.
319 * @param parentcsid the parentcsid
320 * @param itemcsid the itemcsid
323 private String createContactInItem(String parentcsid, String itemcsid) {
325 final String testName = "createContactInItem";
326 if(logger.isDebugEnabled()){
327 logger.debug(testName + ":...");
332 // Submit the request to the service and store the response.
333 PersonAuthorityClient client = new PersonAuthorityClient();
334 String identifier = createIdentifier();
335 MultipartOutput multipart =
336 ContactClientUtils.createContactInstance(parentcsid,
337 itemcsid, identifier, new ContactClient().getCommonPartName());
340 ClientResponse<Response> res =
341 client.createContact(parentcsid, itemcsid, multipart);
343 int statusCode = res.getStatus();
344 // Check the status code of the response: does it match
345 // the expected response(s)?
346 if(logger.isDebugEnabled()){
347 logger.debug(testName + ": status = " + statusCode);
349 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
350 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
351 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
353 newID = PersonAuthorityClientUtils.extractId(res);
355 res.releaseConnection();
358 // Store the ID returned from the first contact resource created
359 // for additional tests below.
360 if (knownContactResourceId == null){
361 knownContactResourceId = newID;
362 if (logger.isDebugEnabled()) {
363 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
367 // Store the IDs from any contact resources created
368 // by tests, along with the IDs of their parent items,
369 // so these items can be deleted after all tests have been run.
370 allContactResourceIdsCreated.put(newID, itemcsid);
377 // Placeholders until the three tests below can be uncommented.
378 // See Issue CSPACE-401.
380 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
383 public void createWithEmptyEntityBody(String testName) throws Exception {
384 //Should this really be empty?
388 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
391 public void createWithMalformedXml(String testName) throws Exception {
392 //Should this really be empty?
396 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
399 public void createWithWrongXmlSchema(String testName) throws Exception {
400 //Should this really be empty?
405 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
406 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
407 public void createWithEmptyEntityBody(String testName) throws Exception {
409 if (logger.isDebugEnabled()) {
410 logger.debug(testBanner(testName, CLASS_NAME));
413 setupCreateWithEmptyEntityBody();
415 // Submit the request to the service and store the response.
416 String method = REQUEST_TYPE.httpMethodName();
417 String url = getServiceRootURL();
418 String mediaType = MediaType.APPLICATION_XML;
419 final String entity = "";
420 int statusCode = submitRequest(method, url, mediaType, entity);
422 // Check the status code of the response: does it match
423 // the expected response(s)?
424 if(logger.isDebugEnabled()) {
425 logger.debug(testName + ": url=" + url +
426 " status=" + statusCode);
428 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
429 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
430 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
434 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
435 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
436 public void createWithMalformedXml(String testName) throws Exception {
438 if (logger.isDebugEnabled()) {
439 logger.debug(testBanner(testName, CLASS_NAME));
442 setupCreateWithMalformedXml();
444 // Submit the request to the service and store the response.
445 String method = REQUEST_TYPE.httpMethodName();
446 String url = getServiceRootURL();
447 String mediaType = MediaType.APPLICATION_XML;
448 final String entity = MALFORMED_XML_DATA; // Constant from base class.
449 int statusCode = submitRequest(method, url, mediaType, entity);
451 // Check the status code of the response: does it match
452 // the expected response(s)?
453 if(logger.isDebugEnabled()){
454 logger.debug(testName + ": url=" + url +
455 " status=" + statusCode);
457 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
458 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
459 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
463 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
464 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
465 public void createWithWrongXmlSchema(String testName) throws Exception {
467 if (logger.isDebugEnabled()) {
468 logger.debug(testBanner(testName, CLASS_NAME));
471 setupCreateWithWrongXmlSchema();
473 // Submit the request to the service and store the response.
474 String method = REQUEST_TYPE.httpMethodName();
475 String url = getServiceRootURL();
476 String mediaType = MediaType.APPLICATION_XML;
477 final String entity = WRONG_XML_SCHEMA_DATA;
478 int statusCode = submitRequest(method, url, mediaType, entity);
480 // Check the status code of the response: does it match
481 // the expected response(s)?
482 if(logger.isDebugEnabled()){
483 logger.debug(testName + ": url=" + url +
484 " status=" + statusCode);
486 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
487 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
488 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
492 // ---------------------------------------------------------------
493 // CRUD tests : CREATE LIST tests
494 // ---------------------------------------------------------------
497 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
500 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
501 groups = {"createList"}, dependsOnGroups = {"create"})
502 public void createList(String testName) throws Exception {
503 if (logger.isDebugEnabled()) {
504 logger.debug(testBanner(testName, CLASS_NAME));
506 for (int i = 0; i < nItemsToCreateInList; i++) {
512 * Creates the item list.
514 * @param testName the test name
515 * @throws Exception the exception
517 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
518 groups = {"createList"}, dependsOnMethods = {"createList"})
519 public void createItemList(String testName) throws Exception {
520 if (logger.isDebugEnabled()) {
521 logger.debug(testBanner(testName, CLASS_NAME));
523 // Add items to the initially-created, known parent record.
524 for (int j = 0; j < nItemsToCreateInList; j++) {
525 createItem(testName);
530 * Creates the contact list.
532 * @param testName the test name
533 * @throws Exception the exception
535 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
536 groups = {"createList"}, dependsOnMethods = {"createItemList"})
537 public void createContactList(String testName) throws Exception {
538 // Add contacts to the initially-created, known item record.
539 for (int j = 0; j < nItemsToCreateInList; j++) {
540 createContact(testName);
544 // ---------------------------------------------------------------
545 // CRUD tests : READ tests
546 // ---------------------------------------------------------------
549 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
552 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
553 groups = {"read"}, dependsOnGroups = {"create"})
554 public void read(String testName) throws Exception {
555 readInternal(testName, knownResourceId, null);
561 * @param testName the test name
562 * @throws Exception the exception
564 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
565 groups = {"read"}, dependsOnGroups = {"create"})
566 public void readByName(String testName) throws Exception {
567 readInternal(testName, null, knownResourceShortIdentifer);
570 protected void readInternal(String testName, String CSID, String shortId) {
571 if (logger.isDebugEnabled()) {
572 logger.debug(testBanner(testName, CLASS_NAME));
577 // Submit the request to the service and store the response.
578 PersonAuthorityClient client = new PersonAuthorityClient();
579 ClientResponse<MultipartInput> res = null;
581 res = client.read(CSID);
582 } else if(shortId!=null) {
583 res = client.readByName(shortId);
585 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
588 int statusCode = res.getStatus();
589 // Check the status code of the response: does it match
590 // the expected response(s)?
591 if(logger.isDebugEnabled()){
592 logger.debug(testName + ": status = " + statusCode);
594 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
595 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
596 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
597 //FIXME: remove the following try catch once Aron fixes signatures
599 MultipartInput input = (MultipartInput) res.getEntity();
600 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
601 client.getCommonPartName(), PersonauthoritiesCommon.class);
602 Assert.assertNotNull(personAuthority);
603 } catch (Exception e) {
604 throw new RuntimeException(e);
607 res.releaseConnection();
614 * @param testName the test name
615 * @throws Exception the exception
617 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
618 groups = {"readItem"}, dependsOnGroups = {"read"})
619 public void readItem(String testName) throws Exception {
620 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
624 * Read item in Named Auth.
626 * @param testName the test name
627 * @throws Exception the exception
629 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
630 groups = {"readItem"}, dependsOnGroups = {"read"})
631 public void readItemInNamedAuth(String testName) throws Exception {
632 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
638 * @param testName the test name
639 * @throws Exception the exception
641 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
642 groups = {"readItem"}, dependsOnGroups = {"read"})
643 public void readNamedItem(String testName) throws Exception {
644 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
648 * Read Named item in Named Auth.
650 * @param testName the test name
651 * @throws Exception the exception
653 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
654 groups = {"readItem"}, dependsOnGroups = {"read"})
655 public void readNamedItemInNamedAuth(String testName) throws Exception {
656 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
659 protected void readItemInternal(String testName,
660 String authCSID, String authShortId, String itemCSID, String itemShortId)
663 if (logger.isDebugEnabled()) {
664 logger.debug(testBanner(testName, CLASS_NAME));
669 // Submit the request to the service and store the response.
670 PersonAuthorityClient client = new PersonAuthorityClient();
671 ClientResponse<MultipartInput> res = null;
674 res = client.readItem(authCSID, itemCSID);
675 } else if(itemShortId!=null) {
676 res = client.readNamedItem(authCSID, itemShortId);
678 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
680 } else if(authShortId!=null) {
682 res = client.readItemInNamedAuthority(authShortId, itemCSID);
683 } else if(itemShortId!=null) {
684 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
686 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
689 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
692 int statusCode = res.getStatus();
694 // Check the status code of the response: does it match
695 // the expected response(s)?
696 if(logger.isDebugEnabled()){
697 logger.debug(testName + ": status = " + statusCode);
699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
703 // Check whether we've received a person.
704 MultipartInput input = (MultipartInput) res.getEntity();
705 PersonsCommon person = (PersonsCommon) extractPart(input,
706 client.getItemCommonPartName(), PersonsCommon.class);
707 Assert.assertNotNull(person);
708 boolean showFull = true;
709 if(showFull && logger.isDebugEnabled()){
710 logger.debug(testName + ": returned payload:");
711 logger.debug(objectAsXmlString(person, PersonsCommon.class));
713 Assert.assertEquals(person.getInAuthority(), knownResourceId);
715 res.releaseConnection();
720 * Verify item display name.
722 * @param testName the test name
723 * @throws Exception the exception
725 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726 dependsOnMethods = {"readItem", "updateItem"})
727 public void verifyItemDisplayName(String testName) throws Exception {
729 if (logger.isDebugEnabled()) {
730 logger.debug(testBanner(testName, CLASS_NAME));
735 // Submit the request to the service and store the response.
736 PersonAuthorityClient client = new PersonAuthorityClient();
737 MultipartInput input =null;
738 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
740 int statusCode = res.getStatus();
742 // Check the status code of the response: does it match
743 // the expected response(s)?
744 if(logger.isDebugEnabled()){
745 logger.debug(testName + ": status = " + statusCode);
747 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
748 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
749 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
751 // Check whether person has expected displayName.
752 input = (MultipartInput) res.getEntity();
754 res.releaseConnection();
757 PersonsCommon person = (PersonsCommon) extractPart(input,
758 client.getItemCommonPartName(), PersonsCommon.class);
759 Assert.assertNotNull(person);
760 String displayName = person.getDisplayName();
761 // Make sure displayName matches computed form
762 String expectedDisplayName =
763 PersonAuthorityClientUtils.prepareDefaultDisplayName(
764 TEST_FORE_NAME, null, TEST_SUR_NAME,
765 TEST_BIRTH_DATE, TEST_DEATH_DATE);
766 Assert.assertNotNull(displayName, expectedDisplayName);
768 // Update the shortName and verify the computed name is updated.
769 person.setCsid(null);
770 person.setDisplayNameComputed(true);
771 person.setForeName("updated-" + TEST_FORE_NAME);
772 expectedDisplayName =
773 PersonAuthorityClientUtils.prepareDefaultDisplayName(
774 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
775 TEST_BIRTH_DATE, TEST_DEATH_DATE);
777 // Submit the updated resource to the service and store the response.
778 MultipartOutput output = new MultipartOutput();
779 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
780 commonPart.getHeaders().add("label", client.getItemCommonPartName());
781 res = client.updateItem(knownResourceId, knownItemResourceId, output);
783 int statusCode = res.getStatus();
785 // Check the status code of the response: does it match the expected response(s)?
786 if(logger.isDebugEnabled()){
787 logger.debug("updateItem: status = " + statusCode);
789 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
790 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
791 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
793 // Retrieve the updated resource and verify that its contents exist.
794 input = (MultipartInput) res.getEntity();
796 res.releaseConnection();
799 PersonsCommon updatedPerson =
800 (PersonsCommon) extractPart(input,
801 client.getItemCommonPartName(), PersonsCommon.class);
802 Assert.assertNotNull(updatedPerson);
804 // Verify that the updated resource received the correct data.
805 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
806 "Updated ForeName in Person did not match submitted data.");
807 // Verify that the updated resource computes the right displayName.
808 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
809 "Updated ForeName in Person not reflected in computed DisplayName.");
811 // Now Update the displayName, not computed and verify the computed name is overriden.
812 person.setDisplayNameComputed(false);
813 expectedDisplayName = "TestName";
814 person.setDisplayName(expectedDisplayName);
816 // Submit the updated resource to the service and store the response.
817 output = new MultipartOutput();
818 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
819 commonPart.getHeaders().add("label", client.getItemCommonPartName());
820 res = client.updateItem(knownResourceId, knownItemResourceId, output);
822 int statusCode = res.getStatus();
824 // Check the status code of the response: does it match the expected response(s)?
825 if(logger.isDebugEnabled()){
826 logger.debug("updateItem: status = " + statusCode);
828 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
829 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
830 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
832 // Retrieve the updated resource and verify that its contents exist.
833 input = (MultipartInput) res.getEntity();
835 res.releaseConnection();
839 (PersonsCommon) extractPart(input,
840 client.getItemCommonPartName(), PersonsCommon.class);
841 Assert.assertNotNull(updatedPerson);
843 // Verify that the updated resource received the correct data.
844 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
845 "Updated displayNameComputed in Person did not match submitted data.");
846 // Verify that the updated resource computes the right displayName.
847 Assert.assertEquals(updatedPerson.getDisplayName(),
849 "Updated DisplayName (not computed) in Person not stored.");
853 * Verify illegal item display name.
855 * @param testName the test name
856 * @throws Exception the exception
858 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
859 dependsOnMethods = {"verifyItemDisplayName"})
860 public void verifyIllegalItemDisplayName(String testName) throws Exception {
862 if (logger.isDebugEnabled()) {
863 logger.debug(testBanner(testName, CLASS_NAME));
866 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
867 // setupUpdateWithWrongXmlSchema(testName);
869 // Submit the request to the service and store the response.
870 PersonAuthorityClient client = new PersonAuthorityClient();
871 MultipartInput input = null;
872 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
874 int statusCode = res.getStatus();
876 // Check the status code of the response: does it match
877 // the expected response(s)?
878 if(logger.isDebugEnabled()){
879 logger.debug(testName + ": status = " + statusCode);
881 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
882 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
883 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
885 // Check whether Person has expected displayName.
886 input = (MultipartInput) res.getEntity();
888 res.releaseConnection();
891 PersonsCommon person = (PersonsCommon) extractPart(input,
892 client.getItemCommonPartName(), PersonsCommon.class);
893 Assert.assertNotNull(person);
894 // Try to Update with computed false and no displayName
895 person.setDisplayNameComputed(false);
896 person.setDisplayName(null);
898 // Submit the updated resource to the service and store the response.
899 MultipartOutput output = new MultipartOutput();
900 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
901 commonPart.getHeaders().add("label", client.getItemCommonPartName());
902 res = client.updateItem(knownResourceId, knownItemResourceId, output);
904 int statusCode = res.getStatus();
906 // Check the status code of the response: does it match the expected response(s)?
907 if(logger.isDebugEnabled()){
908 logger.debug("updateItem: status = " + statusCode);
910 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
911 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
912 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
914 res.releaseConnection();
921 * @param testName the test name
922 * @throws Exception the exception
924 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
925 groups = {"readItem"}, dependsOnMethods = {"readItem"})
926 public void readContact(String testName) throws Exception {
928 if (logger.isDebugEnabled()) {
929 logger.debug(testBanner(testName, CLASS_NAME));
934 // Submit the request to the service and store the response.
935 PersonAuthorityClient client = new PersonAuthorityClient();
936 MultipartInput input = null;
937 ClientResponse<MultipartInput> res =
938 client.readContact(knownResourceId, knownItemResourceId,
939 knownContactResourceId);
941 int statusCode = res.getStatus();
943 // Check the status code of the response: does it match
944 // the expected response(s)?
945 if(logger.isDebugEnabled()){
946 logger.debug(testName + ": status = " + statusCode);
948 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
949 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
950 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
952 // Check whether we've received a contact.
953 input = (MultipartInput) res.getEntity();
955 res.releaseConnection();
958 ContactsCommon contact = (ContactsCommon) extractPart(input,
959 new ContactClient().getCommonPartName(), ContactsCommon.class);
960 Assert.assertNotNull(contact);
961 boolean showFull = true;
962 if(showFull && logger.isDebugEnabled()){
963 logger.debug(testName + ": returned payload:");
964 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
966 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
967 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
973 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
976 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
977 groups = {"read"}, dependsOnMethods = {"read"})
978 public void readNonExistent(String testName) {
980 if (logger.isDebugEnabled()) {
981 logger.debug(testBanner(testName, CLASS_NAME));
984 setupReadNonExistent();
986 // Submit the request to the service and store the response.
987 PersonAuthorityClient client = new PersonAuthorityClient();
988 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
990 int statusCode = res.getStatus();
991 // Check the status code of the response: does it match
992 // the expected response(s)?
993 if(logger.isDebugEnabled()){
994 logger.debug(testName + ": status = " + statusCode);
996 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
997 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
998 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1000 res.releaseConnection();
1005 * Read item non existent.
1007 * @param testName the test name
1009 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1010 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1011 public void readItemNonExistent(String testName) {
1013 if (logger.isDebugEnabled()) {
1014 logger.debug(testBanner(testName, CLASS_NAME));
1017 setupReadNonExistent();
1019 // Submit the request to the service and store the response.
1020 PersonAuthorityClient client = new PersonAuthorityClient();
1021 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1023 int statusCode = res.getStatus();
1025 // Check the status code of the response: does it match
1026 // the expected response(s)?
1027 if(logger.isDebugEnabled()){
1028 logger.debug(testName + ": status = " + statusCode);
1030 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1031 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1032 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1034 res.releaseConnection();
1039 * Read contact non existent.
1041 * @param testName the test name
1043 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1044 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1045 public void readContactNonExistent(String testName) {
1047 if (logger.isDebugEnabled()) {
1048 logger.debug(testBanner(testName, CLASS_NAME));
1051 setupReadNonExistent();
1053 // Submit the request to the service and store the response.
1054 PersonAuthorityClient client = new PersonAuthorityClient();
1055 ClientResponse<MultipartInput> res =
1056 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1058 int statusCode = res.getStatus();
1060 // Check the status code of the response: does it match
1061 // the expected response(s)?
1062 if(logger.isDebugEnabled()){
1063 logger.debug(testName + ": status = " + statusCode);
1065 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1066 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1067 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1069 res.releaseConnection();
1073 // ---------------------------------------------------------------
1074 // CRUD tests : READ_LIST tests
1075 // ---------------------------------------------------------------
1079 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1082 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1083 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1084 public void readList(String testName) throws Exception {
1086 if (logger.isDebugEnabled()) {
1087 logger.debug(testBanner(testName, CLASS_NAME));
1092 // Submit the request to the service and store the response.
1093 PersonAuthorityClient client = new PersonAuthorityClient();
1094 PersonauthoritiesCommonList list = null;
1095 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1097 int statusCode = res.getStatus();
1099 // Check the status code of the response: does it match
1100 // the expected response(s)?
1101 if(logger.isDebugEnabled()){
1102 logger.debug(testName + ": status = " + statusCode);
1104 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1105 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1106 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1108 list = res.getEntity();
1110 res.releaseConnection();
1113 // Optionally output additional data about list members for debugging.
1114 boolean iterateThroughList = false;
1115 if (iterateThroughList && logger.isDebugEnabled()) {
1116 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1117 list.getPersonauthorityListItem();
1119 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1120 String csid = item.getCsid();
1121 logger.debug(testName + ": list-item[" + i + "] csid=" +
1123 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1124 item.getDisplayName());
1125 logger.debug(testName + ": list-item[" + i + "] URI=" +
1127 readItemList(csid, null, testName);
1136 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1137 groups = {"readList"}, dependsOnMethods = {"readList"})
1138 public void readItemList(String testName) {
1139 readItemList(knownResourceId, null, testName);
1143 * Read item list by authority name.
1145 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1146 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1147 public void readItemListByAuthorityName(String testName) {
1148 readItemList(null, knownResourceShortIdentifer, testName);
1154 * @param vcsid the vcsid
1155 * @param name the name
1157 private void readItemList(String vcsid, String name, String testName) {
1162 // Submit the request to the service and store the response.
1163 PersonAuthorityClient client = new PersonAuthorityClient();
1164 ClientResponse<PersonsCommonList> res = null;
1166 res = client.readItemList(vcsid, null, null);
1167 } else if (name!= null) {
1168 res = client.readItemListForNamedAuthority(name, null, null);
1170 Assert.fail("readItemList passed null csid and name!");
1172 PersonsCommonList list = null;
1174 int statusCode = res.getStatus();
1176 // Check the status code of the response: does it match
1177 // the expected response(s)?
1178 if(logger.isDebugEnabled()){
1179 logger.debug(testName + ": status = " + statusCode);
1181 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1182 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1183 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1185 list = res.getEntity();
1187 res.releaseConnection();
1190 List<PersonsCommonList.PersonListItem> items =
1191 list.getPersonListItem();
1192 int nItemsReturned = items.size();
1193 // There will be one item created, associated with a
1194 // known parent resource, by the createItem test.
1196 // In addition, there will be 'nItemsToCreateInList'
1197 // additional items created by the createItemList test,
1198 // all associated with the same parent resource.
1199 int nExpectedItems = nItemsToCreateInList + 1;
1200 if(logger.isDebugEnabled()){
1201 logger.debug(testName + ": Expected "
1202 + nExpectedItems +" items; got: "+nItemsReturned);
1204 Assert.assertEquals(nItemsReturned, nExpectedItems);
1207 for (PersonsCommonList.PersonListItem item : items) {
1208 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1209 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1210 // Optionally output additional data about list members for debugging.
1211 boolean showDetails = true;
1212 if (showDetails && logger.isDebugEnabled()) {
1213 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1215 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1217 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1218 item.getDisplayName());
1219 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1227 * Read contact list.
1229 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1230 public void readContactList() {
1231 readContactList(knownResourceId, knownItemResourceId);
1235 * Read contact list.
1237 * @param parentcsid the parentcsid
1238 * @param itemcsid the itemcsid
1240 private void readContactList(String parentcsid, String itemcsid) {
1241 final String testName = "readContactList";
1246 // Submit the request to the service and store the response.
1247 PersonAuthorityClient client = new PersonAuthorityClient();
1248 ContactsCommonList list = null;
1249 ClientResponse<ContactsCommonList> res =
1250 client.readContactList(parentcsid, itemcsid);
1252 int statusCode = res.getStatus();
1254 // Check the status code of the response: does it match
1255 // the expected response(s)?
1256 if(logger.isDebugEnabled()){
1257 logger.debug(testName + ": status = " + statusCode);
1259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1263 list = res.getEntity();
1265 res.releaseConnection();
1268 List<ContactsCommonList.ContactListItem> listitems =
1269 list.getContactListItem();
1270 int nItemsReturned = listitems.size();
1271 // There will be one item created, associated with a
1272 // known parent resource, by the createItem test.
1274 // In addition, there will be 'nItemsToCreateInList'
1275 // additional items created by the createItemList test,
1276 // all associated with the same parent resource.
1277 int nExpectedItems = nItemsToCreateInList + 1;
1278 if(logger.isDebugEnabled()){
1279 logger.debug(testName + ": Expected "
1280 + nExpectedItems +" items; got: "+nItemsReturned);
1282 Assert.assertEquals(nItemsReturned, nExpectedItems);
1285 for (ContactsCommonList.ContactListItem listitem : listitems) {
1286 // Optionally output additional data about list members for debugging.
1287 boolean showDetails = false;
1288 if (showDetails && logger.isDebugEnabled()) {
1289 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1290 listitem.getCsid());
1291 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1292 listitem.getAddressPlace());
1293 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1302 // There are no failure outcome tests at present.
1304 // ---------------------------------------------------------------
1305 // CRUD tests : UPDATE tests
1306 // ---------------------------------------------------------------
1309 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1312 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1313 groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1314 public void update(String testName) throws Exception {
1316 if (logger.isDebugEnabled()) {
1317 logger.debug(testBanner(testName, CLASS_NAME));
1322 // Retrieve the contents of a resource to update.
1323 PersonAuthorityClient client = new PersonAuthorityClient();
1324 MultipartInput input = null;
1325 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1327 if(logger.isDebugEnabled()){
1328 logger.debug(testName + ": read status = " + res.getStatus());
1330 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1332 if(logger.isDebugEnabled()){
1333 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1335 input = res.getEntity();
1337 res.releaseConnection();
1340 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1341 client.getCommonPartName(), PersonauthoritiesCommon.class);
1342 Assert.assertNotNull(personAuthority);
1344 // Update the contents of this resource.
1345 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1346 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1347 if(logger.isDebugEnabled()){
1348 logger.debug("to be updated PersonAuthority");
1349 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1352 // Submit the updated resource to the service and store the response.
1353 MultipartOutput output = new MultipartOutput();
1354 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1355 commonPart.getHeaders().add("label", client.getCommonPartName());
1356 res = client.update(knownResourceId, output);
1358 int statusCode = res.getStatus();
1360 // Check the status code of the response: does it match the expected response(s)?
1361 if(logger.isDebugEnabled()){
1362 logger.debug(testName + ": status = " + statusCode);
1364 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1365 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1366 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1368 // Retrieve the updated resource and verify that its contents exist.
1369 input = (MultipartInput) res.getEntity();
1371 res.releaseConnection();
1374 PersonauthoritiesCommon updatedPersonAuthority =
1375 (PersonauthoritiesCommon) extractPart(input,
1376 client.getCommonPartName(), PersonauthoritiesCommon.class);
1377 Assert.assertNotNull(updatedPersonAuthority);
1379 // Verify that the updated resource received the correct data.
1380 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1381 personAuthority.getDisplayName(),
1382 "Data in updated object did not match submitted data.");
1388 * @param testName the test name
1389 * @throws Exception the exception
1391 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1392 groups = {"update"}, dependsOnMethods = {"update"})
1393 public void updateItem(String testName) throws Exception {
1395 if (logger.isDebugEnabled()) {
1396 logger.debug(testBanner(testName, CLASS_NAME));
1401 // Retrieve the contents of a resource to update.
1402 PersonAuthorityClient client = new PersonAuthorityClient();
1403 MultipartInput input = null;
1404 ClientResponse<MultipartInput> res =
1405 client.readItem(knownResourceId, knownItemResourceId);
1407 if(logger.isDebugEnabled()){
1408 logger.debug(testName + ": read status = " + res.getStatus());
1410 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1412 if(logger.isDebugEnabled()){
1413 logger.debug("got Person to update with ID: " +
1414 knownItemResourceId +
1415 " in PersonAuthority: " + knownResourceId );
1417 input = res.getEntity();
1419 res.releaseConnection();
1422 PersonsCommon person = (PersonsCommon) extractPart(input,
1423 client.getItemCommonPartName(), PersonsCommon.class);
1424 Assert.assertNotNull(person);
1426 if (logger.isDebugEnabled() == true) {
1427 logger.debug("About to update the following person...");
1428 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1431 // Update the contents of this resource.
1432 person.setCsid(null);
1433 person.setForeName("updated-" + person.getForeName());
1434 if(logger.isDebugEnabled()){
1435 logger.debug("to be updated Person");
1436 logger.debug(objectAsXmlString(person,
1437 PersonsCommon.class));
1440 // Submit the updated resource to the service and store the response.
1441 MultipartOutput output = new MultipartOutput();
1442 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1443 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1444 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1446 int statusCode = res.getStatus();
1448 // Check the status code of the response: does it match the expected response(s)?
1449 if(logger.isDebugEnabled()){
1450 logger.debug(testName + ": status = " + statusCode);
1452 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1453 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1454 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1456 // Retrieve the updated resource and verify that its contents exist.
1457 input = (MultipartInput) res.getEntity();
1459 res.releaseConnection();
1462 PersonsCommon updatedPerson =
1463 (PersonsCommon) extractPart(input,
1464 client.getItemCommonPartName(), PersonsCommon.class);
1465 Assert.assertNotNull(updatedPerson);
1467 if (logger.isDebugEnabled() == true) {
1468 logger.debug("Updated to following person to:");
1469 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1472 // Verify that the updated resource received the correct data.
1473 Assert.assertEquals(updatedPerson.getForeName(),
1474 person.getForeName(),
1475 "Data in updated Person did not match submitted data.");
1481 * @param testName the test name
1482 * @throws Exception the exception
1484 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1485 groups = {"update"}, dependsOnMethods = {"updateItem"})
1486 public void updateContact(String testName) throws Exception {
1488 if (logger.isDebugEnabled()) {
1489 logger.debug(testBanner(testName, CLASS_NAME));
1494 // Retrieve the contents of a resource to update.
1495 PersonAuthorityClient client = new PersonAuthorityClient();
1496 MultipartInput input = null;
1497 ClientResponse<MultipartInput> res =
1498 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1500 if(logger.isDebugEnabled()){
1501 logger.debug(testName + ": read status = " + res.getStatus());
1503 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1505 if(logger.isDebugEnabled()){
1506 logger.debug("got Contact to update with ID: " +
1507 knownContactResourceId +
1508 " in item: " + knownItemResourceId +
1509 " in parent: " + knownResourceId );
1511 input = res.getEntity();
1513 res.releaseConnection();
1516 ContactsCommon contact = (ContactsCommon) extractPart(input,
1517 new ContactClient().getCommonPartName(), ContactsCommon.class);
1518 Assert.assertNotNull(contact);
1520 // Update the contents of this resource.
1521 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1522 if(logger.isDebugEnabled()){
1523 logger.debug("to be updated Contact");
1524 logger.debug(objectAsXmlString(contact,
1525 ContactsCommon.class));
1528 // Submit the updated resource to the service and store the response.
1529 MultipartOutput output = new MultipartOutput();
1530 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1531 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1532 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1534 int statusCode = res.getStatus();
1536 // Check the status code of the response: does it match the expected response(s)?
1537 if(logger.isDebugEnabled()){
1538 logger.debug(testName + ": status = " + statusCode);
1540 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1541 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1542 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1544 // Retrieve the updated resource and verify that its contents exist.
1545 input = (MultipartInput) res.getEntity();
1547 res.releaseConnection();
1549 ContactsCommon updatedContact =
1550 (ContactsCommon) extractPart(input,
1551 new ContactClient().getCommonPartName(), ContactsCommon.class);
1552 Assert.assertNotNull(updatedContact);
1554 // Verify that the updated resource received the correct data.
1555 Assert.assertEquals(updatedContact.getAddressPlace(),
1556 contact.getAddressPlace(),
1557 "Data in updated Contact did not match submitted data.");
1561 // Placeholders until the three tests below can be uncommented.
1562 // See Issue CSPACE-401.
1564 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1567 public void updateWithEmptyEntityBody(String testName) throws Exception {
1568 //Should this really be empty?
1572 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1575 public void updateWithMalformedXml(String testName) throws Exception {
1576 //Should this really be empty?
1580 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1583 public void updateWithWrongXmlSchema(String testName) throws Exception {
1584 //Should this really be empty?
1589 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1590 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1591 public void updateWithEmptyEntityBody(String testName) throws Exception {
1593 if (logger.isDebugEnabled()) {
1594 logger.debug(testBanner(testName, CLASS_NAME));
1597 setupUpdateWithEmptyEntityBody(testName, logger);
1599 // Submit the request to the service and store the response.
1600 String method = REQUEST_TYPE.httpMethodName();
1601 String url = getResourceURL(knownResourceId);
1602 String mediaType = MediaType.APPLICATION_XML;
1603 final String entity = "";
1604 int statusCode = submitRequest(method, url, mediaType, entity);
1606 // Check the status code of the response: does it match
1607 // the expected response(s)?
1608 if(logger.isDebugEnabled()){
1609 logger.debug(testName + ": url=" + url +
1610 " status=" + statusCode);
1612 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1613 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1614 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1618 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1619 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1620 public void updateWithMalformedXml(String testName) throws Exception {
1622 if (logger.isDebugEnabled()) {
1623 logger.debug(testBanner(testName, CLASS_NAME));
1626 setupUpdateWithMalformedXml();
1628 // Submit the request to the service and store the response.
1629 String method = REQUEST_TYPE.httpMethodName();
1630 String url = getResourceURL(knownResourceId);
1631 String mediaType = MediaType.APPLICATION_XML;
1632 final String entity = MALFORMED_XML_DATA;
1633 int statusCode = submitRequest(method, url, mediaType, entity);
1635 // Check the status code of the response: does it match
1636 // the expected response(s)?
1637 if(logger.isDebugEnabled()){
1638 logger.debug(testName + ": url=" + url +
1639 " status=" + statusCode);
1641 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1642 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1643 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1647 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1648 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1649 public void updateWithWrongXmlSchema(String testName) throws Exception {
1651 if (logger.isDebugEnabled()) {
1652 logger.debug(testBanner(testName, CLASS_NAME));
1655 setupUpdateWithWrongXmlSchema();
1657 // Submit the request to the service and store the response.
1658 String method = REQUEST_TYPE.httpMethodName();
1659 String url = getResourceURL(knownResourceId);
1660 String mediaType = MediaType.APPLICATION_XML;
1661 final String entity = WRONG_XML_SCHEMA_DATA;
1662 int statusCode = submitRequest(method, url, mediaType, entity);
1664 // Check the status code of the response: does it match
1665 // the expected response(s)?
1666 if(logger.isDebugEnabled()){
1667 logger.debug("updateWithWrongXmlSchema: url=" + url +
1668 " status=" + statusCode);
1670 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1671 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1672 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1677 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1680 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1681 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1682 public void updateNonExistent(String testName) throws Exception {
1684 if (logger.isDebugEnabled()) {
1685 logger.debug(testBanner(testName, CLASS_NAME));
1688 setupUpdateNonExistent();
1690 // Submit the request to the service and store the response.
1691 // Note: The ID(s) used when creating the request payload may be arbitrary.
1692 // The only relevant ID may be the one used in update(), below.
1693 PersonAuthorityClient client = new PersonAuthorityClient();
1694 String displayName = "displayName-NON_EXISTENT_ID";
1695 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1696 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1697 ClientResponse<MultipartInput> res =
1698 client.update(NON_EXISTENT_ID, multipart);
1700 int statusCode = res.getStatus();
1702 // Check the status code of the response: does it match
1703 // the expected response(s)?
1704 if(logger.isDebugEnabled()){
1705 logger.debug(testName + ": status = " + statusCode);
1707 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1708 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1709 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1711 res.releaseConnection();
1716 * Update non existent item.
1718 * @param testName the test name
1719 * @throws Exception the exception
1721 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1722 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1723 public void updateNonExistentItem(String testName) throws Exception {
1725 if (logger.isDebugEnabled()) {
1726 logger.debug(testBanner(testName, CLASS_NAME));
1729 setupUpdateNonExistent();
1731 // Submit the request to the service and store the response.
1732 // Note: The ID used in this 'create' call may be arbitrary.
1733 // The only relevant ID may be the one used in update(), below.
1734 PersonAuthorityClient client = new PersonAuthorityClient();
1735 Map<String, String> nonexMap = new HashMap<String,String>();
1736 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1737 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1738 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1739 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1740 MultipartOutput multipart =
1741 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1742 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1743 nonexMap, client.getItemCommonPartName() );
1744 ClientResponse<MultipartInput> res =
1745 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1747 int statusCode = res.getStatus();
1749 // Check the status code of the response: does it match
1750 // the expected response(s)?
1751 if(logger.isDebugEnabled()){
1752 logger.debug(testName + ": status = " + statusCode);
1754 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1755 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1756 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1758 res.releaseConnection();
1763 * Update non existent contact.
1765 * @param testName the test name
1766 * @throws Exception the exception
1768 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1769 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1770 public void updateNonExistentContact(String testName) throws Exception {
1771 // Currently a no-op test
1774 // ---------------------------------------------------------------
1775 // CRUD tests : DELETE tests
1776 // ---------------------------------------------------------------
1779 // Note: delete sub-resources in ascending hierarchical order,
1780 // before deleting their parents.
1785 * @param testName the test name
1786 * @throws Exception the exception
1788 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1789 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1790 public void deleteContact(String testName) throws Exception {
1792 if (logger.isDebugEnabled()) {
1793 logger.debug(testBanner(testName, CLASS_NAME));
1798 if(logger.isDebugEnabled()){
1799 logger.debug("parentcsid =" + knownResourceId +
1800 " itemcsid = " + knownItemResourceId +
1801 " csid = " + knownContactResourceId);
1804 // Submit the request to the service and store the response.
1805 PersonAuthorityClient client = new PersonAuthorityClient();
1806 ClientResponse<Response> res =
1807 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1809 int statusCode = res.getStatus();
1811 // Check the status code of the response: does it match
1812 // the expected response(s)?
1813 if(logger.isDebugEnabled()){
1814 logger.debug(testName + ": status = " + statusCode);
1816 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1817 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1818 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1820 res.releaseConnection();
1827 * @param testName the test name
1828 * @throws Exception the exception
1830 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1831 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1832 public void deleteItem(String testName) throws Exception {
1834 if (logger.isDebugEnabled()) {
1835 logger.debug(testBanner(testName, CLASS_NAME));
1840 if(logger.isDebugEnabled()){
1841 logger.debug("parentcsid =" + knownResourceId +
1842 " itemcsid = " + knownItemResourceId);
1845 // Submit the request to the service and store the response.
1846 PersonAuthorityClient client = new PersonAuthorityClient();
1847 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1849 int statusCode = res.getStatus();
1851 // Check the status code of the response: does it match
1852 // the expected response(s)?
1853 if(logger.isDebugEnabled()){
1854 logger.debug(testName + ": status = " + statusCode);
1856 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1857 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1858 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1860 res.releaseConnection();
1865 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1868 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1869 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1870 public void delete(String testName) throws Exception {
1872 if (logger.isDebugEnabled()) {
1873 logger.debug(testBanner(testName, CLASS_NAME));
1878 if(logger.isDebugEnabled()){
1879 logger.debug("parentcsid =" + knownResourceId);
1882 // Submit the request to the service and store the response.
1883 PersonAuthorityClient client = new PersonAuthorityClient();
1884 ClientResponse<Response> res = client.delete(knownResourceId);
1886 int statusCode = res.getStatus();
1888 // Check the status code of the response: does it match
1889 // the expected response(s)?
1890 if(logger.isDebugEnabled()){
1891 logger.debug(testName + ": status = " + statusCode);
1893 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1894 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1895 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1897 res.releaseConnection();
1903 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1906 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1907 groups = {"delete"}, dependsOnMethods = {"delete"})
1908 public void deleteNonExistent(String testName) throws Exception {
1910 if (logger.isDebugEnabled()) {
1911 logger.debug(testBanner(testName, CLASS_NAME));
1914 setupDeleteNonExistent();
1916 // Submit the request to the service and store the response.
1917 PersonAuthorityClient client = new PersonAuthorityClient();
1918 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1920 int statusCode = res.getStatus();
1922 // Check the status code of the response: does it match
1923 // the expected response(s)?
1924 if(logger.isDebugEnabled()){
1925 logger.debug(testName + ": status = " + statusCode);
1927 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1928 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1929 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1931 res.releaseConnection();
1936 * Delete non existent item.
1938 * @param testName the test name
1940 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1941 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1942 public void deleteNonExistentItem(String testName) {
1944 if (logger.isDebugEnabled()) {
1945 logger.debug(testBanner(testName, CLASS_NAME));
1948 setupDeleteNonExistent();
1950 // Submit the request to the service and store the response.
1951 PersonAuthorityClient client = new PersonAuthorityClient();
1952 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1954 int statusCode = res.getStatus();
1956 // Check the status code of the response: does it match
1957 // the expected response(s)?
1958 if(logger.isDebugEnabled()){
1959 logger.debug(testName + ": status = " + statusCode);
1961 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1962 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1963 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1965 res.releaseConnection();
1970 * Delete non existent contact.
1972 * @param testName the test name
1974 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1975 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1976 public void deleteNonExistentContact(String testName) {
1978 if (logger.isDebugEnabled()) {
1979 logger.debug(testBanner(testName, CLASS_NAME));
1982 setupDeleteNonExistent();
1984 // Submit the request to the service and store the response.
1985 PersonAuthorityClient client = new PersonAuthorityClient();
1986 ClientResponse<Response> res =
1987 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1989 int statusCode = res.getStatus();
1991 // Check the status code of the response: does it match
1992 // the expected response(s)?
1993 if(logger.isDebugEnabled()){
1994 logger.debug(testName + ": status = " + statusCode);
1996 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1997 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1998 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2000 res.releaseConnection();
2004 // ---------------------------------------------------------------
2005 // Utility tests : tests of code used in tests above
2006 // ---------------------------------------------------------------
2008 * Tests the code for manually submitting data that is used by several
2009 * of the methods above.
2011 @Test(dependsOnMethods = {"create", "read"})
2012 public void testSubmitRequest() {
2014 // Expected status code: 200 OK
2015 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2017 // Submit the request to the service and store the response.
2018 String method = ServiceRequestType.READ.httpMethodName();
2019 String url = getResourceURL(knownResourceId);
2020 int statusCode = submitRequest(method, url);
2022 // Check the status code of the response: does it match
2023 // the expected response(s)?
2024 if(logger.isDebugEnabled()){
2025 logger.debug("testSubmitRequest: url=" + url +
2026 " status=" + statusCode);
2028 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2033 * Test item submit request.
2035 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2036 public void testItemSubmitRequest() {
2038 // Expected status code: 200 OK
2039 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2041 // Submit the request to the service and store the response.
2042 String method = ServiceRequestType.READ.httpMethodName();
2043 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2044 int statusCode = submitRequest(method, url);
2046 // Check the status code of the response: does it match
2047 // the expected response(s)?
2048 if(logger.isDebugEnabled()){
2049 logger.debug("testItemSubmitRequest: url=" + url +
2050 " status=" + statusCode);
2052 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2057 * Test contact submit request.
2059 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2060 public void testContactSubmitRequest() {
2062 // Expected status code: 200 OK
2063 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2065 // Submit the request to the service and store the response.
2066 String method = ServiceRequestType.READ.httpMethodName();
2067 String url = getContactResourceURL(knownResourceId,
2068 knownItemResourceId, knownContactResourceId);
2069 int statusCode = submitRequest(method, url);
2071 // Check the status code of the response: does it match
2072 // the expected response(s)?
2073 if(logger.isDebugEnabled()){
2074 logger.debug("testItemSubmitRequest: url=" + url +
2075 " status=" + statusCode);
2077 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2082 // ---------------------------------------------------------------
2083 // Cleanup of resources created during testing
2084 // ---------------------------------------------------------------
2087 * Deletes all resources created by tests, after all tests have been run.
2089 * This cleanup method will always be run, even if one or more tests fail.
2090 * For this reason, it attempts to remove all resources created
2091 * at any point during testing, even if some of those resources
2092 * may be expected to be deleted by certain tests.
2095 @AfterClass(alwaysRun=true)
2097 public void cleanUp() {
2098 String noTest = System.getProperty("noTestCleanup");
2099 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2100 if (logger.isDebugEnabled()) {
2101 logger.debug("Skipping Cleanup phase ...");
2105 if (logger.isDebugEnabled()) {
2106 logger.debug("Cleaning up temporary resources created for testing ...");
2108 String parentResourceId;
2109 String itemResourceId;
2110 String contactResourceId;
2111 // Clean up contact resources.
2112 PersonAuthorityClient client = new PersonAuthorityClient();
2113 parentResourceId = knownResourceId;
2114 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2115 contactResourceId = entry.getKey();
2116 itemResourceId = entry.getValue();
2117 // Note: Any non-success responses from the delete operation
2118 // below are ignored and not reported.
2119 ClientResponse<Response> res =
2120 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2121 res.releaseConnection();
2123 // Clean up item resources.
2124 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2125 itemResourceId = entry.getKey();
2126 parentResourceId = entry.getValue();
2127 // Note: Any non-success responses from the delete operation
2128 // below are ignored and not reported.
2129 ClientResponse<Response> res =
2130 client.deleteItem(parentResourceId, itemResourceId);
2131 res.releaseConnection();
2133 // Clean up parent resources.
2137 // ---------------------------------------------------------------
2138 // Utility methods used by tests above
2139 // ---------------------------------------------------------------
2141 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2144 public String getServicePathComponent() {
2145 return SERVICE_PATH_COMPONENT;
2149 * Gets the item service path component.
2151 * @return the item service path component
2153 public String getItemServicePathComponent() {
2154 return ITEM_SERVICE_PATH_COMPONENT;
2158 * Gets the contact service path component.
2160 * @return the contact service path component
2162 public String getContactServicePathComponent() {
2163 return CONTACT_SERVICE_PATH_COMPONENT;
2167 * Returns the root URL for the item service.
2169 * This URL consists of a base URL for all services, followed by
2170 * a path component for the owning parent, followed by the
2171 * path component for the items.
2173 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2174 * parent authority resource of the relevant item resource.
2176 * @return The root URL for the item service.
2178 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2179 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2183 * Returns the URL of a specific item resource managed by a service, and
2184 * designated by an identifier (such as a universally unique ID, or UUID).
2186 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2187 * parent authority resource of the relevant item resource.
2189 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2192 * @return The URL of a specific item resource managed by a service.
2194 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2195 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2200 * Returns the root URL for the contact service.
2202 * This URL consists of a base URL for all services, followed by
2203 * a path component for the owning authority, followed by the
2204 * path component for the owning item, followed by the path component
2205 * for the contact service.
2207 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2208 * parent authority resource of the relevant item resource.
2210 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2213 * @return The root URL for the contact service.
2215 protected String getContactServiceRootURL(String parentResourceIdentifier,
2216 String itemResourceIdentifier) {
2217 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2218 getContactServicePathComponent();
2222 * Returns the URL of a specific contact resource managed by a service, and
2223 * designated by an identifier (such as a universally unique ID, or UUID).
2225 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2226 * parent resource of the relevant item resource.
2228 * @param resourceIdentifier An identifier (such as a UUID) for an
2231 * @return The URL of a specific resource managed by a service.
2233 protected String getContactResourceURL(String parentResourceIdentifier,
2234 String itemResourceIdentifier, String contactResourceIdentifier) {
2235 return getContactServiceRootURL(parentResourceIdentifier,
2236 itemResourceIdentifier) + "/" + contactResourceIdentifier;