2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
32 import org.collectionspace.services.PersonJAXBSchema;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.ContactClient;
35 import org.collectionspace.services.client.ContactClientUtils;
36 import org.collectionspace.services.contact.ContactsCommon;
37 import org.collectionspace.services.contact.ContactsCommonList;
38 import org.collectionspace.services.client.PersonAuthorityClient;
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.person.PersonauthoritiesCommon;
42 import org.collectionspace.services.person.PersonauthoritiesCommonList;
43 import org.collectionspace.services.person.PersonsCommon;
44 import org.collectionspace.services.person.PersonsCommonList;
45 import org.jboss.resteasy.client.ClientResponse;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
47 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
48 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.AfterClass;
53 import org.testng.annotations.Test;
56 * PersonAuthorityServiceTest, carries out tests against a
57 * deployed and running PersonAuthority Service.
59 * $LastChangedRevision: 753 $
60 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
62 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
65 private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
66 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
68 // Instance variables specific to this test.
69 /** The service path component. */
70 final String SERVICE_PATH_COMPONENT = "personauthorities";
72 /** The item service path component. */
73 final String ITEM_SERVICE_PATH_COMPONENT = "items";
75 /** The contact service path component. */
76 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
78 /** The test forename. */
79 final String TEST_FORE_NAME = "John";
81 /** The test middle name. */
82 final String TEST_MIDDLE_NAME = null;
84 /** The test surname. */
85 final String TEST_SUR_NAME = "Wayne";
87 /** The test birthdate. */
88 final String TEST_BIRTH_DATE = "May 26, 1907";
90 /** The test death date. */
91 final String TEST_DEATH_DATE = "June 11, 1979";
93 // Hold some values for a recently created item to verify upon read.
94 private String knownResourceId = null;
95 private String knownResourceShortIdentifer = null;
96 private String knownResourceRefName = null;
97 private String knownItemResourceId = null;
98 private String knownItemResourceShortIdentifer = null;
100 // The resource ID of an item resource used for partial term matching tests.
101 private String knownItemPartialTermResourceId = null;
103 /** The known contact resource id. */
104 private String knownContactResourceId = null;
106 /** The n items to create in list. */
107 private int nItemsToCreateInList = 3;
109 /** The all item resource ids created. */
110 private Map<String, String> allItemResourceIdsCreated =
111 new HashMap<String, String>();
113 /** The all contact resource ids created. */
114 private Map<String, String> allContactResourceIdsCreated =
115 new HashMap<String, String>();
117 protected void setKnownResource( String id, String shortIdentifer,
119 knownResourceId = id;
120 knownResourceShortIdentifer = shortIdentifer;
121 knownResourceRefName = refName;
124 protected void setKnownItemResource( String id, String shortIdentifer ) {
125 knownItemResourceId = id;
126 knownItemResourceShortIdentifer = shortIdentifer;
131 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
134 protected CollectionSpaceClient getClientInstance() {
135 return new PersonAuthorityClient();
139 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
142 protected AbstractCommonList getAbstractCommonList(
143 ClientResponse<AbstractCommonList> response) {
144 return response.getEntity(PersonsCommonList.class);
147 // ---------------------------------------------------------------
148 // CRUD tests : CREATE tests
149 // ---------------------------------------------------------------
152 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
155 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
157 public void create(String testName) throws Exception {
159 if (logger.isDebugEnabled()) {
160 logger.debug(testBanner(testName, CLASS_NAME));
162 // Perform setup, such as initializing the type of service request
163 // (e.g. CREATE, DELETE), its valid and expected status codes, and
164 // its associated HTTP method name (e.g. POST, DELETE).
167 // Submit the request to the service and store the response.
168 PersonAuthorityClient client = new PersonAuthorityClient();
169 String shortId = createIdentifier();
170 String displayName = "displayName-" + shortId;
171 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
172 MultipartOutput multipart =
173 PersonAuthorityClientUtils.createPersonAuthorityInstance(
174 displayName, shortId, client.getCommonPartName());
177 ClientResponse<Response> res = client.create(multipart);
179 int statusCode = res.getStatus();
181 // Check the status code of the response: does it match
182 // the expected response(s)?
185 // Does it fall within the set of valid status codes?
186 // Does it exactly match the expected status code?
187 if(logger.isDebugEnabled()){
188 logger.debug(testName + ": status = " + statusCode);
190 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
191 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
192 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
194 newID = PersonAuthorityClientUtils.extractId(res);
196 res.releaseConnection();
198 // Save values for additional tests
199 if (knownResourceId == null){
200 setKnownResource( newID, shortId, baseRefName );
201 if (logger.isDebugEnabled()) {
202 logger.debug(testName + ": knownResourceId=" + knownResourceId);
205 // Store the IDs from every resource created by tests,
206 // so they can be deleted after tests have been run.
207 allResourceIdsCreated.add(newID);
213 * @param testName the test name
215 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
216 groups = {"create"}, dependsOnMethods = {"create"})
217 public void createItem(String testName) {
218 if (logger.isDebugEnabled()) {
219 logger.debug(testBanner(testName, CLASS_NAME));
222 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
226 * Creates the item in authority.
228 * @param vcsid the vcsid
229 * @param authRefName the auth ref name
232 private String createItemInAuthority(String vcsid, String authRefName) {
234 final String testName = "createItemInAuthority";
235 if(logger.isDebugEnabled()){
236 logger.debug(testName + ":"+vcsid+"...");
239 // Submit the request to the service and store the response.
240 PersonAuthorityClient client = new PersonAuthorityClient();
242 Map<String, String> johnWayneMap = new HashMap<String,String>();
244 // Fill the property map
246 String shortId = "johnWayneActor";
247 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
248 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
249 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
250 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayne");
251 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
253 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
254 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
255 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
256 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
257 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
258 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
259 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
260 "known by his stage name John Wayne, was an American film actor, director " +
261 "and producer. He epitomized rugged masculinity and has become an enduring " +
262 "American icon. He is famous for his distinctive voice, walk and height. " +
263 "He was also known for his conservative political views and his support in " +
264 "the 1950s for anti-communist positions.");
266 Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String,List<String>>();
267 List<String> johnWayneGroups = new ArrayList<String>();
268 johnWayneGroups.add("Irish");
269 johnWayneGroups.add("Scottish");
270 johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
272 MultipartOutput multipart =
273 PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
274 johnWayneRepeatablesMap, client.getItemCommonPartName() );
277 ClientResponse<Response> res = client.createItem(vcsid, multipart);
279 int statusCode = res.getStatus();
280 // Check the status code of the response: does it match
281 // the expected response(s)?
282 if(logger.isDebugEnabled()){
283 logger.debug(testName + ": status = " + statusCode);
285 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
286 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
287 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
289 newID = PersonAuthorityClientUtils.extractId(res);
291 res.releaseConnection();
294 // Store the ID returned from the first item resource created
295 // for additional tests below.
296 if (knownItemResourceId == null){
297 setKnownItemResource(newID, shortId);
298 if (logger.isDebugEnabled()) {
299 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
302 if(logger.isDebugEnabled()){
303 logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")");
306 // Store the IDs from any item resources created
307 // by tests, along with the IDs of their parents, so these items
308 // can be deleted after all tests have been run.
309 allItemResourceIdsCreated.put(newID, vcsid);
315 * Creates the contact.
317 * @param testName the test name
319 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
320 groups = {"create"}, dependsOnMethods = {"createItem"})
321 public void createContact(String testName) {
322 if (logger.isDebugEnabled()) {
323 logger.debug(testBanner(testName, CLASS_NAME));
326 String newID = createContactInItem(knownResourceId, knownItemResourceId);
330 * Creates the contact in item.
332 * @param parentcsid the parentcsid
333 * @param itemcsid the itemcsid
336 private String createContactInItem(String parentcsid, String itemcsid) {
338 final String testName = "createContactInItem";
339 if(logger.isDebugEnabled()){
340 logger.debug(testName + ":...");
345 // Submit the request to the service and store the response.
346 PersonAuthorityClient client = new PersonAuthorityClient();
347 String identifier = createIdentifier();
348 MultipartOutput multipart =
349 ContactClientUtils.createContactInstance(parentcsid,
350 itemcsid, identifier, new ContactClient().getCommonPartName());
353 ClientResponse<Response> res =
354 client.createContact(parentcsid, itemcsid, multipart);
356 int statusCode = res.getStatus();
357 // Check the status code of the response: does it match
358 // the expected response(s)?
359 if(logger.isDebugEnabled()){
360 logger.debug(testName + ": status = " + statusCode);
362 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
366 newID = PersonAuthorityClientUtils.extractId(res);
368 res.releaseConnection();
371 // Store the ID returned from the first contact resource created
372 // for additional tests below.
373 if (knownContactResourceId == null){
374 knownContactResourceId = newID;
375 if (logger.isDebugEnabled()) {
376 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
380 // Store the IDs from any contact resources created
381 // by tests, along with the IDs of their parent items,
382 // so these items can be deleted after all tests have been run.
383 allContactResourceIdsCreated.put(newID, itemcsid);
390 // Placeholders until the three tests below can be uncommented.
391 // See Issue CSPACE-401.
393 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
396 public void createWithEmptyEntityBody(String testName) throws Exception {
397 //Should this really be empty?
401 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
404 public void createWithMalformedXml(String testName) throws Exception {
405 //Should this really be empty?
409 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
412 public void createWithWrongXmlSchema(String testName) throws Exception {
413 //Should this really be empty?
418 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
419 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
420 public void createWithEmptyEntityBody(String testName) throws Exception {
422 if (logger.isDebugEnabled()) {
423 logger.debug(testBanner(testName, CLASS_NAME));
426 setupCreateWithEmptyEntityBody();
428 // Submit the request to the service and store the response.
429 String method = REQUEST_TYPE.httpMethodName();
430 String url = getServiceRootURL();
431 String mediaType = MediaType.APPLICATION_XML;
432 final String entity = "";
433 int statusCode = submitRequest(method, url, mediaType, entity);
435 // Check the status code of the response: does it match
436 // the expected response(s)?
437 if(logger.isDebugEnabled()) {
438 logger.debug(testName + ": url=" + url +
439 " status=" + statusCode);
441 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
442 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
443 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
448 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
449 public void createWithMalformedXml(String testName) throws Exception {
451 if (logger.isDebugEnabled()) {
452 logger.debug(testBanner(testName, CLASS_NAME));
455 setupCreateWithMalformedXml();
457 // Submit the request to the service and store the response.
458 String method = REQUEST_TYPE.httpMethodName();
459 String url = getServiceRootURL();
460 String mediaType = MediaType.APPLICATION_XML;
461 final String entity = MALFORMED_XML_DATA; // Constant from base class.
462 int statusCode = submitRequest(method, url, mediaType, entity);
464 // Check the status code of the response: does it match
465 // the expected response(s)?
466 if(logger.isDebugEnabled()){
467 logger.debug(testName + ": url=" + url +
468 " status=" + statusCode);
470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
476 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
477 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
478 public void createWithWrongXmlSchema(String testName) throws Exception {
480 if (logger.isDebugEnabled()) {
481 logger.debug(testBanner(testName, CLASS_NAME));
484 setupCreateWithWrongXmlSchema();
486 // Submit the request to the service and store the response.
487 String method = REQUEST_TYPE.httpMethodName();
488 String url = getServiceRootURL();
489 String mediaType = MediaType.APPLICATION_XML;
490 final String entity = WRONG_XML_SCHEMA_DATA;
491 int statusCode = submitRequest(method, url, mediaType, entity);
493 // Check the status code of the response: does it match
494 // the expected response(s)?
495 if(logger.isDebugEnabled()){
496 logger.debug(testName + ": url=" + url +
497 " status=" + statusCode);
499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
505 // ---------------------------------------------------------------
506 // CRUD tests : CREATE LIST tests
507 // ---------------------------------------------------------------
510 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
513 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
514 groups = {"createList"}, dependsOnGroups = {"create"})
515 public void createList(String testName) throws Exception {
516 if (logger.isDebugEnabled()) {
517 logger.debug(testBanner(testName, CLASS_NAME));
519 for (int i = 0; i < nItemsToCreateInList; i++) {
525 * Creates the item list.
527 * @param testName the test name
528 * @throws Exception the exception
530 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
531 groups = {"createList"}, dependsOnMethods = {"createList"})
532 public void createItemList(String testName) throws Exception {
533 if (logger.isDebugEnabled()) {
534 logger.debug(testBanner(testName, CLASS_NAME));
536 // Add items to the initially-created, known parent record.
537 for (int j = 0; j < nItemsToCreateInList; j++) {
538 createItem(testName);
543 * Creates the contact list.
545 * @param testName the test name
546 * @throws Exception the exception
548 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
549 groups = {"createList"}, dependsOnMethods = {"createItemList"})
550 public void createContactList(String testName) throws Exception {
551 // Add contacts to the initially-created, known item record.
552 for (int j = 0; j < nItemsToCreateInList; j++) {
553 createContact(testName);
557 // ---------------------------------------------------------------
558 // CRUD tests : READ tests
559 // ---------------------------------------------------------------
562 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
565 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
566 groups = {"read"}, dependsOnGroups = {"create"})
567 public void read(String testName) throws Exception {
568 readInternal(testName, knownResourceId, null);
574 * @param testName the test name
575 * @throws Exception the exception
577 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
578 groups = {"read"}, dependsOnMethods = {"read"})
579 public void readByName(String testName) throws Exception {
580 readInternal(testName, null, knownResourceShortIdentifer);
583 protected void readInternal(String testName, String CSID, String shortId) {
584 if (logger.isDebugEnabled()) {
585 logger.debug(testBanner(testName, CLASS_NAME));
590 // Submit the request to the service and store the response.
591 PersonAuthorityClient client = new PersonAuthorityClient();
592 ClientResponse<MultipartInput> res = null;
594 res = client.read(CSID);
595 } else if(shortId!=null) {
596 res = client.readByName(shortId);
598 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
601 int statusCode = res.getStatus();
602 // Check the status code of the response: does it match
603 // the expected response(s)?
604 if(logger.isDebugEnabled()){
605 logger.debug(testName + ": status = " + statusCode);
607 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 //FIXME: remove the following try catch once Aron fixes signatures
612 MultipartInput input = (MultipartInput) res.getEntity();
613 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
614 client.getCommonPartName(), PersonauthoritiesCommon.class);
615 Assert.assertNotNull(personAuthority);
616 } catch (Exception e) {
617 throw new RuntimeException(e);
620 res.releaseConnection();
627 * @param testName the test name
628 * @throws Exception the exception
630 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
631 groups = {"readItem"}, dependsOnGroups = {"read"})
632 public void readItem(String testName) throws Exception {
633 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
637 * Read item in Named Auth.
639 * @param testName the test name
640 * @throws Exception the exception
642 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
643 groups = {"readItem"}, dependsOnMethods = {"readItem"})
644 public void readItemInNamedAuth(String testName) throws Exception {
645 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
651 * @param testName the test name
652 * @throws Exception the exception
654 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
655 groups = {"readItem"}, dependsOnMethods = {"readItem"})
656 public void readNamedItem(String testName) throws Exception {
657 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
661 * Read Named item in Named Auth.
663 * @param testName the test name
664 * @throws Exception the exception
666 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
667 groups = {"readItem"}, dependsOnMethods = {"readItem"})
668 public void readNamedItemInNamedAuth(String testName) throws Exception {
669 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
672 protected void readItemInternal(String testName,
673 String authCSID, String authShortId, String itemCSID, String itemShortId)
676 if (logger.isDebugEnabled()) {
677 logger.debug(testBanner(testName, CLASS_NAME));
678 logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+
679 ((itemCSID!=null)?authCSID:itemShortId));
684 // Submit the request to the service and store the response.
685 PersonAuthorityClient client = new PersonAuthorityClient();
686 ClientResponse<MultipartInput> res = null;
689 res = client.readItem(authCSID, itemCSID);
690 } else if(itemShortId!=null) {
691 res = client.readNamedItem(authCSID, itemShortId);
693 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
695 } else if(authShortId!=null) {
697 res = client.readItemInNamedAuthority(authShortId, itemCSID);
698 } else if(itemShortId!=null) {
699 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
701 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
704 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
707 int statusCode = res.getStatus();
709 // Check the status code of the response: does it match
710 // the expected response(s)?
711 if(logger.isDebugEnabled()){
712 logger.debug(testName + ": status = " + statusCode);
714 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
715 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
716 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
718 // Check whether we've received a person.
719 MultipartInput input = (MultipartInput) res.getEntity();
720 PersonsCommon person = (PersonsCommon) extractPart(input,
721 client.getItemCommonPartName(), PersonsCommon.class);
722 Assert.assertNotNull(person);
723 boolean showFull = true;
724 if(showFull && logger.isDebugEnabled()){
725 logger.debug(testName + ": returned payload:");
726 logger.debug(objectAsXmlString(person, PersonsCommon.class));
729 // Check that the person item is within the expected Person Authority.
730 Assert.assertEquals(person.getInAuthority(), knownResourceId);
732 // Verify the number and contents of values in a repeatable field,
733 // as created in the instance record used for testing.
734 List<String> groups = person.getGroups().getGroup();
735 Assert.assertTrue(groups.size() > 0);
736 Assert.assertNotNull(groups.get(0));
739 res.releaseConnection();
744 * Verify item display name.
746 * @param testName the test name
747 * @throws Exception the exception
749 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
750 groups = {"update"}, dependsOnMethods = {"updateItem"})
751 public void verifyItemDisplayNames(String testName) throws Exception {
753 if (logger.isDebugEnabled()) {
754 logger.debug(testBanner(testName, CLASS_NAME));
759 // Submit the request to the service and store the response.
760 PersonAuthorityClient client = new PersonAuthorityClient();
761 MultipartInput input =null;
762 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
764 int statusCode = res.getStatus();
766 // Check the status code of the response: does it match
767 // the expected response(s)?
768 if(logger.isDebugEnabled()){
769 logger.debug(testName + ": status = " + statusCode);
771 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
772 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
773 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
775 // Check whether person has expected displayName.
776 input = (MultipartInput) res.getEntity();
778 res.releaseConnection();
781 PersonsCommon person = (PersonsCommon) extractPart(input,
782 client.getItemCommonPartName(), PersonsCommon.class);
783 Assert.assertNotNull(person);
784 String displayName = person.getDisplayName();
785 // Make sure displayName matches computed form
786 String expectedDisplayName =
787 PersonAuthorityClientUtils.prepareDefaultDisplayName(
788 TEST_FORE_NAME, null, TEST_SUR_NAME,
789 TEST_BIRTH_DATE, TEST_DEATH_DATE);
790 Assert.assertFalse(displayName.equals(expectedDisplayName));
792 String shortDisplayName = person.getShortDisplayName();
793 // Make sure displayName matches computed form
794 String expectedShortDisplayName =
795 PersonAuthorityClientUtils.prepareDefaultDisplayName(
796 TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
797 Assert.assertFalse(expectedShortDisplayName.equals(shortDisplayName));
799 // Update the forename and verify the computed name is updated.
800 person.setCsid(null);
801 person.setDisplayNameComputed(true);
802 person.setShortDisplayNameComputed(true);
803 person.setForeName("updated-" + TEST_FORE_NAME);
804 expectedDisplayName =
805 PersonAuthorityClientUtils.prepareDefaultDisplayName(
806 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
807 TEST_BIRTH_DATE, TEST_DEATH_DATE);
808 expectedShortDisplayName =
809 PersonAuthorityClientUtils.prepareDefaultDisplayName(
810 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
812 // Submit the updated resource to the service and store the response.
813 MultipartOutput output = new MultipartOutput();
814 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
815 commonPart.getHeaders().add("label", client.getItemCommonPartName());
816 res = client.updateItem(knownResourceId, knownItemResourceId, output);
818 int statusCode = res.getStatus();
820 // Check the status code of the response: does it match the expected response(s)?
821 if(logger.isDebugEnabled()){
822 logger.debug("updateItem: status = " + statusCode);
824 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
825 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
826 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
828 // Retrieve the updated resource and verify that its contents exist.
829 input = (MultipartInput) res.getEntity();
831 res.releaseConnection();
834 PersonsCommon updatedPerson =
835 (PersonsCommon) extractPart(input,
836 client.getItemCommonPartName(), PersonsCommon.class);
837 Assert.assertNotNull(updatedPerson);
839 // Verify that the updated resource received the correct data.
840 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
841 "Updated ForeName in Person did not match submitted data.");
842 // Verify that the updated resource computes the right displayName.
843 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
844 "Updated ForeName in Person not reflected in computed DisplayName.");
845 // Verify that the updated resource computes the right displayName.
846 Assert.assertEquals(updatedPerson.getShortDisplayName(), expectedShortDisplayName,
847 "Updated ForeName in Person not reflected in computed ShortDisplayName.");
849 // Now Update the displayName, not computed and verify the computed name is overriden.
850 person.setDisplayNameComputed(false);
851 expectedDisplayName = "TestName";
852 person.setDisplayName(expectedDisplayName);
853 person.setShortDisplayNameComputed(false);
854 person.setShortDisplayName(expectedDisplayName);
856 // Submit the updated resource to the service and store the response.
857 output = new MultipartOutput();
858 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
859 commonPart.getHeaders().add("label", client.getItemCommonPartName());
860 res = client.updateItem(knownResourceId, knownItemResourceId, output);
862 int statusCode = res.getStatus();
864 // Check the status code of the response: does it match the expected response(s)?
865 if(logger.isDebugEnabled()){
866 logger.debug("updateItem: status = " + statusCode);
868 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
869 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
870 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
872 // Retrieve the updated resource and verify that its contents exist.
873 input = (MultipartInput) res.getEntity();
875 res.releaseConnection();
879 (PersonsCommon) extractPart(input,
880 client.getItemCommonPartName(), PersonsCommon.class);
881 Assert.assertNotNull(updatedPerson);
883 // Verify that the updated resource received the correct data.
884 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
885 "Updated displayNameComputed in Person did not match submitted data.");
886 // Verify that the updated resource computes the right displayName.
887 Assert.assertEquals(updatedPerson.getDisplayName(),
889 "Updated DisplayName (not computed) in Person not stored.");
890 // Verify that the updated resource received the correct data.
891 Assert.assertEquals(updatedPerson.isShortDisplayNameComputed(), false,
892 "Updated shortDisplayNameComputed in Person did not match submitted data.");
893 // Verify that the updated resource computes the right displayName.
894 Assert.assertEquals(updatedPerson.getShortDisplayName(),
896 "Updated ShortDisplayName (not computed) in Person not stored.");
900 * Verify illegal item display name.
902 * @param testName the test name
903 * @throws Exception the exception
905 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
906 groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"})
907 public void verifyIllegalItemDisplayName(String testName) throws Exception {
909 if (logger.isDebugEnabled()) {
910 logger.debug(testBanner(testName, CLASS_NAME));
913 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
914 // setupUpdateWithWrongXmlSchema(testName);
916 // Submit the request to the service and store the response.
917 PersonAuthorityClient client = new PersonAuthorityClient();
918 MultipartInput input = null;
919 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
921 int statusCode = res.getStatus();
923 // Check the status code of the response: does it match
924 // the expected response(s)?
925 if(logger.isDebugEnabled()){
926 logger.debug(testName + ": status = " + statusCode);
928 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
929 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
930 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
932 // Check whether Person has expected displayName.
933 input = (MultipartInput) res.getEntity();
935 res.releaseConnection();
938 PersonsCommon person = (PersonsCommon) extractPart(input,
939 client.getItemCommonPartName(), PersonsCommon.class);
940 Assert.assertNotNull(person);
941 // Try to Update with computed false and no displayName
942 person.setDisplayNameComputed(false);
943 person.setDisplayName(null);
945 // Submit the updated resource to the service and store the response.
946 MultipartOutput output = new MultipartOutput();
947 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
948 commonPart.getHeaders().add("label", client.getItemCommonPartName());
949 res = client.updateItem(knownResourceId, knownItemResourceId, output);
951 int statusCode = res.getStatus();
953 // Check the status code of the response: does it match the expected response(s)?
954 if(logger.isDebugEnabled()){
955 logger.debug("updateItem: status = " + statusCode);
957 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
958 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
959 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
961 res.releaseConnection();
968 * @param testName the test name
969 * @throws Exception the exception
971 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
972 groups = {"readItem"}, dependsOnMethods = {"readItem"})
973 public void readContact(String testName) throws Exception {
975 if (logger.isDebugEnabled()) {
976 logger.debug(testBanner(testName, CLASS_NAME));
981 // Submit the request to the service and store the response.
982 PersonAuthorityClient client = new PersonAuthorityClient();
983 MultipartInput input = null;
984 ClientResponse<MultipartInput> res =
985 client.readContact(knownResourceId, knownItemResourceId,
986 knownContactResourceId);
988 int statusCode = res.getStatus();
990 // Check the status code of the response: does it match
991 // the expected response(s)?
992 if(logger.isDebugEnabled()){
993 logger.debug(testName + ": status = " + statusCode);
995 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
996 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
997 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
999 // Check whether we've received a contact.
1000 input = (MultipartInput) res.getEntity();
1002 res.releaseConnection();
1005 ContactsCommon contact = (ContactsCommon) extractPart(input,
1006 new ContactClient().getCommonPartName(), ContactsCommon.class);
1007 Assert.assertNotNull(contact);
1008 boolean showFull = true;
1009 if(showFull && logger.isDebugEnabled()){
1010 logger.debug(testName + ": returned payload:");
1011 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
1013 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
1014 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
1020 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
1023 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1024 groups = {"read"}, dependsOnMethods = {"read"})
1025 public void readNonExistent(String testName) {
1027 if (logger.isDebugEnabled()) {
1028 logger.debug(testBanner(testName, CLASS_NAME));
1031 setupReadNonExistent();
1033 // Submit the request to the service and store the response.
1034 PersonAuthorityClient client = new PersonAuthorityClient();
1035 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
1037 int statusCode = res.getStatus();
1038 // Check the status code of the response: does it match
1039 // the expected response(s)?
1040 if(logger.isDebugEnabled()){
1041 logger.debug(testName + ": status = " + statusCode);
1043 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1044 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1045 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1047 res.releaseConnection();
1052 * Read item non existent.
1054 * @param testName the test name
1056 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1057 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1058 public void readItemNonExistent(String testName) {
1060 if (logger.isDebugEnabled()) {
1061 logger.debug(testBanner(testName, CLASS_NAME));
1064 setupReadNonExistent();
1066 // Submit the request to the service and store the response.
1067 PersonAuthorityClient client = new PersonAuthorityClient();
1068 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1070 int statusCode = res.getStatus();
1072 // Check the status code of the response: does it match
1073 // the expected response(s)?
1074 if(logger.isDebugEnabled()){
1075 logger.debug(testName + ": status = " + statusCode);
1077 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1078 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1079 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1081 res.releaseConnection();
1086 * Read contact non existent.
1088 * @param testName the test name
1090 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1091 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1092 public void readContactNonExistent(String testName) {
1094 if (logger.isDebugEnabled()) {
1095 logger.debug(testBanner(testName, CLASS_NAME));
1098 setupReadNonExistent();
1100 // Submit the request to the service and store the response.
1101 PersonAuthorityClient client = new PersonAuthorityClient();
1102 ClientResponse<MultipartInput> res =
1103 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1105 int statusCode = res.getStatus();
1107 // Check the status code of the response: does it match
1108 // the expected response(s)?
1109 if(logger.isDebugEnabled()){
1110 logger.debug(testName + ": status = " + statusCode);
1112 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1113 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1114 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1116 res.releaseConnection();
1120 // ---------------------------------------------------------------
1121 // CRUD tests : READ_LIST tests
1122 // ---------------------------------------------------------------
1126 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1129 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1130 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1131 public void readList(String testName) throws Exception {
1133 if (logger.isDebugEnabled()) {
1134 logger.debug(testBanner(testName, CLASS_NAME));
1139 // Submit the request to the service and store the response.
1140 PersonAuthorityClient client = new PersonAuthorityClient();
1141 PersonauthoritiesCommonList list = null;
1142 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1144 int statusCode = res.getStatus();
1146 // Check the status code of the response: does it match
1147 // the expected response(s)?
1148 if(logger.isDebugEnabled()){
1149 logger.debug(testName + ": status = " + statusCode);
1151 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1152 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1153 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1155 list = res.getEntity();
1157 res.releaseConnection();
1160 // Optionally output additional data about list members for debugging.
1161 boolean iterateThroughList = false;
1162 if (iterateThroughList && logger.isDebugEnabled()) {
1163 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1164 list.getPersonauthorityListItem();
1166 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1167 String csid = item.getCsid();
1168 logger.debug(testName + ": list-item[" + i + "] csid=" +
1170 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1171 item.getDisplayName());
1172 logger.debug(testName + ": list-item[" + i + "] URI=" +
1174 readItemList(csid, null, testName);
1183 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1184 groups = {"readList"}, dependsOnMethods = {"readList"})
1185 public void readItemList(String testName) {
1186 readItemList(knownResourceId, null, testName);
1190 * Read item list by authority name.
1192 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1193 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1194 public void readItemListByAuthorityName(String testName) {
1195 readItemList(null, knownResourceShortIdentifer, testName);
1201 * @param vcsid the vcsid
1202 * @param name the name
1204 private void readItemList(String vcsid, String name, String testName) {
1209 // Submit the request to the service and store the response.
1210 PersonAuthorityClient client = new PersonAuthorityClient();
1211 ClientResponse<PersonsCommonList> res = null;
1213 res = client.readItemList(vcsid, null, null);
1214 } else if (name!= null) {
1215 res = client.readItemListForNamedAuthority(name, null, null);
1217 Assert.fail("readItemList passed null csid and name!");
1219 PersonsCommonList list = null;
1221 int statusCode = res.getStatus();
1223 // Check the status code of the response: does it match
1224 // the expected response(s)?
1225 if(logger.isDebugEnabled()){
1226 logger.debug(testName + ": status = " + statusCode);
1228 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1229 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1230 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1232 list = res.getEntity();
1234 res.releaseConnection();
1237 List<PersonsCommonList.PersonListItem> items =
1238 list.getPersonListItem();
1239 int nItemsReturned = items.size();
1240 // There will be one item created, associated with a
1241 // known parent resource, by the createItem test.
1243 // In addition, there will be 'nItemsToCreateInList'
1244 // additional items created by the createItemList test,
1245 // all associated with the same parent resource.
1246 int nExpectedItems = nItemsToCreateInList + 1;
1247 if(logger.isDebugEnabled()){
1248 logger.debug(testName + ": Expected "
1249 + nExpectedItems +" items; got: "+nItemsReturned);
1251 Assert.assertEquals(nItemsReturned, nExpectedItems);
1254 for (PersonsCommonList.PersonListItem item : items) {
1255 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1256 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1257 // Optionally output additional data about list members for debugging.
1258 boolean showDetails = true;
1259 if (showDetails && logger.isDebugEnabled()) {
1260 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1262 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1264 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1265 item.getDisplayName());
1266 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1274 * Read contact list.
1276 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1277 public void readContactList() {
1278 readContactList(knownResourceId, knownItemResourceId);
1282 * Read contact list.
1284 * @param parentcsid the parentcsid
1285 * @param itemcsid the itemcsid
1287 private void readContactList(String parentcsid, String itemcsid) {
1288 final String testName = "readContactList";
1293 // Submit the request to the service and store the response.
1294 PersonAuthorityClient client = new PersonAuthorityClient();
1295 ContactsCommonList list = null;
1296 ClientResponse<ContactsCommonList> res =
1297 client.readContactList(parentcsid, itemcsid);
1299 int statusCode = res.getStatus();
1301 // Check the status code of the response: does it match
1302 // the expected response(s)?
1303 if(logger.isDebugEnabled()){
1304 logger.debug(testName + ": status = " + statusCode);
1306 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1307 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1308 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1310 list = res.getEntity();
1312 res.releaseConnection();
1315 List<ContactsCommonList.ContactListItem> listitems =
1316 list.getContactListItem();
1317 int nItemsReturned = listitems.size();
1318 // There will be one item created, associated with a
1319 // known parent resource, by the createItem test.
1321 // In addition, there will be 'nItemsToCreateInList'
1322 // additional items created by the createItemList test,
1323 // all associated with the same parent resource.
1324 int nExpectedItems = nItemsToCreateInList + 1;
1325 if(logger.isDebugEnabled()){
1326 logger.debug(testName + ": Expected "
1327 + nExpectedItems +" items; got: "+nItemsReturned);
1329 Assert.assertEquals(nItemsReturned, nExpectedItems);
1332 for (ContactsCommonList.ContactListItem listitem : listitems) {
1333 // Optionally output additional data about list members for debugging.
1334 boolean showDetails = false;
1335 if (showDetails && logger.isDebugEnabled()) {
1336 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1337 listitem.getCsid());
1338 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1339 listitem.getAddressPlace());
1340 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1349 // There are no failure outcome tests at present.
1351 // ---------------------------------------------------------------
1352 // CRUD tests : UPDATE tests
1353 // ---------------------------------------------------------------
1356 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1359 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1360 groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
1361 public void update(String testName) throws Exception {
1363 if (logger.isDebugEnabled()) {
1364 logger.debug(testBanner(testName, CLASS_NAME));
1369 // Retrieve the contents of a resource to update.
1370 PersonAuthorityClient client = new PersonAuthorityClient();
1371 MultipartInput input = null;
1372 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1374 if(logger.isDebugEnabled()){
1375 logger.debug(testName + ": read status = " + res.getStatus());
1377 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1379 if(logger.isDebugEnabled()){
1380 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1382 input = res.getEntity();
1384 res.releaseConnection();
1387 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1388 client.getCommonPartName(), PersonauthoritiesCommon.class);
1389 Assert.assertNotNull(personAuthority);
1391 // Update the contents of this resource.
1392 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1393 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1394 if(logger.isDebugEnabled()){
1395 logger.debug("to be updated PersonAuthority");
1396 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1399 // Submit the updated resource to the service and store the response.
1400 MultipartOutput output = new MultipartOutput();
1401 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1402 commonPart.getHeaders().add("label", client.getCommonPartName());
1403 res = client.update(knownResourceId, output);
1405 int statusCode = res.getStatus();
1407 // Check the status code of the response: does it match the expected response(s)?
1408 if(logger.isDebugEnabled()){
1409 logger.debug(testName + ": status = " + statusCode);
1411 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1412 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1413 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1415 // Retrieve the updated resource and verify that its contents exist.
1416 input = (MultipartInput) res.getEntity();
1418 res.releaseConnection();
1421 PersonauthoritiesCommon updatedPersonAuthority =
1422 (PersonauthoritiesCommon) extractPart(input,
1423 client.getCommonPartName(), PersonauthoritiesCommon.class);
1424 Assert.assertNotNull(updatedPersonAuthority);
1426 // Verify that the updated resource received the correct data.
1427 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1428 personAuthority.getDisplayName(),
1429 "Data in updated object did not match submitted data.");
1435 * @param testName the test name
1436 * @throws Exception the exception
1438 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1439 groups = {"update"}, dependsOnMethods = {"update"})
1440 public void updateItem(String testName) throws Exception {
1442 if (logger.isDebugEnabled()) {
1443 logger.debug(testBanner(testName, CLASS_NAME));
1448 // Retrieve the contents of a resource to update.
1449 PersonAuthorityClient client = new PersonAuthorityClient();
1450 MultipartInput input = null;
1451 ClientResponse<MultipartInput> res =
1452 client.readItem(knownResourceId, knownItemResourceId);
1454 if(logger.isDebugEnabled()){
1455 logger.debug(testName + ": read status = " + res.getStatus());
1457 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1459 if(logger.isDebugEnabled()){
1460 logger.debug("got Person to update with ID: " +
1461 knownItemResourceId +
1462 " in PersonAuthority: " + knownResourceId );
1464 input = res.getEntity();
1466 res.releaseConnection();
1469 PersonsCommon person = (PersonsCommon) extractPart(input,
1470 client.getItemCommonPartName(), PersonsCommon.class);
1471 Assert.assertNotNull(person);
1473 if (logger.isDebugEnabled() == true) {
1474 logger.debug("About to update the following person...");
1475 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1478 // Update the contents of this resource.
1479 person.setCsid(null);
1480 person.setForeName("updated-" + person.getForeName());
1481 if(logger.isDebugEnabled()){
1482 logger.debug("to be updated Person");
1483 logger.debug(objectAsXmlString(person,
1484 PersonsCommon.class));
1487 // Submit the updated resource to the service and store the response.
1488 MultipartOutput output = new MultipartOutput();
1489 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1490 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1491 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1493 int statusCode = res.getStatus();
1495 // Check the status code of the response: does it match the expected response(s)?
1496 if(logger.isDebugEnabled()){
1497 logger.debug(testName + ": status = " + statusCode);
1499 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1500 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1501 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1503 // Retrieve the updated resource and verify that its contents exist.
1504 input = (MultipartInput) res.getEntity();
1506 res.releaseConnection();
1509 PersonsCommon updatedPerson =
1510 (PersonsCommon) extractPart(input,
1511 client.getItemCommonPartName(), PersonsCommon.class);
1512 Assert.assertNotNull(updatedPerson);
1514 if (logger.isDebugEnabled() == true) {
1515 logger.debug("Updated to following person to:");
1516 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1519 // Verify that the updated resource received the correct data.
1520 Assert.assertEquals(updatedPerson.getForeName(),
1521 person.getForeName(),
1522 "Data in updated Person did not match submitted data.");
1528 * @param testName the test name
1529 * @throws Exception the exception
1531 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1532 groups = {"update"}, dependsOnMethods = {"updateItem"})
1533 public void updateContact(String testName) throws Exception {
1535 if (logger.isDebugEnabled()) {
1536 logger.debug(testBanner(testName, CLASS_NAME));
1541 // Retrieve the contents of a resource to update.
1542 PersonAuthorityClient client = new PersonAuthorityClient();
1543 MultipartInput input = null;
1544 ClientResponse<MultipartInput> res =
1545 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1547 if(logger.isDebugEnabled()){
1548 logger.debug(testName + ": read status = " + res.getStatus());
1550 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1552 if(logger.isDebugEnabled()){
1553 logger.debug("got Contact to update with ID: " +
1554 knownContactResourceId +
1555 " in item: " + knownItemResourceId +
1556 " in parent: " + knownResourceId );
1558 input = res.getEntity();
1560 res.releaseConnection();
1563 ContactsCommon contact = (ContactsCommon) extractPart(input,
1564 new ContactClient().getCommonPartName(), ContactsCommon.class);
1565 Assert.assertNotNull(contact);
1567 // Update the contents of this resource.
1568 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1569 if(logger.isDebugEnabled()){
1570 logger.debug("to be updated Contact");
1571 logger.debug(objectAsXmlString(contact,
1572 ContactsCommon.class));
1575 // Submit the updated resource to the service and store the response.
1576 MultipartOutput output = new MultipartOutput();
1577 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1578 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1579 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1581 int statusCode = res.getStatus();
1583 // Check the status code of the response: does it match the expected response(s)?
1584 if(logger.isDebugEnabled()){
1585 logger.debug(testName + ": status = " + statusCode);
1587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1591 // Retrieve the updated resource and verify that its contents exist.
1592 input = (MultipartInput) res.getEntity();
1594 res.releaseConnection();
1596 ContactsCommon updatedContact =
1597 (ContactsCommon) extractPart(input,
1598 new ContactClient().getCommonPartName(), ContactsCommon.class);
1599 Assert.assertNotNull(updatedContact);
1601 // Verify that the updated resource received the correct data.
1602 Assert.assertEquals(updatedContact.getAddressPlace(),
1603 contact.getAddressPlace(),
1604 "Data in updated Contact did not match submitted data.");
1608 // Placeholders until the three tests below can be uncommented.
1609 // See Issue CSPACE-401.
1611 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1614 public void updateWithEmptyEntityBody(String testName) throws Exception {
1615 //Should this really be empty?
1619 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1622 public void updateWithMalformedXml(String testName) throws Exception {
1623 //Should this really be empty?
1627 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1630 public void updateWithWrongXmlSchema(String testName) throws Exception {
1631 //Should this really be empty?
1636 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1637 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1638 public void updateWithEmptyEntityBody(String testName) throws Exception {
1640 if (logger.isDebugEnabled()) {
1641 logger.debug(testBanner(testName, CLASS_NAME));
1644 setupUpdateWithEmptyEntityBody(testName, logger);
1646 // Submit the request to the service and store the response.
1647 String method = REQUEST_TYPE.httpMethodName();
1648 String url = getResourceURL(knownResourceId);
1649 String mediaType = MediaType.APPLICATION_XML;
1650 final String entity = "";
1651 int statusCode = submitRequest(method, url, mediaType, entity);
1653 // Check the status code of the response: does it match
1654 // the expected response(s)?
1655 if(logger.isDebugEnabled()){
1656 logger.debug(testName + ": url=" + url +
1657 " status=" + statusCode);
1659 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1660 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1661 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1665 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1666 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1667 public void updateWithMalformedXml(String testName) throws Exception {
1669 if (logger.isDebugEnabled()) {
1670 logger.debug(testBanner(testName, CLASS_NAME));
1673 setupUpdateWithMalformedXml();
1675 // Submit the request to the service and store the response.
1676 String method = REQUEST_TYPE.httpMethodName();
1677 String url = getResourceURL(knownResourceId);
1678 String mediaType = MediaType.APPLICATION_XML;
1679 final String entity = MALFORMED_XML_DATA;
1680 int statusCode = submitRequest(method, url, mediaType, entity);
1682 // Check the status code of the response: does it match
1683 // the expected response(s)?
1684 if(logger.isDebugEnabled()){
1685 logger.debug(testName + ": url=" + url +
1686 " status=" + statusCode);
1688 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1689 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1690 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1694 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1695 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1696 public void updateWithWrongXmlSchema(String testName) throws Exception {
1698 if (logger.isDebugEnabled()) {
1699 logger.debug(testBanner(testName, CLASS_NAME));
1702 setupUpdateWithWrongXmlSchema();
1704 // Submit the request to the service and store the response.
1705 String method = REQUEST_TYPE.httpMethodName();
1706 String url = getResourceURL(knownResourceId);
1707 String mediaType = MediaType.APPLICATION_XML;
1708 final String entity = WRONG_XML_SCHEMA_DATA;
1709 int statusCode = submitRequest(method, url, mediaType, entity);
1711 // Check the status code of the response: does it match
1712 // the expected response(s)?
1713 if(logger.isDebugEnabled()){
1714 logger.debug("updateWithWrongXmlSchema: url=" + url +
1715 " status=" + statusCode);
1717 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1718 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1719 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1724 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1727 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1728 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1729 public void updateNonExistent(String testName) throws Exception {
1731 if (logger.isDebugEnabled()) {
1732 logger.debug(testBanner(testName, CLASS_NAME));
1735 setupUpdateNonExistent();
1737 // Submit the request to the service and store the response.
1738 // Note: The ID(s) used when creating the request payload may be arbitrary.
1739 // The only relevant ID may be the one used in update(), below.
1740 PersonAuthorityClient client = new PersonAuthorityClient();
1741 String displayName = "displayName-NON_EXISTENT_ID";
1742 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1743 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1744 ClientResponse<MultipartInput> res =
1745 client.update(NON_EXISTENT_ID, multipart);
1747 int statusCode = res.getStatus();
1749 // Check the status code of the response: does it match
1750 // the expected response(s)?
1751 if(logger.isDebugEnabled()){
1752 logger.debug(testName + ": status = " + statusCode);
1754 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1755 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1756 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1758 res.releaseConnection();
1763 * Update non existent item.
1765 * @param testName the test name
1766 * @throws Exception the exception
1768 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1769 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1770 public void updateNonExistentItem(String testName) throws Exception {
1772 if (logger.isDebugEnabled()) {
1773 logger.debug(testBanner(testName, CLASS_NAME));
1776 setupUpdateNonExistent();
1778 // Submit the request to the service and store the response.
1779 // Note: The ID used in this 'create' call may be arbitrary.
1780 // The only relevant ID may be the one used in update(), below.
1781 PersonAuthorityClient client = new PersonAuthorityClient();
1782 Map<String, String> nonexMap = new HashMap<String,String>();
1783 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1784 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1785 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1786 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1787 Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1788 MultipartOutput multipart =
1789 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1790 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1791 nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() );
1792 ClientResponse<MultipartInput> res =
1793 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1795 int statusCode = res.getStatus();
1797 // Check the status code of the response: does it match
1798 // the expected response(s)?
1799 if(logger.isDebugEnabled()){
1800 logger.debug(testName + ": status = " + statusCode);
1802 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1803 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1804 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1806 res.releaseConnection();
1811 * Update non existent contact.
1813 * @param testName the test name
1814 * @throws Exception the exception
1816 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1817 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1818 public void updateNonExistentContact(String testName) throws Exception {
1819 // Currently a no-op test
1822 // ---------------------------------------------------------------
1823 // CRUD tests : DELETE tests
1824 // ---------------------------------------------------------------
1827 // Note: delete sub-resources in ascending hierarchical order,
1828 // before deleting their parents.
1833 * @param testName the test name
1834 * @throws Exception the exception
1836 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1837 groups = {"delete"}, dependsOnGroups = {"update"})
1838 public void deleteContact(String testName) throws Exception {
1840 if (logger.isDebugEnabled()) {
1841 logger.debug(testBanner(testName, CLASS_NAME));
1846 if(logger.isDebugEnabled()){
1847 logger.debug("parentcsid =" + knownResourceId +
1848 " itemcsid = " + knownItemResourceId +
1849 " csid = " + knownContactResourceId);
1852 // Submit the request to the service and store the response.
1853 PersonAuthorityClient client = new PersonAuthorityClient();
1854 ClientResponse<Response> res =
1855 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1857 int statusCode = res.getStatus();
1859 // Check the status code of the response: does it match
1860 // the expected response(s)?
1861 if(logger.isDebugEnabled()){
1862 logger.debug(testName + ": status = " + statusCode);
1864 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1865 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1866 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1868 res.releaseConnection();
1875 * @param testName the test name
1876 * @throws Exception the exception
1878 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1879 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1880 public void deleteItem(String testName) throws Exception {
1882 if (logger.isDebugEnabled()) {
1883 logger.debug(testBanner(testName, CLASS_NAME));
1888 if(logger.isDebugEnabled()){
1889 logger.debug("parentcsid =" + knownResourceId +
1890 " itemcsid = " + knownItemResourceId);
1893 // Submit the request to the service and store the response.
1894 PersonAuthorityClient client = new PersonAuthorityClient();
1895 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1897 int statusCode = res.getStatus();
1899 // Check the status code of the response: does it match
1900 // the expected response(s)?
1901 if(logger.isDebugEnabled()){
1902 logger.debug(testName + ": status = " + statusCode);
1904 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1905 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1906 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1908 res.releaseConnection();
1913 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1916 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1917 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1918 public void delete(String testName) throws Exception {
1920 if (logger.isDebugEnabled()) {
1921 logger.debug(testBanner(testName, CLASS_NAME));
1926 if(logger.isDebugEnabled()){
1927 logger.debug("parentcsid =" + knownResourceId);
1930 // Submit the request to the service and store the response.
1931 PersonAuthorityClient client = new PersonAuthorityClient();
1932 ClientResponse<Response> res = client.delete(knownResourceId);
1934 int statusCode = res.getStatus();
1936 // Check the status code of the response: does it match
1937 // the expected response(s)?
1938 if(logger.isDebugEnabled()){
1939 logger.debug(testName + ": status = " + statusCode);
1941 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1942 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1943 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1945 res.releaseConnection();
1951 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1954 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1955 groups = {"delete"}, dependsOnMethods = {"delete"})
1956 public void deleteNonExistent(String testName) throws Exception {
1958 if (logger.isDebugEnabled()) {
1959 logger.debug(testBanner(testName, CLASS_NAME));
1962 setupDeleteNonExistent();
1964 // Submit the request to the service and store the response.
1965 PersonAuthorityClient client = new PersonAuthorityClient();
1966 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1968 int statusCode = res.getStatus();
1970 // Check the status code of the response: does it match
1971 // the expected response(s)?
1972 if(logger.isDebugEnabled()){
1973 logger.debug(testName + ": status = " + statusCode);
1975 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1976 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1977 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1979 res.releaseConnection();
1984 * Delete non existent item.
1986 * @param testName the test name
1988 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1989 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1990 public void deleteNonExistentItem(String testName) {
1992 if (logger.isDebugEnabled()) {
1993 logger.debug(testBanner(testName, CLASS_NAME));
1996 setupDeleteNonExistent();
1998 // Submit the request to the service and store the response.
1999 PersonAuthorityClient client = new PersonAuthorityClient();
2000 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
2002 int statusCode = res.getStatus();
2004 // Check the status code of the response: does it match
2005 // the expected response(s)?
2006 if(logger.isDebugEnabled()){
2007 logger.debug(testName + ": status = " + statusCode);
2009 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2010 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2011 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2013 res.releaseConnection();
2018 * Delete non existent contact.
2020 * @param testName the test name
2022 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2023 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2024 public void deleteNonExistentContact(String testName) {
2026 if (logger.isDebugEnabled()) {
2027 logger.debug(testBanner(testName, CLASS_NAME));
2030 setupDeleteNonExistent();
2032 // Submit the request to the service and store the response.
2033 PersonAuthorityClient client = new PersonAuthorityClient();
2034 ClientResponse<Response> res =
2035 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2037 int statusCode = res.getStatus();
2039 // Check the status code of the response: does it match
2040 // the expected response(s)?
2041 if(logger.isDebugEnabled()){
2042 logger.debug(testName + ": status = " + statusCode);
2044 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2045 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2046 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2048 res.releaseConnection();
2052 // ---------------------------------------------------------------
2053 // Utility tests : tests of code used in tests above
2054 // ---------------------------------------------------------------
2056 * Tests the code for manually submitting data that is used by several
2057 * of the methods above.
2059 @Test(dependsOnMethods = {"create", "read"})
2060 public void testSubmitRequest() {
2062 // Expected status code: 200 OK
2063 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2065 // Submit the request to the service and store the response.
2066 String method = ServiceRequestType.READ.httpMethodName();
2067 String url = getResourceURL(knownResourceId);
2068 int statusCode = submitRequest(method, url);
2070 // Check the status code of the response: does it match
2071 // the expected response(s)?
2072 if(logger.isDebugEnabled()){
2073 logger.debug("testSubmitRequest: url=" + url +
2074 " status=" + statusCode);
2076 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2081 * Test item submit request.
2083 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2084 public void testItemSubmitRequest() {
2086 // Expected status code: 200 OK
2087 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2089 // Submit the request to the service and store the response.
2090 String method = ServiceRequestType.READ.httpMethodName();
2091 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2092 int statusCode = submitRequest(method, url);
2094 // Check the status code of the response: does it match
2095 // the expected response(s)?
2096 if(logger.isDebugEnabled()){
2097 logger.debug("testItemSubmitRequest: url=" + url +
2098 " status=" + statusCode);
2100 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2105 * Test contact submit request.
2107 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2108 public void testContactSubmitRequest() {
2110 // Expected status code: 200 OK
2111 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2113 // Submit the request to the service and store the response.
2114 String method = ServiceRequestType.READ.httpMethodName();
2115 String url = getContactResourceURL(knownResourceId,
2116 knownItemResourceId, knownContactResourceId);
2117 int statusCode = submitRequest(method, url);
2119 // Check the status code of the response: does it match
2120 // the expected response(s)?
2121 if(logger.isDebugEnabled()){
2122 logger.debug("testItemSubmitRequest: url=" + url +
2123 " status=" + statusCode);
2125 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2130 // ---------------------------------------------------------------
2131 // Cleanup of resources created during testing
2132 // ---------------------------------------------------------------
2135 * Deletes all resources created by tests, after all tests have been run.
2137 * This cleanup method will always be run, even if one or more tests fail.
2138 * For this reason, it attempts to remove all resources created
2139 * at any point during testing, even if some of those resources
2140 * may be expected to be deleted by certain tests.
2143 @AfterClass(alwaysRun=true)
2145 public void cleanUp() {
2146 String noTest = System.getProperty("noTestCleanup");
2147 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2148 if (logger.isDebugEnabled()) {
2149 logger.debug("Skipping Cleanup phase ...");
2153 if (logger.isDebugEnabled()) {
2154 logger.debug("Cleaning up temporary resources created for testing ...");
2156 String parentResourceId;
2157 String itemResourceId;
2158 String contactResourceId;
2159 // Clean up contact resources.
2160 PersonAuthorityClient client = new PersonAuthorityClient();
2161 parentResourceId = knownResourceId;
2162 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2163 contactResourceId = entry.getKey();
2164 itemResourceId = entry.getValue();
2165 // Note: Any non-success responses from the delete operation
2166 // below are ignored and not reported.
2167 ClientResponse<Response> res =
2168 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2169 res.releaseConnection();
2171 // Clean up item resources.
2172 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2173 itemResourceId = entry.getKey();
2174 parentResourceId = entry.getValue();
2175 // Note: Any non-success responses from the delete operation
2176 // below are ignored and not reported.
2177 ClientResponse<Response> res =
2178 client.deleteItem(parentResourceId, itemResourceId);
2179 res.releaseConnection();
2181 // Clean up parent resources.
2185 // ---------------------------------------------------------------
2186 // Utility methods used by tests above
2187 // ---------------------------------------------------------------
2189 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2192 public String getServicePathComponent() {
2193 return SERVICE_PATH_COMPONENT;
2197 * Gets the item service path component.
2199 * @return the item service path component
2201 public String getItemServicePathComponent() {
2202 return ITEM_SERVICE_PATH_COMPONENT;
2206 * Gets the contact service path component.
2208 * @return the contact service path component
2210 public String getContactServicePathComponent() {
2211 return CONTACT_SERVICE_PATH_COMPONENT;
2215 * Returns the root URL for the item service.
2217 * This URL consists of a base URL for all services, followed by
2218 * a path component for the owning parent, followed by the
2219 * path component for the items.
2221 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2222 * parent authority resource of the relevant item resource.
2224 * @return The root URL for the item service.
2226 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2227 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2231 * Returns the URL of a specific item resource managed by a service, and
2232 * designated by an identifier (such as a universally unique ID, or UUID).
2234 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2235 * parent authority resource of the relevant item resource.
2237 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2240 * @return The URL of a specific item resource managed by a service.
2242 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2243 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2248 * Returns the root URL for the contact service.
2250 * This URL consists of a base URL for all services, followed by
2251 * a path component for the owning authority, followed by the
2252 * path component for the owning item, followed by the path component
2253 * for the contact service.
2255 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2256 * parent authority resource of the relevant item resource.
2258 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2261 * @return The root URL for the contact service.
2263 protected String getContactServiceRootURL(String parentResourceIdentifier,
2264 String itemResourceIdentifier) {
2265 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2266 getContactServicePathComponent();
2270 * Returns the URL of a specific contact resource managed by a service, and
2271 * designated by an identifier (such as a universally unique ID, or UUID).
2273 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2274 * parent resource of the relevant item resource.
2276 * @param resourceIdentifier An identifier (such as a UUID) for an
2279 * @return The URL of a specific resource managed by a service.
2281 protected String getContactResourceURL(String parentResourceIdentifier,
2282 String itemResourceIdentifier, String contactResourceIdentifier) {
2283 return getContactServiceRootURL(parentResourceIdentifier,
2284 itemResourceIdentifier) + "/" + contactResourceIdentifier;