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 + ":"+vcsid+"...");
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);
292 if(logger.isDebugEnabled()){
293 logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")");
296 // Store the IDs from any item resources created
297 // by tests, along with the IDs of their parents, so these items
298 // can be deleted after all tests have been run.
299 allItemResourceIdsCreated.put(newID, vcsid);
305 * Creates the contact.
307 * @param testName the test name
309 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
310 groups = {"create"}, dependsOnMethods = {"createItem"})
311 public void createContact(String testName) {
312 if (logger.isDebugEnabled()) {
313 logger.debug(testBanner(testName, CLASS_NAME));
316 String newID = createContactInItem(knownResourceId, knownItemResourceId);
320 * Creates the contact in item.
322 * @param parentcsid the parentcsid
323 * @param itemcsid the itemcsid
326 private String createContactInItem(String parentcsid, String itemcsid) {
328 final String testName = "createContactInItem";
329 if(logger.isDebugEnabled()){
330 logger.debug(testName + ":...");
335 // Submit the request to the service and store the response.
336 PersonAuthorityClient client = new PersonAuthorityClient();
337 String identifier = createIdentifier();
338 MultipartOutput multipart =
339 ContactClientUtils.createContactInstance(parentcsid,
340 itemcsid, identifier, new ContactClient().getCommonPartName());
343 ClientResponse<Response> res =
344 client.createContact(parentcsid, itemcsid, multipart);
346 int statusCode = res.getStatus();
347 // Check the status code of the response: does it match
348 // the expected response(s)?
349 if(logger.isDebugEnabled()){
350 logger.debug(testName + ": status = " + statusCode);
352 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
353 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
354 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
356 newID = PersonAuthorityClientUtils.extractId(res);
358 res.releaseConnection();
361 // Store the ID returned from the first contact resource created
362 // for additional tests below.
363 if (knownContactResourceId == null){
364 knownContactResourceId = newID;
365 if (logger.isDebugEnabled()) {
366 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
370 // Store the IDs from any contact resources created
371 // by tests, along with the IDs of their parent items,
372 // so these items can be deleted after all tests have been run.
373 allContactResourceIdsCreated.put(newID, itemcsid);
380 // Placeholders until the three tests below can be uncommented.
381 // See Issue CSPACE-401.
383 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
386 public void createWithEmptyEntityBody(String testName) throws Exception {
387 //Should this really be empty?
391 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
394 public void createWithMalformedXml(String testName) throws Exception {
395 //Should this really be empty?
399 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
402 public void createWithWrongXmlSchema(String testName) throws Exception {
403 //Should this really be empty?
408 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
409 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
410 public void createWithEmptyEntityBody(String testName) throws Exception {
412 if (logger.isDebugEnabled()) {
413 logger.debug(testBanner(testName, CLASS_NAME));
416 setupCreateWithEmptyEntityBody();
418 // Submit the request to the service and store the response.
419 String method = REQUEST_TYPE.httpMethodName();
420 String url = getServiceRootURL();
421 String mediaType = MediaType.APPLICATION_XML;
422 final String entity = "";
423 int statusCode = submitRequest(method, url, mediaType, entity);
425 // Check the status code of the response: does it match
426 // the expected response(s)?
427 if(logger.isDebugEnabled()) {
428 logger.debug(testName + ": url=" + url +
429 " status=" + statusCode);
431 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
432 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
433 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
437 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
438 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
439 public void createWithMalformedXml(String testName) throws Exception {
441 if (logger.isDebugEnabled()) {
442 logger.debug(testBanner(testName, CLASS_NAME));
445 setupCreateWithMalformedXml();
447 // Submit the request to the service and store the response.
448 String method = REQUEST_TYPE.httpMethodName();
449 String url = getServiceRootURL();
450 String mediaType = MediaType.APPLICATION_XML;
451 final String entity = MALFORMED_XML_DATA; // Constant from base class.
452 int statusCode = submitRequest(method, url, mediaType, entity);
454 // Check the status code of the response: does it match
455 // the expected response(s)?
456 if(logger.isDebugEnabled()){
457 logger.debug(testName + ": url=" + url +
458 " status=" + statusCode);
460 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
461 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
462 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
466 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
467 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
468 public void createWithWrongXmlSchema(String testName) throws Exception {
470 if (logger.isDebugEnabled()) {
471 logger.debug(testBanner(testName, CLASS_NAME));
474 setupCreateWithWrongXmlSchema();
476 // Submit the request to the service and store the response.
477 String method = REQUEST_TYPE.httpMethodName();
478 String url = getServiceRootURL();
479 String mediaType = MediaType.APPLICATION_XML;
480 final String entity = WRONG_XML_SCHEMA_DATA;
481 int statusCode = submitRequest(method, url, mediaType, entity);
483 // Check the status code of the response: does it match
484 // the expected response(s)?
485 if(logger.isDebugEnabled()){
486 logger.debug(testName + ": url=" + url +
487 " status=" + statusCode);
489 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
490 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
491 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
495 // ---------------------------------------------------------------
496 // CRUD tests : CREATE LIST tests
497 // ---------------------------------------------------------------
500 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
503 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
504 groups = {"createList"}, dependsOnGroups = {"create"})
505 public void createList(String testName) throws Exception {
506 if (logger.isDebugEnabled()) {
507 logger.debug(testBanner(testName, CLASS_NAME));
509 for (int i = 0; i < nItemsToCreateInList; i++) {
515 * Creates the item list.
517 * @param testName the test name
518 * @throws Exception the exception
520 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
521 groups = {"createList"}, dependsOnMethods = {"createList"})
522 public void createItemList(String testName) throws Exception {
523 if (logger.isDebugEnabled()) {
524 logger.debug(testBanner(testName, CLASS_NAME));
526 // Add items to the initially-created, known parent record.
527 for (int j = 0; j < nItemsToCreateInList; j++) {
528 createItem(testName);
533 * Creates the contact list.
535 * @param testName the test name
536 * @throws Exception the exception
538 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
539 groups = {"createList"}, dependsOnMethods = {"createItemList"})
540 public void createContactList(String testName) throws Exception {
541 // Add contacts to the initially-created, known item record.
542 for (int j = 0; j < nItemsToCreateInList; j++) {
543 createContact(testName);
547 // ---------------------------------------------------------------
548 // CRUD tests : READ tests
549 // ---------------------------------------------------------------
552 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
555 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
556 groups = {"read"}, dependsOnGroups = {"create"})
557 public void read(String testName) throws Exception {
558 readInternal(testName, knownResourceId, null);
564 * @param testName the test name
565 * @throws Exception the exception
567 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
568 groups = {"read"}, dependsOnGroups = {"create"})
569 public void readByName(String testName) throws Exception {
570 readInternal(testName, null, knownResourceShortIdentifer);
573 protected void readInternal(String testName, String CSID, String shortId) {
574 if (logger.isDebugEnabled()) {
575 logger.debug(testBanner(testName, CLASS_NAME));
580 // Submit the request to the service and store the response.
581 PersonAuthorityClient client = new PersonAuthorityClient();
582 ClientResponse<MultipartInput> res = null;
584 res = client.read(CSID);
585 } else if(shortId!=null) {
586 res = client.readByName(shortId);
588 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
591 int statusCode = res.getStatus();
592 // Check the status code of the response: does it match
593 // the expected response(s)?
594 if(logger.isDebugEnabled()){
595 logger.debug(testName + ": status = " + statusCode);
597 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
598 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
599 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
600 //FIXME: remove the following try catch once Aron fixes signatures
602 MultipartInput input = (MultipartInput) res.getEntity();
603 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
604 client.getCommonPartName(), PersonauthoritiesCommon.class);
605 Assert.assertNotNull(personAuthority);
606 } catch (Exception e) {
607 throw new RuntimeException(e);
610 res.releaseConnection();
617 * @param testName the test name
618 * @throws Exception the exception
620 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
621 groups = {"readItem"}, dependsOnGroups = {"read"})
622 public void readItem(String testName) throws Exception {
623 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
627 * Read item in Named Auth.
629 * @param testName the test name
630 * @throws Exception the exception
632 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
633 groups = {"readItem"}, dependsOnGroups = {"read"})
634 public void readItemInNamedAuth(String testName) throws Exception {
635 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
641 * @param testName the test name
642 * @throws Exception the exception
644 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
645 groups = {"readItem"}, dependsOnGroups = {"read"})
646 public void readNamedItem(String testName) throws Exception {
647 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
651 * Read Named item in Named Auth.
653 * @param testName the test name
654 * @throws Exception the exception
656 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
657 groups = {"readItem"}, dependsOnGroups = {"read"})
658 public void readNamedItemInNamedAuth(String testName) throws Exception {
659 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
662 protected void readItemInternal(String testName,
663 String authCSID, String authShortId, String itemCSID, String itemShortId)
666 if (logger.isDebugEnabled()) {
667 logger.debug(testBanner(testName, CLASS_NAME));
668 logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+
669 ((itemCSID!=null)?authCSID:itemShortId));
674 // Submit the request to the service and store the response.
675 PersonAuthorityClient client = new PersonAuthorityClient();
676 ClientResponse<MultipartInput> res = null;
679 res = client.readItem(authCSID, itemCSID);
680 } else if(itemShortId!=null) {
681 res = client.readNamedItem(authCSID, itemShortId);
683 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
685 } else if(authShortId!=null) {
687 res = client.readItemInNamedAuthority(authShortId, itemCSID);
688 } else if(itemShortId!=null) {
689 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
691 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
694 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
697 int statusCode = res.getStatus();
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if(logger.isDebugEnabled()){
702 logger.debug(testName + ": status = " + statusCode);
704 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
708 // Check whether we've received a person.
709 MultipartInput input = (MultipartInput) res.getEntity();
710 PersonsCommon person = (PersonsCommon) extractPart(input,
711 client.getItemCommonPartName(), PersonsCommon.class);
712 Assert.assertNotNull(person);
713 boolean showFull = true;
714 if(showFull && logger.isDebugEnabled()){
715 logger.debug(testName + ": returned payload:");
716 logger.debug(objectAsXmlString(person, PersonsCommon.class));
718 Assert.assertEquals(person.getInAuthority(), knownResourceId);
720 res.releaseConnection();
725 * Verify item display name.
727 * @param testName the test name
728 * @throws Exception the exception
730 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
731 dependsOnMethods = {"readItem", "updateItem"})
732 public void verifyItemDisplayName(String testName) throws Exception {
734 if (logger.isDebugEnabled()) {
735 logger.debug(testBanner(testName, CLASS_NAME));
740 // Submit the request to the service and store the response.
741 PersonAuthorityClient client = new PersonAuthorityClient();
742 MultipartInput input =null;
743 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
745 int statusCode = res.getStatus();
747 // Check the status code of the response: does it match
748 // the expected response(s)?
749 if(logger.isDebugEnabled()){
750 logger.debug(testName + ": status = " + statusCode);
752 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
753 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
754 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
756 // Check whether person has expected displayName.
757 input = (MultipartInput) res.getEntity();
759 res.releaseConnection();
762 PersonsCommon person = (PersonsCommon) extractPart(input,
763 client.getItemCommonPartName(), PersonsCommon.class);
764 Assert.assertNotNull(person);
765 String displayName = person.getDisplayName();
766 // Make sure displayName matches computed form
767 String expectedDisplayName =
768 PersonAuthorityClientUtils.prepareDefaultDisplayName(
769 TEST_FORE_NAME, null, TEST_SUR_NAME,
770 TEST_BIRTH_DATE, TEST_DEATH_DATE);
771 Assert.assertNotNull(displayName, expectedDisplayName);
773 // Update the shortName and verify the computed name is updated.
774 person.setCsid(null);
775 person.setDisplayNameComputed(true);
776 person.setForeName("updated-" + TEST_FORE_NAME);
777 expectedDisplayName =
778 PersonAuthorityClientUtils.prepareDefaultDisplayName(
779 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
780 TEST_BIRTH_DATE, TEST_DEATH_DATE);
782 // Submit the updated resource to the service and store the response.
783 MultipartOutput output = new MultipartOutput();
784 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
785 commonPart.getHeaders().add("label", client.getItemCommonPartName());
786 res = client.updateItem(knownResourceId, knownItemResourceId, output);
788 int statusCode = res.getStatus();
790 // Check the status code of the response: does it match the expected response(s)?
791 if(logger.isDebugEnabled()){
792 logger.debug("updateItem: status = " + statusCode);
794 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
795 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
796 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
798 // Retrieve the updated resource and verify that its contents exist.
799 input = (MultipartInput) res.getEntity();
801 res.releaseConnection();
804 PersonsCommon updatedPerson =
805 (PersonsCommon) extractPart(input,
806 client.getItemCommonPartName(), PersonsCommon.class);
807 Assert.assertNotNull(updatedPerson);
809 // Verify that the updated resource received the correct data.
810 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
811 "Updated ForeName in Person did not match submitted data.");
812 // Verify that the updated resource computes the right displayName.
813 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
814 "Updated ForeName in Person not reflected in computed DisplayName.");
816 // Now Update the displayName, not computed and verify the computed name is overriden.
817 person.setDisplayNameComputed(false);
818 expectedDisplayName = "TestName";
819 person.setDisplayName(expectedDisplayName);
821 // Submit the updated resource to the service and store the response.
822 output = new MultipartOutput();
823 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
824 commonPart.getHeaders().add("label", client.getItemCommonPartName());
825 res = client.updateItem(knownResourceId, knownItemResourceId, output);
827 int statusCode = res.getStatus();
829 // Check the status code of the response: does it match the expected response(s)?
830 if(logger.isDebugEnabled()){
831 logger.debug("updateItem: status = " + statusCode);
833 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
834 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
835 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
837 // Retrieve the updated resource and verify that its contents exist.
838 input = (MultipartInput) res.getEntity();
840 res.releaseConnection();
844 (PersonsCommon) extractPart(input,
845 client.getItemCommonPartName(), PersonsCommon.class);
846 Assert.assertNotNull(updatedPerson);
848 // Verify that the updated resource received the correct data.
849 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
850 "Updated displayNameComputed in Person did not match submitted data.");
851 // Verify that the updated resource computes the right displayName.
852 Assert.assertEquals(updatedPerson.getDisplayName(),
854 "Updated DisplayName (not computed) in Person not stored.");
858 * Verify illegal item display name.
860 * @param testName the test name
861 * @throws Exception the exception
863 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
864 dependsOnMethods = {"verifyItemDisplayName"})
865 public void verifyIllegalItemDisplayName(String testName) throws Exception {
867 if (logger.isDebugEnabled()) {
868 logger.debug(testBanner(testName, CLASS_NAME));
871 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
872 // setupUpdateWithWrongXmlSchema(testName);
874 // Submit the request to the service and store the response.
875 PersonAuthorityClient client = new PersonAuthorityClient();
876 MultipartInput input = null;
877 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
879 int statusCode = res.getStatus();
881 // Check the status code of the response: does it match
882 // the expected response(s)?
883 if(logger.isDebugEnabled()){
884 logger.debug(testName + ": status = " + statusCode);
886 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
887 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
888 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
890 // Check whether Person has expected displayName.
891 input = (MultipartInput) res.getEntity();
893 res.releaseConnection();
896 PersonsCommon person = (PersonsCommon) extractPart(input,
897 client.getItemCommonPartName(), PersonsCommon.class);
898 Assert.assertNotNull(person);
899 // Try to Update with computed false and no displayName
900 person.setDisplayNameComputed(false);
901 person.setDisplayName(null);
903 // Submit the updated resource to the service and store the response.
904 MultipartOutput output = new MultipartOutput();
905 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
906 commonPart.getHeaders().add("label", client.getItemCommonPartName());
907 res = client.updateItem(knownResourceId, knownItemResourceId, output);
909 int statusCode = res.getStatus();
911 // Check the status code of the response: does it match the expected response(s)?
912 if(logger.isDebugEnabled()){
913 logger.debug("updateItem: status = " + statusCode);
915 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
916 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
917 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
919 res.releaseConnection();
926 * @param testName the test name
927 * @throws Exception the exception
929 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
930 groups = {"readItem"}, dependsOnMethods = {"readItem"})
931 public void readContact(String testName) throws Exception {
933 if (logger.isDebugEnabled()) {
934 logger.debug(testBanner(testName, CLASS_NAME));
939 // Submit the request to the service and store the response.
940 PersonAuthorityClient client = new PersonAuthorityClient();
941 MultipartInput input = null;
942 ClientResponse<MultipartInput> res =
943 client.readContact(knownResourceId, knownItemResourceId,
944 knownContactResourceId);
946 int statusCode = res.getStatus();
948 // Check the status code of the response: does it match
949 // the expected response(s)?
950 if(logger.isDebugEnabled()){
951 logger.debug(testName + ": status = " + statusCode);
953 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
954 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
955 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
957 // Check whether we've received a contact.
958 input = (MultipartInput) res.getEntity();
960 res.releaseConnection();
963 ContactsCommon contact = (ContactsCommon) extractPart(input,
964 new ContactClient().getCommonPartName(), ContactsCommon.class);
965 Assert.assertNotNull(contact);
966 boolean showFull = true;
967 if(showFull && logger.isDebugEnabled()){
968 logger.debug(testName + ": returned payload:");
969 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
971 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
972 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
978 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
981 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
982 groups = {"read"}, dependsOnMethods = {"read"})
983 public void readNonExistent(String testName) {
985 if (logger.isDebugEnabled()) {
986 logger.debug(testBanner(testName, CLASS_NAME));
989 setupReadNonExistent();
991 // Submit the request to the service and store the response.
992 PersonAuthorityClient client = new PersonAuthorityClient();
993 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
995 int statusCode = res.getStatus();
996 // Check the status code of the response: does it match
997 // the expected response(s)?
998 if(logger.isDebugEnabled()){
999 logger.debug(testName + ": status = " + statusCode);
1001 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1002 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1003 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1005 res.releaseConnection();
1010 * Read item non existent.
1012 * @param testName the test name
1014 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1015 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1016 public void readItemNonExistent(String testName) {
1018 if (logger.isDebugEnabled()) {
1019 logger.debug(testBanner(testName, CLASS_NAME));
1022 setupReadNonExistent();
1024 // Submit the request to the service and store the response.
1025 PersonAuthorityClient client = new PersonAuthorityClient();
1026 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1028 int statusCode = res.getStatus();
1030 // Check the status code of the response: does it match
1031 // the expected response(s)?
1032 if(logger.isDebugEnabled()){
1033 logger.debug(testName + ": status = " + statusCode);
1035 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1036 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1037 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1039 res.releaseConnection();
1044 * Read contact non existent.
1046 * @param testName the test name
1048 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1049 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1050 public void readContactNonExistent(String testName) {
1052 if (logger.isDebugEnabled()) {
1053 logger.debug(testBanner(testName, CLASS_NAME));
1056 setupReadNonExistent();
1058 // Submit the request to the service and store the response.
1059 PersonAuthorityClient client = new PersonAuthorityClient();
1060 ClientResponse<MultipartInput> res =
1061 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1063 int statusCode = res.getStatus();
1065 // Check the status code of the response: does it match
1066 // the expected response(s)?
1067 if(logger.isDebugEnabled()){
1068 logger.debug(testName + ": status = " + statusCode);
1070 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1071 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1072 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1074 res.releaseConnection();
1078 // ---------------------------------------------------------------
1079 // CRUD tests : READ_LIST tests
1080 // ---------------------------------------------------------------
1084 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1087 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1088 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1089 public void readList(String testName) throws Exception {
1091 if (logger.isDebugEnabled()) {
1092 logger.debug(testBanner(testName, CLASS_NAME));
1097 // Submit the request to the service and store the response.
1098 PersonAuthorityClient client = new PersonAuthorityClient();
1099 PersonauthoritiesCommonList list = null;
1100 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1102 int statusCode = res.getStatus();
1104 // Check the status code of the response: does it match
1105 // the expected response(s)?
1106 if(logger.isDebugEnabled()){
1107 logger.debug(testName + ": status = " + statusCode);
1109 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1110 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1111 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1113 list = res.getEntity();
1115 res.releaseConnection();
1118 // Optionally output additional data about list members for debugging.
1119 boolean iterateThroughList = false;
1120 if (iterateThroughList && logger.isDebugEnabled()) {
1121 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1122 list.getPersonauthorityListItem();
1124 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1125 String csid = item.getCsid();
1126 logger.debug(testName + ": list-item[" + i + "] csid=" +
1128 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1129 item.getDisplayName());
1130 logger.debug(testName + ": list-item[" + i + "] URI=" +
1132 readItemList(csid, null, testName);
1141 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1142 groups = {"readList"}, dependsOnMethods = {"readList"})
1143 public void readItemList(String testName) {
1144 readItemList(knownResourceId, null, testName);
1148 * Read item list by authority name.
1150 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1151 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1152 public void readItemListByAuthorityName(String testName) {
1153 readItemList(null, knownResourceShortIdentifer, testName);
1159 * @param vcsid the vcsid
1160 * @param name the name
1162 private void readItemList(String vcsid, String name, String testName) {
1167 // Submit the request to the service and store the response.
1168 PersonAuthorityClient client = new PersonAuthorityClient();
1169 ClientResponse<PersonsCommonList> res = null;
1171 res = client.readItemList(vcsid, null, null);
1172 } else if (name!= null) {
1173 res = client.readItemListForNamedAuthority(name, null, null);
1175 Assert.fail("readItemList passed null csid and name!");
1177 PersonsCommonList list = null;
1179 int statusCode = res.getStatus();
1181 // Check the status code of the response: does it match
1182 // the expected response(s)?
1183 if(logger.isDebugEnabled()){
1184 logger.debug(testName + ": status = " + statusCode);
1186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1190 list = res.getEntity();
1192 res.releaseConnection();
1195 List<PersonsCommonList.PersonListItem> items =
1196 list.getPersonListItem();
1197 int nItemsReturned = items.size();
1198 // There will be one item created, associated with a
1199 // known parent resource, by the createItem test.
1201 // In addition, there will be 'nItemsToCreateInList'
1202 // additional items created by the createItemList test,
1203 // all associated with the same parent resource.
1204 int nExpectedItems = nItemsToCreateInList + 1;
1205 if(logger.isDebugEnabled()){
1206 logger.debug(testName + ": Expected "
1207 + nExpectedItems +" items; got: "+nItemsReturned);
1209 Assert.assertEquals(nItemsReturned, nExpectedItems);
1212 for (PersonsCommonList.PersonListItem item : items) {
1213 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1214 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1215 // Optionally output additional data about list members for debugging.
1216 boolean showDetails = true;
1217 if (showDetails && logger.isDebugEnabled()) {
1218 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1220 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1222 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1223 item.getDisplayName());
1224 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1232 * Read contact list.
1234 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1235 public void readContactList() {
1236 readContactList(knownResourceId, knownItemResourceId);
1240 * Read contact list.
1242 * @param parentcsid the parentcsid
1243 * @param itemcsid the itemcsid
1245 private void readContactList(String parentcsid, String itemcsid) {
1246 final String testName = "readContactList";
1251 // Submit the request to the service and store the response.
1252 PersonAuthorityClient client = new PersonAuthorityClient();
1253 ContactsCommonList list = null;
1254 ClientResponse<ContactsCommonList> res =
1255 client.readContactList(parentcsid, itemcsid);
1257 int statusCode = res.getStatus();
1259 // Check the status code of the response: does it match
1260 // the expected response(s)?
1261 if(logger.isDebugEnabled()){
1262 logger.debug(testName + ": status = " + statusCode);
1264 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1265 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1266 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1268 list = res.getEntity();
1270 res.releaseConnection();
1273 List<ContactsCommonList.ContactListItem> listitems =
1274 list.getContactListItem();
1275 int nItemsReturned = listitems.size();
1276 // There will be one item created, associated with a
1277 // known parent resource, by the createItem test.
1279 // In addition, there will be 'nItemsToCreateInList'
1280 // additional items created by the createItemList test,
1281 // all associated with the same parent resource.
1282 int nExpectedItems = nItemsToCreateInList + 1;
1283 if(logger.isDebugEnabled()){
1284 logger.debug(testName + ": Expected "
1285 + nExpectedItems +" items; got: "+nItemsReturned);
1287 Assert.assertEquals(nItemsReturned, nExpectedItems);
1290 for (ContactsCommonList.ContactListItem listitem : listitems) {
1291 // Optionally output additional data about list members for debugging.
1292 boolean showDetails = false;
1293 if (showDetails && logger.isDebugEnabled()) {
1294 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1295 listitem.getCsid());
1296 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1297 listitem.getAddressPlace());
1298 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1307 // There are no failure outcome tests at present.
1309 // ---------------------------------------------------------------
1310 // CRUD tests : UPDATE tests
1311 // ---------------------------------------------------------------
1314 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1317 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1318 groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1319 public void update(String testName) throws Exception {
1321 if (logger.isDebugEnabled()) {
1322 logger.debug(testBanner(testName, CLASS_NAME));
1327 // Retrieve the contents of a resource to update.
1328 PersonAuthorityClient client = new PersonAuthorityClient();
1329 MultipartInput input = null;
1330 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1332 if(logger.isDebugEnabled()){
1333 logger.debug(testName + ": read status = " + res.getStatus());
1335 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1337 if(logger.isDebugEnabled()){
1338 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1340 input = res.getEntity();
1342 res.releaseConnection();
1345 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1346 client.getCommonPartName(), PersonauthoritiesCommon.class);
1347 Assert.assertNotNull(personAuthority);
1349 // Update the contents of this resource.
1350 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1351 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1352 if(logger.isDebugEnabled()){
1353 logger.debug("to be updated PersonAuthority");
1354 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1357 // Submit the updated resource to the service and store the response.
1358 MultipartOutput output = new MultipartOutput();
1359 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1360 commonPart.getHeaders().add("label", client.getCommonPartName());
1361 res = client.update(knownResourceId, output);
1363 int statusCode = res.getStatus();
1365 // Check the status code of the response: does it match the expected response(s)?
1366 if(logger.isDebugEnabled()){
1367 logger.debug(testName + ": status = " + statusCode);
1369 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1370 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1371 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1373 // Retrieve the updated resource and verify that its contents exist.
1374 input = (MultipartInput) res.getEntity();
1376 res.releaseConnection();
1379 PersonauthoritiesCommon updatedPersonAuthority =
1380 (PersonauthoritiesCommon) extractPart(input,
1381 client.getCommonPartName(), PersonauthoritiesCommon.class);
1382 Assert.assertNotNull(updatedPersonAuthority);
1384 // Verify that the updated resource received the correct data.
1385 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1386 personAuthority.getDisplayName(),
1387 "Data in updated object did not match submitted data.");
1393 * @param testName the test name
1394 * @throws Exception the exception
1396 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1397 groups = {"update"}, dependsOnMethods = {"update"})
1398 public void updateItem(String testName) throws Exception {
1400 if (logger.isDebugEnabled()) {
1401 logger.debug(testBanner(testName, CLASS_NAME));
1406 // Retrieve the contents of a resource to update.
1407 PersonAuthorityClient client = new PersonAuthorityClient();
1408 MultipartInput input = null;
1409 ClientResponse<MultipartInput> res =
1410 client.readItem(knownResourceId, knownItemResourceId);
1412 if(logger.isDebugEnabled()){
1413 logger.debug(testName + ": read status = " + res.getStatus());
1415 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1417 if(logger.isDebugEnabled()){
1418 logger.debug("got Person to update with ID: " +
1419 knownItemResourceId +
1420 " in PersonAuthority: " + knownResourceId );
1422 input = res.getEntity();
1424 res.releaseConnection();
1427 PersonsCommon person = (PersonsCommon) extractPart(input,
1428 client.getItemCommonPartName(), PersonsCommon.class);
1429 Assert.assertNotNull(person);
1431 if (logger.isDebugEnabled() == true) {
1432 logger.debug("About to update the following person...");
1433 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1436 // Update the contents of this resource.
1437 person.setCsid(null);
1438 person.setForeName("updated-" + person.getForeName());
1439 if(logger.isDebugEnabled()){
1440 logger.debug("to be updated Person");
1441 logger.debug(objectAsXmlString(person,
1442 PersonsCommon.class));
1445 // Submit the updated resource to the service and store the response.
1446 MultipartOutput output = new MultipartOutput();
1447 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1448 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1449 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1451 int statusCode = res.getStatus();
1453 // Check the status code of the response: does it match the expected response(s)?
1454 if(logger.isDebugEnabled()){
1455 logger.debug(testName + ": status = " + statusCode);
1457 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1458 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1459 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1461 // Retrieve the updated resource and verify that its contents exist.
1462 input = (MultipartInput) res.getEntity();
1464 res.releaseConnection();
1467 PersonsCommon updatedPerson =
1468 (PersonsCommon) extractPart(input,
1469 client.getItemCommonPartName(), PersonsCommon.class);
1470 Assert.assertNotNull(updatedPerson);
1472 if (logger.isDebugEnabled() == true) {
1473 logger.debug("Updated to following person to:");
1474 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1477 // Verify that the updated resource received the correct data.
1478 Assert.assertEquals(updatedPerson.getForeName(),
1479 person.getForeName(),
1480 "Data in updated Person did not match submitted data.");
1486 * @param testName the test name
1487 * @throws Exception the exception
1489 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1490 groups = {"update"}, dependsOnMethods = {"updateItem"})
1491 public void updateContact(String testName) throws Exception {
1493 if (logger.isDebugEnabled()) {
1494 logger.debug(testBanner(testName, CLASS_NAME));
1499 // Retrieve the contents of a resource to update.
1500 PersonAuthorityClient client = new PersonAuthorityClient();
1501 MultipartInput input = null;
1502 ClientResponse<MultipartInput> res =
1503 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1505 if(logger.isDebugEnabled()){
1506 logger.debug(testName + ": read status = " + res.getStatus());
1508 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1510 if(logger.isDebugEnabled()){
1511 logger.debug("got Contact to update with ID: " +
1512 knownContactResourceId +
1513 " in item: " + knownItemResourceId +
1514 " in parent: " + knownResourceId );
1516 input = res.getEntity();
1518 res.releaseConnection();
1521 ContactsCommon contact = (ContactsCommon) extractPart(input,
1522 new ContactClient().getCommonPartName(), ContactsCommon.class);
1523 Assert.assertNotNull(contact);
1525 // Update the contents of this resource.
1526 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1527 if(logger.isDebugEnabled()){
1528 logger.debug("to be updated Contact");
1529 logger.debug(objectAsXmlString(contact,
1530 ContactsCommon.class));
1533 // Submit the updated resource to the service and store the response.
1534 MultipartOutput output = new MultipartOutput();
1535 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1536 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1537 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1539 int statusCode = res.getStatus();
1541 // Check the status code of the response: does it match the expected response(s)?
1542 if(logger.isDebugEnabled()){
1543 logger.debug(testName + ": status = " + statusCode);
1545 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1546 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1547 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1549 // Retrieve the updated resource and verify that its contents exist.
1550 input = (MultipartInput) res.getEntity();
1552 res.releaseConnection();
1554 ContactsCommon updatedContact =
1555 (ContactsCommon) extractPart(input,
1556 new ContactClient().getCommonPartName(), ContactsCommon.class);
1557 Assert.assertNotNull(updatedContact);
1559 // Verify that the updated resource received the correct data.
1560 Assert.assertEquals(updatedContact.getAddressPlace(),
1561 contact.getAddressPlace(),
1562 "Data in updated Contact did not match submitted data.");
1566 // Placeholders until the three tests below can be uncommented.
1567 // See Issue CSPACE-401.
1569 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1572 public void updateWithEmptyEntityBody(String testName) throws Exception {
1573 //Should this really be empty?
1577 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1580 public void updateWithMalformedXml(String testName) throws Exception {
1581 //Should this really be empty?
1585 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1588 public void updateWithWrongXmlSchema(String testName) throws Exception {
1589 //Should this really be empty?
1594 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1595 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1596 public void updateWithEmptyEntityBody(String testName) throws Exception {
1598 if (logger.isDebugEnabled()) {
1599 logger.debug(testBanner(testName, CLASS_NAME));
1602 setupUpdateWithEmptyEntityBody(testName, logger);
1604 // Submit the request to the service and store the response.
1605 String method = REQUEST_TYPE.httpMethodName();
1606 String url = getResourceURL(knownResourceId);
1607 String mediaType = MediaType.APPLICATION_XML;
1608 final String entity = "";
1609 int statusCode = submitRequest(method, url, mediaType, entity);
1611 // Check the status code of the response: does it match
1612 // the expected response(s)?
1613 if(logger.isDebugEnabled()){
1614 logger.debug(testName + ": url=" + url +
1615 " status=" + statusCode);
1617 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1618 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1619 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1623 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1624 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1625 public void updateWithMalformedXml(String testName) throws Exception {
1627 if (logger.isDebugEnabled()) {
1628 logger.debug(testBanner(testName, CLASS_NAME));
1631 setupUpdateWithMalformedXml();
1633 // Submit the request to the service and store the response.
1634 String method = REQUEST_TYPE.httpMethodName();
1635 String url = getResourceURL(knownResourceId);
1636 String mediaType = MediaType.APPLICATION_XML;
1637 final String entity = MALFORMED_XML_DATA;
1638 int statusCode = submitRequest(method, url, mediaType, entity);
1640 // Check the status code of the response: does it match
1641 // the expected response(s)?
1642 if(logger.isDebugEnabled()){
1643 logger.debug(testName + ": url=" + url +
1644 " status=" + statusCode);
1646 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1647 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1648 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1652 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1653 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1654 public void updateWithWrongXmlSchema(String testName) throws Exception {
1656 if (logger.isDebugEnabled()) {
1657 logger.debug(testBanner(testName, CLASS_NAME));
1660 setupUpdateWithWrongXmlSchema();
1662 // Submit the request to the service and store the response.
1663 String method = REQUEST_TYPE.httpMethodName();
1664 String url = getResourceURL(knownResourceId);
1665 String mediaType = MediaType.APPLICATION_XML;
1666 final String entity = WRONG_XML_SCHEMA_DATA;
1667 int statusCode = submitRequest(method, url, mediaType, entity);
1669 // Check the status code of the response: does it match
1670 // the expected response(s)?
1671 if(logger.isDebugEnabled()){
1672 logger.debug("updateWithWrongXmlSchema: url=" + url +
1673 " status=" + statusCode);
1675 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1676 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1677 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1682 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1685 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1686 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1687 public void updateNonExistent(String testName) throws Exception {
1689 if (logger.isDebugEnabled()) {
1690 logger.debug(testBanner(testName, CLASS_NAME));
1693 setupUpdateNonExistent();
1695 // Submit the request to the service and store the response.
1696 // Note: The ID(s) used when creating the request payload may be arbitrary.
1697 // The only relevant ID may be the one used in update(), below.
1698 PersonAuthorityClient client = new PersonAuthorityClient();
1699 String displayName = "displayName-NON_EXISTENT_ID";
1700 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1701 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1702 ClientResponse<MultipartInput> res =
1703 client.update(NON_EXISTENT_ID, multipart);
1705 int statusCode = res.getStatus();
1707 // Check the status code of the response: does it match
1708 // the expected response(s)?
1709 if(logger.isDebugEnabled()){
1710 logger.debug(testName + ": status = " + statusCode);
1712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1716 res.releaseConnection();
1721 * Update non existent item.
1723 * @param testName the test name
1724 * @throws Exception the exception
1726 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1727 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1728 public void updateNonExistentItem(String testName) throws Exception {
1730 if (logger.isDebugEnabled()) {
1731 logger.debug(testBanner(testName, CLASS_NAME));
1734 setupUpdateNonExistent();
1736 // Submit the request to the service and store the response.
1737 // Note: The ID used in this 'create' call may be arbitrary.
1738 // The only relevant ID may be the one used in update(), below.
1739 PersonAuthorityClient client = new PersonAuthorityClient();
1740 Map<String, String> nonexMap = new HashMap<String,String>();
1741 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1742 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1743 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1744 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1745 MultipartOutput multipart =
1746 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1747 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1748 nonexMap, client.getItemCommonPartName() );
1749 ClientResponse<MultipartInput> res =
1750 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1752 int statusCode = res.getStatus();
1754 // Check the status code of the response: does it match
1755 // the expected response(s)?
1756 if(logger.isDebugEnabled()){
1757 logger.debug(testName + ": status = " + statusCode);
1759 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1760 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1761 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1763 res.releaseConnection();
1768 * Update non existent contact.
1770 * @param testName the test name
1771 * @throws Exception the exception
1773 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1774 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1775 public void updateNonExistentContact(String testName) throws Exception {
1776 // Currently a no-op test
1779 // ---------------------------------------------------------------
1780 // CRUD tests : DELETE tests
1781 // ---------------------------------------------------------------
1784 // Note: delete sub-resources in ascending hierarchical order,
1785 // before deleting their parents.
1790 * @param testName the test name
1791 * @throws Exception the exception
1793 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1794 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1795 public void deleteContact(String testName) throws Exception {
1797 if (logger.isDebugEnabled()) {
1798 logger.debug(testBanner(testName, CLASS_NAME));
1803 if(logger.isDebugEnabled()){
1804 logger.debug("parentcsid =" + knownResourceId +
1805 " itemcsid = " + knownItemResourceId +
1806 " csid = " + knownContactResourceId);
1809 // Submit the request to the service and store the response.
1810 PersonAuthorityClient client = new PersonAuthorityClient();
1811 ClientResponse<Response> res =
1812 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1814 int statusCode = res.getStatus();
1816 // Check the status code of the response: does it match
1817 // the expected response(s)?
1818 if(logger.isDebugEnabled()){
1819 logger.debug(testName + ": status = " + statusCode);
1821 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1822 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1823 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1825 res.releaseConnection();
1832 * @param testName the test name
1833 * @throws Exception the exception
1835 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1836 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1837 public void deleteItem(String testName) throws Exception {
1839 if (logger.isDebugEnabled()) {
1840 logger.debug(testBanner(testName, CLASS_NAME));
1845 if(logger.isDebugEnabled()){
1846 logger.debug("parentcsid =" + knownResourceId +
1847 " itemcsid = " + knownItemResourceId);
1850 // Submit the request to the service and store the response.
1851 PersonAuthorityClient client = new PersonAuthorityClient();
1852 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1854 int statusCode = res.getStatus();
1856 // Check the status code of the response: does it match
1857 // the expected response(s)?
1858 if(logger.isDebugEnabled()){
1859 logger.debug(testName + ": status = " + statusCode);
1861 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1862 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1863 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1865 res.releaseConnection();
1870 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1873 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1874 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1875 public void delete(String testName) throws Exception {
1877 if (logger.isDebugEnabled()) {
1878 logger.debug(testBanner(testName, CLASS_NAME));
1883 if(logger.isDebugEnabled()){
1884 logger.debug("parentcsid =" + knownResourceId);
1887 // Submit the request to the service and store the response.
1888 PersonAuthorityClient client = new PersonAuthorityClient();
1889 ClientResponse<Response> res = client.delete(knownResourceId);
1891 int statusCode = res.getStatus();
1893 // Check the status code of the response: does it match
1894 // the expected response(s)?
1895 if(logger.isDebugEnabled()){
1896 logger.debug(testName + ": status = " + statusCode);
1898 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1899 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1900 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1902 res.releaseConnection();
1908 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1911 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1912 groups = {"delete"}, dependsOnMethods = {"delete"})
1913 public void deleteNonExistent(String testName) throws Exception {
1915 if (logger.isDebugEnabled()) {
1916 logger.debug(testBanner(testName, CLASS_NAME));
1919 setupDeleteNonExistent();
1921 // Submit the request to the service and store the response.
1922 PersonAuthorityClient client = new PersonAuthorityClient();
1923 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1925 int statusCode = res.getStatus();
1927 // Check the status code of the response: does it match
1928 // the expected response(s)?
1929 if(logger.isDebugEnabled()){
1930 logger.debug(testName + ": status = " + statusCode);
1932 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1933 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1934 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1936 res.releaseConnection();
1941 * Delete non existent item.
1943 * @param testName the test name
1945 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1946 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1947 public void deleteNonExistentItem(String testName) {
1949 if (logger.isDebugEnabled()) {
1950 logger.debug(testBanner(testName, CLASS_NAME));
1953 setupDeleteNonExistent();
1955 // Submit the request to the service and store the response.
1956 PersonAuthorityClient client = new PersonAuthorityClient();
1957 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1959 int statusCode = res.getStatus();
1961 // Check the status code of the response: does it match
1962 // the expected response(s)?
1963 if(logger.isDebugEnabled()){
1964 logger.debug(testName + ": status = " + statusCode);
1966 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1967 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1968 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1970 res.releaseConnection();
1975 * Delete non existent contact.
1977 * @param testName the test name
1979 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1980 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1981 public void deleteNonExistentContact(String testName) {
1983 if (logger.isDebugEnabled()) {
1984 logger.debug(testBanner(testName, CLASS_NAME));
1987 setupDeleteNonExistent();
1989 // Submit the request to the service and store the response.
1990 PersonAuthorityClient client = new PersonAuthorityClient();
1991 ClientResponse<Response> res =
1992 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1994 int statusCode = res.getStatus();
1996 // Check the status code of the response: does it match
1997 // the expected response(s)?
1998 if(logger.isDebugEnabled()){
1999 logger.debug(testName + ": status = " + statusCode);
2001 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2002 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2003 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2005 res.releaseConnection();
2009 // ---------------------------------------------------------------
2010 // Utility tests : tests of code used in tests above
2011 // ---------------------------------------------------------------
2013 * Tests the code for manually submitting data that is used by several
2014 * of the methods above.
2016 @Test(dependsOnMethods = {"create", "read"})
2017 public void testSubmitRequest() {
2019 // Expected status code: 200 OK
2020 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2022 // Submit the request to the service and store the response.
2023 String method = ServiceRequestType.READ.httpMethodName();
2024 String url = getResourceURL(knownResourceId);
2025 int statusCode = submitRequest(method, url);
2027 // Check the status code of the response: does it match
2028 // the expected response(s)?
2029 if(logger.isDebugEnabled()){
2030 logger.debug("testSubmitRequest: url=" + url +
2031 " status=" + statusCode);
2033 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2038 * Test item submit request.
2040 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2041 public void testItemSubmitRequest() {
2043 // Expected status code: 200 OK
2044 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2046 // Submit the request to the service and store the response.
2047 String method = ServiceRequestType.READ.httpMethodName();
2048 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2049 int statusCode = submitRequest(method, url);
2051 // Check the status code of the response: does it match
2052 // the expected response(s)?
2053 if(logger.isDebugEnabled()){
2054 logger.debug("testItemSubmitRequest: url=" + url +
2055 " status=" + statusCode);
2057 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2062 * Test contact submit request.
2064 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2065 public void testContactSubmitRequest() {
2067 // Expected status code: 200 OK
2068 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2070 // Submit the request to the service and store the response.
2071 String method = ServiceRequestType.READ.httpMethodName();
2072 String url = getContactResourceURL(knownResourceId,
2073 knownItemResourceId, knownContactResourceId);
2074 int statusCode = submitRequest(method, url);
2076 // Check the status code of the response: does it match
2077 // the expected response(s)?
2078 if(logger.isDebugEnabled()){
2079 logger.debug("testItemSubmitRequest: url=" + url +
2080 " status=" + statusCode);
2082 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2087 // ---------------------------------------------------------------
2088 // Cleanup of resources created during testing
2089 // ---------------------------------------------------------------
2092 * Deletes all resources created by tests, after all tests have been run.
2094 * This cleanup method will always be run, even if one or more tests fail.
2095 * For this reason, it attempts to remove all resources created
2096 * at any point during testing, even if some of those resources
2097 * may be expected to be deleted by certain tests.
2100 @AfterClass(alwaysRun=true)
2102 public void cleanUp() {
2103 String noTest = System.getProperty("noTestCleanup");
2104 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2105 if (logger.isDebugEnabled()) {
2106 logger.debug("Skipping Cleanup phase ...");
2110 if (logger.isDebugEnabled()) {
2111 logger.debug("Cleaning up temporary resources created for testing ...");
2113 String parentResourceId;
2114 String itemResourceId;
2115 String contactResourceId;
2116 // Clean up contact resources.
2117 PersonAuthorityClient client = new PersonAuthorityClient();
2118 parentResourceId = knownResourceId;
2119 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2120 contactResourceId = entry.getKey();
2121 itemResourceId = entry.getValue();
2122 // Note: Any non-success responses from the delete operation
2123 // below are ignored and not reported.
2124 ClientResponse<Response> res =
2125 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2126 res.releaseConnection();
2128 // Clean up item resources.
2129 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2130 itemResourceId = entry.getKey();
2131 parentResourceId = entry.getValue();
2132 // Note: Any non-success responses from the delete operation
2133 // below are ignored and not reported.
2134 ClientResponse<Response> res =
2135 client.deleteItem(parentResourceId, itemResourceId);
2136 res.releaseConnection();
2138 // Clean up parent resources.
2142 // ---------------------------------------------------------------
2143 // Utility methods used by tests above
2144 // ---------------------------------------------------------------
2146 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2149 public String getServicePathComponent() {
2150 return SERVICE_PATH_COMPONENT;
2154 * Gets the item service path component.
2156 * @return the item service path component
2158 public String getItemServicePathComponent() {
2159 return ITEM_SERVICE_PATH_COMPONENT;
2163 * Gets the contact service path component.
2165 * @return the contact service path component
2167 public String getContactServicePathComponent() {
2168 return CONTACT_SERVICE_PATH_COMPONENT;
2172 * Returns the root URL for the item service.
2174 * This URL consists of a base URL for all services, followed by
2175 * a path component for the owning parent, followed by the
2176 * path component for the items.
2178 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2179 * parent authority resource of the relevant item resource.
2181 * @return The root URL for the item service.
2183 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2184 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2188 * Returns the URL of a specific item resource managed by a service, and
2189 * designated by an identifier (such as a universally unique ID, or UUID).
2191 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2192 * parent authority resource of the relevant item resource.
2194 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2197 * @return The URL of a specific item resource managed by a service.
2199 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2200 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2205 * Returns the root URL for the contact service.
2207 * This URL consists of a base URL for all services, followed by
2208 * a path component for the owning authority, followed by the
2209 * path component for the owning item, followed by the path component
2210 * for the contact service.
2212 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2213 * parent authority resource of the relevant item resource.
2215 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2218 * @return The root URL for the contact service.
2220 protected String getContactServiceRootURL(String parentResourceIdentifier,
2221 String itemResourceIdentifier) {
2222 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2223 getContactServicePathComponent();
2227 * Returns the URL of a specific contact resource managed by a service, and
2228 * designated by an identifier (such as a universally unique ID, or UUID).
2230 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2231 * parent resource of the relevant item resource.
2233 * @param resourceIdentifier An identifier (such as a UUID) for an
2236 * @return The URL of a specific resource managed by a service.
2238 protected String getContactResourceURL(String parentResourceIdentifier,
2239 String itemResourceIdentifier, String contactResourceIdentifier) {
2240 return getContactServiceRootURL(parentResourceIdentifier,
2241 itemResourceIdentifier) + "/" + contactResourceIdentifier;