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 /** The known resource id. */
93 private String knownResourceId = null;
95 /** The known resource display name. */
96 private String knownResourceDisplayName = null;
98 /** The known resource ref name. */
99 private String knownResourceRefName = null;
101 /** The known item resource id. */
102 private String knownItemResourceId = null;
104 // The resource ID of an item resource used for partial term matching tests.
105 private String knownItemPartialTermResourceId = null;
107 /** The known contact resource id. */
108 private String knownContactResourceId = null;
110 /** The n items to create in list. */
111 private int nItemsToCreateInList = 3;
113 /** The all item resource ids created. */
114 private Map<String, String> allItemResourceIdsCreated =
115 new HashMap<String, String>();
117 /** The all contact resource ids created. */
118 private Map<String, String> allContactResourceIdsCreated =
119 new HashMap<String, String>();
122 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
125 protected CollectionSpaceClient getClientInstance() {
126 return new PersonAuthorityClient();
130 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
133 protected AbstractCommonList getAbstractCommonList(
134 ClientResponse<AbstractCommonList> response) {
135 return response.getEntity(PersonsCommonList.class);
138 // ---------------------------------------------------------------
139 // CRUD tests : CREATE tests
140 // ---------------------------------------------------------------
143 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
146 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
148 public void create(String testName) throws Exception {
150 if (logger.isDebugEnabled()) {
151 logger.debug(testBanner(testName, CLASS_NAME));
153 // Perform setup, such as initializing the type of service request
154 // (e.g. CREATE, DELETE), its valid and expected status codes, and
155 // its associated HTTP method name (e.g. POST, DELETE).
158 // Submit the request to the service and store the response.
159 PersonAuthorityClient client = new PersonAuthorityClient();
160 String identifier = createIdentifier();
161 String displayName = "displayName-" + identifier;
162 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
163 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
164 MultipartOutput multipart =
165 PersonAuthorityClientUtils.createPersonAuthorityInstance(
166 displayName, fullRefName, client.getCommonPartName());
169 ClientResponse<Response> res = client.create(multipart);
171 int statusCode = res.getStatus();
173 // Check the status code of the response: does it match
174 // the expected response(s)?
177 // Does it fall within the set of valid status codes?
178 // Does it exactly match the expected status code?
179 if(logger.isDebugEnabled()){
180 logger.debug(testName + ": status = " + statusCode);
182 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
183 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
184 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
186 newID = PersonAuthorityClientUtils.extractId(res);
188 res.releaseConnection();
190 // Store the refname from the first resource created
191 // for additional tests below.
192 knownResourceRefName = baseRefName;
193 // Store the ID returned from the first resource created
194 // for additional tests below.
195 if (knownResourceId == null){
196 knownResourceId = newID;
197 knownResourceDisplayName = displayName;
198 if (logger.isDebugEnabled()) {
199 logger.debug(testName + ": knownResourceId=" + knownResourceId);
202 // Store the IDs from every resource created by tests,
203 // so they can be deleted after tests have been run.
204 allResourceIdsCreated.add(newID);
210 * @param testName the test name
212 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
213 groups = {"create"}, dependsOnMethods = {"create"})
214 public void createItem(String testName) {
215 if (logger.isDebugEnabled()) {
216 logger.debug(testBanner(testName, CLASS_NAME));
219 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
223 * Creates the item in authority.
225 * @param vcsid the vcsid
226 * @param authRefName the auth ref name
229 private String createItemInAuthority(String vcsid, String authRefName) {
231 final String testName = "createItemInAuthority";
232 if(logger.isDebugEnabled()){
233 logger.debug(testName + ":...");
236 // Submit the request to the service and store the response.
237 PersonAuthorityClient client = new PersonAuthorityClient();
238 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
239 Map<String, String> johnWayneMap = new HashMap<String,String>();
241 // Fill the property map
243 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
244 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
246 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
247 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
248 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
249 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
250 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
251 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
252 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
253 "known by his stage name John Wayne, was an American film actor, director " +
254 "and producer. He epitomized rugged masculinity and has become an enduring " +
255 "American icon. He is famous for his distinctive voice, walk and height. " +
256 "He was also known for his conservative political views and his support in " +
257 "the 1950s for anti-communist positions.");
258 MultipartOutput multipart =
259 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
260 client.getItemCommonPartName() );
263 ClientResponse<Response> res = client.createItem(vcsid, multipart);
265 int statusCode = res.getStatus();
266 // Check the status code of the response: does it match
267 // the expected response(s)?
268 if(logger.isDebugEnabled()){
269 logger.debug(testName + ": status = " + statusCode);
271 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
272 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
273 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
275 newID = PersonAuthorityClientUtils.extractId(res);
277 res.releaseConnection();
280 // Store the ID returned from the first item resource created
281 // for additional tests below.
282 if (knownItemResourceId == null){
283 knownItemResourceId = newID;
284 if (logger.isDebugEnabled()) {
285 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
289 // Store the IDs from any item resources created
290 // by tests, along with the IDs of their parents, so these items
291 // can be deleted after all tests have been run.
292 allItemResourceIdsCreated.put(newID, vcsid);
298 * Creates the contact.
300 * @param testName the test name
302 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
303 groups = {"create"}, dependsOnMethods = {"createItem"})
304 public void createContact(String testName) {
305 if (logger.isDebugEnabled()) {
306 logger.debug(testBanner(testName, CLASS_NAME));
309 String newID = createContactInItem(knownResourceId, knownItemResourceId);
313 * Creates the contact in item.
315 * @param parentcsid the parentcsid
316 * @param itemcsid the itemcsid
319 private String createContactInItem(String parentcsid, String itemcsid) {
321 final String testName = "createContactInItem";
322 if(logger.isDebugEnabled()){
323 logger.debug(testName + ":...");
328 // Submit the request to the service and store the response.
329 PersonAuthorityClient client = new PersonAuthorityClient();
330 String identifier = createIdentifier();
331 MultipartOutput multipart =
332 ContactClientUtils.createContactInstance(parentcsid,
333 itemcsid, identifier, new ContactClient().getCommonPartName());
336 ClientResponse<Response> res =
337 client.createContact(parentcsid, itemcsid, multipart);
339 int statusCode = res.getStatus();
340 // Check the status code of the response: does it match
341 // the expected response(s)?
342 if(logger.isDebugEnabled()){
343 logger.debug(testName + ": status = " + statusCode);
345 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
346 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
347 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
349 newID = PersonAuthorityClientUtils.extractId(res);
351 res.releaseConnection();
354 // Store the ID returned from the first contact resource created
355 // for additional tests below.
356 if (knownContactResourceId == null){
357 knownContactResourceId = newID;
358 if (logger.isDebugEnabled()) {
359 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
363 // Store the IDs from any contact resources created
364 // by tests, along with the IDs of their parent items,
365 // so these items can be deleted after all tests have been run.
366 allContactResourceIdsCreated.put(newID, itemcsid);
373 // Placeholders until the three tests below can be uncommented.
374 // See Issue CSPACE-401.
376 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
379 public void createWithEmptyEntityBody(String testName) throws Exception {
380 //Should this really be empty?
384 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
387 public void createWithMalformedXml(String testName) throws Exception {
388 //Should this really be empty?
392 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
395 public void createWithWrongXmlSchema(String testName) throws Exception {
396 //Should this really be empty?
401 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
402 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
403 public void createWithEmptyEntityBody(String testName) throws Exception {
405 if (logger.isDebugEnabled()) {
406 logger.debug(testBanner(testName, CLASS_NAME));
409 setupCreateWithEmptyEntityBody();
411 // Submit the request to the service and store the response.
412 String method = REQUEST_TYPE.httpMethodName();
413 String url = getServiceRootURL();
414 String mediaType = MediaType.APPLICATION_XML;
415 final String entity = "";
416 int statusCode = submitRequest(method, url, mediaType, entity);
418 // Check the status code of the response: does it match
419 // the expected response(s)?
420 if(logger.isDebugEnabled()) {
421 logger.debug(testName + ": url=" + url +
422 " status=" + statusCode);
424 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
425 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
426 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
430 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
431 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
432 public void createWithMalformedXml(String testName) throws Exception {
434 if (logger.isDebugEnabled()) {
435 logger.debug(testBanner(testName, CLASS_NAME));
438 setupCreateWithMalformedXml();
440 // Submit the request to the service and store the response.
441 String method = REQUEST_TYPE.httpMethodName();
442 String url = getServiceRootURL();
443 String mediaType = MediaType.APPLICATION_XML;
444 final String entity = MALFORMED_XML_DATA; // Constant from base class.
445 int statusCode = submitRequest(method, url, mediaType, entity);
447 // Check the status code of the response: does it match
448 // the expected response(s)?
449 if(logger.isDebugEnabled()){
450 logger.debug(testName + ": url=" + url +
451 " status=" + statusCode);
453 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
454 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
455 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
459 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
460 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
461 public void createWithWrongXmlSchema(String testName) throws Exception {
463 if (logger.isDebugEnabled()) {
464 logger.debug(testBanner(testName, CLASS_NAME));
467 setupCreateWithWrongXmlSchema();
469 // Submit the request to the service and store the response.
470 String method = REQUEST_TYPE.httpMethodName();
471 String url = getServiceRootURL();
472 String mediaType = MediaType.APPLICATION_XML;
473 final String entity = WRONG_XML_SCHEMA_DATA;
474 int statusCode = submitRequest(method, url, mediaType, entity);
476 // Check the status code of the response: does it match
477 // the expected response(s)?
478 if(logger.isDebugEnabled()){
479 logger.debug(testName + ": url=" + url +
480 " status=" + statusCode);
482 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
483 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
484 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
488 // ---------------------------------------------------------------
489 // CRUD tests : CREATE LIST tests
490 // ---------------------------------------------------------------
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
496 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
497 groups = {"createList"}, dependsOnGroups = {"create"})
498 public void createList(String testName) throws Exception {
499 if (logger.isDebugEnabled()) {
500 logger.debug(testBanner(testName, CLASS_NAME));
502 for (int i = 0; i < nItemsToCreateInList; i++) {
508 * Creates the item list.
510 * @param testName the test name
511 * @throws Exception the exception
513 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
514 groups = {"createList"}, dependsOnMethods = {"createList"})
515 public void createItemList(String testName) throws Exception {
516 if (logger.isDebugEnabled()) {
517 logger.debug(testBanner(testName, CLASS_NAME));
519 // Add items to the initially-created, known parent record.
520 for (int j = 0; j < nItemsToCreateInList; j++) {
521 createItem(testName);
526 * Creates the contact list.
528 * @param testName the test name
529 * @throws Exception the exception
531 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
532 groups = {"createList"}, dependsOnMethods = {"createItemList"})
533 public void createContactList(String testName) throws Exception {
534 // Add contacts to the initially-created, known item record.
535 for (int j = 0; j < nItemsToCreateInList; j++) {
536 createContact(testName);
540 // ---------------------------------------------------------------
541 // CRUD tests : READ tests
542 // ---------------------------------------------------------------
545 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
548 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
549 groups = {"read"}, dependsOnGroups = {"create"})
550 public void read(String testName) throws Exception {
552 if (logger.isDebugEnabled()) {
553 logger.debug(testBanner(testName, CLASS_NAME));
558 // Submit the request to the service and store the response.
559 PersonAuthorityClient client = new PersonAuthorityClient();
560 ClientResponse<MultipartInput> res = client.read(knownResourceId);
562 int statusCode = res.getStatus();
563 // Check the status code of the response: does it match
564 // the expected response(s)?
565 if(logger.isDebugEnabled()){
566 logger.debug(testName + ": status = " + statusCode);
568 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
569 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
570 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
571 //FIXME: remove the following try catch once Aron fixes signatures
573 MultipartInput input = (MultipartInput) res.getEntity();
574 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
575 client.getCommonPartName(), PersonauthoritiesCommon.class);
576 Assert.assertNotNull(personAuthority);
577 } catch (Exception e) {
578 throw new RuntimeException(e);
581 res.releaseConnection();
588 * @param testName the test name
589 * @throws Exception the exception
591 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
592 groups = {"read"}, dependsOnGroups = {"create"})
593 public void readByName(String testName) throws Exception {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
601 // Submit the request to the service and store the response.
602 PersonAuthorityClient client = new PersonAuthorityClient();
603 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
605 int statusCode = res.getStatus();
606 // Check the status code of the response: does it match
607 // the expected response(s)?
608 if(logger.isDebugEnabled()){
609 logger.debug(testName + ": status = " + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
614 //FIXME: remove the following try catch once Aron fixes signatures
616 MultipartInput input = (MultipartInput) res.getEntity();
617 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
618 client.getCommonPartName(), PersonauthoritiesCommon.class);
619 Assert.assertNotNull(personAuthority);
620 } catch (Exception e) {
621 throw new RuntimeException(e);
624 res.releaseConnection();
629 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
630 groups = {"read"}, dependsOnMethods = {"read"})
631 public void readByName(String testName) throws Exception {
633 if (logger.isDebugEnabled()) {
634 logger.debug(testBanner(testName, CLASS_NAME));
639 // Submit the request to the service and store the response.
640 ClientResponse<MultipartInput> res = client.read(knownResourceId);
641 int statusCode = res.getStatus();
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": status = " + statusCode);
648 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
649 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
650 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
651 //FIXME: remove the following try catch once Aron fixes signatures
653 MultipartInput input = (MultipartInput) res.getEntity();
654 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
655 client.getCommonPartName(), PersonauthoritiesCommon.class);
656 Assert.assertNotNull(personAuthority);
657 } catch (Exception e) {
658 throw new RuntimeException(e);
666 * @param testName the test name
667 * @throws Exception the exception
669 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
670 groups = {"read"}, dependsOnMethods = {"read"})
671 public void readItem(String testName) throws Exception {
673 if (logger.isDebugEnabled()) {
674 logger.debug(testBanner(testName, CLASS_NAME));
679 // Submit the request to the service and store the response.
680 PersonAuthorityClient client = new PersonAuthorityClient();
681 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
683 int statusCode = res.getStatus();
685 // Check the status code of the response: does it match
686 // the expected response(s)?
687 if(logger.isDebugEnabled()){
688 logger.debug(testName + ": status = " + statusCode);
690 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
691 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
692 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
694 // Check whether we've received a person.
695 MultipartInput input = (MultipartInput) res.getEntity();
696 PersonsCommon person = (PersonsCommon) extractPart(input,
697 client.getItemCommonPartName(), PersonsCommon.class);
698 Assert.assertNotNull(person);
699 boolean showFull = true;
700 if(showFull && logger.isDebugEnabled()){
701 logger.debug(testName + ": returned payload:");
702 logger.debug(objectAsXmlString(person, PersonsCommon.class));
704 Assert.assertEquals(person.getInAuthority(), knownResourceId);
706 res.releaseConnection();
711 * Verify item display name.
713 * @param testName the test name
714 * @throws Exception the exception
716 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
717 dependsOnMethods = {"readItem", "updateItem"})
718 public void verifyItemDisplayName(String testName) throws Exception {
720 if (logger.isDebugEnabled()) {
721 logger.debug(testBanner(testName, CLASS_NAME));
726 // Submit the request to the service and store the response.
727 PersonAuthorityClient client = new PersonAuthorityClient();
728 MultipartInput input =null;
729 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
731 int statusCode = res.getStatus();
733 // Check the status code of the response: does it match
734 // the expected response(s)?
735 if(logger.isDebugEnabled()){
736 logger.debug(testName + ": status = " + statusCode);
738 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
739 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
740 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
742 // Check whether person has expected displayName.
743 input = (MultipartInput) res.getEntity();
745 res.releaseConnection();
748 PersonsCommon person = (PersonsCommon) extractPart(input,
749 client.getItemCommonPartName(), PersonsCommon.class);
750 Assert.assertNotNull(person);
751 String displayName = person.getDisplayName();
752 // Make sure displayName matches computed form
753 String expectedDisplayName =
754 PersonAuthorityClientUtils.prepareDefaultDisplayName(
755 TEST_FORE_NAME, null, TEST_SUR_NAME,
756 TEST_BIRTH_DATE, TEST_DEATH_DATE);
757 Assert.assertNotNull(displayName, expectedDisplayName);
759 // Update the shortName and verify the computed name is updated.
760 person.setCsid(null);
761 person.setDisplayNameComputed(true);
762 person.setForeName("updated-" + TEST_FORE_NAME);
763 expectedDisplayName =
764 PersonAuthorityClientUtils.prepareDefaultDisplayName(
765 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
766 TEST_BIRTH_DATE, TEST_DEATH_DATE);
768 // Submit the updated resource to the service and store the response.
769 MultipartOutput output = new MultipartOutput();
770 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
771 commonPart.getHeaders().add("label", client.getItemCommonPartName());
772 res = client.updateItem(knownResourceId, knownItemResourceId, output);
774 int statusCode = res.getStatus();
776 // Check the status code of the response: does it match the expected response(s)?
777 if(logger.isDebugEnabled()){
778 logger.debug("updateItem: status = " + statusCode);
780 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
781 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
782 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
784 // Retrieve the updated resource and verify that its contents exist.
785 input = (MultipartInput) res.getEntity();
787 res.releaseConnection();
790 PersonsCommon updatedPerson =
791 (PersonsCommon) extractPart(input,
792 client.getItemCommonPartName(), PersonsCommon.class);
793 Assert.assertNotNull(updatedPerson);
795 // Verify that the updated resource received the correct data.
796 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
797 "Updated ForeName in Person did not match submitted data.");
798 // Verify that the updated resource computes the right displayName.
799 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
800 "Updated ForeName in Person not reflected in computed DisplayName.");
802 // Now Update the displayName, not computed and verify the computed name is overriden.
803 person.setDisplayNameComputed(false);
804 expectedDisplayName = "TestName";
805 person.setDisplayName(expectedDisplayName);
807 // Submit the updated resource to the service and store the response.
808 output = new MultipartOutput();
809 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
810 commonPart.getHeaders().add("label", client.getItemCommonPartName());
811 res = client.updateItem(knownResourceId, knownItemResourceId, output);
813 int statusCode = res.getStatus();
815 // Check the status code of the response: does it match the expected response(s)?
816 if(logger.isDebugEnabled()){
817 logger.debug("updateItem: status = " + statusCode);
819 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
820 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
821 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
823 // Retrieve the updated resource and verify that its contents exist.
824 input = (MultipartInput) res.getEntity();
826 res.releaseConnection();
830 (PersonsCommon) extractPart(input,
831 client.getItemCommonPartName(), PersonsCommon.class);
832 Assert.assertNotNull(updatedPerson);
834 // Verify that the updated resource received the correct data.
835 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
836 "Updated displayNameComputed in Person did not match submitted data.");
837 // Verify that the updated resource computes the right displayName.
838 Assert.assertEquals(updatedPerson.getDisplayName(),
840 "Updated DisplayName (not computed) in Person not stored.");
844 * Verify illegal item display name.
846 * @param testName the test name
847 * @throws Exception the exception
849 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
850 dependsOnMethods = {"verifyItemDisplayName"})
851 public void verifyIllegalItemDisplayName(String testName) throws Exception {
853 if (logger.isDebugEnabled()) {
854 logger.debug(testBanner(testName, CLASS_NAME));
857 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
858 // setupUpdateWithWrongXmlSchema(testName);
860 // Submit the request to the service and store the response.
861 PersonAuthorityClient client = new PersonAuthorityClient();
862 MultipartInput input = null;
863 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
865 int statusCode = res.getStatus();
867 // Check the status code of the response: does it match
868 // the expected response(s)?
869 if(logger.isDebugEnabled()){
870 logger.debug(testName + ": status = " + statusCode);
872 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
873 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
874 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
876 // Check whether Person has expected displayName.
877 input = (MultipartInput) res.getEntity();
879 res.releaseConnection();
882 PersonsCommon person = (PersonsCommon) extractPart(input,
883 client.getItemCommonPartName(), PersonsCommon.class);
884 Assert.assertNotNull(person);
885 // Try to Update with computed false and no displayName
886 person.setDisplayNameComputed(false);
887 person.setDisplayName(null);
889 // Submit the updated resource to the service and store the response.
890 MultipartOutput output = new MultipartOutput();
891 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
892 commonPart.getHeaders().add("label", client.getItemCommonPartName());
893 res = client.updateItem(knownResourceId, knownItemResourceId, output);
895 int statusCode = res.getStatus();
897 // Check the status code of the response: does it match the expected response(s)?
898 if(logger.isDebugEnabled()){
899 logger.debug("updateItem: status = " + statusCode);
901 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
902 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
903 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
905 res.releaseConnection();
912 * @param testName the test name
913 * @throws Exception the exception
915 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
916 groups = {"read"}, dependsOnMethods = {"readItem"})
917 public void readContact(String testName) throws Exception {
919 if (logger.isDebugEnabled()) {
920 logger.debug(testBanner(testName, CLASS_NAME));
925 // Submit the request to the service and store the response.
926 PersonAuthorityClient client = new PersonAuthorityClient();
927 MultipartInput input = null;
928 ClientResponse<MultipartInput> res =
929 client.readContact(knownResourceId, knownItemResourceId,
930 knownContactResourceId);
932 int statusCode = res.getStatus();
934 // Check the status code of the response: does it match
935 // the expected response(s)?
936 if(logger.isDebugEnabled()){
937 logger.debug(testName + ": status = " + statusCode);
939 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
940 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
941 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
943 // Check whether we've received a contact.
944 input = (MultipartInput) res.getEntity();
946 res.releaseConnection();
949 ContactsCommon contact = (ContactsCommon) extractPart(input,
950 new ContactClient().getCommonPartName(), ContactsCommon.class);
951 Assert.assertNotNull(contact);
952 boolean showFull = true;
953 if(showFull && logger.isDebugEnabled()){
954 logger.debug(testName + ": returned payload:");
955 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
957 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
958 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
964 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
967 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
968 groups = {"read"}, dependsOnMethods = {"read"})
969 public void readNonExistent(String testName) {
971 if (logger.isDebugEnabled()) {
972 logger.debug(testBanner(testName, CLASS_NAME));
975 setupReadNonExistent();
977 // Submit the request to the service and store the response.
978 PersonAuthorityClient client = new PersonAuthorityClient();
979 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
981 int statusCode = res.getStatus();
982 // Check the status code of the response: does it match
983 // the expected response(s)?
984 if(logger.isDebugEnabled()){
985 logger.debug(testName + ": status = " + statusCode);
987 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
988 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
989 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
991 res.releaseConnection();
996 * Read item non existent.
998 * @param testName the test name
1000 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1001 groups = {"read"}, dependsOnMethods = {"readItem"})
1002 public void readItemNonExistent(String testName) {
1004 if (logger.isDebugEnabled()) {
1005 logger.debug(testBanner(testName, CLASS_NAME));
1008 setupReadNonExistent();
1010 // Submit the request to the service and store the response.
1011 PersonAuthorityClient client = new PersonAuthorityClient();
1012 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1014 int statusCode = res.getStatus();
1016 // Check the status code of the response: does it match
1017 // the expected response(s)?
1018 if(logger.isDebugEnabled()){
1019 logger.debug(testName + ": status = " + statusCode);
1021 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1022 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1023 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1025 res.releaseConnection();
1030 * Read contact non existent.
1032 * @param testName the test name
1034 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1035 groups = {"read"}, dependsOnMethods = {"readContact"})
1036 public void readContactNonExistent(String testName) {
1038 if (logger.isDebugEnabled()) {
1039 logger.debug(testBanner(testName, CLASS_NAME));
1042 setupReadNonExistent();
1044 // Submit the request to the service and store the response.
1045 PersonAuthorityClient client = new PersonAuthorityClient();
1046 ClientResponse<MultipartInput> res =
1047 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1049 int statusCode = res.getStatus();
1051 // Check the status code of the response: does it match
1052 // the expected response(s)?
1053 if(logger.isDebugEnabled()){
1054 logger.debug(testName + ": status = " + statusCode);
1056 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1057 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1058 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1060 res.releaseConnection();
1064 // ---------------------------------------------------------------
1065 // CRUD tests : READ_LIST tests
1066 // ---------------------------------------------------------------
1070 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1073 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1074 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1075 public void readList(String testName) throws Exception {
1077 if (logger.isDebugEnabled()) {
1078 logger.debug(testBanner(testName, CLASS_NAME));
1083 // Submit the request to the service and store the response.
1084 PersonAuthorityClient client = new PersonAuthorityClient();
1085 PersonauthoritiesCommonList list = null;
1086 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1088 int statusCode = res.getStatus();
1090 // Check the status code of the response: does it match
1091 // the expected response(s)?
1092 if(logger.isDebugEnabled()){
1093 logger.debug(testName + ": status = " + statusCode);
1095 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1096 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1097 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1099 list = res.getEntity();
1101 res.releaseConnection();
1104 // Optionally output additional data about list members for debugging.
1105 boolean iterateThroughList = false;
1106 if (iterateThroughList && logger.isDebugEnabled()) {
1107 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1108 list.getPersonauthorityListItem();
1110 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1111 String csid = item.getCsid();
1112 logger.debug(testName + ": list-item[" + i + "] csid=" +
1114 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1115 item.getDisplayName());
1116 logger.debug(testName + ": list-item[" + i + "] URI=" +
1118 readItemList(csid, null);
1127 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1128 public void readItemList() {
1129 readItemList(knownResourceId, null);
1133 * Read item list by authority name.
1135 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1136 public void readItemListByAuthorityName() {
1137 readItemList(null, knownResourceDisplayName);
1143 * @param vcsid the vcsid
1144 * @param name the name
1146 private void readItemList(String vcsid, String name) {
1148 final String testName = "readItemList";
1153 // Submit the request to the service and store the response.
1154 PersonAuthorityClient client = new PersonAuthorityClient();
1155 ClientResponse<PersonsCommonList> res = null;
1157 res = client.readItemList(vcsid);
1158 } else if (name!= null) {
1159 res = client.readItemListForNamedAuthority(name);
1161 Assert.fail("readItemList passed null csid and name!");
1163 PersonsCommonList list = null;
1165 int statusCode = res.getStatus();
1167 // Check the status code of the response: does it match
1168 // the expected response(s)?
1169 if(logger.isDebugEnabled()){
1170 logger.debug(testName + ": status = " + statusCode);
1172 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1173 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1174 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1176 list = res.getEntity();
1178 res.releaseConnection();
1181 List<PersonsCommonList.PersonListItem> items =
1182 list.getPersonListItem();
1183 int nItemsReturned = items.size();
1184 // There will be one item created, associated with a
1185 // known parent resource, by the createItem test.
1187 // In addition, there will be 'nItemsToCreateInList'
1188 // additional items created by the createItemList test,
1189 // all associated with the same parent resource.
1190 int nExpectedItems = nItemsToCreateInList + 1;
1191 if(logger.isDebugEnabled()){
1192 logger.debug(testName + ": Expected "
1193 + nExpectedItems +" items; got: "+nItemsReturned);
1195 Assert.assertEquals(nItemsReturned, nExpectedItems);
1198 for (PersonsCommonList.PersonListItem item : items) {
1199 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1200 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1201 // Optionally output additional data about list members for debugging.
1202 boolean showDetails = true;
1203 if (showDetails && logger.isDebugEnabled()) {
1204 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1206 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1208 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1209 item.getDisplayName());
1210 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1218 * Read contact list.
1220 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1221 public void readContactList() {
1222 readContactList(knownResourceId, knownItemResourceId);
1226 * Read contact list.
1228 * @param parentcsid the parentcsid
1229 * @param itemcsid the itemcsid
1231 private void readContactList(String parentcsid, String itemcsid) {
1232 final String testName = "readContactList";
1237 // Submit the request to the service and store the response.
1238 PersonAuthorityClient client = new PersonAuthorityClient();
1239 ContactsCommonList list = null;
1240 ClientResponse<ContactsCommonList> res =
1241 client.readContactList(parentcsid, itemcsid);
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 list = res.getEntity();
1256 res.releaseConnection();
1259 List<ContactsCommonList.ContactListItem> listitems =
1260 list.getContactListItem();
1261 int nItemsReturned = listitems.size();
1262 // There will be one item created, associated with a
1263 // known parent resource, by the createItem test.
1265 // In addition, there will be 'nItemsToCreateInList'
1266 // additional items created by the createItemList test,
1267 // all associated with the same parent resource.
1268 int nExpectedItems = nItemsToCreateInList + 1;
1269 if(logger.isDebugEnabled()){
1270 logger.debug(testName + ": Expected "
1271 + nExpectedItems +" items; got: "+nItemsReturned);
1273 Assert.assertEquals(nItemsReturned, nExpectedItems);
1276 for (ContactsCommonList.ContactListItem listitem : listitems) {
1277 // Optionally output additional data about list members for debugging.
1278 boolean showDetails = false;
1279 if (showDetails && logger.isDebugEnabled()) {
1280 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1281 listitem.getCsid());
1282 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1283 listitem.getAddressPlace());
1284 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1293 // There are no failure outcome tests at present.
1295 // ---------------------------------------------------------------
1296 // CRUD tests : UPDATE tests
1297 // ---------------------------------------------------------------
1300 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1303 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1304 groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1305 public void update(String testName) throws Exception {
1307 if (logger.isDebugEnabled()) {
1308 logger.debug(testBanner(testName, CLASS_NAME));
1313 // Retrieve the contents of a resource to update.
1314 PersonAuthorityClient client = new PersonAuthorityClient();
1315 MultipartInput input = null;
1316 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1318 if(logger.isDebugEnabled()){
1319 logger.debug(testName + ": read status = " + res.getStatus());
1321 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1323 if(logger.isDebugEnabled()){
1324 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1326 input = res.getEntity();
1328 res.releaseConnection();
1331 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1332 client.getCommonPartName(), PersonauthoritiesCommon.class);
1333 Assert.assertNotNull(personAuthority);
1335 // Update the contents of this resource.
1336 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1337 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1338 if(logger.isDebugEnabled()){
1339 logger.debug("to be updated PersonAuthority");
1340 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1343 // Submit the updated resource to the service and store the response.
1344 MultipartOutput output = new MultipartOutput();
1345 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1346 commonPart.getHeaders().add("label", client.getCommonPartName());
1347 res = client.update(knownResourceId, output);
1349 int statusCode = res.getStatus();
1351 // Check the status code of the response: does it match the expected response(s)?
1352 if(logger.isDebugEnabled()){
1353 logger.debug(testName + ": status = " + statusCode);
1355 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1356 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1357 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1359 // Retrieve the updated resource and verify that its contents exist.
1360 input = (MultipartInput) res.getEntity();
1362 res.releaseConnection();
1365 PersonauthoritiesCommon updatedPersonAuthority =
1366 (PersonauthoritiesCommon) extractPart(input,
1367 client.getCommonPartName(), PersonauthoritiesCommon.class);
1368 Assert.assertNotNull(updatedPersonAuthority);
1370 // Verify that the updated resource received the correct data.
1371 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1372 personAuthority.getDisplayName(),
1373 "Data in updated object did not match submitted data.");
1379 * @param testName the test name
1380 * @throws Exception the exception
1382 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1383 groups = {"update"}, dependsOnMethods = {"update"})
1384 public void updateItem(String testName) throws Exception {
1386 if (logger.isDebugEnabled()) {
1387 logger.debug(testBanner(testName, CLASS_NAME));
1392 // Retrieve the contents of a resource to update.
1393 PersonAuthorityClient client = new PersonAuthorityClient();
1394 MultipartInput input = null;
1395 ClientResponse<MultipartInput> res =
1396 client.readItem(knownResourceId, knownItemResourceId);
1398 if(logger.isDebugEnabled()){
1399 logger.debug(testName + ": read status = " + res.getStatus());
1401 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1403 if(logger.isDebugEnabled()){
1404 logger.debug("got Person to update with ID: " +
1405 knownItemResourceId +
1406 " in PersonAuthority: " + knownResourceId );
1408 input = res.getEntity();
1410 res.releaseConnection();
1413 PersonsCommon person = (PersonsCommon) extractPart(input,
1414 client.getItemCommonPartName(), PersonsCommon.class);
1415 Assert.assertNotNull(person);
1417 if (logger.isDebugEnabled() == true) {
1418 logger.debug("About to update the following person...");
1419 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1422 // Update the contents of this resource.
1423 person.setCsid(null);
1424 person.setForeName("updated-" + person.getForeName());
1425 if(logger.isDebugEnabled()){
1426 logger.debug("to be updated Person");
1427 logger.debug(objectAsXmlString(person,
1428 PersonsCommon.class));
1431 // Submit the updated resource to the service and store the response.
1432 MultipartOutput output = new MultipartOutput();
1433 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1434 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1435 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1437 int statusCode = res.getStatus();
1439 // Check the status code of the response: does it match the expected response(s)?
1440 if(logger.isDebugEnabled()){
1441 logger.debug(testName + ": status = " + statusCode);
1443 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1444 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1445 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1447 // Retrieve the updated resource and verify that its contents exist.
1448 input = (MultipartInput) res.getEntity();
1450 res.releaseConnection();
1453 PersonsCommon updatedPerson =
1454 (PersonsCommon) extractPart(input,
1455 client.getItemCommonPartName(), PersonsCommon.class);
1456 Assert.assertNotNull(updatedPerson);
1458 if (logger.isDebugEnabled() == true) {
1459 logger.debug("Updated to following person to:");
1460 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1463 // Verify that the updated resource received the correct data.
1464 Assert.assertEquals(updatedPerson.getForeName(),
1465 person.getForeName(),
1466 "Data in updated Person did not match submitted data.");
1472 * @param testName the test name
1473 * @throws Exception the exception
1475 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1476 groups = {"update"}, dependsOnMethods = {"updateItem"})
1477 public void updateContact(String testName) throws Exception {
1479 if (logger.isDebugEnabled()) {
1480 logger.debug(testBanner(testName, CLASS_NAME));
1485 // Retrieve the contents of a resource to update.
1486 PersonAuthorityClient client = new PersonAuthorityClient();
1487 MultipartInput input = null;
1488 ClientResponse<MultipartInput> res =
1489 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1491 if(logger.isDebugEnabled()){
1492 logger.debug(testName + ": read status = " + res.getStatus());
1494 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1496 if(logger.isDebugEnabled()){
1497 logger.debug("got Contact to update with ID: " +
1498 knownContactResourceId +
1499 " in item: " + knownItemResourceId +
1500 " in parent: " + knownResourceId );
1502 input = res.getEntity();
1504 res.releaseConnection();
1507 ContactsCommon contact = (ContactsCommon) extractPart(input,
1508 new ContactClient().getCommonPartName(), ContactsCommon.class);
1509 Assert.assertNotNull(contact);
1511 // Update the contents of this resource.
1512 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1513 if(logger.isDebugEnabled()){
1514 logger.debug("to be updated Contact");
1515 logger.debug(objectAsXmlString(contact,
1516 ContactsCommon.class));
1519 // Submit the updated resource to the service and store the response.
1520 MultipartOutput output = new MultipartOutput();
1521 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1522 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1523 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1525 int statusCode = res.getStatus();
1527 // Check the status code of the response: does it match the expected response(s)?
1528 if(logger.isDebugEnabled()){
1529 logger.debug(testName + ": status = " + statusCode);
1531 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1532 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1533 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1535 // Retrieve the updated resource and verify that its contents exist.
1536 input = (MultipartInput) res.getEntity();
1538 res.releaseConnection();
1540 ContactsCommon updatedContact =
1541 (ContactsCommon) extractPart(input,
1542 new ContactClient().getCommonPartName(), ContactsCommon.class);
1543 Assert.assertNotNull(updatedContact);
1545 // Verify that the updated resource received the correct data.
1546 Assert.assertEquals(updatedContact.getAddressPlace(),
1547 contact.getAddressPlace(),
1548 "Data in updated Contact did not match submitted data.");
1552 // Placeholders until the three tests below can be uncommented.
1553 // See Issue CSPACE-401.
1555 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1558 public void updateWithEmptyEntityBody(String testName) throws Exception {
1559 //Should this really be empty?
1563 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1566 public void updateWithMalformedXml(String testName) throws Exception {
1567 //Should this really be empty?
1571 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1574 public void updateWithWrongXmlSchema(String testName) throws Exception {
1575 //Should this really be empty?
1580 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1581 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1582 public void updateWithEmptyEntityBody(String testName) throws Exception {
1584 if (logger.isDebugEnabled()) {
1585 logger.debug(testBanner(testName, CLASS_NAME));
1588 setupUpdateWithEmptyEntityBody(testName, logger);
1590 // Submit the request to the service and store the response.
1591 String method = REQUEST_TYPE.httpMethodName();
1592 String url = getResourceURL(knownResourceId);
1593 String mediaType = MediaType.APPLICATION_XML;
1594 final String entity = "";
1595 int statusCode = submitRequest(method, url, mediaType, entity);
1597 // Check the status code of the response: does it match
1598 // the expected response(s)?
1599 if(logger.isDebugEnabled()){
1600 logger.debug(testName + ": url=" + url +
1601 " status=" + statusCode);
1603 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1604 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1605 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1609 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1610 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1611 public void updateWithMalformedXml(String testName) throws Exception {
1613 if (logger.isDebugEnabled()) {
1614 logger.debug(testBanner(testName, CLASS_NAME));
1617 setupUpdateWithMalformedXml();
1619 // Submit the request to the service and store the response.
1620 String method = REQUEST_TYPE.httpMethodName();
1621 String url = getResourceURL(knownResourceId);
1622 String mediaType = MediaType.APPLICATION_XML;
1623 final String entity = MALFORMED_XML_DATA;
1624 int statusCode = submitRequest(method, url, mediaType, entity);
1626 // Check the status code of the response: does it match
1627 // the expected response(s)?
1628 if(logger.isDebugEnabled()){
1629 logger.debug(testName + ": url=" + url +
1630 " status=" + statusCode);
1632 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1633 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1634 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1638 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1639 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1640 public void updateWithWrongXmlSchema(String testName) throws Exception {
1642 if (logger.isDebugEnabled()) {
1643 logger.debug(testBanner(testName, CLASS_NAME));
1646 setupUpdateWithWrongXmlSchema();
1648 // Submit the request to the service and store the response.
1649 String method = REQUEST_TYPE.httpMethodName();
1650 String url = getResourceURL(knownResourceId);
1651 String mediaType = MediaType.APPLICATION_XML;
1652 final String entity = WRONG_XML_SCHEMA_DATA;
1653 int statusCode = submitRequest(method, url, mediaType, entity);
1655 // Check the status code of the response: does it match
1656 // the expected response(s)?
1657 if(logger.isDebugEnabled()){
1658 logger.debug("updateWithWrongXmlSchema: url=" + url +
1659 " status=" + statusCode);
1661 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1662 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1663 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1668 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1671 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1672 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1673 public void updateNonExistent(String testName) throws Exception {
1675 if (logger.isDebugEnabled()) {
1676 logger.debug(testBanner(testName, CLASS_NAME));
1679 setupUpdateNonExistent();
1681 // Submit the request to the service and store the response.
1682 // Note: The ID(s) used when creating the request payload may be arbitrary.
1683 // The only relevant ID may be the one used in update(), below.
1684 PersonAuthorityClient client = new PersonAuthorityClient();
1685 String displayName = "displayName-NON_EXISTENT_ID";
1686 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1687 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1688 displayName, fullRefName, client.getCommonPartName());
1689 ClientResponse<MultipartInput> res =
1690 client.update(NON_EXISTENT_ID, multipart);
1692 int statusCode = res.getStatus();
1694 // Check the status code of the response: does it match
1695 // the expected response(s)?
1696 if(logger.isDebugEnabled()){
1697 logger.debug(testName + ": status = " + statusCode);
1699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1703 res.releaseConnection();
1708 * Update non existent item.
1710 * @param testName the test name
1711 * @throws Exception the exception
1713 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1714 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1715 public void updateNonExistentItem(String testName) throws Exception {
1717 if (logger.isDebugEnabled()) {
1718 logger.debug(testBanner(testName, CLASS_NAME));
1721 setupUpdateNonExistent();
1723 // Submit the request to the service and store the response.
1724 // Note: The ID used in this 'create' call may be arbitrary.
1725 // The only relevant ID may be the one used in update(), below.
1726 PersonAuthorityClient client = new PersonAuthorityClient();
1727 Map<String, String> nonexMap = new HashMap<String,String>();
1728 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1729 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1730 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1731 MultipartOutput multipart =
1732 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1733 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1734 client.getItemCommonPartName() );
1735 ClientResponse<MultipartInput> res =
1736 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1738 int statusCode = res.getStatus();
1740 // Check the status code of the response: does it match
1741 // the expected response(s)?
1742 if(logger.isDebugEnabled()){
1743 logger.debug(testName + ": status = " + statusCode);
1745 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1746 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1747 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1749 res.releaseConnection();
1754 * Update non existent contact.
1756 * @param testName the test name
1757 * @throws Exception the exception
1759 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1760 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1761 public void updateNonExistentContact(String testName) throws Exception {
1762 // Currently a no-op test
1765 // ---------------------------------------------------------------
1766 // CRUD tests : DELETE tests
1767 // ---------------------------------------------------------------
1770 // Note: delete sub-resources in ascending hierarchical order,
1771 // before deleting their parents.
1776 * @param testName the test name
1777 * @throws Exception the exception
1779 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1780 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1781 public void deleteContact(String testName) throws Exception {
1783 if (logger.isDebugEnabled()) {
1784 logger.debug(testBanner(testName, CLASS_NAME));
1789 if(logger.isDebugEnabled()){
1790 logger.debug("parentcsid =" + knownResourceId +
1791 " itemcsid = " + knownItemResourceId +
1792 " csid = " + knownContactResourceId);
1795 // Submit the request to the service and store the response.
1796 PersonAuthorityClient client = new PersonAuthorityClient();
1797 ClientResponse<Response> res =
1798 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1799 int statusCode = res.getStatus();
1800 res.releaseConnection();
1802 // Check the status code of the response: does it match
1803 // the expected response(s)?
1804 if(logger.isDebugEnabled()){
1805 logger.debug(testName + ": status = " + statusCode);
1807 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1808 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1809 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1815 * @param testName the test name
1816 * @throws Exception the exception
1818 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1819 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1820 public void deleteItem(String testName) throws Exception {
1822 if (logger.isDebugEnabled()) {
1823 logger.debug(testBanner(testName, CLASS_NAME));
1828 if(logger.isDebugEnabled()){
1829 logger.debug("parentcsid =" + knownResourceId +
1830 " itemcsid = " + knownItemResourceId);
1833 // Submit the request to the service and store the response.
1834 PersonAuthorityClient client = new PersonAuthorityClient();
1835 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1836 int statusCode = res.getStatus();
1837 res.releaseConnection();
1839 // Check the status code of the response: does it match
1840 // the expected response(s)?
1841 if(logger.isDebugEnabled()){
1842 logger.debug(testName + ": status = " + statusCode);
1844 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1845 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1846 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1850 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1853 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1854 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1855 public void delete(String testName) throws Exception {
1857 if (logger.isDebugEnabled()) {
1858 logger.debug(testBanner(testName, CLASS_NAME));
1863 if(logger.isDebugEnabled()){
1864 logger.debug("parentcsid =" + knownResourceId);
1867 // Submit the request to the service and store the response.
1868 PersonAuthorityClient client = new PersonAuthorityClient();
1869 ClientResponse<Response> res = client.delete(knownResourceId);
1870 int statusCode = res.getStatus();
1871 res.releaseConnection();
1873 // Check the status code of the response: does it match
1874 // the expected response(s)?
1875 if(logger.isDebugEnabled()){
1876 logger.debug(testName + ": status = " + statusCode);
1878 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1879 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1880 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1885 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1888 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1889 groups = {"delete"}, dependsOnMethods = {"delete"})
1890 public void deleteNonExistent(String testName) throws Exception {
1892 if (logger.isDebugEnabled()) {
1893 logger.debug(testBanner(testName, CLASS_NAME));
1896 setupDeleteNonExistent();
1898 // Submit the request to the service and store the response.
1899 PersonAuthorityClient client = new PersonAuthorityClient();
1900 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1901 int statusCode = res.getStatus();
1902 res.releaseConnection();
1904 // Check the status code of the response: does it match
1905 // the expected response(s)?
1906 if(logger.isDebugEnabled()){
1907 logger.debug(testName + ": status = " + statusCode);
1909 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1910 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1911 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1915 * Delete non existent item.
1917 * @param testName the test name
1919 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1920 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1921 public void deleteNonExistentItem(String testName) {
1923 if (logger.isDebugEnabled()) {
1924 logger.debug(testBanner(testName, CLASS_NAME));
1927 setupDeleteNonExistent();
1929 // Submit the request to the service and store the response.
1930 PersonAuthorityClient client = new PersonAuthorityClient();
1931 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1932 int statusCode = res.getStatus();
1933 res.releaseConnection();
1935 // Check the status code of the response: does it match
1936 // the expected response(s)?
1937 if(logger.isDebugEnabled()){
1938 logger.debug(testName + ": status = " + statusCode);
1940 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1941 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1942 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1946 * Delete non existent contact.
1948 * @param testName the test name
1950 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1951 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1952 public void deleteNonExistentContact(String testName) {
1954 if (logger.isDebugEnabled()) {
1955 logger.debug(testBanner(testName, CLASS_NAME));
1958 setupDeleteNonExistent();
1960 // Submit the request to the service and store the response.
1961 PersonAuthorityClient client = new PersonAuthorityClient();
1962 ClientResponse<Response> res =
1963 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1964 int statusCode = res.getStatus();
1965 res.releaseConnection();
1967 // Check the status code of the response: does it match
1968 // the expected response(s)?
1969 if(logger.isDebugEnabled()){
1970 logger.debug(testName + ": status = " + statusCode);
1972 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1973 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1974 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1977 // ---------------------------------------------------------------
1978 // Utility tests : tests of code used in tests above
1979 // ---------------------------------------------------------------
1981 * Tests the code for manually submitting data that is used by several
1982 * of the methods above.
1984 @Test(dependsOnMethods = {"create", "read"})
1985 public void testSubmitRequest() {
1987 // Expected status code: 200 OK
1988 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1990 // Submit the request to the service and store the response.
1991 String method = ServiceRequestType.READ.httpMethodName();
1992 String url = getResourceURL(knownResourceId);
1993 int statusCode = submitRequest(method, url);
1995 // Check the status code of the response: does it match
1996 // the expected response(s)?
1997 if(logger.isDebugEnabled()){
1998 logger.debug("testSubmitRequest: url=" + url +
1999 " status=" + statusCode);
2001 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2006 * Test item submit request.
2008 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2009 public void testItemSubmitRequest() {
2011 // Expected status code: 200 OK
2012 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2014 // Submit the request to the service and store the response.
2015 String method = ServiceRequestType.READ.httpMethodName();
2016 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2017 int statusCode = submitRequest(method, url);
2019 // Check the status code of the response: does it match
2020 // the expected response(s)?
2021 if(logger.isDebugEnabled()){
2022 logger.debug("testItemSubmitRequest: url=" + url +
2023 " status=" + statusCode);
2025 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2030 * Test contact submit request.
2032 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2033 public void testContactSubmitRequest() {
2035 // Expected status code: 200 OK
2036 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2038 // Submit the request to the service and store the response.
2039 String method = ServiceRequestType.READ.httpMethodName();
2040 String url = getContactResourceURL(knownResourceId,
2041 knownItemResourceId, knownContactResourceId);
2042 int statusCode = submitRequest(method, url);
2044 // Check the status code of the response: does it match
2045 // the expected response(s)?
2046 if(logger.isDebugEnabled()){
2047 logger.debug("testItemSubmitRequest: url=" + url +
2048 " status=" + statusCode);
2050 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2055 // ---------------------------------------------------------------
2056 // Cleanup of resources created during testing
2057 // ---------------------------------------------------------------
2060 * Deletes all resources created by tests, after all tests have been run.
2062 * This cleanup method will always be run, even if one or more tests fail.
2063 * For this reason, it attempts to remove all resources created
2064 * at any point during testing, even if some of those resources
2065 * may be expected to be deleted by certain tests.
2068 @AfterClass(alwaysRun=true)
2070 public void cleanUp() {
2071 String noTest = System.getProperty("noTestCleanup");
2072 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2073 if (logger.isDebugEnabled()) {
2074 logger.debug("Skipping Cleanup phase ...");
2078 if (logger.isDebugEnabled()) {
2079 logger.debug("Cleaning up temporary resources created for testing ...");
2081 String parentResourceId;
2082 String itemResourceId;
2083 String contactResourceId;
2084 // Clean up contact resources.
2085 PersonAuthorityClient client = new PersonAuthorityClient();
2086 parentResourceId = knownResourceId;
2087 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2088 contactResourceId = entry.getKey();
2089 itemResourceId = entry.getValue();
2090 // Note: Any non-success responses from the delete operation
2091 // below are ignored and not reported.
2092 ClientResponse<Response> res =
2093 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2094 res.releaseConnection();
2096 // Clean up item resources.
2097 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2098 itemResourceId = entry.getKey();
2099 parentResourceId = entry.getValue();
2100 // Note: Any non-success responses from the delete operation
2101 // below are ignored and not reported.
2102 ClientResponse<Response> res =
2103 client.deleteItem(parentResourceId, itemResourceId);
2104 res.releaseConnection();
2106 // Clean up parent resources.
2110 // ---------------------------------------------------------------
2111 // Utility methods used by tests above
2112 // ---------------------------------------------------------------
2114 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2117 public String getServicePathComponent() {
2118 return SERVICE_PATH_COMPONENT;
2122 * Gets the item service path component.
2124 * @return the item service path component
2126 public String getItemServicePathComponent() {
2127 return ITEM_SERVICE_PATH_COMPONENT;
2131 * Gets the contact service path component.
2133 * @return the contact service path component
2135 public String getContactServicePathComponent() {
2136 return CONTACT_SERVICE_PATH_COMPONENT;
2140 * Returns the root URL for the item service.
2142 * This URL consists of a base URL for all services, followed by
2143 * a path component for the owning parent, followed by the
2144 * path component for the items.
2146 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2147 * parent authority resource of the relevant item resource.
2149 * @return The root URL for the item service.
2151 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2152 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2156 * Returns the URL of a specific item resource managed by a service, and
2157 * designated by an identifier (such as a universally unique ID, or UUID).
2159 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2160 * parent authority resource of the relevant item resource.
2162 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2165 * @return The URL of a specific item resource managed by a service.
2167 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2168 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2173 * Returns the root URL for the contact service.
2175 * This URL consists of a base URL for all services, followed by
2176 * a path component for the owning authority, followed by the
2177 * path component for the owning item, followed by the path component
2178 * for the contact service.
2180 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2181 * parent authority resource of the relevant item resource.
2183 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2186 * @return The root URL for the contact service.
2188 protected String getContactServiceRootURL(String parentResourceIdentifier,
2189 String itemResourceIdentifier) {
2190 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2191 getContactServicePathComponent();
2195 * Returns the URL of a specific contact resource managed by a service, and
2196 * designated by an identifier (such as a universally unique ID, or UUID).
2198 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2199 * parent resource of the relevant item resource.
2201 * @param resourceIdentifier An identifier (such as a UUID) for an
2204 * @return The URL of a specific resource managed by a service.
2206 protected String getContactResourceURL(String parentResourceIdentifier,
2207 String itemResourceIdentifier, String contactResourceIdentifier) {
2208 return getContactServiceRootURL(parentResourceIdentifier,
2209 itemResourceIdentifier) + "/" + contactResourceIdentifier;