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_IDENTIFIER, shortId);
251 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
252 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
253 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
254 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
255 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
256 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
257 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
258 "known by his stage name John Wayne, was an American film actor, director " +
259 "and producer. He epitomized rugged masculinity and has become an enduring " +
260 "American icon. He is famous for his distinctive voice, walk and height. " +
261 "He was also known for his conservative political views and his support in " +
262 "the 1950s for anti-communist positions.");
264 Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String,List<String>>();
265 List<String> johnWayneGroups = new ArrayList<String>();
266 johnWayneGroups.add("Irish");
267 johnWayneGroups.add("Scottish");
268 johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
270 MultipartOutput multipart =
271 PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
272 johnWayneRepeatablesMap, client.getItemCommonPartName() );
275 ClientResponse<Response> res = client.createItem(vcsid, multipart);
277 int statusCode = res.getStatus();
278 // Check the status code of the response: does it match
279 // the expected response(s)?
280 if(logger.isDebugEnabled()){
281 logger.debug(testName + ": status = " + statusCode);
283 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
284 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
285 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
287 newID = PersonAuthorityClientUtils.extractId(res);
289 res.releaseConnection();
292 // Store the ID returned from the first item resource created
293 // for additional tests below.
294 if (knownItemResourceId == null){
295 setKnownItemResource(newID, shortId);
296 if (logger.isDebugEnabled()) {
297 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
300 if(logger.isDebugEnabled()){
301 logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")");
304 // Store the IDs from any item resources created
305 // by tests, along with the IDs of their parents, so these items
306 // can be deleted after all tests have been run.
307 allItemResourceIdsCreated.put(newID, vcsid);
313 * Creates the contact.
315 * @param testName the test name
317 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
318 groups = {"create"}, dependsOnMethods = {"createItem"})
319 public void createContact(String testName) {
320 if (logger.isDebugEnabled()) {
321 logger.debug(testBanner(testName, CLASS_NAME));
324 String newID = createContactInItem(knownResourceId, knownItemResourceId);
328 * Creates the contact in item.
330 * @param parentcsid the parentcsid
331 * @param itemcsid the itemcsid
334 private String createContactInItem(String parentcsid, String itemcsid) {
336 final String testName = "createContactInItem";
337 if(logger.isDebugEnabled()){
338 logger.debug(testName + ":...");
343 // Submit the request to the service and store the response.
344 PersonAuthorityClient client = new PersonAuthorityClient();
345 String identifier = createIdentifier();
346 MultipartOutput multipart =
347 ContactClientUtils.createContactInstance(parentcsid,
348 itemcsid, identifier, new ContactClient().getCommonPartName());
351 ClientResponse<Response> res =
352 client.createContact(parentcsid, itemcsid, multipart);
354 int statusCode = res.getStatus();
355 // Check the status code of the response: does it match
356 // the expected response(s)?
357 if(logger.isDebugEnabled()){
358 logger.debug(testName + ": status = " + statusCode);
360 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
361 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
362 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
364 newID = PersonAuthorityClientUtils.extractId(res);
366 res.releaseConnection();
369 // Store the ID returned from the first contact resource created
370 // for additional tests below.
371 if (knownContactResourceId == null){
372 knownContactResourceId = newID;
373 if (logger.isDebugEnabled()) {
374 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
378 // Store the IDs from any contact resources created
379 // by tests, along with the IDs of their parent items,
380 // so these items can be deleted after all tests have been run.
381 allContactResourceIdsCreated.put(newID, itemcsid);
388 // Placeholders until the three tests below can be uncommented.
389 // See Issue CSPACE-401.
391 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
394 public void createWithEmptyEntityBody(String testName) throws Exception {
395 //Should this really be empty?
399 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
402 public void createWithMalformedXml(String testName) throws Exception {
403 //Should this really be empty?
407 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
410 public void createWithWrongXmlSchema(String testName) throws Exception {
411 //Should this really be empty?
416 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
417 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
418 public void createWithEmptyEntityBody(String testName) throws Exception {
420 if (logger.isDebugEnabled()) {
421 logger.debug(testBanner(testName, CLASS_NAME));
424 setupCreateWithEmptyEntityBody();
426 // Submit the request to the service and store the response.
427 String method = REQUEST_TYPE.httpMethodName();
428 String url = getServiceRootURL();
429 String mediaType = MediaType.APPLICATION_XML;
430 final String entity = "";
431 int statusCode = submitRequest(method, url, mediaType, entity);
433 // Check the status code of the response: does it match
434 // the expected response(s)?
435 if(logger.isDebugEnabled()) {
436 logger.debug(testName + ": url=" + url +
437 " status=" + statusCode);
439 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
440 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
441 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
445 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
446 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
447 public void createWithMalformedXml(String testName) throws Exception {
449 if (logger.isDebugEnabled()) {
450 logger.debug(testBanner(testName, CLASS_NAME));
453 setupCreateWithMalformedXml();
455 // Submit the request to the service and store the response.
456 String method = REQUEST_TYPE.httpMethodName();
457 String url = getServiceRootURL();
458 String mediaType = MediaType.APPLICATION_XML;
459 final String entity = MALFORMED_XML_DATA; // Constant from base class.
460 int statusCode = submitRequest(method, url, mediaType, entity);
462 // Check the status code of the response: does it match
463 // the expected response(s)?
464 if(logger.isDebugEnabled()){
465 logger.debug(testName + ": url=" + url +
466 " status=" + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
474 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
475 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
476 public void createWithWrongXmlSchema(String testName) throws Exception {
478 if (logger.isDebugEnabled()) {
479 logger.debug(testBanner(testName, CLASS_NAME));
482 setupCreateWithWrongXmlSchema();
484 // Submit the request to the service and store the response.
485 String method = REQUEST_TYPE.httpMethodName();
486 String url = getServiceRootURL();
487 String mediaType = MediaType.APPLICATION_XML;
488 final String entity = WRONG_XML_SCHEMA_DATA;
489 int statusCode = submitRequest(method, url, mediaType, entity);
491 // Check the status code of the response: does it match
492 // the expected response(s)?
493 if(logger.isDebugEnabled()){
494 logger.debug(testName + ": url=" + url +
495 " status=" + statusCode);
497 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
498 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
499 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
503 // ---------------------------------------------------------------
504 // CRUD tests : CREATE LIST tests
505 // ---------------------------------------------------------------
508 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
511 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
512 groups = {"createList"}, dependsOnGroups = {"create"})
513 public void createList(String testName) throws Exception {
514 if (logger.isDebugEnabled()) {
515 logger.debug(testBanner(testName, CLASS_NAME));
517 for (int i = 0; i < nItemsToCreateInList; i++) {
523 * Creates the item list.
525 * @param testName the test name
526 * @throws Exception the exception
528 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
529 groups = {"createList"}, dependsOnMethods = {"createList"})
530 public void createItemList(String testName) throws Exception {
531 if (logger.isDebugEnabled()) {
532 logger.debug(testBanner(testName, CLASS_NAME));
534 // Add items to the initially-created, known parent record.
535 for (int j = 0; j < nItemsToCreateInList; j++) {
536 createItem(testName);
541 * Creates the contact list.
543 * @param testName the test name
544 * @throws Exception the exception
546 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
547 groups = {"createList"}, dependsOnMethods = {"createItemList"})
548 public void createContactList(String testName) throws Exception {
549 // Add contacts to the initially-created, known item record.
550 for (int j = 0; j < nItemsToCreateInList; j++) {
551 createContact(testName);
555 // ---------------------------------------------------------------
556 // CRUD tests : READ tests
557 // ---------------------------------------------------------------
560 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
563 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
564 groups = {"read"}, dependsOnGroups = {"create"})
565 public void read(String testName) throws Exception {
566 readInternal(testName, knownResourceId, null);
572 * @param testName the test name
573 * @throws Exception the exception
575 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
576 groups = {"read"}, dependsOnMethods = {"read"})
577 public void readByName(String testName) throws Exception {
578 readInternal(testName, null, knownResourceShortIdentifer);
581 protected void readInternal(String testName, String CSID, String shortId) {
582 if (logger.isDebugEnabled()) {
583 logger.debug(testBanner(testName, CLASS_NAME));
588 // Submit the request to the service and store the response.
589 PersonAuthorityClient client = new PersonAuthorityClient();
590 ClientResponse<MultipartInput> res = null;
592 res = client.read(CSID);
593 } else if(shortId!=null) {
594 res = client.readByName(shortId);
596 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
599 int statusCode = res.getStatus();
600 // Check the status code of the response: does it match
601 // the expected response(s)?
602 if(logger.isDebugEnabled()){
603 logger.debug(testName + ": status = " + statusCode);
605 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
606 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
607 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
608 //FIXME: remove the following try catch once Aron fixes signatures
610 MultipartInput input = (MultipartInput) res.getEntity();
611 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
612 client.getCommonPartName(), PersonauthoritiesCommon.class);
613 Assert.assertNotNull(personAuthority);
614 } catch (Exception e) {
615 throw new RuntimeException(e);
618 res.releaseConnection();
625 * @param testName the test name
626 * @throws Exception the exception
628 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
629 groups = {"readItem"}, dependsOnGroups = {"read"})
630 public void readItem(String testName) throws Exception {
631 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
635 * Read item in Named Auth.
637 * @param testName the test name
638 * @throws Exception the exception
640 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
641 groups = {"readItem"}, dependsOnMethods = {"readItem"})
642 public void readItemInNamedAuth(String testName) throws Exception {
643 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
649 * @param testName the test name
650 * @throws Exception the exception
652 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
653 groups = {"readItem"}, dependsOnMethods = {"readItem"})
654 public void readNamedItem(String testName) throws Exception {
655 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
659 * Read Named item in Named Auth.
661 * @param testName the test name
662 * @throws Exception the exception
664 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
665 groups = {"readItem"}, dependsOnMethods = {"readItem"})
666 public void readNamedItemInNamedAuth(String testName) throws Exception {
667 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
670 protected void readItemInternal(String testName,
671 String authCSID, String authShortId, String itemCSID, String itemShortId)
674 if (logger.isDebugEnabled()) {
675 logger.debug(testBanner(testName, CLASS_NAME));
676 logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+
677 ((itemCSID!=null)?authCSID:itemShortId));
682 // Submit the request to the service and store the response.
683 PersonAuthorityClient client = new PersonAuthorityClient();
684 ClientResponse<MultipartInput> res = null;
687 res = client.readItem(authCSID, itemCSID);
688 } else if(itemShortId!=null) {
689 res = client.readNamedItem(authCSID, itemShortId);
691 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
693 } else if(authShortId!=null) {
695 res = client.readItemInNamedAuthority(authShortId, itemCSID);
696 } else if(itemShortId!=null) {
697 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
699 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
702 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if(logger.isDebugEnabled()){
710 logger.debug(testName + ": status = " + statusCode);
712 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
714 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
716 // Check whether we've received a person.
717 MultipartInput input = (MultipartInput) res.getEntity();
718 PersonsCommon person = (PersonsCommon) extractPart(input,
719 client.getItemCommonPartName(), PersonsCommon.class);
720 Assert.assertNotNull(person);
721 boolean showFull = true;
722 if(showFull && logger.isDebugEnabled()){
723 logger.debug(testName + ": returned payload:");
724 logger.debug(objectAsXmlString(person, PersonsCommon.class));
727 // Check that the person item is within the expected Person Authority.
728 Assert.assertEquals(person.getInAuthority(), knownResourceId);
730 // Verify the number and contents of values in a repeatable field,
731 // as created in the instance record used for testing.
732 List<String> groups = person.getGroups().getGroup();
733 Assert.assertTrue(groups.size() > 0);
734 Assert.assertNotNull(groups.get(0));
737 res.releaseConnection();
742 * Verify item display name.
744 * @param testName the test name
745 * @throws Exception the exception
747 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
748 groups = {"update"}, dependsOnMethods = {"updateItem"})
749 public void verifyItemDisplayName(String testName) throws Exception {
751 if (logger.isDebugEnabled()) {
752 logger.debug(testBanner(testName, CLASS_NAME));
757 // Submit the request to the service and store the response.
758 PersonAuthorityClient client = new PersonAuthorityClient();
759 MultipartInput input =null;
760 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
762 int statusCode = res.getStatus();
764 // Check the status code of the response: does it match
765 // the expected response(s)?
766 if(logger.isDebugEnabled()){
767 logger.debug(testName + ": status = " + statusCode);
769 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
770 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
771 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
773 // Check whether person has expected displayName.
774 input = (MultipartInput) res.getEntity();
776 res.releaseConnection();
779 PersonsCommon person = (PersonsCommon) extractPart(input,
780 client.getItemCommonPartName(), PersonsCommon.class);
781 Assert.assertNotNull(person);
782 String displayName = person.getDisplayName();
783 // Make sure displayName matches computed form
784 String expectedDisplayName =
785 PersonAuthorityClientUtils.prepareDefaultDisplayName(
786 TEST_FORE_NAME, null, TEST_SUR_NAME,
787 TEST_BIRTH_DATE, TEST_DEATH_DATE);
788 Assert.assertNotNull(displayName, expectedDisplayName);
790 // Update the shortName and verify the computed name is updated.
791 person.setCsid(null);
792 person.setDisplayNameComputed(true);
793 person.setForeName("updated-" + TEST_FORE_NAME);
794 expectedDisplayName =
795 PersonAuthorityClientUtils.prepareDefaultDisplayName(
796 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
797 TEST_BIRTH_DATE, TEST_DEATH_DATE);
799 // Submit the updated resource to the service and store the response.
800 MultipartOutput output = new MultipartOutput();
801 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
802 commonPart.getHeaders().add("label", client.getItemCommonPartName());
803 res = client.updateItem(knownResourceId, knownItemResourceId, output);
805 int statusCode = res.getStatus();
807 // Check the status code of the response: does it match the expected response(s)?
808 if(logger.isDebugEnabled()){
809 logger.debug("updateItem: status = " + statusCode);
811 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
812 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
813 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
815 // Retrieve the updated resource and verify that its contents exist.
816 input = (MultipartInput) res.getEntity();
818 res.releaseConnection();
821 PersonsCommon updatedPerson =
822 (PersonsCommon) extractPart(input,
823 client.getItemCommonPartName(), PersonsCommon.class);
824 Assert.assertNotNull(updatedPerson);
826 // Verify that the updated resource received the correct data.
827 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
828 "Updated ForeName in Person did not match submitted data.");
829 // Verify that the updated resource computes the right displayName.
830 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
831 "Updated ForeName in Person not reflected in computed DisplayName.");
833 // Now Update the displayName, not computed and verify the computed name is overriden.
834 person.setDisplayNameComputed(false);
835 expectedDisplayName = "TestName";
836 person.setDisplayName(expectedDisplayName);
838 // Submit the updated resource to the service and store the response.
839 output = new MultipartOutput();
840 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
841 commonPart.getHeaders().add("label", client.getItemCommonPartName());
842 res = client.updateItem(knownResourceId, knownItemResourceId, output);
844 int statusCode = res.getStatus();
846 // Check the status code of the response: does it match the expected response(s)?
847 if(logger.isDebugEnabled()){
848 logger.debug("updateItem: status = " + statusCode);
850 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
851 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
852 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
854 // Retrieve the updated resource and verify that its contents exist.
855 input = (MultipartInput) res.getEntity();
857 res.releaseConnection();
861 (PersonsCommon) extractPart(input,
862 client.getItemCommonPartName(), PersonsCommon.class);
863 Assert.assertNotNull(updatedPerson);
865 // Verify that the updated resource received the correct data.
866 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
867 "Updated displayNameComputed in Person did not match submitted data.");
868 // Verify that the updated resource computes the right displayName.
869 Assert.assertEquals(updatedPerson.getDisplayName(),
871 "Updated DisplayName (not computed) in Person not stored.");
875 * Verify illegal item display name.
877 * @param testName the test name
878 * @throws Exception the exception
880 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
881 groups = {"update"}, dependsOnMethods = {"verifyItemDisplayName"})
882 public void verifyIllegalItemDisplayName(String testName) throws Exception {
884 if (logger.isDebugEnabled()) {
885 logger.debug(testBanner(testName, CLASS_NAME));
888 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
889 // setupUpdateWithWrongXmlSchema(testName);
891 // Submit the request to the service and store the response.
892 PersonAuthorityClient client = new PersonAuthorityClient();
893 MultipartInput input = null;
894 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
896 int statusCode = res.getStatus();
898 // Check the status code of the response: does it match
899 // the expected response(s)?
900 if(logger.isDebugEnabled()){
901 logger.debug(testName + ": status = " + statusCode);
903 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
904 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
905 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
907 // Check whether Person has expected displayName.
908 input = (MultipartInput) res.getEntity();
910 res.releaseConnection();
913 PersonsCommon person = (PersonsCommon) extractPart(input,
914 client.getItemCommonPartName(), PersonsCommon.class);
915 Assert.assertNotNull(person);
916 // Try to Update with computed false and no displayName
917 person.setDisplayNameComputed(false);
918 person.setDisplayName(null);
920 // Submit the updated resource to the service and store the response.
921 MultipartOutput output = new MultipartOutput();
922 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
923 commonPart.getHeaders().add("label", client.getItemCommonPartName());
924 res = client.updateItem(knownResourceId, knownItemResourceId, output);
926 int statusCode = res.getStatus();
928 // Check the status code of the response: does it match the expected response(s)?
929 if(logger.isDebugEnabled()){
930 logger.debug("updateItem: status = " + statusCode);
932 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
933 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
934 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
936 res.releaseConnection();
943 * @param testName the test name
944 * @throws Exception the exception
946 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
947 groups = {"readItem"}, dependsOnMethods = {"readItem"})
948 public void readContact(String testName) throws Exception {
950 if (logger.isDebugEnabled()) {
951 logger.debug(testBanner(testName, CLASS_NAME));
956 // Submit the request to the service and store the response.
957 PersonAuthorityClient client = new PersonAuthorityClient();
958 MultipartInput input = null;
959 ClientResponse<MultipartInput> res =
960 client.readContact(knownResourceId, knownItemResourceId,
961 knownContactResourceId);
963 int statusCode = res.getStatus();
965 // Check the status code of the response: does it match
966 // the expected response(s)?
967 if(logger.isDebugEnabled()){
968 logger.debug(testName + ": status = " + statusCode);
970 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
971 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
972 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
974 // Check whether we've received a contact.
975 input = (MultipartInput) res.getEntity();
977 res.releaseConnection();
980 ContactsCommon contact = (ContactsCommon) extractPart(input,
981 new ContactClient().getCommonPartName(), ContactsCommon.class);
982 Assert.assertNotNull(contact);
983 boolean showFull = true;
984 if(showFull && logger.isDebugEnabled()){
985 logger.debug(testName + ": returned payload:");
986 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
988 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
989 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
995 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
998 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
999 groups = {"read"}, dependsOnMethods = {"read"})
1000 public void readNonExistent(String testName) {
1002 if (logger.isDebugEnabled()) {
1003 logger.debug(testBanner(testName, CLASS_NAME));
1006 setupReadNonExistent();
1008 // Submit the request to the service and store the response.
1009 PersonAuthorityClient client = new PersonAuthorityClient();
1010 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
1012 int statusCode = res.getStatus();
1013 // Check the status code of the response: does it match
1014 // the expected response(s)?
1015 if(logger.isDebugEnabled()){
1016 logger.debug(testName + ": status = " + statusCode);
1018 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1019 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1020 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1022 res.releaseConnection();
1027 * Read item non existent.
1029 * @param testName the test name
1031 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1032 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1033 public void readItemNonExistent(String testName) {
1035 if (logger.isDebugEnabled()) {
1036 logger.debug(testBanner(testName, CLASS_NAME));
1039 setupReadNonExistent();
1041 // Submit the request to the service and store the response.
1042 PersonAuthorityClient client = new PersonAuthorityClient();
1043 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1045 int statusCode = res.getStatus();
1047 // Check the status code of the response: does it match
1048 // the expected response(s)?
1049 if(logger.isDebugEnabled()){
1050 logger.debug(testName + ": status = " + statusCode);
1052 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1053 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1054 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1056 res.releaseConnection();
1061 * Read contact non existent.
1063 * @param testName the test name
1065 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1066 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1067 public void readContactNonExistent(String testName) {
1069 if (logger.isDebugEnabled()) {
1070 logger.debug(testBanner(testName, CLASS_NAME));
1073 setupReadNonExistent();
1075 // Submit the request to the service and store the response.
1076 PersonAuthorityClient client = new PersonAuthorityClient();
1077 ClientResponse<MultipartInput> res =
1078 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1080 int statusCode = res.getStatus();
1082 // Check the status code of the response: does it match
1083 // the expected response(s)?
1084 if(logger.isDebugEnabled()){
1085 logger.debug(testName + ": status = " + statusCode);
1087 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1088 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1089 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1091 res.releaseConnection();
1095 // ---------------------------------------------------------------
1096 // CRUD tests : READ_LIST tests
1097 // ---------------------------------------------------------------
1101 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1104 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1105 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1106 public void readList(String testName) throws Exception {
1108 if (logger.isDebugEnabled()) {
1109 logger.debug(testBanner(testName, CLASS_NAME));
1114 // Submit the request to the service and store the response.
1115 PersonAuthorityClient client = new PersonAuthorityClient();
1116 PersonauthoritiesCommonList list = null;
1117 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1119 int statusCode = res.getStatus();
1121 // Check the status code of the response: does it match
1122 // the expected response(s)?
1123 if(logger.isDebugEnabled()){
1124 logger.debug(testName + ": status = " + statusCode);
1126 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1127 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1128 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1130 list = res.getEntity();
1132 res.releaseConnection();
1135 // Optionally output additional data about list members for debugging.
1136 boolean iterateThroughList = false;
1137 if (iterateThroughList && logger.isDebugEnabled()) {
1138 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1139 list.getPersonauthorityListItem();
1141 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1142 String csid = item.getCsid();
1143 logger.debug(testName + ": list-item[" + i + "] csid=" +
1145 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1146 item.getDisplayName());
1147 logger.debug(testName + ": list-item[" + i + "] URI=" +
1149 readItemList(csid, null, testName);
1158 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1159 groups = {"readList"}, dependsOnMethods = {"readList"})
1160 public void readItemList(String testName) {
1161 readItemList(knownResourceId, null, testName);
1165 * Read item list by authority name.
1167 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1168 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1169 public void readItemListByAuthorityName(String testName) {
1170 readItemList(null, knownResourceShortIdentifer, testName);
1176 * @param vcsid the vcsid
1177 * @param name the name
1179 private void readItemList(String vcsid, String name, String testName) {
1184 // Submit the request to the service and store the response.
1185 PersonAuthorityClient client = new PersonAuthorityClient();
1186 ClientResponse<PersonsCommonList> res = null;
1188 res = client.readItemList(vcsid, null, null);
1189 } else if (name!= null) {
1190 res = client.readItemListForNamedAuthority(name, null, null);
1192 Assert.fail("readItemList passed null csid and name!");
1194 PersonsCommonList list = null;
1196 int statusCode = res.getStatus();
1198 // Check the status code of the response: does it match
1199 // the expected response(s)?
1200 if(logger.isDebugEnabled()){
1201 logger.debug(testName + ": status = " + statusCode);
1203 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1204 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1205 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1207 list = res.getEntity();
1209 res.releaseConnection();
1212 List<PersonsCommonList.PersonListItem> items =
1213 list.getPersonListItem();
1214 int nItemsReturned = items.size();
1215 // There will be one item created, associated with a
1216 // known parent resource, by the createItem test.
1218 // In addition, there will be 'nItemsToCreateInList'
1219 // additional items created by the createItemList test,
1220 // all associated with the same parent resource.
1221 int nExpectedItems = nItemsToCreateInList + 1;
1222 if(logger.isDebugEnabled()){
1223 logger.debug(testName + ": Expected "
1224 + nExpectedItems +" items; got: "+nItemsReturned);
1226 Assert.assertEquals(nItemsReturned, nExpectedItems);
1229 for (PersonsCommonList.PersonListItem item : items) {
1230 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1231 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1232 // Optionally output additional data about list members for debugging.
1233 boolean showDetails = true;
1234 if (showDetails && logger.isDebugEnabled()) {
1235 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1237 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1239 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1240 item.getDisplayName());
1241 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1249 * Read contact list.
1251 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1252 public void readContactList() {
1253 readContactList(knownResourceId, knownItemResourceId);
1257 * Read contact list.
1259 * @param parentcsid the parentcsid
1260 * @param itemcsid the itemcsid
1262 private void readContactList(String parentcsid, String itemcsid) {
1263 final String testName = "readContactList";
1268 // Submit the request to the service and store the response.
1269 PersonAuthorityClient client = new PersonAuthorityClient();
1270 ContactsCommonList list = null;
1271 ClientResponse<ContactsCommonList> res =
1272 client.readContactList(parentcsid, itemcsid);
1274 int statusCode = res.getStatus();
1276 // Check the status code of the response: does it match
1277 // the expected response(s)?
1278 if(logger.isDebugEnabled()){
1279 logger.debug(testName + ": status = " + statusCode);
1281 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1282 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1283 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1285 list = res.getEntity();
1287 res.releaseConnection();
1290 List<ContactsCommonList.ContactListItem> listitems =
1291 list.getContactListItem();
1292 int nItemsReturned = listitems.size();
1293 // There will be one item created, associated with a
1294 // known parent resource, by the createItem test.
1296 // In addition, there will be 'nItemsToCreateInList'
1297 // additional items created by the createItemList test,
1298 // all associated with the same parent resource.
1299 int nExpectedItems = nItemsToCreateInList + 1;
1300 if(logger.isDebugEnabled()){
1301 logger.debug(testName + ": Expected "
1302 + nExpectedItems +" items; got: "+nItemsReturned);
1304 Assert.assertEquals(nItemsReturned, nExpectedItems);
1307 for (ContactsCommonList.ContactListItem listitem : listitems) {
1308 // Optionally output additional data about list members for debugging.
1309 boolean showDetails = false;
1310 if (showDetails && logger.isDebugEnabled()) {
1311 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1312 listitem.getCsid());
1313 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1314 listitem.getAddressPlace());
1315 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1324 // There are no failure outcome tests at present.
1326 // ---------------------------------------------------------------
1327 // CRUD tests : UPDATE tests
1328 // ---------------------------------------------------------------
1331 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1334 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1335 groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
1336 public void update(String testName) throws Exception {
1338 if (logger.isDebugEnabled()) {
1339 logger.debug(testBanner(testName, CLASS_NAME));
1344 // Retrieve the contents of a resource to update.
1345 PersonAuthorityClient client = new PersonAuthorityClient();
1346 MultipartInput input = null;
1347 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1349 if(logger.isDebugEnabled()){
1350 logger.debug(testName + ": read status = " + res.getStatus());
1352 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1354 if(logger.isDebugEnabled()){
1355 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1357 input = res.getEntity();
1359 res.releaseConnection();
1362 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1363 client.getCommonPartName(), PersonauthoritiesCommon.class);
1364 Assert.assertNotNull(personAuthority);
1366 // Update the contents of this resource.
1367 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1368 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1369 if(logger.isDebugEnabled()){
1370 logger.debug("to be updated PersonAuthority");
1371 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1374 // Submit the updated resource to the service and store the response.
1375 MultipartOutput output = new MultipartOutput();
1376 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1377 commonPart.getHeaders().add("label", client.getCommonPartName());
1378 res = client.update(knownResourceId, output);
1380 int statusCode = res.getStatus();
1382 // Check the status code of the response: does it match the expected response(s)?
1383 if(logger.isDebugEnabled()){
1384 logger.debug(testName + ": status = " + statusCode);
1386 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1387 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1388 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1390 // Retrieve the updated resource and verify that its contents exist.
1391 input = (MultipartInput) res.getEntity();
1393 res.releaseConnection();
1396 PersonauthoritiesCommon updatedPersonAuthority =
1397 (PersonauthoritiesCommon) extractPart(input,
1398 client.getCommonPartName(), PersonauthoritiesCommon.class);
1399 Assert.assertNotNull(updatedPersonAuthority);
1401 // Verify that the updated resource received the correct data.
1402 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1403 personAuthority.getDisplayName(),
1404 "Data in updated object did not match submitted data.");
1410 * @param testName the test name
1411 * @throws Exception the exception
1413 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1414 groups = {"update"}, dependsOnMethods = {"update"})
1415 public void updateItem(String testName) throws Exception {
1417 if (logger.isDebugEnabled()) {
1418 logger.debug(testBanner(testName, CLASS_NAME));
1423 // Retrieve the contents of a resource to update.
1424 PersonAuthorityClient client = new PersonAuthorityClient();
1425 MultipartInput input = null;
1426 ClientResponse<MultipartInput> res =
1427 client.readItem(knownResourceId, knownItemResourceId);
1429 if(logger.isDebugEnabled()){
1430 logger.debug(testName + ": read status = " + res.getStatus());
1432 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1434 if(logger.isDebugEnabled()){
1435 logger.debug("got Person to update with ID: " +
1436 knownItemResourceId +
1437 " in PersonAuthority: " + knownResourceId );
1439 input = res.getEntity();
1441 res.releaseConnection();
1444 PersonsCommon person = (PersonsCommon) extractPart(input,
1445 client.getItemCommonPartName(), PersonsCommon.class);
1446 Assert.assertNotNull(person);
1448 if (logger.isDebugEnabled() == true) {
1449 logger.debug("About to update the following person...");
1450 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1453 // Update the contents of this resource.
1454 person.setCsid(null);
1455 person.setForeName("updated-" + person.getForeName());
1456 if(logger.isDebugEnabled()){
1457 logger.debug("to be updated Person");
1458 logger.debug(objectAsXmlString(person,
1459 PersonsCommon.class));
1462 // Submit the updated resource to the service and store the response.
1463 MultipartOutput output = new MultipartOutput();
1464 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1465 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1466 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1468 int statusCode = res.getStatus();
1470 // Check the status code of the response: does it match the expected response(s)?
1471 if(logger.isDebugEnabled()){
1472 logger.debug(testName + ": status = " + statusCode);
1474 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1475 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1476 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1478 // Retrieve the updated resource and verify that its contents exist.
1479 input = (MultipartInput) res.getEntity();
1481 res.releaseConnection();
1484 PersonsCommon updatedPerson =
1485 (PersonsCommon) extractPart(input,
1486 client.getItemCommonPartName(), PersonsCommon.class);
1487 Assert.assertNotNull(updatedPerson);
1489 if (logger.isDebugEnabled() == true) {
1490 logger.debug("Updated to following person to:");
1491 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1494 // Verify that the updated resource received the correct data.
1495 Assert.assertEquals(updatedPerson.getForeName(),
1496 person.getForeName(),
1497 "Data in updated Person did not match submitted data.");
1503 * @param testName the test name
1504 * @throws Exception the exception
1506 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1507 groups = {"update"}, dependsOnMethods = {"updateItem"})
1508 public void updateContact(String testName) throws Exception {
1510 if (logger.isDebugEnabled()) {
1511 logger.debug(testBanner(testName, CLASS_NAME));
1516 // Retrieve the contents of a resource to update.
1517 PersonAuthorityClient client = new PersonAuthorityClient();
1518 MultipartInput input = null;
1519 ClientResponse<MultipartInput> res =
1520 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1522 if(logger.isDebugEnabled()){
1523 logger.debug(testName + ": read status = " + res.getStatus());
1525 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1527 if(logger.isDebugEnabled()){
1528 logger.debug("got Contact to update with ID: " +
1529 knownContactResourceId +
1530 " in item: " + knownItemResourceId +
1531 " in parent: " + knownResourceId );
1533 input = res.getEntity();
1535 res.releaseConnection();
1538 ContactsCommon contact = (ContactsCommon) extractPart(input,
1539 new ContactClient().getCommonPartName(), ContactsCommon.class);
1540 Assert.assertNotNull(contact);
1542 // Update the contents of this resource.
1543 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1544 if(logger.isDebugEnabled()){
1545 logger.debug("to be updated Contact");
1546 logger.debug(objectAsXmlString(contact,
1547 ContactsCommon.class));
1550 // Submit the updated resource to the service and store the response.
1551 MultipartOutput output = new MultipartOutput();
1552 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1553 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1554 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1556 int statusCode = res.getStatus();
1558 // Check the status code of the response: does it match the expected response(s)?
1559 if(logger.isDebugEnabled()){
1560 logger.debug(testName + ": status = " + statusCode);
1562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1566 // Retrieve the updated resource and verify that its contents exist.
1567 input = (MultipartInput) res.getEntity();
1569 res.releaseConnection();
1571 ContactsCommon updatedContact =
1572 (ContactsCommon) extractPart(input,
1573 new ContactClient().getCommonPartName(), ContactsCommon.class);
1574 Assert.assertNotNull(updatedContact);
1576 // Verify that the updated resource received the correct data.
1577 Assert.assertEquals(updatedContact.getAddressPlace(),
1578 contact.getAddressPlace(),
1579 "Data in updated Contact did not match submitted data.");
1583 // Placeholders until the three tests below can be uncommented.
1584 // See Issue CSPACE-401.
1586 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1589 public void updateWithEmptyEntityBody(String testName) throws Exception {
1590 //Should this really be empty?
1594 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1597 public void updateWithMalformedXml(String testName) throws Exception {
1598 //Should this really be empty?
1602 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1605 public void updateWithWrongXmlSchema(String testName) throws Exception {
1606 //Should this really be empty?
1611 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1612 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1613 public void updateWithEmptyEntityBody(String testName) throws Exception {
1615 if (logger.isDebugEnabled()) {
1616 logger.debug(testBanner(testName, CLASS_NAME));
1619 setupUpdateWithEmptyEntityBody(testName, logger);
1621 // Submit the request to the service and store the response.
1622 String method = REQUEST_TYPE.httpMethodName();
1623 String url = getResourceURL(knownResourceId);
1624 String mediaType = MediaType.APPLICATION_XML;
1625 final String entity = "";
1626 int statusCode = submitRequest(method, url, mediaType, entity);
1628 // Check the status code of the response: does it match
1629 // the expected response(s)?
1630 if(logger.isDebugEnabled()){
1631 logger.debug(testName + ": url=" + url +
1632 " status=" + statusCode);
1634 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1635 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1636 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1640 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1641 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1642 public void updateWithMalformedXml(String testName) throws Exception {
1644 if (logger.isDebugEnabled()) {
1645 logger.debug(testBanner(testName, CLASS_NAME));
1648 setupUpdateWithMalformedXml();
1650 // Submit the request to the service and store the response.
1651 String method = REQUEST_TYPE.httpMethodName();
1652 String url = getResourceURL(knownResourceId);
1653 String mediaType = MediaType.APPLICATION_XML;
1654 final String entity = MALFORMED_XML_DATA;
1655 int statusCode = submitRequest(method, url, mediaType, entity);
1657 // Check the status code of the response: does it match
1658 // the expected response(s)?
1659 if(logger.isDebugEnabled()){
1660 logger.debug(testName + ": url=" + url +
1661 " status=" + statusCode);
1663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1669 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1670 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1671 public void updateWithWrongXmlSchema(String testName) throws Exception {
1673 if (logger.isDebugEnabled()) {
1674 logger.debug(testBanner(testName, CLASS_NAME));
1677 setupUpdateWithWrongXmlSchema();
1679 // Submit the request to the service and store the response.
1680 String method = REQUEST_TYPE.httpMethodName();
1681 String url = getResourceURL(knownResourceId);
1682 String mediaType = MediaType.APPLICATION_XML;
1683 final String entity = WRONG_XML_SCHEMA_DATA;
1684 int statusCode = submitRequest(method, url, mediaType, entity);
1686 // Check the status code of the response: does it match
1687 // the expected response(s)?
1688 if(logger.isDebugEnabled()){
1689 logger.debug("updateWithWrongXmlSchema: url=" + url +
1690 " status=" + statusCode);
1692 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1693 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1694 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1699 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1702 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1703 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1704 public void updateNonExistent(String testName) throws Exception {
1706 if (logger.isDebugEnabled()) {
1707 logger.debug(testBanner(testName, CLASS_NAME));
1710 setupUpdateNonExistent();
1712 // Submit the request to the service and store the response.
1713 // Note: The ID(s) used when creating the request payload may be arbitrary.
1714 // The only relevant ID may be the one used in update(), below.
1715 PersonAuthorityClient client = new PersonAuthorityClient();
1716 String displayName = "displayName-NON_EXISTENT_ID";
1717 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1718 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1719 ClientResponse<MultipartInput> res =
1720 client.update(NON_EXISTENT_ID, multipart);
1722 int statusCode = res.getStatus();
1724 // Check the status code of the response: does it match
1725 // the expected response(s)?
1726 if(logger.isDebugEnabled()){
1727 logger.debug(testName + ": status = " + statusCode);
1729 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1730 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1731 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1733 res.releaseConnection();
1738 * Update non existent item.
1740 * @param testName the test name
1741 * @throws Exception the exception
1743 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1744 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1745 public void updateNonExistentItem(String testName) throws Exception {
1747 if (logger.isDebugEnabled()) {
1748 logger.debug(testBanner(testName, CLASS_NAME));
1751 setupUpdateNonExistent();
1753 // Submit the request to the service and store the response.
1754 // Note: The ID used in this 'create' call may be arbitrary.
1755 // The only relevant ID may be the one used in update(), below.
1756 PersonAuthorityClient client = new PersonAuthorityClient();
1757 Map<String, String> nonexMap = new HashMap<String,String>();
1758 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1759 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1760 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1761 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1762 Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1763 MultipartOutput multipart =
1764 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1765 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1766 nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() );
1767 ClientResponse<MultipartInput> res =
1768 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1770 int statusCode = res.getStatus();
1772 // Check the status code of the response: does it match
1773 // the expected response(s)?
1774 if(logger.isDebugEnabled()){
1775 logger.debug(testName + ": status = " + statusCode);
1777 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1778 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1779 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1781 res.releaseConnection();
1786 * Update non existent contact.
1788 * @param testName the test name
1789 * @throws Exception the exception
1791 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1792 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1793 public void updateNonExistentContact(String testName) throws Exception {
1794 // Currently a no-op test
1797 // ---------------------------------------------------------------
1798 // CRUD tests : DELETE tests
1799 // ---------------------------------------------------------------
1802 // Note: delete sub-resources in ascending hierarchical order,
1803 // before deleting their parents.
1808 * @param testName the test name
1809 * @throws Exception the exception
1811 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1812 groups = {"delete"}, dependsOnGroups = {"update"})
1813 public void deleteContact(String testName) throws Exception {
1815 if (logger.isDebugEnabled()) {
1816 logger.debug(testBanner(testName, CLASS_NAME));
1821 if(logger.isDebugEnabled()){
1822 logger.debug("parentcsid =" + knownResourceId +
1823 " itemcsid = " + knownItemResourceId +
1824 " csid = " + knownContactResourceId);
1827 // Submit the request to the service and store the response.
1828 PersonAuthorityClient client = new PersonAuthorityClient();
1829 ClientResponse<Response> res =
1830 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1832 int statusCode = res.getStatus();
1834 // Check the status code of the response: does it match
1835 // the expected response(s)?
1836 if(logger.isDebugEnabled()){
1837 logger.debug(testName + ": status = " + statusCode);
1839 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1840 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1841 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1843 res.releaseConnection();
1850 * @param testName the test name
1851 * @throws Exception the exception
1853 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1854 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1855 public void deleteItem(String testName) throws Exception {
1857 if (logger.isDebugEnabled()) {
1858 logger.debug(testBanner(testName, CLASS_NAME));
1863 if(logger.isDebugEnabled()){
1864 logger.debug("parentcsid =" + knownResourceId +
1865 " itemcsid = " + knownItemResourceId);
1868 // Submit the request to the service and store the response.
1869 PersonAuthorityClient client = new PersonAuthorityClient();
1870 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1872 int statusCode = res.getStatus();
1874 // Check the status code of the response: does it match
1875 // the expected response(s)?
1876 if(logger.isDebugEnabled()){
1877 logger.debug(testName + ": status = " + statusCode);
1879 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1880 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1881 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1883 res.releaseConnection();
1888 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1891 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1892 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1893 public void delete(String testName) throws Exception {
1895 if (logger.isDebugEnabled()) {
1896 logger.debug(testBanner(testName, CLASS_NAME));
1901 if(logger.isDebugEnabled()){
1902 logger.debug("parentcsid =" + knownResourceId);
1905 // Submit the request to the service and store the response.
1906 PersonAuthorityClient client = new PersonAuthorityClient();
1907 ClientResponse<Response> res = client.delete(knownResourceId);
1909 int statusCode = res.getStatus();
1911 // Check the status code of the response: does it match
1912 // the expected response(s)?
1913 if(logger.isDebugEnabled()){
1914 logger.debug(testName + ": status = " + statusCode);
1916 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1917 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1918 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1920 res.releaseConnection();
1926 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1929 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1930 groups = {"delete"}, dependsOnMethods = {"delete"})
1931 public void deleteNonExistent(String testName) throws Exception {
1933 if (logger.isDebugEnabled()) {
1934 logger.debug(testBanner(testName, CLASS_NAME));
1937 setupDeleteNonExistent();
1939 // Submit the request to the service and store the response.
1940 PersonAuthorityClient client = new PersonAuthorityClient();
1941 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1943 int statusCode = res.getStatus();
1945 // Check the status code of the response: does it match
1946 // the expected response(s)?
1947 if(logger.isDebugEnabled()){
1948 logger.debug(testName + ": status = " + statusCode);
1950 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1951 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1952 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1954 res.releaseConnection();
1959 * Delete non existent item.
1961 * @param testName the test name
1963 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1964 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1965 public void deleteNonExistentItem(String testName) {
1967 if (logger.isDebugEnabled()) {
1968 logger.debug(testBanner(testName, CLASS_NAME));
1971 setupDeleteNonExistent();
1973 // Submit the request to the service and store the response.
1974 PersonAuthorityClient client = new PersonAuthorityClient();
1975 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1977 int statusCode = res.getStatus();
1979 // Check the status code of the response: does it match
1980 // the expected response(s)?
1981 if(logger.isDebugEnabled()){
1982 logger.debug(testName + ": status = " + statusCode);
1984 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1985 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1986 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1988 res.releaseConnection();
1993 * Delete non existent contact.
1995 * @param testName the test name
1997 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1998 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1999 public void deleteNonExistentContact(String testName) {
2001 if (logger.isDebugEnabled()) {
2002 logger.debug(testBanner(testName, CLASS_NAME));
2005 setupDeleteNonExistent();
2007 // Submit the request to the service and store the response.
2008 PersonAuthorityClient client = new PersonAuthorityClient();
2009 ClientResponse<Response> res =
2010 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2012 int statusCode = res.getStatus();
2014 // Check the status code of the response: does it match
2015 // the expected response(s)?
2016 if(logger.isDebugEnabled()){
2017 logger.debug(testName + ": status = " + statusCode);
2019 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2020 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2021 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2023 res.releaseConnection();
2027 // ---------------------------------------------------------------
2028 // Utility tests : tests of code used in tests above
2029 // ---------------------------------------------------------------
2031 * Tests the code for manually submitting data that is used by several
2032 * of the methods above.
2034 @Test(dependsOnMethods = {"create", "read"})
2035 public void testSubmitRequest() {
2037 // Expected status code: 200 OK
2038 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2040 // Submit the request to the service and store the response.
2041 String method = ServiceRequestType.READ.httpMethodName();
2042 String url = getResourceURL(knownResourceId);
2043 int statusCode = submitRequest(method, url);
2045 // Check the status code of the response: does it match
2046 // the expected response(s)?
2047 if(logger.isDebugEnabled()){
2048 logger.debug("testSubmitRequest: url=" + url +
2049 " status=" + statusCode);
2051 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2056 * Test item submit request.
2058 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2059 public void testItemSubmitRequest() {
2061 // Expected status code: 200 OK
2062 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2064 // Submit the request to the service and store the response.
2065 String method = ServiceRequestType.READ.httpMethodName();
2066 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2067 int statusCode = submitRequest(method, url);
2069 // Check the status code of the response: does it match
2070 // the expected response(s)?
2071 if(logger.isDebugEnabled()){
2072 logger.debug("testItemSubmitRequest: url=" + url +
2073 " status=" + statusCode);
2075 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2080 * Test contact submit request.
2082 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2083 public void testContactSubmitRequest() {
2085 // Expected status code: 200 OK
2086 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2088 // Submit the request to the service and store the response.
2089 String method = ServiceRequestType.READ.httpMethodName();
2090 String url = getContactResourceURL(knownResourceId,
2091 knownItemResourceId, knownContactResourceId);
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 // ---------------------------------------------------------------
2106 // Cleanup of resources created during testing
2107 // ---------------------------------------------------------------
2110 * Deletes all resources created by tests, after all tests have been run.
2112 * This cleanup method will always be run, even if one or more tests fail.
2113 * For this reason, it attempts to remove all resources created
2114 * at any point during testing, even if some of those resources
2115 * may be expected to be deleted by certain tests.
2118 @AfterClass(alwaysRun=true)
2120 public void cleanUp() {
2121 String noTest = System.getProperty("noTestCleanup");
2122 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2123 if (logger.isDebugEnabled()) {
2124 logger.debug("Skipping Cleanup phase ...");
2128 if (logger.isDebugEnabled()) {
2129 logger.debug("Cleaning up temporary resources created for testing ...");
2131 String parentResourceId;
2132 String itemResourceId;
2133 String contactResourceId;
2134 // Clean up contact resources.
2135 PersonAuthorityClient client = new PersonAuthorityClient();
2136 parentResourceId = knownResourceId;
2137 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2138 contactResourceId = entry.getKey();
2139 itemResourceId = entry.getValue();
2140 // Note: Any non-success responses from the delete operation
2141 // below are ignored and not reported.
2142 ClientResponse<Response> res =
2143 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2144 res.releaseConnection();
2146 // Clean up item resources.
2147 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2148 itemResourceId = entry.getKey();
2149 parentResourceId = entry.getValue();
2150 // Note: Any non-success responses from the delete operation
2151 // below are ignored and not reported.
2152 ClientResponse<Response> res =
2153 client.deleteItem(parentResourceId, itemResourceId);
2154 res.releaseConnection();
2156 // Clean up parent resources.
2160 // ---------------------------------------------------------------
2161 // Utility methods used by tests above
2162 // ---------------------------------------------------------------
2164 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2167 public String getServicePathComponent() {
2168 return SERVICE_PATH_COMPONENT;
2172 * Gets the item service path component.
2174 * @return the item service path component
2176 public String getItemServicePathComponent() {
2177 return ITEM_SERVICE_PATH_COMPONENT;
2181 * Gets the contact service path component.
2183 * @return the contact service path component
2185 public String getContactServicePathComponent() {
2186 return CONTACT_SERVICE_PATH_COMPONENT;
2190 * Returns the root URL for the item service.
2192 * This URL consists of a base URL for all services, followed by
2193 * a path component for the owning parent, followed by the
2194 * path component for the items.
2196 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2197 * parent authority resource of the relevant item resource.
2199 * @return The root URL for the item service.
2201 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2202 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2206 * Returns the URL of a specific item resource managed by a service, and
2207 * designated by an identifier (such as a universally unique ID, or UUID).
2209 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2210 * parent authority resource of the relevant item resource.
2212 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2215 * @return The URL of a specific item resource managed by a service.
2217 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2218 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2223 * Returns the root URL for the contact service.
2225 * This URL consists of a base URL for all services, followed by
2226 * a path component for the owning authority, followed by the
2227 * path component for the owning item, followed by the path component
2228 * for the contact service.
2230 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2231 * parent authority resource of the relevant item resource.
2233 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2236 * @return The root URL for the contact service.
2238 protected String getContactServiceRootURL(String parentResourceIdentifier,
2239 String itemResourceIdentifier) {
2240 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2241 getContactServicePathComponent();
2245 * Returns the URL of a specific contact resource managed by a service, and
2246 * designated by an identifier (such as a universally unique ID, or UUID).
2248 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2249 * parent resource of the relevant item resource.
2251 * @param resourceIdentifier An identifier (such as a UUID) for an
2254 * @return The URL of a specific resource managed by a service.
2256 protected String getContactResourceURL(String parentResourceIdentifier,
2257 String itemResourceIdentifier, String contactResourceIdentifier) {
2258 return getContactServiceRootURL(parentResourceIdentifier,
2259 itemResourceIdentifier) + "/" + contactResourceIdentifier;