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.client.AuthorityClient;
33 import org.collectionspace.services.client.CollectionSpaceClient;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
39 import org.collectionspace.services.client.ContactClient;
40 import org.collectionspace.services.client.ContactClientUtils;
41 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
42 import org.collectionspace.services.contact.ContactsCommon;
43 import org.collectionspace.services.contact.ContactsCommonList;
45 import org.collectionspace.services.client.PersonAuthorityClient;
46 import org.collectionspace.services.client.PersonAuthorityClientUtils;
47 import org.collectionspace.services.PersonJAXBSchema;
48 import org.collectionspace.services.person.PersonauthoritiesCommon;
49 import org.collectionspace.services.person.PersonauthoritiesCommonList;
50 import org.collectionspace.services.person.PersonsCommon;
51 import org.collectionspace.services.person.PersonsCommonList;
53 import org.jboss.resteasy.client.ClientResponse;
54 //import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57 import org.testng.Assert;
58 import org.testng.annotations.AfterClass;
59 import org.testng.annotations.Test;
62 * PersonAuthorityServiceTest, carries out tests against a
63 * deployed and running PersonAuthority Service.
65 * $LastChangedRevision: 753 $
66 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
68 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
71 private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
72 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
75 public String getServicePathComponent() {
76 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
80 protected String getServiceName() {
81 return PersonAuthorityClient.SERVICE_NAME;
84 public String getItemServicePathComponent() {
85 return AuthorityClient.ITEMS;
88 /** The test forename. */
89 final String TEST_FORE_NAME = "John";
91 /** The test middle name. */
92 final String TEST_MIDDLE_NAME = null;
94 /** The test surname. */
95 final String TEST_SUR_NAME = "Wayne";
97 /** The test birthdate. */
98 final String TEST_BIRTH_DATE = "May 26, 1907";
100 /** The test death date. */
101 final String TEST_DEATH_DATE = "June 11, 1979";
103 // Hold some values for a recently created item to verify upon read.
104 private String knownResourceId = null;
105 private String knownResourceShortIdentifer = null;
106 private String knownResourceRefName = null;
107 private String knownItemResourceId = null;
108 private String knownItemResourceShortIdentifer = null;
110 // The resource ID of an item resource used for partial term matching tests.
111 private String knownItemPartialTermResourceId = null;
113 /** The known contact resource id. */
114 private String knownContactResourceId = null;
116 /** The n items to create in list. */
117 private int nItemsToCreateInList = 3;
119 /** The all item resource ids created. */
120 private Map<String, String> allItemResourceIdsCreated =
121 new HashMap<String, String>();
123 /** The all contact resource ids created. */
124 private Map<String, String> allContactResourceIdsCreated =
125 new HashMap<String, String>();
127 protected void setKnownResource( String id, String shortIdentifer,
129 knownResourceId = id;
130 knownResourceShortIdentifer = shortIdentifer;
131 knownResourceRefName = refName;
134 protected void setKnownItemResource( String id, String shortIdentifer ) {
135 knownItemResourceId = id;
136 knownItemResourceShortIdentifer = shortIdentifer;
141 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
144 protected CollectionSpaceClient getClientInstance() {
145 return new PersonAuthorityClient();
149 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
152 protected AbstractCommonList getAbstractCommonList(
153 ClientResponse<AbstractCommonList> response) {
154 return response.getEntity(PersonsCommonList.class);
157 // ---------------------------------------------------------------
158 // CRUD tests : CREATE tests
159 // ---------------------------------------------------------------
162 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
165 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
167 public void create(String testName) throws Exception {
169 if (logger.isDebugEnabled()) {
170 logger.debug(testBanner(testName, CLASS_NAME));
172 // Perform setup, such as initializing the type of service request
173 // (e.g. CREATE, DELETE), its valid and expected status codes, and
174 // its associated HTTP method name (e.g. POST, DELETE).
177 // Submit the request to the service and store the response.
178 PersonAuthorityClient client = new PersonAuthorityClient();
179 String shortId = createIdentifier();
180 String displayName = "displayName-" + shortId;
181 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
182 PoxPayloadOut multipart =
183 PersonAuthorityClientUtils.createPersonAuthorityInstance(
184 displayName, shortId, client.getCommonPartName());
187 ClientResponse<Response> res = client.create(multipart);
189 int statusCode = res.getStatus();
191 // Check the status code of the response: does it match
192 // the expected response(s)?
195 // Does it fall within the set of valid status codes?
196 // Does it exactly match the expected status code?
197 if(logger.isDebugEnabled()){
198 logger.debug(testName + ": status = " + statusCode);
200 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
201 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
202 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
204 newID = PersonAuthorityClientUtils.extractId(res);
206 res.releaseConnection();
208 // Save values for additional tests
209 if (knownResourceId == null){
210 setKnownResource( newID, shortId, baseRefName );
211 if (logger.isDebugEnabled()) {
212 logger.debug(testName + ": knownResourceId=" + knownResourceId);
215 // Store the IDs from every resource created by tests,
216 // so they can be deleted after tests have been run.
217 allResourceIdsCreated.add(newID);
221 protected PoxPayloadOut createInstance(String identifier) {
222 PersonAuthorityClient client = new PersonAuthorityClient();
223 String displayName = "displayName-" + identifier;
224 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
225 displayName, identifier, client.getCommonPartName());
230 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
231 String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
232 HashMap<String, String> personInfo = new HashMap<String, String>();
233 String shortId = "johnWayneTempActor";
234 personInfo.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
235 personInfo.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne Temp");
236 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
237 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayneTemp");
238 personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
240 return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel);
246 * @param testName the test name
248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
249 groups = {"create"}, dependsOnMethods = {"create"})
250 public void createItem(String testName) {
251 if (logger.isDebugEnabled()) {
252 logger.debug(testBanner(testName, CLASS_NAME));
255 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
259 * Creates the item with an empty short identifier.
261 * @param testName the test name
264 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
265 groups = {"create"}, dependsOnMethods = {"create"})
266 public void createItemWithEmptyShortId(String testName) {
267 if (logger.isDebugEnabled()) {
268 logger.debug(testBanner(testName, CLASS_NAME));
272 // Fill the property map
274 Map<String, String> fieldProperties = new HashMap<String,String>();
275 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
276 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck");
277 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
278 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck");
280 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
281 String newID = createItemInAuthority(knownResourceId, knownResourceRefName,
282 shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES);
283 allResourceIdsCreated.add(newID);
288 * Creates an item in an authority, using test data.
290 * @param vcsid the vcsid
291 * @param authRefName the auth ref name
294 private String createItemInAuthority(String vcsid, String authRefName) {
296 final String testName = "createItemInAuthority";
297 if(logger.isDebugEnabled()){
298 logger.debug(testName + ":"+vcsid+"...");
301 Map<String, String> johnWayneMap = new HashMap<String,String>();
303 // Fill the property map
305 String shortId = "johnWayneActor";
306 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
307 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
308 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
309 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayne");
310 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
312 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
313 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
314 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
315 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
316 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
317 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
318 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
319 "known by his stage name John Wayne, was an American film actor, director " +
320 "and producer. He epitomized rugged masculinity and has become an enduring " +
321 "American icon. He is famous for his distinctive voice, walk and height. " +
322 "He was also known for his conservative political views and his support in " +
323 "the 1950s for anti-communist positions.");
325 Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String,List<String>>();
326 List<String> johnWayneGroups = new ArrayList<String>();
327 johnWayneGroups.add("Irish");
328 johnWayneGroups.add("Scottish");
329 johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
331 return createItemInAuthority(vcsid, authRefName, shortId, johnWayneMap, johnWayneRepeatablesMap);
336 * Creates an item in an authority.
338 * @param vcsid the vcsid
339 * @param authRefName the auth ref name
340 * @param itemFieldProperties a set of properties specifying the values of fields.
341 * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
344 private String createItemInAuthority(String vcsid, String authRefName, String shortId,
345 Map itemFieldProperties, Map itemRepeatableFieldProperties) {
347 final String testName = "createItemInAuthority";
348 if(logger.isDebugEnabled()){
349 logger.debug(testName + ":"+vcsid+"...");
352 // Submit the request to the service and store the response.
353 PersonAuthorityClient client = new PersonAuthorityClient();
355 PoxPayloadOut multipart =
356 PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, itemFieldProperties,
357 itemRepeatableFieldProperties, client.getItemCommonPartName() );
360 ClientResponse<Response> res = client.createItem(vcsid, multipart);
362 int statusCode = res.getStatus();
363 // Check the status code of the response: does it match
364 // the expected response(s)?
365 if(logger.isDebugEnabled()){
366 logger.debug(testName + ": status = " + statusCode);
368 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
369 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
370 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
372 newID = PersonAuthorityClientUtils.extractId(res);
374 res.releaseConnection();
377 // Store the ID returned from the first item resource created
378 // for additional tests below.
379 if (knownItemResourceId == null){
380 setKnownItemResource(newID, shortId);
381 if (logger.isDebugEnabled()) {
382 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
385 if(logger.isDebugEnabled()){
386 logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")");
389 // Store the IDs from any item resources created
390 // by tests, along with the IDs of their parents, so these items
391 // can be deleted after all tests have been run.
392 allItemResourceIdsCreated.put(newID, vcsid);
398 * Creates the contact.
400 * @param testName the test name
402 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
403 groups = {"create"}, dependsOnMethods = {"createItem"})
404 public void createContact(String testName) {
405 if (logger.isDebugEnabled()) {
406 logger.debug(testBanner(testName, CLASS_NAME));
409 String newID = createContactInItem(knownResourceId, knownItemResourceId);
413 * Creates the contact in item.
415 * @param parentcsid the parentcsid
416 * @param itemcsid the itemcsid
419 private String createContactInItem(String parentcsid, String itemcsid) {
421 final String testName = "createContactInItem";
422 if(logger.isDebugEnabled()){
423 logger.debug(testName + ":...");
428 // Submit the request to the service and store the response.
429 PersonAuthorityClient client = new PersonAuthorityClient();
430 String identifier = createIdentifier();
431 PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
432 itemcsid, identifier, new ContactClient().getCommonPartName());
435 ClientResponse<Response> res =
436 client.createContact(parentcsid, itemcsid, multipart);
438 int statusCode = res.getStatus();
439 // Check the status code of the response: does it match
440 // the expected response(s)?
441 if(logger.isDebugEnabled()){
442 logger.debug(testName + ": status = " + statusCode);
444 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
445 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
446 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
448 newID = PersonAuthorityClientUtils.extractId(res);
450 res.releaseConnection();
453 // Store the ID returned from the first contact resource created
454 // for additional tests below.
455 if (knownContactResourceId == null){
456 knownContactResourceId = newID;
457 if (logger.isDebugEnabled()) {
458 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
462 // Store the IDs from any contact resources created
463 // by tests, along with the IDs of their parent items,
464 // so these items can be deleted after all tests have been run.
465 allContactResourceIdsCreated.put(newID, itemcsid);
472 // Placeholders until the three tests below can be uncommented.
473 // See Issue CSPACE-401.
475 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
478 public void createWithEmptyEntityBody(String testName) throws Exception {
479 //Should this really be empty?
483 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
486 public void createWithMalformedXml(String testName) throws Exception {
487 //Should this really be empty?
491 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
494 public void createWithWrongXmlSchema(String testName) throws Exception {
495 //Should this really be empty?
500 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
501 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
502 public void createWithEmptyEntityBody(String testName) throws Exception {
504 if (logger.isDebugEnabled()) {
505 logger.debug(testBanner(testName, CLASS_NAME));
508 setupCreateWithEmptyEntityBody();
510 // Submit the request to the service and store the response.
511 String method = REQUEST_TYPE.httpMethodName();
512 String url = getServiceRootURL();
513 String mediaType = MediaType.APPLICATION_XML;
514 final String entity = "";
515 int statusCode = submitRequest(method, url, mediaType, entity);
517 // Check the status code of the response: does it match
518 // the expected response(s)?
519 if(logger.isDebugEnabled()) {
520 logger.debug(testName + ": url=" + url +
521 " status=" + statusCode);
523 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
524 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
525 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
529 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
530 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
531 public void createWithMalformedXml(String testName) throws Exception {
533 if (logger.isDebugEnabled()) {
534 logger.debug(testBanner(testName, CLASS_NAME));
537 setupCreateWithMalformedXml();
539 // Submit the request to the service and store the response.
540 String method = REQUEST_TYPE.httpMethodName();
541 String url = getServiceRootURL();
542 String mediaType = MediaType.APPLICATION_XML;
543 final String entity = MALFORMED_XML_DATA; // Constant from base class.
544 int statusCode = submitRequest(method, url, mediaType, entity);
546 // Check the status code of the response: does it match
547 // the expected response(s)?
548 if(logger.isDebugEnabled()){
549 logger.debug(testName + ": url=" + url +
550 " status=" + statusCode);
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
558 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
559 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
560 public void createWithWrongXmlSchema(String testName) throws Exception {
562 if (logger.isDebugEnabled()) {
563 logger.debug(testBanner(testName, CLASS_NAME));
566 setupCreateWithWrongXmlSchema();
568 // Submit the request to the service and store the response.
569 String method = REQUEST_TYPE.httpMethodName();
570 String url = getServiceRootURL();
571 String mediaType = MediaType.APPLICATION_XML;
572 final String entity = WRONG_XML_SCHEMA_DATA;
573 int statusCode = submitRequest(method, url, mediaType, entity);
575 // Check the status code of the response: does it match
576 // the expected response(s)?
577 if(logger.isDebugEnabled()){
578 logger.debug(testName + ": url=" + url +
579 " status=" + statusCode);
581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 * Attempts to create an authority with an short identifier that contains
589 * non-word characters.
591 * @param testName the test name
593 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
594 groups = {"create", "nonWordCharsInShortId"})
595 public void createWithShortIdNonWordChars(String testName) throws Exception {
596 if (logger.isDebugEnabled()) {
597 logger.debug(testBanner(testName, CLASS_NAME));
599 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
600 REQUEST_TYPE = ServiceRequestType.CREATE;
601 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
603 // Create the payload to be included in the body of the request
604 PersonAuthorityClient client = new PersonAuthorityClient();
605 String shortId = createIdentifier() + "*" + createIdentifier();
606 String displayName = "displayName-" + shortId;
607 PoxPayloadOut multipart =
608 PersonAuthorityClientUtils.createPersonAuthorityInstance(
609 displayName, shortId, client.getCommonPartName());
611 // Submit the request to the service and store the response.
612 ClientResponse<Response> res = client.create(multipart);
614 // Check the status code of the response: does it match
615 // the expected response(s)?
617 int statusCode = res.getStatus();
618 if(logger.isDebugEnabled()){
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
625 res.releaseConnection();
631 * Attempts to create an item with an short identifier that contains
632 * non-word characters.
634 * @param testName the test name
636 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
637 groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"})
638 public void createItemWithShortIdNonWordChars(String testName) {
639 if (logger.isDebugEnabled()) {
640 logger.debug(testBanner(testName, CLASS_NAME));
642 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
643 REQUEST_TYPE = ServiceRequestType.CREATE;
644 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
646 PersonAuthorityClient client = new PersonAuthorityClient();
648 // Create the payload to be included in the body of the request
649 String shortId = "7-Eleven";
650 Map<String, String> fieldProperties = new HashMap<String,String>();
651 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
652 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, shortId);
653 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
654 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, shortId);
655 fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
656 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
657 PoxPayloadOut multipart =
658 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
659 knownResourceRefName, fieldProperties,
660 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
662 // Send the request and receive a response
663 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
665 // Check the status code of the response: does it match
666 // the expected response(s)?
668 int statusCode = res.getStatus();
669 // Check the status code of the response: does it match
670 // the expected response(s)?
671 if(logger.isDebugEnabled()){
672 logger.debug(testName + ": status = " + statusCode);
674 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
675 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
676 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 res.releaseConnection();
683 // ---------------------------------------------------------------
684 // CRUD tests : CREATE LIST tests
685 // ---------------------------------------------------------------
688 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
691 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
692 groups = {"createList"}, dependsOnGroups = {"create"})
693 public void createList(String testName) throws Exception {
694 if (logger.isDebugEnabled()) {
695 logger.debug(testBanner(testName, CLASS_NAME));
697 for (int i = 0; i < nItemsToCreateInList; i++) {
703 * Creates the item list.
705 * @param testName the test name
706 * @throws Exception the exception
708 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
709 groups = {"createList"}, dependsOnMethods = {"createList"})
710 public void createItemList(String testName) throws Exception {
711 if (logger.isDebugEnabled()) {
712 logger.debug(testBanner(testName, CLASS_NAME));
714 // Add items to the initially-created, known parent record.
715 for (int j = 0; j < nItemsToCreateInList; j++) {
716 createItem(testName);
721 * Creates the contact list.
723 * @param testName the test name
724 * @throws Exception the exception
726 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
727 groups = {"createList"}, dependsOnMethods = {"createItemList"})
728 public void createContactList(String testName) throws Exception {
729 // Add contacts to the initially-created, known item record.
730 for (int j = 0; j < nItemsToCreateInList; j++) {
731 createContact(testName);
735 // ---------------------------------------------------------------
736 // CRUD tests : READ tests
737 // ---------------------------------------------------------------
740 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
743 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
744 groups = {"read"}, dependsOnGroups = {"create"})
745 public void read(String testName) throws Exception {
746 readInternal(testName, knownResourceId, null);
752 * @param testName the test name
753 * @throws Exception the exception
755 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
756 groups = {"read"}, dependsOnMethods = {"read"})
757 public void readByName(String testName) throws Exception {
758 readInternal(testName, null, knownResourceShortIdentifer);
761 protected void readInternal(String testName, String CSID, String shortId) {
762 if (logger.isDebugEnabled()) {
763 logger.debug(testBanner(testName, CLASS_NAME));
768 // Submit the request to the service and store the response.
769 PersonAuthorityClient client = new PersonAuthorityClient();
770 ClientResponse<String> res = null;
772 res = client.read(CSID);
773 } else if(shortId!=null) {
774 res = client.readByName(shortId);
776 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
779 int statusCode = res.getStatus();
780 // Check the status code of the response: does it match
781 // the expected response(s)?
782 if(logger.isDebugEnabled()){
783 logger.debug(testName + ": status = " + statusCode);
785 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
786 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
787 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
788 //FIXME: remove the following try catch once Aron fixes signatures
790 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
791 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
792 client.getCommonPartName(), PersonauthoritiesCommon.class);
793 Assert.assertNotNull(personAuthority);
794 } catch (Exception e) {
795 throw new RuntimeException(e);
798 res.releaseConnection();
805 * @param testName the test name
806 * @throws Exception the exception
808 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
809 groups = {"readItem"}, dependsOnGroups = {"read"})
810 public void readItem(String testName) throws Exception {
811 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
815 * Read item in Named Auth.
817 * @param testName the test name
818 * @throws Exception the exception
820 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
821 groups = {"readItem"}, dependsOnMethods = {"readItem"})
822 public void readItemInNamedAuth(String testName) throws Exception {
823 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
829 * @param testName the test name
830 * @throws Exception the exception
832 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
833 groups = {"readItem"}, dependsOnMethods = {"readItem"})
834 public void readNamedItem(String testName) throws Exception {
835 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
839 * Read Named item in Named Auth.
841 * @param testName the test name
842 * @throws Exception the exception
844 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
845 groups = {"readItem"}, dependsOnMethods = {"readItem"})
846 public void readNamedItemInNamedAuth(String testName) throws Exception {
847 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
850 protected void readItemInternal(String testName,
851 String authCSID, String authShortId, String itemCSID, String itemShortId)
854 if (logger.isDebugEnabled()) {
855 logger.debug(testBanner(testName, CLASS_NAME));
856 logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+
857 ((itemCSID!=null)?authCSID:itemShortId));
862 // Submit the request to the service and store the response.
863 PersonAuthorityClient client = new PersonAuthorityClient();
864 ClientResponse<String> res = null;
867 res = client.readItem(authCSID, itemCSID);
868 } else if(itemShortId!=null) {
869 res = client.readNamedItem(authCSID, itemShortId);
871 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
873 } else if(authShortId!=null) {
875 res = client.readItemInNamedAuthority(authShortId, itemCSID);
876 } else if(itemShortId!=null) {
877 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
879 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
882 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
885 int statusCode = res.getStatus();
887 // Check the status code of the response: does it match
888 // the expected response(s)?
889 if(logger.isDebugEnabled()){
890 logger.debug(testName + ": status = " + statusCode);
892 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
893 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
894 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
896 // Check whether we've received a person.
897 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
898 PersonsCommon person = (PersonsCommon) extractPart(input,
899 client.getItemCommonPartName(), PersonsCommon.class);
900 Assert.assertNotNull(person);
901 boolean showFull = true;
902 if(showFull && logger.isDebugEnabled()){
903 logger.debug(testName + ": returned payload:");
904 logger.debug(objectAsXmlString(person, PersonsCommon.class));
907 // Check that the person item is within the expected Person Authority.
908 Assert.assertEquals(person.getInAuthority(), knownResourceId);
910 // Verify the number and contents of values in a repeatable field,
911 // as created in the instance record used for testing.
912 List<String> groups = person.getGroups().getGroup();
913 Assert.assertTrue(groups.size() > 0);
914 Assert.assertNotNull(groups.get(0));
917 res.releaseConnection();
922 * Verify item display name.
924 * @param testName the test name
925 * @throws Exception the exception
927 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
928 groups = {"update"}, dependsOnMethods = {"updateItem"})
929 public void verifyItemDisplayNames(String testName) throws Exception {
931 if (logger.isDebugEnabled()) {
932 logger.debug(testBanner(testName, CLASS_NAME));
937 // Submit the request to the service and store the response.
938 PersonAuthorityClient client = new PersonAuthorityClient();
939 PoxPayloadIn input =null;
940 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
942 int statusCode = res.getStatus();
944 // Check the status code of the response: does it match
945 // the expected response(s)?
946 if(logger.isDebugEnabled()){
947 logger.debug(testName + ": status = " + statusCode);
949 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
950 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
951 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
953 // Check whether person has expected displayName.
954 input = new PoxPayloadIn(res.getEntity());
956 res.releaseConnection();
959 PersonsCommon person = (PersonsCommon) extractPart(input,
960 client.getItemCommonPartName(), PersonsCommon.class);
961 Assert.assertNotNull(person);
962 String displayName = person.getDisplayName();
963 // Make sure displayName matches computed form
964 String expectedDisplayName =
965 PersonAuthorityClientUtils.prepareDefaultDisplayName(
966 TEST_FORE_NAME, null, TEST_SUR_NAME,
967 TEST_BIRTH_DATE, TEST_DEATH_DATE);
968 Assert.assertFalse(displayName.equals(expectedDisplayName));
970 String shortDisplayName = person.getShortDisplayName();
971 // Make sure displayName matches computed form
972 String expectedShortDisplayName =
973 PersonAuthorityClientUtils.prepareDefaultDisplayName(
974 TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
975 Assert.assertFalse(expectedShortDisplayName.equals(shortDisplayName));
977 // Update the forename and verify the computed name is updated.
978 person.setCsid(null);
979 person.setDisplayNameComputed(true);
980 person.setShortDisplayNameComputed(true);
981 person.setForeName("updated-" + TEST_FORE_NAME);
982 expectedDisplayName =
983 PersonAuthorityClientUtils.prepareDefaultDisplayName(
984 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
985 TEST_BIRTH_DATE, TEST_DEATH_DATE);
986 expectedShortDisplayName =
987 PersonAuthorityClientUtils.prepareDefaultDisplayName(
988 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
990 // Submit the updated resource to the service and store the response.
991 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
992 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
993 commonPart.setLabel(client.getItemCommonPartName());
994 res = client.updateItem(knownResourceId, knownItemResourceId, output);
996 int statusCode = res.getStatus();
998 // Check the status code of the response: does it match the expected response(s)?
999 if(logger.isDebugEnabled()){
1000 logger.debug("updateItem: status = " + statusCode);
1002 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1003 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1004 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1006 // Retrieve the updated resource and verify that its contents exist.
1007 input = new PoxPayloadIn(res.getEntity());
1009 res.releaseConnection();
1012 PersonsCommon updatedPerson =
1013 (PersonsCommon) extractPart(input,
1014 client.getItemCommonPartName(), PersonsCommon.class);
1015 Assert.assertNotNull(updatedPerson);
1017 // Verify that the updated resource received the correct data.
1018 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
1019 "Updated ForeName in Person did not match submitted data.");
1020 // Verify that the updated resource computes the right displayName.
1021 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
1022 "Updated ForeName in Person not reflected in computed DisplayName.");
1023 // Verify that the updated resource computes the right displayName.
1024 Assert.assertEquals(updatedPerson.getShortDisplayName(), expectedShortDisplayName,
1025 "Updated ForeName in Person not reflected in computed ShortDisplayName.");
1027 // Now Update the displayName, not computed and verify the computed name is overriden.
1028 person.setDisplayNameComputed(false);
1029 expectedDisplayName = "TestName";
1030 person.setDisplayName(expectedDisplayName);
1031 person.setShortDisplayNameComputed(false);
1032 person.setShortDisplayName(expectedDisplayName);
1034 // Submit the updated resource to the service and store the response.
1035 output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1036 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1037 commonPart.setLabel(client.getItemCommonPartName());
1038 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1040 int statusCode = res.getStatus();
1042 // Check the status code of the response: does it match the expected response(s)?
1043 if(logger.isDebugEnabled()){
1044 logger.debug("updateItem: status = " + statusCode);
1046 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1047 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1048 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1050 // Retrieve the updated resource and verify that its contents exist.
1051 input = new PoxPayloadIn(res.getEntity());
1053 res.releaseConnection();
1057 (PersonsCommon) extractPart(input,
1058 client.getItemCommonPartName(), PersonsCommon.class);
1059 Assert.assertNotNull(updatedPerson);
1061 // Verify that the updated resource received the correct data.
1062 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
1063 "Updated displayNameComputed in Person did not match submitted data.");
1064 // Verify that the updated resource computes the right displayName.
1065 Assert.assertEquals(updatedPerson.getDisplayName(),
1066 expectedDisplayName,
1067 "Updated DisplayName (not computed) in Person not stored.");
1068 // Verify that the updated resource received the correct data.
1069 Assert.assertEquals(updatedPerson.isShortDisplayNameComputed(), false,
1070 "Updated shortDisplayNameComputed in Person did not match submitted data.");
1071 // Verify that the updated resource computes the right displayName.
1072 Assert.assertEquals(updatedPerson.getShortDisplayName(),
1073 expectedDisplayName,
1074 "Updated ShortDisplayName (not computed) in Person not stored.");
1078 * Verify illegal item display name.
1080 * @param testName the test name
1081 * @throws Exception the exception
1083 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1084 groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"})
1085 public void verifyIllegalItemDisplayName(String testName) throws Exception {
1087 if (logger.isDebugEnabled()) {
1088 logger.debug(testBanner(testName, CLASS_NAME));
1091 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
1092 // setupUpdateWithWrongXmlSchema(testName);
1094 // Submit the request to the service and store the response.
1095 PersonAuthorityClient client = new PersonAuthorityClient();
1096 PoxPayloadIn input = null;
1097 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
1099 int statusCode = res.getStatus();
1101 // Check the status code of the response: does it match
1102 // the expected response(s)?
1103 if(logger.isDebugEnabled()){
1104 logger.debug(testName + ": status = " + statusCode);
1106 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1107 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1108 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
1110 // Check whether Person has expected displayName.
1111 input = new PoxPayloadIn(res.getEntity());
1113 res.releaseConnection();
1116 PersonsCommon person = (PersonsCommon) extractPart(input,
1117 client.getItemCommonPartName(), PersonsCommon.class);
1118 Assert.assertNotNull(person);
1119 // Try to Update with computed false and no displayName
1120 person.setDisplayNameComputed(false);
1121 person.setDisplayName(null);
1123 // Submit the updated resource to the service and store the response.
1124 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1125 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1126 commonPart.setLabel(client.getItemCommonPartName());
1127 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1129 int statusCode = res.getStatus();
1131 // Check the status code of the response: does it match the expected response(s)?
1132 if(logger.isDebugEnabled()){
1133 logger.debug("updateItem: status = " + statusCode);
1135 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1136 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1137 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1139 res.releaseConnection();
1146 * @param testName the test name
1147 * @throws Exception the exception
1149 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1150 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1151 public void readContact(String testName) throws Exception {
1153 if (logger.isDebugEnabled()) {
1154 logger.debug(testBanner(testName, CLASS_NAME));
1159 // Submit the request to the service and store the response.
1160 PersonAuthorityClient client = new PersonAuthorityClient();
1161 PoxPayloadIn input = null;
1162 ClientResponse<String> res =
1163 client.readContact(knownResourceId, knownItemResourceId,
1164 knownContactResourceId);
1166 int statusCode = res.getStatus();
1168 // Check the status code of the response: does it match
1169 // the expected response(s)?
1170 if(logger.isDebugEnabled()){
1171 logger.debug(testName + ": status = " + statusCode);
1173 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1174 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1175 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1177 // Check whether we've received a contact.
1178 input = new PoxPayloadIn(res.getEntity());
1180 res.releaseConnection();
1183 ContactsCommon contact = (ContactsCommon) extractPart(input,
1184 new ContactClient().getCommonPartName(), ContactsCommon.class);
1185 Assert.assertNotNull(contact);
1186 boolean showFull = true;
1187 if(showFull && logger.isDebugEnabled()){
1188 logger.debug(testName + ": returned payload:");
1189 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
1191 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
1192 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
1198 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
1201 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1202 groups = {"read"}, dependsOnMethods = {"read"})
1203 public void readNonExistent(String testName) {
1205 if (logger.isDebugEnabled()) {
1206 logger.debug(testBanner(testName, CLASS_NAME));
1209 setupReadNonExistent();
1211 // Submit the request to the service and store the response.
1212 PersonAuthorityClient client = new PersonAuthorityClient();
1213 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
1215 int statusCode = res.getStatus();
1216 // Check the status code of the response: does it match
1217 // the expected response(s)?
1218 if(logger.isDebugEnabled()){
1219 logger.debug(testName + ": status = " + statusCode);
1221 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1222 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1223 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1225 res.releaseConnection();
1230 * Read item non existent.
1232 * @param testName the test name
1234 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1235 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1236 public void readItemNonExistent(String testName) {
1238 if (logger.isDebugEnabled()) {
1239 logger.debug(testBanner(testName, CLASS_NAME));
1242 setupReadNonExistent();
1244 // Submit the request to the service and store the response.
1245 PersonAuthorityClient client = new PersonAuthorityClient();
1246 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1248 int statusCode = res.getStatus();
1250 // Check the status code of the response: does it match
1251 // the expected response(s)?
1252 if(logger.isDebugEnabled()){
1253 logger.debug(testName + ": status = " + statusCode);
1255 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1256 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1257 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1259 res.releaseConnection();
1264 * Read contact non existent.
1266 * @param testName the test name
1268 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1269 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1270 public void readContactNonExistent(String testName) {
1272 if (logger.isDebugEnabled()) {
1273 logger.debug(testBanner(testName, CLASS_NAME));
1276 setupReadNonExistent();
1278 // Submit the request to the service and store the response.
1279 PersonAuthorityClient client = new PersonAuthorityClient();
1280 ClientResponse<String> res =
1281 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1283 int statusCode = res.getStatus();
1285 // Check the status code of the response: does it match
1286 // the expected response(s)?
1287 if(logger.isDebugEnabled()){
1288 logger.debug(testName + ": status = " + statusCode);
1290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1294 res.releaseConnection();
1298 // ---------------------------------------------------------------
1299 // CRUD tests : READ_LIST tests
1300 // ---------------------------------------------------------------
1304 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1307 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1308 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1309 public void readList(String testName) throws Exception {
1311 if (logger.isDebugEnabled()) {
1312 logger.debug(testBanner(testName, CLASS_NAME));
1317 // Submit the request to the service and store the response.
1318 PersonAuthorityClient client = new PersonAuthorityClient();
1319 PersonauthoritiesCommonList list = null;
1320 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1322 int statusCode = res.getStatus();
1324 // Check the status code of the response: does it match
1325 // the expected response(s)?
1326 if(logger.isDebugEnabled()){
1327 logger.debug(testName + ": status = " + statusCode);
1329 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1330 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1331 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1333 list = res.getEntity();
1335 res.releaseConnection();
1338 // Optionally output additional data about list members for debugging.
1339 boolean iterateThroughList = false;
1340 if (iterateThroughList && logger.isDebugEnabled()) {
1341 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1342 list.getPersonauthorityListItem();
1344 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1345 String csid = item.getCsid();
1346 logger.debug(testName + ": list-item[" + i + "] csid=" +
1348 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1349 item.getDisplayName());
1350 logger.debug(testName + ": list-item[" + i + "] URI=" +
1352 readItemList(csid, null, testName);
1361 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1362 groups = {"readList"}, dependsOnMethods = {"readList"})
1363 public void readItemList(String testName) {
1364 readItemList(knownResourceId, null, testName);
1368 * Read item list by authority name.
1370 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1371 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1372 public void readItemListByAuthorityName(String testName) {
1373 readItemList(null, knownResourceShortIdentifer, testName);
1379 * @param vcsid the vcsid
1380 * @param name the name
1382 private void readItemList(String vcsid, String name, String testName) {
1387 // Submit the request to the service and store the response.
1388 PersonAuthorityClient client = new PersonAuthorityClient();
1389 ClientResponse<PersonsCommonList> res = null;
1391 res = client.readItemList(vcsid, null, null);
1392 } else if (name!= null) {
1393 res = client.readItemListForNamedAuthority(name, null, null);
1395 Assert.fail("readItemList passed null csid and name!");
1397 PersonsCommonList list = null;
1399 int statusCode = res.getStatus();
1401 // Check the status code of the response: does it match
1402 // the expected response(s)?
1403 if(logger.isDebugEnabled()){
1404 logger.debug(testName + ": status = " + statusCode);
1406 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1407 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1408 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1410 list = res.getEntity();
1412 res.releaseConnection();
1415 List<PersonsCommonList.PersonListItem> items =
1416 list.getPersonListItem();
1417 int nItemsReturned = items.size();
1418 // There will be one item created, associated with a
1419 // known parent resource, by the createItem test.
1421 // In addition, there will be 'nItemsToCreateInList'
1422 // additional items created by the createItemList test,
1423 // all associated with the same parent resource.
1424 int nExpectedItems = nItemsToCreateInList + 1;
1425 if(logger.isDebugEnabled()){
1426 logger.debug(testName + ": Expected "
1427 + nExpectedItems +" items; got: "+nItemsReturned);
1429 Assert.assertEquals(nItemsReturned, nExpectedItems);
1432 for (PersonsCommonList.PersonListItem item : items) {
1433 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1434 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1435 // Optionally output additional data about list members for debugging.
1436 boolean showDetails = true;
1437 if (showDetails && logger.isDebugEnabled()) {
1438 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1440 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1442 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1443 item.getDisplayName());
1444 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1452 * Read contact list.
1454 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1455 public void readContactList() {
1456 readContactList(knownResourceId, knownItemResourceId);
1460 * Read contact list.
1462 * @param parentcsid the parentcsid
1463 * @param itemcsid the itemcsid
1465 private void readContactList(String parentcsid, String itemcsid) {
1466 final String testName = "readContactList";
1471 // Submit the request to the service and store the response.
1472 PersonAuthorityClient client = new PersonAuthorityClient();
1473 ContactsCommonList list = null;
1474 ClientResponse<ContactsCommonList> res =
1475 client.readContactList(parentcsid, itemcsid);
1477 int statusCode = res.getStatus();
1479 // Check the status code of the response: does it match
1480 // the expected response(s)?
1481 if(logger.isDebugEnabled()){
1482 logger.debug(testName + ": status = " + statusCode);
1484 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1485 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1486 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1488 list = res.getEntity();
1490 res.releaseConnection();
1493 List<ContactsCommonList.ContactListItem> listitems =
1494 list.getContactListItem();
1495 int nItemsReturned = listitems.size();
1496 // There will be one item created, associated with a
1497 // known parent resource, by the createItem test.
1499 // In addition, there will be 'nItemsToCreateInList'
1500 // additional items created by the createItemList test,
1501 // all associated with the same parent resource.
1502 int nExpectedItems = nItemsToCreateInList + 1;
1503 if(logger.isDebugEnabled()){
1504 logger.debug(testName + ": Expected "
1505 + nExpectedItems +" items; got: "+nItemsReturned);
1507 Assert.assertEquals(nItemsReturned, nExpectedItems);
1510 for (ContactsCommonList.ContactListItem listitem : listitems) {
1511 // Optionally output additional data about list members for debugging.
1512 boolean showDetails = false;
1513 if (showDetails && logger.isDebugEnabled()) {
1514 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1515 listitem.getCsid());
1516 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1517 listitem.getAddressPlace());
1518 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1527 // There are no failure outcome tests at present.
1529 // ---------------------------------------------------------------
1530 // CRUD tests : UPDATE tests
1531 // ---------------------------------------------------------------
1534 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1537 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1538 groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
1539 public void update(String testName) throws Exception {
1541 if (logger.isDebugEnabled()) {
1542 logger.debug(testBanner(testName, CLASS_NAME));
1547 // Retrieve the contents of a resource to update.
1548 PersonAuthorityClient client = new PersonAuthorityClient();
1549 PoxPayloadIn input = null;
1550 ClientResponse<String> res = client.read(knownResourceId);
1552 if(logger.isDebugEnabled()){
1553 logger.debug(testName + ": read status = " + res.getStatus());
1555 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1557 if(logger.isDebugEnabled()){
1558 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1560 input = new PoxPayloadIn(res.getEntity());
1562 res.releaseConnection();
1565 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1566 client.getCommonPartName(), PersonauthoritiesCommon.class);
1567 Assert.assertNotNull(personAuthority);
1569 // Update the contents of this resource.
1570 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1571 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1572 if(logger.isDebugEnabled()){
1573 logger.debug("to be updated PersonAuthority");
1574 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1577 // Submit the updated resource to the service and store the response.
1578 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
1579 PayloadOutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1580 commonPart.setLabel(client.getCommonPartName());
1581 res = client.update(knownResourceId, output);
1583 int statusCode = res.getStatus();
1585 // Check the status code of the response: does it match the expected response(s)?
1586 if(logger.isDebugEnabled()){
1587 logger.debug(testName + ": status = " + statusCode);
1589 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1590 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1591 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1593 // Retrieve the updated resource and verify that its contents exist.
1594 input = new PoxPayloadIn(res.getEntity());
1596 res.releaseConnection();
1599 PersonauthoritiesCommon updatedPersonAuthority =
1600 (PersonauthoritiesCommon) extractPart(input,
1601 client.getCommonPartName(), PersonauthoritiesCommon.class);
1602 Assert.assertNotNull(updatedPersonAuthority);
1604 // Verify that the updated resource received the correct data.
1605 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1606 personAuthority.getDisplayName(),
1607 "Data in updated object did not match submitted data.");
1613 * @param testName the test name
1614 * @throws Exception the exception
1616 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1617 groups = {"update"}, dependsOnMethods = {"update"})
1618 public void updateItem(String testName) throws Exception {
1620 if (logger.isDebugEnabled()) {
1621 logger.debug(testBanner(testName, CLASS_NAME));
1626 // Retrieve the contents of a resource to update.
1627 PersonAuthorityClient client = new PersonAuthorityClient();
1628 PoxPayloadIn input = null;
1629 ClientResponse<String> res =
1630 client.readItem(knownResourceId, knownItemResourceId);
1632 if(logger.isDebugEnabled()){
1633 logger.debug(testName + ": read status = " + res.getStatus());
1635 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1637 if(logger.isDebugEnabled()){
1638 logger.debug("got Person to update with ID: " +
1639 knownItemResourceId +
1640 " in PersonAuthority: " + knownResourceId );
1642 input = new PoxPayloadIn(res.getEntity());
1644 res.releaseConnection();
1647 PersonsCommon person = (PersonsCommon) extractPart(input,
1648 client.getItemCommonPartName(), PersonsCommon.class);
1649 Assert.assertNotNull(person);
1651 if (logger.isDebugEnabled() == true) {
1652 logger.debug("About to update the following person...");
1653 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1656 // Update the contents of this resource.
1657 person.setCsid(null);
1658 person.setForeName("updated-" + person.getForeName());
1659 if(logger.isDebugEnabled()){
1660 logger.debug("to be updated Person");
1661 logger.debug(objectAsXmlString(person,
1662 PersonsCommon.class));
1665 // Submit the updated resource to the service and store the response.
1666 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1667 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1668 commonPart.setLabel(client.getItemCommonPartName());
1669 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1671 int statusCode = res.getStatus();
1673 // Check the status code of the response: does it match the expected response(s)?
1674 if(logger.isDebugEnabled()){
1675 logger.debug(testName + ": status = " + statusCode);
1677 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1678 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1679 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1681 // Retrieve the updated resource and verify that its contents exist.
1682 input = new PoxPayloadIn(res.getEntity());
1684 res.releaseConnection();
1687 PersonsCommon updatedPerson =
1688 (PersonsCommon) extractPart(input,
1689 client.getItemCommonPartName(), PersonsCommon.class);
1690 Assert.assertNotNull(updatedPerson);
1692 if (logger.isDebugEnabled() == true) {
1693 logger.debug("Updated to following person to:");
1694 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1697 // Verify that the updated resource received the correct data.
1698 Assert.assertEquals(updatedPerson.getForeName(),
1699 person.getForeName(),
1700 "Data in updated Person did not match submitted data.");
1706 * @param testName the test name
1707 * @throws Exception the exception
1709 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1710 groups = {"update"}, dependsOnMethods = {"updateItem"})
1711 public void updateContact(String testName) throws Exception {
1713 if (logger.isDebugEnabled()) {
1714 logger.debug(testBanner(testName, CLASS_NAME));
1719 // Retrieve the contents of a resource to update.
1720 PersonAuthorityClient client = new PersonAuthorityClient();
1721 PoxPayloadIn input = null;
1722 ClientResponse<String> res =
1723 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1725 if(logger.isDebugEnabled()){
1726 logger.debug(testName + ": read status = " + res.getStatus());
1728 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1730 if(logger.isDebugEnabled()){
1731 logger.debug("got Contact to update with ID: " +
1732 knownContactResourceId +
1733 " in item: " + knownItemResourceId +
1734 " in parent: " + knownResourceId );
1736 input = new PoxPayloadIn(res.getEntity());
1738 res.releaseConnection();
1741 ContactsCommon contact = (ContactsCommon) extractPart(input,
1742 new ContactClient().getCommonPartName(), ContactsCommon.class);
1743 Assert.assertNotNull(contact);
1745 // Update the contents of this resource.
1746 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1747 if(logger.isDebugEnabled()){
1748 logger.debug("to be updated Contact");
1749 logger.debug(objectAsXmlString(contact,
1750 ContactsCommon.class));
1753 // Submit the updated resource to the service and store the response.
1754 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1755 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); //FIXME: REM - Replace with output.addPart(contact, client.getCommonPartName())
1756 commonPart.setLabel(client.getCommonPartName());
1757 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1759 int statusCode = res.getStatus();
1761 // Check the status code of the response: does it match the expected response(s)?
1762 if(logger.isDebugEnabled()){
1763 logger.debug(testName + ": status = " + statusCode);
1765 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1766 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1767 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1769 // Retrieve the updated resource and verify that its contents exist.
1770 input = new PoxPayloadIn(res.getEntity());;
1772 res.releaseConnection();
1774 ContactsCommon updatedContact =
1775 (ContactsCommon) extractPart(input,
1776 new ContactClient().getCommonPartName(), ContactsCommon.class);
1777 Assert.assertNotNull(updatedContact);
1779 // Verify that the updated resource received the correct data.
1780 Assert.assertEquals(updatedContact.getAddressPlace(),
1781 contact.getAddressPlace(),
1782 "Data in updated Contact did not match submitted data.");
1786 // Placeholders until the three tests below can be uncommented.
1787 // See Issue CSPACE-401.
1789 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1792 public void updateWithEmptyEntityBody(String testName) throws Exception {
1793 //Should this really be empty?
1797 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1800 public void updateWithMalformedXml(String testName) throws Exception {
1801 //Should this really be empty?
1805 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1808 public void updateWithWrongXmlSchema(String testName) throws Exception {
1809 //Should this really be empty?
1812 /* //FIXME: REM - Can we kill all this dead code please?
1814 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1815 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1816 public void updateWithEmptyEntityBody(String testName) throws Exception {
1818 if (logger.isDebugEnabled()) {
1819 logger.debug(testBanner(testName, CLASS_NAME));
1822 setupUpdateWithEmptyEntityBody(testName, logger);
1824 // Submit the request to the service and store the response.
1825 String method = REQUEST_TYPE.httpMethodName();
1826 String url = getResourceURL(knownResourceId);
1827 String mediaType = MediaType.APPLICATION_XML;
1828 final String entity = "";
1829 int statusCode = submitRequest(method, url, mediaType, entity);
1831 // Check the status code of the response: does it match
1832 // the expected response(s)?
1833 if(logger.isDebugEnabled()){
1834 logger.debug(testName + ": url=" + url +
1835 " status=" + statusCode);
1837 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1838 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1839 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1843 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1844 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1845 public void updateWithMalformedXml(String testName) throws Exception {
1847 if (logger.isDebugEnabled()) {
1848 logger.debug(testBanner(testName, CLASS_NAME));
1851 setupUpdateWithMalformedXml();
1853 // Submit the request to the service and store the response.
1854 String method = REQUEST_TYPE.httpMethodName();
1855 String url = getResourceURL(knownResourceId);
1856 String mediaType = MediaType.APPLICATION_XML;
1857 final String entity = MALFORMED_XML_DATA;
1858 int statusCode = submitRequest(method, url, mediaType, entity);
1860 // Check the status code of the response: does it match
1861 // the expected response(s)?
1862 if(logger.isDebugEnabled()){
1863 logger.debug(testName + ": url=" + url +
1864 " status=" + statusCode);
1866 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1867 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1868 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1872 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1873 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1874 public void updateWithWrongXmlSchema(String testName) throws Exception {
1876 if (logger.isDebugEnabled()) {
1877 logger.debug(testBanner(testName, CLASS_NAME));
1880 setupUpdateWithWrongXmlSchema();
1882 // Submit the request to the service and store the response.
1883 String method = REQUEST_TYPE.httpMethodName();
1884 String url = getResourceURL(knownResourceId);
1885 String mediaType = MediaType.APPLICATION_XML;
1886 final String entity = WRONG_XML_SCHEMA_DATA;
1887 int statusCode = submitRequest(method, url, mediaType, entity);
1889 // Check the status code of the response: does it match
1890 // the expected response(s)?
1891 if(logger.isDebugEnabled()){
1892 logger.debug("updateWithWrongXmlSchema: url=" + url +
1893 " status=" + statusCode);
1895 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1896 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1897 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1902 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1905 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1906 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1907 public void updateNonExistent(String testName) throws Exception {
1909 if (logger.isDebugEnabled()) {
1910 logger.debug(testBanner(testName, CLASS_NAME));
1913 setupUpdateNonExistent();
1915 // Submit the request to the service and store the response.
1916 // Note: The ID(s) used when creating the request payload may be arbitrary.
1917 // The only relevant ID may be the one used in update(), below.
1918 PersonAuthorityClient client = new PersonAuthorityClient();
1919 String displayName = "displayName-NON_EXISTENT_ID";
1920 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1921 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1922 ClientResponse<String> res =
1923 client.update(NON_EXISTENT_ID, multipart);
1925 int statusCode = res.getStatus();
1927 // Check the status code of the response: does it match
1928 // the expected response(s)?
1929 if(logger.isDebugEnabled()){
1930 logger.debug(testName + ": status = " + statusCode);
1932 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1933 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1934 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1936 res.releaseConnection();
1941 * Update non existent item.
1943 * @param testName the test name
1944 * @throws Exception the exception
1946 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1947 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1948 public void updateNonExistentItem(String testName) throws Exception {
1950 if (logger.isDebugEnabled()) {
1951 logger.debug(testBanner(testName, CLASS_NAME));
1954 setupUpdateNonExistent();
1956 // Submit the request to the service and store the response.
1957 // Note: The ID used in this 'create' call may be arbitrary.
1958 // The only relevant ID may be the one used in update(), below.
1959 PersonAuthorityClient client = new PersonAuthorityClient();
1960 Map<String, String> nonexMap = new HashMap<String,String>();
1961 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1962 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1963 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1964 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1965 Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1966 PoxPayloadOut multipart =
1967 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1968 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1969 nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() );
1970 ClientResponse<String> res =
1971 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1973 int statusCode = res.getStatus();
1975 // Check the status code of the response: does it match
1976 // the expected response(s)?
1977 if(logger.isDebugEnabled()){
1978 logger.debug(testName + ": status = " + statusCode);
1980 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1981 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1982 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1984 res.releaseConnection();
1989 * Update non existent contact.
1991 * @param testName the test name
1992 * @throws Exception the exception
1994 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1995 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1996 public void updateNonExistentContact(String testName) throws Exception {
1997 // Currently a no-op test
2000 // ---------------------------------------------------------------
2001 // CRUD tests : DELETE tests
2002 // ---------------------------------------------------------------
2005 // Note: delete sub-resources in ascending hierarchical order,
2006 // before deleting their parents.
2011 * @param testName the test name
2012 * @throws Exception the exception
2014 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2015 groups = {"delete"}, dependsOnGroups = {"update"})
2016 public void deleteContact(String testName) throws Exception {
2018 if (logger.isDebugEnabled()) {
2019 logger.debug(testBanner(testName, CLASS_NAME));
2024 if(logger.isDebugEnabled()){
2025 logger.debug("parentcsid =" + knownResourceId +
2026 " itemcsid = " + knownItemResourceId +
2027 " csid = " + knownContactResourceId);
2030 // Submit the request to the service and store the response.
2031 PersonAuthorityClient client = new PersonAuthorityClient();
2032 ClientResponse<Response> res =
2033 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
2035 int statusCode = res.getStatus();
2037 // Check the status code of the response: does it match
2038 // the expected response(s)?
2039 if(logger.isDebugEnabled()){
2040 logger.debug(testName + ": status = " + statusCode);
2042 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2043 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2044 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2046 res.releaseConnection();
2053 * @param testName the test name
2054 * @throws Exception the exception
2056 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2057 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2058 public void deleteItem(String testName) throws Exception {
2060 if (logger.isDebugEnabled()) {
2061 logger.debug(testBanner(testName, CLASS_NAME));
2066 if(logger.isDebugEnabled()){
2067 logger.debug("parentcsid =" + knownResourceId +
2068 " itemcsid = " + knownItemResourceId);
2071 // Submit the request to the service and store the response.
2072 PersonAuthorityClient client = new PersonAuthorityClient();
2073 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
2075 int statusCode = res.getStatus();
2077 // Check the status code of the response: does it match
2078 // the expected response(s)?
2079 if(logger.isDebugEnabled()){
2080 logger.debug(testName + ": status = " + statusCode);
2082 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2083 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2084 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2086 res.releaseConnection();
2091 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
2094 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2095 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2096 public void delete(String testName) throws Exception {
2098 if (logger.isDebugEnabled()) {
2099 logger.debug(testBanner(testName, CLASS_NAME));
2104 if(logger.isDebugEnabled()){
2105 logger.debug("parentcsid =" + knownResourceId);
2108 // Submit the request to the service and store the response.
2109 PersonAuthorityClient client = new PersonAuthorityClient();
2110 ClientResponse<Response> res = client.delete(knownResourceId);
2112 int statusCode = res.getStatus();
2114 // Check the status code of the response: does it match
2115 // the expected response(s)?
2116 if(logger.isDebugEnabled()){
2117 logger.debug(testName + ": status = " + statusCode);
2119 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2120 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2121 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2123 res.releaseConnection();
2129 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
2132 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2133 groups = {"delete"}, dependsOnMethods = {"delete"})
2134 public void deleteNonExistent(String testName) throws Exception {
2136 if (logger.isDebugEnabled()) {
2137 logger.debug(testBanner(testName, CLASS_NAME));
2140 setupDeleteNonExistent();
2142 // Submit the request to the service and store the response.
2143 PersonAuthorityClient client = new PersonAuthorityClient();
2144 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
2146 int statusCode = res.getStatus();
2148 // Check the status code of the response: does it match
2149 // the expected response(s)?
2150 if(logger.isDebugEnabled()){
2151 logger.debug(testName + ": status = " + statusCode);
2153 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2154 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2155 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2157 res.releaseConnection();
2162 * Delete non existent item.
2164 * @param testName the test name
2166 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2167 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2168 public void deleteNonExistentItem(String testName) {
2170 if (logger.isDebugEnabled()) {
2171 logger.debug(testBanner(testName, CLASS_NAME));
2174 setupDeleteNonExistent();
2176 // Submit the request to the service and store the response.
2177 PersonAuthorityClient client = new PersonAuthorityClient();
2178 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
2180 int statusCode = res.getStatus();
2182 // Check the status code of the response: does it match
2183 // the expected response(s)?
2184 if(logger.isDebugEnabled()){
2185 logger.debug(testName + ": status = " + statusCode);
2187 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2188 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2189 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2191 res.releaseConnection();
2196 * Delete non existent contact.
2198 * @param testName the test name
2200 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2201 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2202 public void deleteNonExistentContact(String testName) {
2204 if (logger.isDebugEnabled()) {
2205 logger.debug(testBanner(testName, CLASS_NAME));
2208 setupDeleteNonExistent();
2210 // Submit the request to the service and store the response.
2211 PersonAuthorityClient client = new PersonAuthorityClient();
2212 ClientResponse<Response> res =
2213 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2215 int statusCode = res.getStatus();
2217 // Check the status code of the response: does it match
2218 // the expected response(s)?
2219 if(logger.isDebugEnabled()){
2220 logger.debug(testName + ": status = " + statusCode);
2222 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2223 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2224 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2226 res.releaseConnection();
2230 // ---------------------------------------------------------------
2231 // Utility tests : tests of code used in tests above
2232 // ---------------------------------------------------------------
2234 * Tests the code for manually submitting data that is used by several
2235 * of the methods above.
2237 @Test(dependsOnMethods = {"create", "read"})
2238 public void testSubmitRequest() {
2240 // Expected status code: 200 OK
2241 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2243 // Submit the request to the service and store the response.
2244 String method = ServiceRequestType.READ.httpMethodName();
2245 String url = getResourceURL(knownResourceId);
2246 int statusCode = submitRequest(method, url);
2248 // Check the status code of the response: does it match
2249 // the expected response(s)?
2250 if(logger.isDebugEnabled()){
2251 logger.debug("testSubmitRequest: url=" + url +
2252 " status=" + statusCode);
2254 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2259 * Test item submit request.
2261 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2262 public void testItemSubmitRequest() {
2264 // Expected status code: 200 OK
2265 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2267 // Submit the request to the service and store the response.
2268 String method = ServiceRequestType.READ.httpMethodName();
2269 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2270 int statusCode = submitRequest(method, url);
2272 // Check the status code of the response: does it match
2273 // the expected response(s)?
2274 if(logger.isDebugEnabled()){
2275 logger.debug("testItemSubmitRequest: url=" + url +
2276 " status=" + statusCode);
2278 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2283 * Test contact submit request.
2285 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2286 public void testContactSubmitRequest() {
2288 // Expected status code: 200 OK
2289 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2291 // Submit the request to the service and store the response.
2292 String method = ServiceRequestType.READ.httpMethodName();
2293 String url = getContactResourceURL(knownResourceId,
2294 knownItemResourceId, knownContactResourceId);
2295 int statusCode = submitRequest(method, url);
2297 // Check the status code of the response: does it match
2298 // the expected response(s)?
2299 if(logger.isDebugEnabled()){
2300 logger.debug("testItemSubmitRequest: url=" + url +
2301 " status=" + statusCode);
2303 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2308 // ---------------------------------------------------------------
2309 // Cleanup of resources created during testing
2310 // ---------------------------------------------------------------
2313 * Deletes all resources created by tests, after all tests have been run.
2315 * This cleanup method will always be run, even if one or more tests fail.
2316 * For this reason, it attempts to remove all resources created
2317 * at any point during testing, even if some of those resources
2318 * may be expected to be deleted by certain tests.
2321 @AfterClass(alwaysRun=true)
2323 public void cleanUp() {
2324 String noTest = System.getProperty("noTestCleanup");
2325 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2326 if (logger.isDebugEnabled()) {
2327 logger.debug("Skipping Cleanup phase ...");
2331 if (logger.isDebugEnabled()) {
2332 logger.debug("Cleaning up temporary resources created for testing ...");
2334 String parentResourceId;
2335 String itemResourceId;
2336 String contactResourceId;
2337 // Clean up contact resources.
2338 PersonAuthorityClient client = new PersonAuthorityClient();
2339 parentResourceId = knownResourceId;
2340 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2341 contactResourceId = entry.getKey();
2342 itemResourceId = entry.getValue();
2343 // Note: Any non-success responses from the delete operation
2344 // below are ignored and not reported.
2345 ClientResponse<Response> res =
2346 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2347 res.releaseConnection();
2349 // Clean up item resources.
2350 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2351 itemResourceId = entry.getKey();
2352 parentResourceId = entry.getValue();
2353 // Note: Any non-success responses from the delete operation
2354 // below are ignored and not reported.
2355 ClientResponse<Response> res =
2356 client.deleteItem(parentResourceId, itemResourceId);
2357 res.releaseConnection();
2359 // Clean up parent resources.
2363 // ---------------------------------------------------------------
2364 // Utility methods used by tests above
2365 // ---------------------------------------------------------------
2367 * Gets the contact service path component.
2369 * @return the contact service path component
2371 public String getContactServicePathComponent() {
2372 return ContactClient.SERVICE_PATH_COMPONENT;
2376 * Returns the root URL for the item service.
2378 * This URL consists of a base URL for all services, followed by
2379 * a path component for the owning parent, followed by the
2380 * path component for the items.
2382 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2383 * parent authority resource of the relevant item resource.
2385 * @return The root URL for the item service.
2387 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2388 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2392 * Returns the URL of a specific item resource managed by a service, and
2393 * designated by an identifier (such as a universally unique ID, or UUID).
2395 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2396 * parent authority resource of the relevant item resource.
2398 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2401 * @return The URL of a specific item resource managed by a service.
2403 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2404 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2409 * Returns the root URL for the contact service.
2411 * This URL consists of a base URL for all services, followed by
2412 * a path component for the owning authority, followed by the
2413 * path component for the owning item, followed by the path component
2414 * for the contact service.
2416 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2417 * parent authority resource of the relevant item resource.
2419 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2422 * @return The root URL for the contact service.
2424 protected String getContactServiceRootURL(String parentResourceIdentifier,
2425 String itemResourceIdentifier) {
2426 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2427 getContactServicePathComponent();
2431 * Returns the URL of a specific contact resource managed by a service, and
2432 * designated by an identifier (such as a universally unique ID, or UUID).
2434 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2435 * parent resource of the relevant item resource.
2437 * @param resourceIdentifier An identifier (such as a UUID) for an
2440 * @return The URL of a specific resource managed by a service.
2442 protected String getContactResourceURL(String parentResourceIdentifier,
2443 String itemResourceIdentifier, String contactResourceIdentifier) {
2444 return getContactServiceRootURL(parentResourceIdentifier,
2445 itemResourceIdentifier) + "/" + contactResourceIdentifier;