2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright (c)) 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 package org.collectionspace.services.client.test;
25 import java.util.HashMap;
26 import java.util.List;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.PersonJAXBSchema;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.contact.ContactsCommon;
36 import org.collectionspace.services.contact.ContactsCommonList;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonauthoritiesCommon;
41 import org.collectionspace.services.person.PersonauthoritiesCommonList;
42 import org.collectionspace.services.person.PersonsCommon;
43 import org.collectionspace.services.person.PersonsCommonList;
44 import org.jboss.resteasy.client.ClientResponse;
45 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
55 * PersonAuthorityServiceTest, carries out tests against a
56 * deployed and running PersonAuthority Service.
58 * $LastChangedRevision: 753 $
59 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
61 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
64 private final Logger logger =
65 LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
67 // Instance variables specific to this test.
68 /** The service path component. */
69 final String SERVICE_PATH_COMPONENT = "personauthorities";
71 /** The item service path component. */
72 final String ITEM_SERVICE_PATH_COMPONENT = "items";
74 /** The contact service path component. */
75 final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
77 /** The test forename. */
78 final String TEST_FORE_NAME = "John";
80 /** The test middle name. */
81 final String TEST_MIDDLE_NAME = null;
83 /** The test surname. */
84 final String TEST_SUR_NAME = "Wayne";
86 /** The test birthdate. */
87 final String TEST_BIRTH_DATE = "May 26, 1907";
89 /** The test death date. */
90 final String TEST_DEATH_DATE = "June 11, 1979";
92 // Test name for partial term matching: Lech Walesa
93 final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
94 // Contains two non-USASCII range Unicode UTF-8 characters
95 final String TEST_PARTIAL_TERM_SUR_NAME = "Wa" + "\u0142" + "\u0119" + "sa";
96 final String TEST_PARTIAL_TERM_DISPLAY_NAME =
97 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME;
99 /** The known resource id. */
100 private String knownResourceId = null;
102 /** The known resource display name. */
103 private String knownResourceDisplayName = null;
105 /** The known resource ref name. */
106 private String knownResourceRefName = null;
108 /** The known item resource id. */
109 private String knownItemResourceId = null;
111 // The resource ID of an item resource used for partial term matching tests.
112 private String knownItemPartialTermResourceId = null;
114 /** The known contact resource id. */
115 private String knownContactResourceId = null;
117 /** The n items to create in list. */
118 private int nItemsToCreateInList = 3;
120 /** The all item resource ids created. */
121 private Map<String, String> allItemResourceIdsCreated =
122 new HashMap<String, String>();
124 /** The all contact resource ids created. */
125 private Map<String, String> allContactResourceIdsCreated =
126 new HashMap<String, String>();
129 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
132 protected CollectionSpaceClient getClientInstance() {
133 return new PersonAuthorityClient();
137 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
140 protected AbstractCommonList getAbstractCommonList(
141 ClientResponse<AbstractCommonList> response) {
142 return response.getEntity(PersonsCommonList.class);
145 // ---------------------------------------------------------------
146 // CRUD tests : CREATE tests
147 // ---------------------------------------------------------------
150 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
153 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
155 public void create(String testName) throws Exception {
157 // Perform setup, such as initializing the type of service request
158 // (e.g. CREATE, DELETE), its valid and expected status codes, and
159 // its associated HTTP method name (e.g. POST, DELETE).
160 setupCreate(testName);
162 // Submit the request to the service and store the response.
163 PersonAuthorityClient client = new PersonAuthorityClient();
164 String identifier = createIdentifier();
165 String displayName = "displayName-" + identifier;
166 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, false);
167 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
168 MultipartOutput multipart =
169 PersonAuthorityClientUtils.createPersonAuthorityInstance(
170 displayName, fullRefName, client.getCommonPartName());
173 ClientResponse<Response> res = client.create(multipart);
175 int statusCode = res.getStatus();
177 // Check the status code of the response: does it match
178 // the expected response(s)?
181 // Does it fall within the set of valid status codes?
182 // Does it exactly match the expected status code?
183 if(logger.isDebugEnabled()){
184 logger.debug(testName + ": status = " + statusCode);
186 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
187 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
188 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
190 newID = PersonAuthorityClientUtils.extractId(res);
192 res.releaseConnection();
194 // Store the refname from the first resource created
195 // for additional tests below.
196 knownResourceRefName = baseRefName;
197 // Store the ID returned from the first resource created
198 // for additional tests below.
199 if (knownResourceId == null){
200 knownResourceId = newID;
201 knownResourceDisplayName = displayName;
202 if (logger.isDebugEnabled()) {
203 logger.debug(testName + ": knownResourceId=" + knownResourceId);
206 // Store the IDs from every resource created by tests,
207 // so they can be deleted after tests have been run.
208 allResourceIdsCreated.add(newID);
214 * @param testName the test name
216 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
217 groups = {"create"}, dependsOnMethods = {"create"})
218 public void createItem(String testName) {
219 setupCreate(testName);
220 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
224 * Creates the item in authority.
226 * @param vcsid the vcsid
227 * @param authRefName the auth ref name
230 private String createItemInAuthority(String vcsid, String authRefName) {
232 final String testName = "createItemInAuthority";
233 if(logger.isDebugEnabled()){
234 logger.debug(testName + ":...");
237 // Submit the request to the service and store the response.
238 PersonAuthorityClient client = new PersonAuthorityClient();
239 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
240 Map<String, String> johnWayneMap = new HashMap<String,String>();
242 // Fill the property map
244 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
245 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
247 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
248 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
249 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
250 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
251 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
252 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
253 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
254 "known by his stage name John Wayne, was an American film actor, director " +
255 "and producer. He epitomized rugged masculinity and has become an enduring " +
256 "American icon. He is famous for his distinctive voice, walk and height. " +
257 "He was also known for his conservative political views and his support in " +
258 "the 1950s for anti-communist positions.");
259 MultipartOutput multipart =
260 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, johnWayneMap,
261 client.getItemCommonPartName() );
264 ClientResponse<Response> res = client.createItem(vcsid, multipart);
266 int statusCode = res.getStatus();
267 // Check the status code of the response: does it match
268 // the expected response(s)?
269 if(logger.isDebugEnabled()){
270 logger.debug(testName + ": status = " + statusCode);
272 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
273 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
274 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276 newID = PersonAuthorityClientUtils.extractId(res);
278 res.releaseConnection();
281 // Store the ID returned from the first item resource created
282 // for additional tests below.
283 if (knownItemResourceId == null){
284 knownItemResourceId = newID;
285 if (logger.isDebugEnabled()) {
286 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
290 // Store the IDs from any item resources created
291 // by tests, along with the IDs of their parents, so these items
292 // can be deleted after all tests have been run.
293 allItemResourceIdsCreated.put(newID, vcsid);
299 * Creates an item in the authority, used for partial term matching tests.
301 * @param vcsid the vcsid
302 * @param authRefName the auth ref name
305 private String createItemInAuthorityForPartialTermMatch(String vcsid, String authRefName) {
307 final String testName = "createItemInAuthorityForPartialTermMatch";
308 if(logger.isDebugEnabled()){
309 logger.debug(testName + ":...");
312 setupCreate(testName);
314 // Submit the request to the service and store the response.
315 PersonAuthorityClient client = new PersonAuthorityClient();
316 String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName,
317 TEST_PARTIAL_TERM_DISPLAY_NAME, true);
318 Map<String, String> partialTermPersonMap = new HashMap<String,String>();
320 // Fill the property map
322 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
323 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
324 partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
325 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
326 partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
327 MultipartOutput multipart =
328 PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, partialTermPersonMap,
329 client.getItemCommonPartName() );
332 ClientResponse<Response> res = client.createItem(vcsid, multipart);
334 int statusCode = res.getStatus();
335 // Check the status code of the response: does it match
336 // the expected response(s)?
337 if(logger.isDebugEnabled()){
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
344 newID = PersonAuthorityClientUtils.extractId(res);
346 res.releaseConnection();
349 // Store the ID returned from the first item resource created
350 // for additional tests below.
351 if (knownItemResourceId == null){
352 knownItemResourceId = newID;
353 if (logger.isDebugEnabled()) {
354 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
358 // Store the IDs from any item resources created
359 // by tests, along with the IDs of their parents, so these items
360 // can be deleted after all tests have been run.
361 allItemResourceIdsCreated.put(newID, vcsid);
367 * Creates the contact.
369 * @param testName the test name
371 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
372 groups = {"create"}, dependsOnMethods = {"createItem"})
373 public void createContact(String testName) {
374 setupCreate(testName);
375 String newID = createContactInItem(knownResourceId, knownItemResourceId);
379 * Creates the contact in item.
381 * @param parentcsid the parentcsid
382 * @param itemcsid the itemcsid
385 private String createContactInItem(String parentcsid, String itemcsid) {
387 final String testName = "createContactInItem";
388 setupCreate(testName);
389 if(logger.isDebugEnabled()){
390 logger.debug(testName + ":...");
393 // Submit the request to the service and store the response.
394 PersonAuthorityClient client = new PersonAuthorityClient();
395 String identifier = createIdentifier();
396 MultipartOutput multipart =
397 ContactClientUtils.createContactInstance(parentcsid,
398 itemcsid, identifier, new ContactClient().getCommonPartName());
401 ClientResponse<Response> res =
402 client.createContact(parentcsid, itemcsid, multipart);
404 int statusCode = res.getStatus();
405 // Check the status code of the response: does it match
406 // the expected response(s)?
407 if(logger.isDebugEnabled()){
408 logger.debug(testName + ": status = " + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
414 newID = PersonAuthorityClientUtils.extractId(res);
416 res.releaseConnection();
419 // Store the ID returned from the first contact resource created
420 // for additional tests below.
421 if (knownContactResourceId == null){
422 knownContactResourceId = newID;
423 if (logger.isDebugEnabled()) {
424 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
428 // Store the IDs from any contact resources created
429 // by tests, along with the IDs of their parent items,
430 // so these items can be deleted after all tests have been run.
431 allContactResourceIdsCreated.put(newID, itemcsid);
438 // Placeholders until the three tests below can be uncommented.
439 // See Issue CSPACE-401.
441 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
444 public void createWithEmptyEntityBody(String testName) throws Exception {
445 //Should this really be empty?
449 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
452 public void createWithMalformedXml(String testName) throws Exception {
453 //Should this really be empty?
457 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
460 public void createWithWrongXmlSchema(String testName) throws Exception {
461 //Should this really be empty?
466 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
467 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
468 public void createWithEmptyEntityBody(String testName) throws Exception {
471 setupCreateWithEmptyEntityBody(testName);
473 // Submit the request to the service and store the response.
474 String method = REQUEST_TYPE.httpMethodName();
475 String url = getServiceRootURL();
476 String mediaType = MediaType.APPLICATION_XML;
477 final String entity = "";
478 int statusCode = submitRequest(method, url, mediaType, entity);
480 // Check the status code of the response: does it match
481 // the expected response(s)?
482 if(logger.isDebugEnabled()) {
483 logger.debug(testName + ": url=" + url +
484 " status=" + statusCode);
486 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
487 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
488 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
492 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
493 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
494 public void createWithMalformedXml(String testName) throws Exception {
497 setupCreateWithMalformedXml(testName);
499 // Submit the request to the service and store the response.
500 String method = REQUEST_TYPE.httpMethodName();
501 String url = getServiceRootURL();
502 String mediaType = MediaType.APPLICATION_XML;
503 final String entity = MALFORMED_XML_DATA; // Constant from base class.
504 int statusCode = submitRequest(method, url, mediaType, entity);
506 // Check the status code of the response: does it match
507 // the expected response(s)?
508 if(logger.isDebugEnabled()){
509 logger.debug(testName + ": url=" + url +
510 " status=" + statusCode);
512 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
513 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
514 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
518 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
519 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
520 public void createWithWrongXmlSchema(String testName) throws Exception {
523 setupCreateWithWrongXmlSchema(testName);
525 // Submit the request to the service and store the response.
526 String method = REQUEST_TYPE.httpMethodName();
527 String url = getServiceRootURL();
528 String mediaType = MediaType.APPLICATION_XML;
529 final String entity = WRONG_XML_SCHEMA_DATA;
530 int statusCode = submitRequest(method, url, mediaType, entity);
532 // Check the status code of the response: does it match
533 // the expected response(s)?
534 if(logger.isDebugEnabled()){
535 logger.debug(testName + ": url=" + url +
536 " status=" + statusCode);
538 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
539 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
540 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
544 // ---------------------------------------------------------------
545 // CRUD tests : CREATE LIST tests
546 // ---------------------------------------------------------------
549 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
552 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
553 groups = {"createList"}, dependsOnGroups = {"create"})
554 public void createList(String testName) throws Exception {
555 for (int i = 0; i < nItemsToCreateInList; i++) {
561 * Creates the item list.
563 * @param testName the test name
564 * @throws Exception the exception
566 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
567 groups = {"createList"}, dependsOnMethods = {"createList"})
568 public void createItemList(String testName) throws Exception {
569 // Add items to the initially-created, known parent record.
570 for (int j = 0; j < nItemsToCreateInList; j++) {
571 createItem(testName);
576 * Creates the contact list.
578 * @param testName the test name
579 * @throws Exception the exception
581 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
582 groups = {"createList"}, dependsOnMethods = {"createItemList"})
583 public void createContactList(String testName) throws Exception {
584 // Add contacts to the initially-created, known item record.
585 for (int j = 0; j < nItemsToCreateInList; j++) {
586 createContact(testName);
590 // ---------------------------------------------------------------
591 // CRUD tests : READ tests
592 // ---------------------------------------------------------------
595 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
598 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
599 groups = {"read"}, dependsOnGroups = {"create"})
600 public void read(String testName) throws Exception {
605 // Submit the request to the service and store the response.
606 PersonAuthorityClient client = new PersonAuthorityClient();
607 ClientResponse<MultipartInput> res = client.read(knownResourceId);
609 int statusCode = res.getStatus();
610 // Check the status code of the response: does it match
611 // the expected response(s)?
612 if(logger.isDebugEnabled()){
613 logger.debug(testName + ": status = " + statusCode);
615 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
616 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
617 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
618 //FIXME: remove the following try catch once Aron fixes signatures
620 MultipartInput input = (MultipartInput) res.getEntity();
621 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
622 client.getCommonPartName(), PersonauthoritiesCommon.class);
623 Assert.assertNotNull(personAuthority);
624 } catch (Exception e) {
625 throw new RuntimeException(e);
628 res.releaseConnection();
635 * @param testName the test name
636 * @throws Exception the exception
638 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
639 groups = {"read"}, dependsOnGroups = {"create"})
640 public void readByName(String testName) throws Exception {
645 // Submit the request to the service and store the response.
646 PersonAuthorityClient client = new PersonAuthorityClient();
647 ClientResponse<MultipartInput> res = client.readByName(knownResourceDisplayName);
649 int statusCode = res.getStatus();
650 // Check the status code of the response: does it match
651 // the expected response(s)?
652 if(logger.isDebugEnabled()){
653 logger.debug(testName + ": status = " + statusCode);
655 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
656 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
657 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
658 //FIXME: remove the following try catch once Aron fixes signatures
660 MultipartInput input = (MultipartInput) res.getEntity();
661 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
662 client.getCommonPartName(), PersonauthoritiesCommon.class);
663 Assert.assertNotNull(personAuthority);
664 } catch (Exception e) {
665 throw new RuntimeException(e);
668 res.releaseConnection();
673 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
674 groups = {"read"}, dependsOnMethods = {"read"})
675 public void readByName(String testName) throws Exception {
680 // Submit the request to the service and store the response.
681 ClientResponse<MultipartInput> res = client.read(knownResourceId);
682 int statusCode = res.getStatus();
684 // Check the status code of the response: does it match
685 // the expected response(s)?
686 if(logger.isDebugEnabled()){
687 logger.debug(testName + ": status = " + statusCode);
689 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
690 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
691 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
692 //FIXME: remove the following try catch once Aron fixes signatures
694 MultipartInput input = (MultipartInput) res.getEntity();
695 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
696 client.getCommonPartName(), PersonauthoritiesCommon.class);
697 Assert.assertNotNull(personAuthority);
698 } catch (Exception e) {
699 throw new RuntimeException(e);
707 * @param testName the test name
708 * @throws Exception the exception
710 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
711 groups = {"read"}, dependsOnMethods = {"read"})
712 public void readItem(String testName) throws Exception {
716 // Submit the request to the service and store the response.
717 PersonAuthorityClient client = new PersonAuthorityClient();
718 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
720 int statusCode = res.getStatus();
722 // Check the status code of the response: does it match
723 // the expected response(s)?
724 if(logger.isDebugEnabled()){
725 logger.debug(testName + ": status = " + statusCode);
727 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
728 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
729 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
731 // Check whether we've received a person.
732 MultipartInput input = (MultipartInput) res.getEntity();
733 PersonsCommon person = (PersonsCommon) extractPart(input,
734 client.getItemCommonPartName(), PersonsCommon.class);
735 Assert.assertNotNull(person);
736 boolean showFull = true;
737 if(showFull && logger.isDebugEnabled()){
738 logger.debug(testName + ": returned payload:");
739 logger.debug(objectAsXmlString(person, PersonsCommon.class));
741 Assert.assertEquals(person.getInAuthority(), knownResourceId);
743 res.releaseConnection();
748 * Verify item display name.
750 * @param testName the test name
751 * @throws Exception the exception
753 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
754 dependsOnMethods = {"readItem", "updateItem"})
755 public void verifyItemDisplayName(String testName) throws Exception {
757 setupUpdate(testName);
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.assertNotNull(displayName, expectedDisplayName);
792 // Update the shortName and verify the computed name is updated.
793 person.setCsid(null);
794 person.setDisplayNameComputed(true);
795 person.setForeName("updated-" + TEST_FORE_NAME);
796 expectedDisplayName =
797 PersonAuthorityClientUtils.prepareDefaultDisplayName(
798 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
799 TEST_BIRTH_DATE, TEST_DEATH_DATE);
801 // Submit the updated resource to the service and store the response.
802 MultipartOutput output = new MultipartOutput();
803 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
804 commonPart.getHeaders().add("label", client.getItemCommonPartName());
805 res = client.updateItem(knownResourceId, knownItemResourceId, output);
807 int statusCode = res.getStatus();
809 // Check the status code of the response: does it match the expected response(s)?
810 if(logger.isDebugEnabled()){
811 logger.debug("updateItem: status = " + statusCode);
813 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
814 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
815 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
817 // Retrieve the updated resource and verify that its contents exist.
818 input = (MultipartInput) res.getEntity();
820 res.releaseConnection();
823 PersonsCommon updatedPerson =
824 (PersonsCommon) extractPart(input,
825 client.getItemCommonPartName(), PersonsCommon.class);
826 Assert.assertNotNull(updatedPerson);
828 // Verify that the updated resource received the correct data.
829 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
830 "Updated ForeName in Person did not match submitted data.");
831 // Verify that the updated resource computes the right displayName.
832 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
833 "Updated ForeName in Person not reflected in computed DisplayName.");
835 // Now Update the displayName, not computed and verify the computed name is overriden.
836 person.setDisplayNameComputed(false);
837 expectedDisplayName = "TestName";
838 person.setDisplayName(expectedDisplayName);
840 // Submit the updated resource to the service and store the response.
841 output = new MultipartOutput();
842 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
843 commonPart.getHeaders().add("label", client.getItemCommonPartName());
844 res = client.updateItem(knownResourceId, knownItemResourceId, output);
846 int statusCode = res.getStatus();
848 // Check the status code of the response: does it match the expected response(s)?
849 if(logger.isDebugEnabled()){
850 logger.debug("updateItem: status = " + statusCode);
852 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
853 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
854 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
856 // Retrieve the updated resource and verify that its contents exist.
857 input = (MultipartInput) res.getEntity();
859 res.releaseConnection();
863 (PersonsCommon) extractPart(input,
864 client.getItemCommonPartName(), PersonsCommon.class);
865 Assert.assertNotNull(updatedPerson);
867 // Verify that the updated resource received the correct data.
868 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
869 "Updated displayNameComputed in Person did not match submitted data.");
870 // Verify that the updated resource computes the right displayName.
871 Assert.assertEquals(updatedPerson.getDisplayName(),
873 "Updated DisplayName (not computed) in Person not stored.");
877 * Verify illegal item display name.
879 * @param testName the test name
880 * @throws Exception the exception
882 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
883 dependsOnMethods = {"verifyItemDisplayName"})
884 public void verifyIllegalItemDisplayName(String testName) throws Exception {
887 setupUpdateWithWrongXmlSchema(testName);
889 // Submit the request to the service and store the response.
890 PersonAuthorityClient client = new PersonAuthorityClient();
891 MultipartInput input = null;
892 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, knownItemResourceId);
894 int statusCode = res.getStatus();
896 // Check the status code of the response: does it match
897 // the expected response(s)?
898 if(logger.isDebugEnabled()){
899 logger.debug(testName + ": status = " + statusCode);
901 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
902 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
903 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
905 // Check whether Person has expected displayName.
906 input = (MultipartInput) res.getEntity();
908 res.releaseConnection();
911 PersonsCommon person = (PersonsCommon) extractPart(input,
912 client.getItemCommonPartName(), PersonsCommon.class);
913 Assert.assertNotNull(person);
914 // Try to Update with computed false and no displayName
915 person.setDisplayNameComputed(false);
916 person.setDisplayName(null);
918 // Submit the updated resource to the service and store the response.
919 MultipartOutput output = new MultipartOutput();
920 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
921 commonPart.getHeaders().add("label", client.getItemCommonPartName());
922 res = client.updateItem(knownResourceId, knownItemResourceId, output);
924 int statusCode = res.getStatus();
926 // Check the status code of the response: does it match the expected response(s)?
927 if(logger.isDebugEnabled()){
928 logger.debug("updateItem: status = " + statusCode);
930 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
931 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
932 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
934 res.releaseConnection();
941 * @param testName the test name
942 * @throws Exception the exception
944 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
945 groups = {"read"}, dependsOnMethods = {"readItem"})
946 public void readContact(String testName) throws Exception {
950 // Submit the request to the service and store the response.
951 PersonAuthorityClient client = new PersonAuthorityClient();
952 MultipartInput input = null;
953 ClientResponse<MultipartInput> res =
954 client.readContact(knownResourceId, knownItemResourceId,
955 knownContactResourceId);
957 int statusCode = res.getStatus();
959 // Check the status code of the response: does it match
960 // the expected response(s)?
961 if(logger.isDebugEnabled()){
962 logger.debug(testName + ": status = " + statusCode);
964 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
965 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
966 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
968 // Check whether we've received a contact.
969 input = (MultipartInput) res.getEntity();
971 res.releaseConnection();
974 ContactsCommon contact = (ContactsCommon) extractPart(input,
975 new ContactClient().getCommonPartName(), ContactsCommon.class);
976 Assert.assertNotNull(contact);
977 boolean showFull = true;
978 if(showFull && logger.isDebugEnabled()){
979 logger.debug(testName + ": returned payload:");
980 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
982 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
983 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
989 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
992 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
993 groups = {"read"}, dependsOnMethods = {"read"})
994 public void readNonExistent(String testName) {
997 setupReadNonExistent(testName);
999 // Submit the request to the service and store the response.
1000 PersonAuthorityClient client = new PersonAuthorityClient();
1001 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
1003 int statusCode = res.getStatus();
1004 // Check the status code of the response: does it match
1005 // the expected response(s)?
1006 if(logger.isDebugEnabled()){
1007 logger.debug(testName + ": status = " + statusCode);
1009 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1010 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1011 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1013 res.releaseConnection();
1018 * Read item non existent.
1020 * @param testName the test name
1022 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1023 groups = {"read"}, dependsOnMethods = {"readItem"})
1024 public void readItemNonExistent(String testName) {
1027 setupReadNonExistent(testName);
1029 // Submit the request to the service and store the response.
1030 PersonAuthorityClient client = new PersonAuthorityClient();
1031 ClientResponse<MultipartInput> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1033 int statusCode = res.getStatus();
1035 // Check the status code of the response: does it match
1036 // the expected response(s)?
1037 if(logger.isDebugEnabled()){
1038 logger.debug(testName + ": status = " + statusCode);
1040 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1041 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1042 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1044 res.releaseConnection();
1049 * Read contact non existent.
1051 * @param testName the test name
1053 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1054 groups = {"read"}, dependsOnMethods = {"readContact"})
1055 public void readContactNonExistent(String testName) {
1058 setupReadNonExistent(testName);
1060 // Submit the request to the service and store the response.
1061 PersonAuthorityClient client = new PersonAuthorityClient();
1062 ClientResponse<MultipartInput> res =
1063 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1065 int statusCode = res.getStatus();
1067 // Check the status code of the response: does it match
1068 // the expected response(s)?
1069 if(logger.isDebugEnabled()){
1070 logger.debug(testName + ": status = " + statusCode);
1072 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1073 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1074 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1076 res.releaseConnection();
1080 // ---------------------------------------------------------------
1081 // CRUD tests : READ_LIST tests
1082 // ---------------------------------------------------------------
1086 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1089 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1090 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1091 public void readList(String testName) throws Exception {
1094 setupReadList(testName);
1096 // Submit the request to the service and store the response.
1097 PersonAuthorityClient client = new PersonAuthorityClient();
1098 PersonauthoritiesCommonList list = null;
1099 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1101 int statusCode = res.getStatus();
1103 // Check the status code of the response: does it match
1104 // the expected response(s)?
1105 if(logger.isDebugEnabled()){
1106 logger.debug(testName + ": status = " + statusCode);
1108 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1109 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1110 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1112 list = res.getEntity();
1114 res.releaseConnection();
1117 // Optionally output additional data about list members for debugging.
1118 boolean iterateThroughList = false;
1119 if (iterateThroughList && logger.isDebugEnabled()) {
1120 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1121 list.getPersonauthorityListItem();
1123 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1124 String csid = item.getCsid();
1125 logger.debug(testName + ": list-item[" + i + "] csid=" +
1127 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1128 item.getDisplayName());
1129 logger.debug(testName + ": list-item[" + i + "] URI=" +
1131 readItemList(csid, null);
1140 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
1141 public void readItemList() {
1142 readItemList(knownResourceId, null);
1146 * Read item list by authority name.
1148 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1149 public void readItemListByAuthorityName() {
1150 readItemList(null, knownResourceDisplayName);
1156 * @param vcsid the vcsid
1157 * @param name the name
1159 private void readItemList(String vcsid, String name) {
1161 final String testName = "readItemList";
1164 setupReadList(testName);
1166 // Submit the request to the service and store the response.
1167 PersonAuthorityClient client = new PersonAuthorityClient();
1168 ClientResponse<PersonsCommonList> res = null;
1170 res = client.readItemList(vcsid);
1171 } else if (name!= null) {
1172 res = client.readItemListForNamedAuthority(name);
1174 Assert.fail("readItemList passed null csid and name!");
1176 PersonsCommonList list = null;
1178 int statusCode = res.getStatus();
1180 // Check the status code of the response: does it match
1181 // the expected response(s)?
1182 if(logger.isDebugEnabled()){
1183 logger.debug(testName + ": status = " + statusCode);
1185 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1186 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1187 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1189 list = res.getEntity();
1191 res.releaseConnection();
1194 List<PersonsCommonList.PersonListItem> items =
1195 list.getPersonListItem();
1196 int nItemsReturned = items.size();
1197 // There will be one item created, associated with a
1198 // known parent resource, by the createItem test.
1200 // In addition, there will be 'nItemsToCreateInList'
1201 // additional items created by the createItemList test,
1202 // all associated with the same parent resource.
1203 int nExpectedItems = nItemsToCreateInList + 1;
1204 if(logger.isDebugEnabled()){
1205 logger.debug(testName + ": Expected "
1206 + nExpectedItems +" items; got: "+nItemsReturned);
1208 Assert.assertEquals(nItemsReturned, nExpectedItems);
1211 for (PersonsCommonList.PersonListItem item : items) {
1212 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1213 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1214 // Optionally output additional data about list members for debugging.
1215 boolean showDetails = true;
1216 if (showDetails && logger.isDebugEnabled()) {
1217 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1219 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1221 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1222 item.getDisplayName());
1223 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1231 * Read contact list.
1233 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1234 public void readContactList() {
1235 readContactList(knownResourceId, knownItemResourceId);
1239 * Read contact list.
1241 * @param parentcsid the parentcsid
1242 * @param itemcsid the itemcsid
1244 private void readContactList(String parentcsid, String itemcsid) {
1245 final String testName = "readContactList";
1248 setupReadList(testName);
1250 // Submit the request to the service and store the response.
1251 PersonAuthorityClient client = new PersonAuthorityClient();
1252 ContactsCommonList list = null;
1253 ClientResponse<ContactsCommonList> res =
1254 client.readContactList(parentcsid, itemcsid);
1256 int statusCode = res.getStatus();
1258 // Check the status code of the response: does it match
1259 // the expected response(s)?
1260 if(logger.isDebugEnabled()){
1261 logger.debug(testName + ": status = " + statusCode);
1263 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1264 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1265 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1267 list = res.getEntity();
1269 res.releaseConnection();
1272 List<ContactsCommonList.ContactListItem> listitems =
1273 list.getContactListItem();
1274 int nItemsReturned = listitems.size();
1275 // There will be one item created, associated with a
1276 // known parent resource, by the createItem test.
1278 // In addition, there will be 'nItemsToCreateInList'
1279 // additional items created by the createItemList test,
1280 // all associated with the same parent resource.
1281 int nExpectedItems = nItemsToCreateInList + 1;
1282 if(logger.isDebugEnabled()){
1283 logger.debug(testName + ": Expected "
1284 + nExpectedItems +" items; got: "+nItemsReturned);
1286 Assert.assertEquals(nItemsReturned, nExpectedItems);
1289 for (ContactsCommonList.ContactListItem listitem : listitems) {
1290 // Optionally output additional data about list members for debugging.
1291 boolean showDetails = false;
1292 if (showDetails && logger.isDebugEnabled()) {
1293 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1294 listitem.getCsid());
1295 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1296 listitem.getAddressPlace());
1297 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1306 // There are no failure outcome tests at present.
1308 // ---------------------------------------------------------------
1309 // CRUD tests : READ_LIST tests by partial term match.
1310 // ---------------------------------------------------------------
1315 * Read item list by partial term.
1317 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1318 groups = {"readListByPartialTerm"}, dependsOnGroups = {"readList"})
1319 public void readItemListByPartialTerm(String testName) {
1320 int numMatchesFound = 0;
1321 final String PARTIAL_TERM = TEST_PARTIAL_TERM_FORE_NAME;
1322 // setupCreate(testName);
1323 String newID = createItemInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
1325 readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM);
1326 final int NUM_MATCHES_EXPECTED = 1;
1327 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1331 * Read item list by partial term, where the case of at
1332 * least one character of the partial term doesn't match that
1333 * of the full term expected to be matched.
1335 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1336 groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1337 public void readItemListByPartialTermNonMatchingCase(String testName) {
1339 setupReadList(testName);
1340 int numMatchesFound = 0;
1341 final int NUM_MATCHES_EXPECTED = 1;
1343 final String PARTIAL_TERM_LOWERCASE = TEST_PARTIAL_TERM_FORE_NAME.toLowerCase();
1345 readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_LOWERCASE);
1346 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1348 final String PARTIAL_TERM_UPPERCASE = TEST_PARTIAL_TERM_FORE_NAME.toUpperCase();
1350 readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UPPERCASE);
1351 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1356 * Read item list by partial term, with at least one Unicode UTF-8 character
1357 * (outside the USASCII range) in the partial term.
1359 // FIXME: Test currently fails with a true UTF-8 String - need to investigate why.
1360 // Will be commented out for now until we get this working ...
1362 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1363 groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1364 public void readItemListByPartialTermUTF8(String testName) {
1365 int numMatchesFound = 0;
1366 final String PARTIAL_TERM_UTF8 = TEST_PARTIAL_TERM_SUR_NAME;
1367 if (logger.isDebugEnabled()) {
1368 logger.debug("Attempting match on partial term '" + PARTIAL_TERM_UTF8 + "' ...");
1371 readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UTF8);
1372 if (logger.isDebugEnabled()) {
1373 logger.debug("Found " + numMatchesFound + " match(es).");
1375 final int NUM_MATCHES_EXPECTED = 1;
1376 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1383 * Read item list by partial term, where the partial term is not
1384 * expected to be matched by any term in any resource.
1386 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1387 groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
1388 public void readItemListByNonexistentPartialTerm(String testName) {
1389 int numMatchesFound = 0;
1390 final String NON_EXISTENT_PARTIAL_TERM = "jlmbsoq";
1392 readItemListByPartialTerm(testName, knownResourceId, NON_EXISTENT_PARTIAL_TERM);
1393 final int NUM_MATCHES_EXPECTED = 0;
1394 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
1400 * Read item list by partial term.
1402 * @param testName The name of the test which has invoked this method.
1403 * @param vcsid The CSID of the authority within which partial term matching
1404 * will be performed.
1405 * @param partialTerm A partial term to match item resources.
1406 * @return The number of item resources matched by the partial term.
1408 private int readItemListByPartialTerm(String testName, String vcsid, String partialTerm) {
1411 setupReadList(testName);
1413 // Submit the request to the service and store the response.
1414 PersonAuthorityClient client = new PersonAuthorityClient();
1415 ClientResponse<PersonsCommonList> res = null;
1416 if (vcsid != null) {
1417 res = client.readItemList(vcsid, partialTerm);
1419 Assert.fail("readItemListByPartialTerm passed null csid!");
1421 PersonsCommonList list = null;
1423 int statusCode = res.getStatus();
1425 // Check the status code of the response: does it match
1426 // the expected response(s)?
1427 if(logger.isDebugEnabled()){
1428 logger.debug(testName + ": status = " + statusCode);
1430 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1431 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1432 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1434 list = res.getEntity();
1436 res.releaseConnection();
1439 List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
1440 int nItemsReturned = items.size();
1442 return nItemsReturned;
1445 // ---------------------------------------------------------------
1446 // CRUD tests : UPDATE tests
1447 // ---------------------------------------------------------------
1450 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1453 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1454 groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
1455 public void update(String testName) throws Exception {
1458 setupUpdate(testName);
1460 // Retrieve the contents of a resource to update.
1461 PersonAuthorityClient client = new PersonAuthorityClient();
1462 MultipartInput input = null;
1463 ClientResponse<MultipartInput> res = client.read(knownResourceId);
1465 if(logger.isDebugEnabled()){
1466 logger.debug(testName + ": read status = " + res.getStatus());
1468 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1470 if(logger.isDebugEnabled()){
1471 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1473 input = res.getEntity();
1475 res.releaseConnection();
1478 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1479 client.getCommonPartName(), PersonauthoritiesCommon.class);
1480 Assert.assertNotNull(personAuthority);
1482 // Update the contents of this resource.
1483 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1484 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1485 if(logger.isDebugEnabled()){
1486 logger.debug("to be updated PersonAuthority");
1487 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1490 // Submit the updated resource to the service and store the response.
1491 MultipartOutput output = new MultipartOutput();
1492 OutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1493 commonPart.getHeaders().add("label", client.getCommonPartName());
1494 res = client.update(knownResourceId, output);
1496 int statusCode = res.getStatus();
1498 // Check the status code of the response: does it match the expected response(s)?
1499 if(logger.isDebugEnabled()){
1500 logger.debug(testName + ": status = " + statusCode);
1502 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1503 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1504 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1506 // Retrieve the updated resource and verify that its contents exist.
1507 input = (MultipartInput) res.getEntity();
1509 res.releaseConnection();
1512 PersonauthoritiesCommon updatedPersonAuthority =
1513 (PersonauthoritiesCommon) extractPart(input,
1514 client.getCommonPartName(), PersonauthoritiesCommon.class);
1515 Assert.assertNotNull(updatedPersonAuthority);
1517 // Verify that the updated resource received the correct data.
1518 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1519 personAuthority.getDisplayName(),
1520 "Data in updated object did not match submitted data.");
1526 * @param testName the test name
1527 * @throws Exception the exception
1529 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1530 groups = {"update"}, dependsOnMethods = {"update"})
1531 public void updateItem(String testName) throws Exception {
1534 setupUpdate(testName);
1536 // Retrieve the contents of a resource to update.
1537 PersonAuthorityClient client = new PersonAuthorityClient();
1538 MultipartInput input = null;
1539 ClientResponse<MultipartInput> res =
1540 client.readItem(knownResourceId, knownItemResourceId);
1542 if(logger.isDebugEnabled()){
1543 logger.debug(testName + ": read status = " + res.getStatus());
1545 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1547 if(logger.isDebugEnabled()){
1548 logger.debug("got Person to update with ID: " +
1549 knownItemResourceId +
1550 " in PersonAuthority: " + knownResourceId );
1552 input = res.getEntity();
1554 res.releaseConnection();
1557 PersonsCommon person = (PersonsCommon) extractPart(input,
1558 client.getItemCommonPartName(), PersonsCommon.class);
1559 Assert.assertNotNull(person);
1561 if (logger.isDebugEnabled() == true) {
1562 logger.debug("About to update the following person...");
1563 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1566 // Update the contents of this resource.
1567 person.setCsid(null);
1568 person.setForeName("updated-" + person.getForeName());
1569 if(logger.isDebugEnabled()){
1570 logger.debug("to be updated Person");
1571 logger.debug(objectAsXmlString(person,
1572 PersonsCommon.class));
1575 // Submit the updated resource to the service and store the response.
1576 MultipartOutput output = new MultipartOutput();
1577 OutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1578 commonPart.getHeaders().add("label", client.getItemCommonPartName());
1579 res = client.updateItem(knownResourceId, knownItemResourceId, 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();
1597 PersonsCommon updatedPerson =
1598 (PersonsCommon) extractPart(input,
1599 client.getItemCommonPartName(), PersonsCommon.class);
1600 Assert.assertNotNull(updatedPerson);
1602 if (logger.isDebugEnabled() == true) {
1603 logger.debug("Updated to following person to:");
1604 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1607 // Verify that the updated resource received the correct data.
1608 Assert.assertEquals(updatedPerson.getForeName(),
1609 person.getForeName(),
1610 "Data in updated Person did not match submitted data.");
1616 * @param testName the test name
1617 * @throws Exception the exception
1619 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1620 groups = {"update"}, dependsOnMethods = {"updateItem"})
1621 public void updateContact(String testName) throws Exception {
1623 setupUpdate(testName);
1625 // Retrieve the contents of a resource to update.
1626 PersonAuthorityClient client = new PersonAuthorityClient();
1627 MultipartInput input = null;
1628 ClientResponse<MultipartInput> res =
1629 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1631 if(logger.isDebugEnabled()){
1632 logger.debug(testName + ": read status = " + res.getStatus());
1634 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1636 if(logger.isDebugEnabled()){
1637 logger.debug("got Contact to update with ID: " +
1638 knownContactResourceId +
1639 " in item: " + knownItemResourceId +
1640 " in parent: " + knownResourceId );
1642 input = res.getEntity();
1644 res.releaseConnection();
1647 ContactsCommon contact = (ContactsCommon) extractPart(input,
1648 new ContactClient().getCommonPartName(), ContactsCommon.class);
1649 Assert.assertNotNull(contact);
1651 // Update the contents of this resource.
1652 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1653 if(logger.isDebugEnabled()){
1654 logger.debug("to be updated Contact");
1655 logger.debug(objectAsXmlString(contact,
1656 ContactsCommon.class));
1659 // Submit the updated resource to the service and store the response.
1660 MultipartOutput output = new MultipartOutput();
1661 OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE);
1662 commonPart.getHeaders().add("label", new ContactClient().getCommonPartName());
1663 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1665 int statusCode = res.getStatus();
1667 // Check the status code of the response: does it match the expected response(s)?
1668 if(logger.isDebugEnabled()){
1669 logger.debug(testName + ": status = " + statusCode);
1671 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1672 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1673 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1675 // Retrieve the updated resource and verify that its contents exist.
1676 input = (MultipartInput) res.getEntity();
1678 res.releaseConnection();
1680 ContactsCommon updatedContact =
1681 (ContactsCommon) extractPart(input,
1682 new ContactClient().getCommonPartName(), ContactsCommon.class);
1683 Assert.assertNotNull(updatedContact);
1685 // Verify that the updated resource received the correct data.
1686 Assert.assertEquals(updatedContact.getAddressPlace(),
1687 contact.getAddressPlace(),
1688 "Data in updated Contact did not match submitted data.");
1692 // Placeholders until the three tests below can be uncommented.
1693 // See Issue CSPACE-401.
1695 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1698 public void updateWithEmptyEntityBody(String testName) throws Exception {
1699 //Should this really be empty?
1703 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1706 public void updateWithMalformedXml(String testName) throws Exception {
1707 //Should this really be empty?
1711 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1714 public void updateWithWrongXmlSchema(String testName) throws Exception {
1715 //Should this really be empty?
1720 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1721 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1722 public void updateWithEmptyEntityBody(String testName) throws Exception {
1725 setupUpdateWithEmptyEntityBody(testName);
1727 // Submit the request to the service and store the response.
1728 String method = REQUEST_TYPE.httpMethodName();
1729 String url = getResourceURL(knownResourceId);
1730 String mediaType = MediaType.APPLICATION_XML;
1731 final String entity = "";
1732 int statusCode = submitRequest(method, url, mediaType, entity);
1734 // Check the status code of the response: does it match
1735 // the expected response(s)?
1736 if(logger.isDebugEnabled()){
1737 logger.debug(testName + ": url=" + url +
1738 " status=" + statusCode);
1740 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1741 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1742 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1746 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1747 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1748 public void updateWithMalformedXml(String testName) throws Exception {
1751 setupUpdateWithMalformedXml(testName);
1753 // Submit the request to the service and store the response.
1754 String method = REQUEST_TYPE.httpMethodName();
1755 String url = getResourceURL(knownResourceId);
1756 String mediaType = MediaType.APPLICATION_XML;
1757 final String entity = MALFORMED_XML_DATA;
1758 int statusCode = submitRequest(method, url, mediaType, entity);
1760 // Check the status code of the response: does it match
1761 // the expected response(s)?
1762 if(logger.isDebugEnabled()){
1763 logger.debug(testName + ": url=" + url +
1764 " status=" + statusCode);
1766 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1767 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1768 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1772 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1773 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1774 public void updateWithWrongXmlSchema(String testName) throws Exception {
1777 setupUpdateWithWrongXmlSchema(testName);
1779 // Submit the request to the service and store the response.
1780 String method = REQUEST_TYPE.httpMethodName();
1781 String url = getResourceURL(knownResourceId);
1782 String mediaType = MediaType.APPLICATION_XML;
1783 final String entity = WRONG_XML_SCHEMA_DATA;
1784 int statusCode = submitRequest(method, url, mediaType, entity);
1786 // Check the status code of the response: does it match
1787 // the expected response(s)?
1788 if(logger.isDebugEnabled()){
1789 logger.debug("updateWithWrongXmlSchema: url=" + url +
1790 " status=" + statusCode);
1792 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1793 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1794 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1799 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1802 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1803 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1804 public void updateNonExistent(String testName) throws Exception {
1807 setupUpdateNonExistent(testName);
1809 // Submit the request to the service and store the response.
1810 // Note: The ID(s) used when creating the request payload may be arbitrary.
1811 // The only relevant ID may be the one used in update(), below.
1812 PersonAuthorityClient client = new PersonAuthorityClient();
1813 String displayName = "displayName-NON_EXISTENT_ID";
1814 String fullRefName = PersonAuthorityClientUtils.createPersonAuthRefName(displayName, true);
1815 MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1816 displayName, fullRefName, client.getCommonPartName());
1817 ClientResponse<MultipartInput> res =
1818 client.update(NON_EXISTENT_ID, multipart);
1820 int statusCode = res.getStatus();
1822 // Check the status code of the response: does it match
1823 // the expected response(s)?
1824 if(logger.isDebugEnabled()){
1825 logger.debug(testName + ": status = " + statusCode);
1827 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1828 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1829 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1831 res.releaseConnection();
1836 * Update non existent item.
1838 * @param testName the test name
1839 * @throws Exception the exception
1841 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1842 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1843 public void updateNonExistentItem(String testName) throws Exception {
1846 setupUpdateNonExistent(testName);
1848 // Submit the request to the service and store the response.
1849 // Note: The ID used in this 'create' call may be arbitrary.
1850 // The only relevant ID may be the one used in update(), below.
1851 PersonAuthorityClient client = new PersonAuthorityClient();
1852 Map<String, String> nonexMap = new HashMap<String,String>();
1853 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1854 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1855 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1856 MultipartOutput multipart =
1857 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1858 PersonAuthorityClientUtils.createPersonRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap,
1859 client.getItemCommonPartName() );
1860 ClientResponse<MultipartInput> res =
1861 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1863 int statusCode = res.getStatus();
1865 // Check the status code of the response: does it match
1866 // the expected response(s)?
1867 if(logger.isDebugEnabled()){
1868 logger.debug(testName + ": status = " + statusCode);
1870 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1871 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1872 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1874 res.releaseConnection();
1879 * Update non existent contact.
1881 * @param testName the test name
1882 * @throws Exception the exception
1884 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1885 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1886 public void updateNonExistentContact(String testName) throws Exception {
1887 // Currently a no-op test
1890 // ---------------------------------------------------------------
1891 // CRUD tests : DELETE tests
1892 // ---------------------------------------------------------------
1895 // Note: delete sub-resources in ascending hierarchical order,
1896 // before deleting their parents.
1901 * @param testName the test name
1902 * @throws Exception the exception
1904 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1905 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1906 public void deleteContact(String testName) throws Exception {
1909 setupDelete(testName);
1911 if(logger.isDebugEnabled()){
1912 logger.debug("parentcsid =" + knownResourceId +
1913 " itemcsid = " + knownItemResourceId +
1914 " csid = " + knownContactResourceId);
1917 // Submit the request to the service and store the response.
1918 PersonAuthorityClient client = new PersonAuthorityClient();
1919 ClientResponse<Response> res =
1920 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1921 int statusCode = res.getStatus();
1922 res.releaseConnection();
1924 // Check the status code of the response: does it match
1925 // the expected response(s)?
1926 if(logger.isDebugEnabled()){
1927 logger.debug(testName + ": status = " + statusCode);
1929 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1930 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1931 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1937 * @param testName the test name
1938 * @throws Exception the exception
1940 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1941 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1942 public void deleteItem(String testName) throws Exception {
1945 setupDelete(testName);
1947 if(logger.isDebugEnabled()){
1948 logger.debug("parentcsid =" + knownResourceId +
1949 " itemcsid = " + knownItemResourceId);
1952 // Submit the request to the service and store the response.
1953 PersonAuthorityClient client = new PersonAuthorityClient();
1954 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1955 int statusCode = res.getStatus();
1956 res.releaseConnection();
1958 // Check the status code of the response: does it match
1959 // the expected response(s)?
1960 if(logger.isDebugEnabled()){
1961 logger.debug(testName + ": status = " + statusCode);
1963 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1964 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1965 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1969 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1972 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1973 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1974 public void delete(String testName) throws Exception {
1977 setupDelete(testName);
1979 if(logger.isDebugEnabled()){
1980 logger.debug("parentcsid =" + knownResourceId);
1983 // Submit the request to the service and store the response.
1984 PersonAuthorityClient client = new PersonAuthorityClient();
1985 ClientResponse<Response> res = client.delete(knownResourceId);
1986 int statusCode = res.getStatus();
1987 res.releaseConnection();
1989 // Check the status code of the response: does it match
1990 // the expected response(s)?
1991 if(logger.isDebugEnabled()){
1992 logger.debug(testName + ": status = " + statusCode);
1994 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1995 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1996 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2001 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
2004 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2005 groups = {"delete"}, dependsOnMethods = {"delete"})
2006 public void deleteNonExistent(String testName) throws Exception {
2009 setupDeleteNonExistent(testName);
2011 // Submit the request to the service and store the response.
2012 PersonAuthorityClient client = new PersonAuthorityClient();
2013 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
2014 int statusCode = res.getStatus();
2015 res.releaseConnection();
2017 // Check the status code of the response: does it match
2018 // the expected response(s)?
2019 if(logger.isDebugEnabled()){
2020 logger.debug(testName + ": status = " + statusCode);
2022 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2023 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2024 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2028 * Delete non existent item.
2030 * @param testName the test name
2032 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2033 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2034 public void deleteNonExistentItem(String testName) {
2037 setupDeleteNonExistent(testName);
2039 // Submit the request to the service and store the response.
2040 PersonAuthorityClient client = new PersonAuthorityClient();
2041 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
2042 int statusCode = res.getStatus();
2043 res.releaseConnection();
2045 // Check the status code of the response: does it match
2046 // the expected response(s)?
2047 if(logger.isDebugEnabled()){
2048 logger.debug(testName + ": status = " + statusCode);
2050 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2051 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2052 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2056 * Delete non existent contact.
2058 * @param testName the test name
2060 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2061 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2062 public void deleteNonExistentContact(String testName) {
2065 setupDeleteNonExistent(testName);
2067 // Submit the request to the service and store the response.
2068 PersonAuthorityClient client = new PersonAuthorityClient();
2069 ClientResponse<Response> res =
2070 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2071 int statusCode = res.getStatus();
2072 res.releaseConnection();
2074 // Check the status code of the response: does it match
2075 // the expected response(s)?
2076 if(logger.isDebugEnabled()){
2077 logger.debug(testName + ": status = " + statusCode);
2079 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2080 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2081 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2084 // ---------------------------------------------------------------
2085 // Utility tests : tests of code used in tests above
2086 // ---------------------------------------------------------------
2088 * Tests the code for manually submitting data that is used by several
2089 * of the methods above.
2091 @Test(dependsOnMethods = {"create", "read"})
2092 public void testSubmitRequest() {
2094 // Expected status code: 200 OK
2095 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2097 // Submit the request to the service and store the response.
2098 String method = ServiceRequestType.READ.httpMethodName();
2099 String url = getResourceURL(knownResourceId);
2100 int statusCode = submitRequest(method, url);
2102 // Check the status code of the response: does it match
2103 // the expected response(s)?
2104 if(logger.isDebugEnabled()){
2105 logger.debug("testSubmitRequest: url=" + url +
2106 " status=" + statusCode);
2108 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2113 * Test item submit request.
2115 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2116 public void testItemSubmitRequest() {
2118 // Expected status code: 200 OK
2119 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2121 // Submit the request to the service and store the response.
2122 String method = ServiceRequestType.READ.httpMethodName();
2123 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2124 int statusCode = submitRequest(method, url);
2126 // Check the status code of the response: does it match
2127 // the expected response(s)?
2128 if(logger.isDebugEnabled()){
2129 logger.debug("testItemSubmitRequest: url=" + url +
2130 " status=" + statusCode);
2132 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2137 * Test contact submit request.
2139 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2140 public void testContactSubmitRequest() {
2142 // Expected status code: 200 OK
2143 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2145 // Submit the request to the service and store the response.
2146 String method = ServiceRequestType.READ.httpMethodName();
2147 String url = getContactResourceURL(knownResourceId,
2148 knownItemResourceId, knownContactResourceId);
2149 int statusCode = submitRequest(method, url);
2151 // Check the status code of the response: does it match
2152 // the expected response(s)?
2153 if(logger.isDebugEnabled()){
2154 logger.debug("testItemSubmitRequest: url=" + url +
2155 " status=" + statusCode);
2157 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2162 // ---------------------------------------------------------------
2163 // Cleanup of resources created during testing
2164 // ---------------------------------------------------------------
2167 * Deletes all resources created by tests, after all tests have been run.
2169 * This cleanup method will always be run, even if one or more tests fail.
2170 * For this reason, it attempts to remove all resources created
2171 * at any point during testing, even if some of those resources
2172 * may be expected to be deleted by certain tests.
2175 @AfterClass(alwaysRun=true)
2177 public void cleanUp() {
2178 String noTest = System.getProperty("noTestCleanup");
2179 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2180 if (logger.isDebugEnabled()) {
2181 logger.debug("Skipping Cleanup phase ...");
2185 if (logger.isDebugEnabled()) {
2186 logger.debug("Cleaning up temporary resources created for testing ...");
2188 String parentResourceId;
2189 String itemResourceId;
2190 String contactResourceId;
2191 // Clean up contact resources.
2192 PersonAuthorityClient client = new PersonAuthorityClient();
2193 parentResourceId = knownResourceId;
2194 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2195 contactResourceId = entry.getKey();
2196 itemResourceId = entry.getValue();
2197 // Note: Any non-success responses from the delete operation
2198 // below are ignored and not reported.
2199 ClientResponse<Response> res =
2200 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2201 res.releaseConnection();
2203 // Clean up item resources.
2204 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2205 itemResourceId = entry.getKey();
2206 parentResourceId = entry.getValue();
2207 // Note: Any non-success responses from the delete operation
2208 // below are ignored and not reported.
2209 ClientResponse<Response> res =
2210 client.deleteItem(parentResourceId, itemResourceId);
2211 res.releaseConnection();
2213 // Clean up parent resources.
2217 // ---------------------------------------------------------------
2218 // Utility methods used by tests above
2219 // ---------------------------------------------------------------
2221 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
2224 public String getServicePathComponent() {
2225 return SERVICE_PATH_COMPONENT;
2229 * Gets the item service path component.
2231 * @return the item service path component
2233 public String getItemServicePathComponent() {
2234 return ITEM_SERVICE_PATH_COMPONENT;
2238 * Gets the contact service path component.
2240 * @return the contact service path component
2242 public String getContactServicePathComponent() {
2243 return CONTACT_SERVICE_PATH_COMPONENT;
2247 * Returns the root URL for the item service.
2249 * This URL consists of a base URL for all services, followed by
2250 * a path component for the owning parent, followed by the
2251 * path component for the items.
2253 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2254 * parent authority resource of the relevant item resource.
2256 * @return The root URL for the item service.
2258 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2259 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2263 * Returns the URL of a specific item resource managed by a service, and
2264 * designated by an identifier (such as a universally unique ID, or UUID).
2266 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2267 * parent authority resource of the relevant item resource.
2269 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2272 * @return The URL of a specific item resource managed by a service.
2274 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2275 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2280 * Returns the root URL for the contact service.
2282 * This URL consists of a base URL for all services, followed by
2283 * a path component for the owning authority, followed by the
2284 * path component for the owning item, followed by the path component
2285 * for the contact service.
2287 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2288 * parent authority resource of the relevant item resource.
2290 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2293 * @return The root URL for the contact service.
2295 protected String getContactServiceRootURL(String parentResourceIdentifier,
2296 String itemResourceIdentifier) {
2297 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2298 getContactServicePathComponent();
2302 * Returns the URL of a specific contact resource managed by a service, and
2303 * designated by an identifier (such as a universally unique ID, or UUID).
2305 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2306 * parent resource of the relevant item resource.
2308 * @param resourceIdentifier An identifier (such as a UUID) for an
2311 * @return The URL of a specific resource managed by a service.
2313 protected String getContactResourceURL(String parentResourceIdentifier,
2314 String itemResourceIdentifier, String contactResourceIdentifier) {
2315 return getContactServiceRootURL(parentResourceIdentifier,
2316 itemResourceIdentifier) + "/" + contactResourceIdentifier;