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.CollectionSpaceClient;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.client.ContactClient;
39 import org.collectionspace.services.client.ContactClientUtils;
40 import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema;
41 import org.collectionspace.services.contact.ContactsCommon;
42 import org.collectionspace.services.contact.ContactsCommonList;
44 import org.collectionspace.services.client.PersonAuthorityClient;
45 import org.collectionspace.services.client.PersonAuthorityClientUtils;
46 import org.collectionspace.services.PersonJAXBSchema;
47 import org.collectionspace.services.person.PersonauthoritiesCommon;
48 import org.collectionspace.services.person.PersonauthoritiesCommonList;
49 import org.collectionspace.services.person.PersonsCommon;
50 import org.collectionspace.services.person.PersonsCommonList;
52 import org.jboss.resteasy.client.ClientResponse;
53 //import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
56 import org.testng.Assert;
57 import org.testng.annotations.AfterClass;
58 import org.testng.annotations.Test;
61 * PersonAuthorityServiceTest, carries out tests against a
62 * deployed and running PersonAuthority Service.
64 * $LastChangedRevision: 753 $
65 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
67 public class PersonAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
70 private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
71 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
74 public String getServicePathComponent() {
75 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
79 protected String getServiceName() {
80 return PersonAuthorityClient.SERVICE_NAME;
83 public String getItemServicePathComponent() {
84 return PersonAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
87 /** The test forename. */
88 final String TEST_FORE_NAME = "John";
90 /** The test middle name. */
91 final String TEST_MIDDLE_NAME = null;
93 /** The test surname. */
94 final String TEST_SUR_NAME = "Wayne";
96 /** The test birthdate. */
97 final String TEST_BIRTH_DATE = "May 26, 1907";
99 /** The test death date. */
100 final String TEST_DEATH_DATE = "June 11, 1979";
102 // Hold some values for a recently created item to verify upon read.
103 private String knownResourceId = null;
104 private String knownResourceShortIdentifer = null;
105 private String knownResourceRefName = null;
106 private String knownItemResourceId = null;
107 private String knownItemResourceShortIdentifer = null;
109 // The resource ID of an item resource used for partial term matching tests.
110 private String knownItemPartialTermResourceId = null;
112 /** The known contact resource id. */
113 private String knownContactResourceId = null;
115 /** The n items to create in list. */
116 private int nItemsToCreateInList = 3;
118 /** The all item resource ids created. */
119 private Map<String, String> allItemResourceIdsCreated =
120 new HashMap<String, String>();
122 /** The all contact resource ids created. */
123 private Map<String, String> allContactResourceIdsCreated =
124 new HashMap<String, String>();
126 protected void setKnownResource( String id, String shortIdentifer,
128 knownResourceId = id;
129 knownResourceShortIdentifer = shortIdentifer;
130 knownResourceRefName = refName;
133 protected void setKnownItemResource( String id, String shortIdentifer ) {
134 knownItemResourceId = id;
135 knownItemResourceShortIdentifer = shortIdentifer;
140 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
143 protected CollectionSpaceClient getClientInstance() {
144 return new PersonAuthorityClient();
148 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
151 protected AbstractCommonList getAbstractCommonList(
152 ClientResponse<AbstractCommonList> response) {
153 return response.getEntity(PersonsCommonList.class);
156 // ---------------------------------------------------------------
157 // CRUD tests : CREATE tests
158 // ---------------------------------------------------------------
161 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
164 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
166 public void create(String testName) throws Exception {
168 if (logger.isDebugEnabled()) {
169 logger.debug(testBanner(testName, CLASS_NAME));
171 // Perform setup, such as initializing the type of service request
172 // (e.g. CREATE, DELETE), its valid and expected status codes, and
173 // its associated HTTP method name (e.g. POST, DELETE).
176 // Submit the request to the service and store the response.
177 PersonAuthorityClient client = new PersonAuthorityClient();
178 String shortId = createIdentifier();
179 String displayName = "displayName-" + shortId;
180 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
181 PoxPayloadOut multipart =
182 PersonAuthorityClientUtils.createPersonAuthorityInstance(
183 displayName, shortId, client.getCommonPartName());
186 ClientResponse<Response> res = client.create(multipart);
188 int statusCode = res.getStatus();
190 // Check the status code of the response: does it match
191 // the expected response(s)?
194 // Does it fall within the set of valid status codes?
195 // Does it exactly match the expected status code?
196 if(logger.isDebugEnabled()){
197 logger.debug(testName + ": status = " + statusCode);
199 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
200 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
201 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
203 newID = PersonAuthorityClientUtils.extractId(res);
205 res.releaseConnection();
207 // Save values for additional tests
208 if (knownResourceId == null){
209 setKnownResource( newID, shortId, baseRefName );
210 if (logger.isDebugEnabled()) {
211 logger.debug(testName + ": knownResourceId=" + knownResourceId);
214 // Store the IDs from every resource created by tests,
215 // so they can be deleted after tests have been run.
216 allResourceIdsCreated.add(newID);
220 protected PoxPayloadOut createInstance(String identifier) {
221 PersonAuthorityClient client = new PersonAuthorityClient();
222 String displayName = "displayName-" + identifier;
223 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
224 displayName, identifier, client.getCommonPartName());
229 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
230 String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
231 HashMap<String, String> personInfo = new HashMap<String, String>();
232 String shortId = "johnWayneTempActor";
233 personInfo.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
234 personInfo.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne Temp");
235 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
236 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayneTemp");
237 personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
239 return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel);
245 * @param testName the test name
247 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
248 groups = {"create"}, dependsOnMethods = {"create"})
249 public void createItem(String testName) {
250 if (logger.isDebugEnabled()) {
251 logger.debug(testBanner(testName, CLASS_NAME));
254 String newID = createItemInAuthority(knownResourceId, knownResourceRefName);
258 * Creates the item with an empty short identifier.
260 * @param testName the test name
263 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
264 groups = {"create"}, dependsOnMethods = {"create"})
265 public void createItemWithEmptyShortId(String testName) {
266 if (logger.isDebugEnabled()) {
267 logger.debug(testBanner(testName, CLASS_NAME));
271 // Fill the property map
273 Map<String, String> fieldProperties = new HashMap<String,String>();
274 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
275 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck");
276 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
277 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck");
279 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
280 String newID = createItemInAuthority(knownResourceId, knownResourceRefName,
281 shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES);
282 allResourceIdsCreated.add(newID);
287 * Creates an item in an authority, using test data.
289 * @param vcsid the vcsid
290 * @param authRefName the auth ref name
293 private String createItemInAuthority(String vcsid, String authRefName) {
295 final String testName = "createItemInAuthority";
296 if(logger.isDebugEnabled()){
297 logger.debug(testName + ":"+vcsid+"...");
300 Map<String, String> johnWayneMap = new HashMap<String,String>();
302 // Fill the property map
304 String shortId = "johnWayneActor";
305 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
306 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
307 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
308 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayne");
309 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
311 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
312 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
313 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
314 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
315 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
316 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
317 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
318 "known by his stage name John Wayne, was an American film actor, director " +
319 "and producer. He epitomized rugged masculinity and has become an enduring " +
320 "American icon. He is famous for his distinctive voice, walk and height. " +
321 "He was also known for his conservative political views and his support in " +
322 "the 1950s for anti-communist positions.");
324 Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String,List<String>>();
325 List<String> johnWayneGroups = new ArrayList<String>();
326 johnWayneGroups.add("Irish");
327 johnWayneGroups.add("Scottish");
328 johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
330 return createItemInAuthority(vcsid, authRefName, shortId, johnWayneMap, johnWayneRepeatablesMap);
335 * Creates an item in an authority.
337 * @param vcsid the vcsid
338 * @param authRefName the auth ref name
339 * @param itemFieldProperties a set of properties specifying the values of fields.
340 * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
343 private String createItemInAuthority(String vcsid, String authRefName, String shortId,
344 Map itemFieldProperties, Map itemRepeatableFieldProperties) {
346 final String testName = "createItemInAuthority";
347 if(logger.isDebugEnabled()){
348 logger.debug(testName + ":"+vcsid+"...");
351 // Submit the request to the service and store the response.
352 PersonAuthorityClient client = new PersonAuthorityClient();
354 PoxPayloadOut multipart =
355 PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, itemFieldProperties,
356 itemRepeatableFieldProperties, client.getItemCommonPartName() );
359 ClientResponse<Response> res = client.createItem(vcsid, multipart);
361 int statusCode = res.getStatus();
362 // Check the status code of the response: does it match
363 // the expected response(s)?
364 if(logger.isDebugEnabled()){
365 logger.debug(testName + ": status = " + statusCode);
367 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
368 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
369 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
371 newID = PersonAuthorityClientUtils.extractId(res);
373 res.releaseConnection();
376 // Store the ID returned from the first item resource created
377 // for additional tests below.
378 if (knownItemResourceId == null){
379 setKnownItemResource(newID, shortId);
380 if (logger.isDebugEnabled()) {
381 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
384 if(logger.isDebugEnabled()){
385 logger.debug(testName + " (created):"+vcsid+"/("+newID+","+shortId+")");
388 // Store the IDs from any item resources created
389 // by tests, along with the IDs of their parents, so these items
390 // can be deleted after all tests have been run.
391 allItemResourceIdsCreated.put(newID, vcsid);
397 * Creates the contact.
399 * @param testName the test name
401 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
402 groups = {"create"}, dependsOnMethods = {"createItem"})
403 public void createContact(String testName) {
404 if (logger.isDebugEnabled()) {
405 logger.debug(testBanner(testName, CLASS_NAME));
408 String newID = createContactInItem(knownResourceId, knownItemResourceId);
412 * Creates the contact in item.
414 * @param parentcsid the parentcsid
415 * @param itemcsid the itemcsid
418 private String createContactInItem(String parentcsid, String itemcsid) {
420 final String testName = "createContactInItem";
421 if(logger.isDebugEnabled()){
422 logger.debug(testName + ":...");
427 // Submit the request to the service and store the response.
428 PersonAuthorityClient client = new PersonAuthorityClient();
429 String identifier = createIdentifier();
430 PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
431 itemcsid, identifier, new ContactClient().getCommonPartName());
434 ClientResponse<Response> res =
435 client.createContact(parentcsid, itemcsid, multipart);
437 int statusCode = res.getStatus();
438 // Check the status code of the response: does it match
439 // the expected response(s)?
440 if(logger.isDebugEnabled()){
441 logger.debug(testName + ": status = " + statusCode);
443 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
444 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
445 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
447 newID = PersonAuthorityClientUtils.extractId(res);
449 res.releaseConnection();
452 // Store the ID returned from the first contact resource created
453 // for additional tests below.
454 if (knownContactResourceId == null){
455 knownContactResourceId = newID;
456 if (logger.isDebugEnabled()) {
457 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
461 // Store the IDs from any contact resources created
462 // by tests, along with the IDs of their parent items,
463 // so these items can be deleted after all tests have been run.
464 allContactResourceIdsCreated.put(newID, itemcsid);
471 // Placeholders until the three tests below can be uncommented.
472 // See Issue CSPACE-401.
474 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
477 public void createWithEmptyEntityBody(String testName) throws Exception {
478 //Should this really be empty?
482 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
485 public void createWithMalformedXml(String testName) throws Exception {
486 //Should this really be empty?
490 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
493 public void createWithWrongXmlSchema(String testName) throws Exception {
494 //Should this really be empty?
499 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
500 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
501 public void createWithEmptyEntityBody(String testName) throws Exception {
503 if (logger.isDebugEnabled()) {
504 logger.debug(testBanner(testName, CLASS_NAME));
507 setupCreateWithEmptyEntityBody();
509 // Submit the request to the service and store the response.
510 String method = REQUEST_TYPE.httpMethodName();
511 String url = getServiceRootURL();
512 String mediaType = MediaType.APPLICATION_XML;
513 final String entity = "";
514 int statusCode = submitRequest(method, url, mediaType, entity);
516 // Check the status code of the response: does it match
517 // the expected response(s)?
518 if(logger.isDebugEnabled()) {
519 logger.debug(testName + ": url=" + url +
520 " status=" + statusCode);
522 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
523 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
524 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
528 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
529 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
530 public void createWithMalformedXml(String testName) throws Exception {
532 if (logger.isDebugEnabled()) {
533 logger.debug(testBanner(testName, CLASS_NAME));
536 setupCreateWithMalformedXml();
538 // Submit the request to the service and store the response.
539 String method = REQUEST_TYPE.httpMethodName();
540 String url = getServiceRootURL();
541 String mediaType = MediaType.APPLICATION_XML;
542 final String entity = MALFORMED_XML_DATA; // Constant from base class.
543 int statusCode = submitRequest(method, url, mediaType, entity);
545 // Check the status code of the response: does it match
546 // the expected response(s)?
547 if(logger.isDebugEnabled()){
548 logger.debug(testName + ": url=" + url +
549 " status=" + statusCode);
551 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
552 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
553 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
557 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
558 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
559 public void createWithWrongXmlSchema(String testName) throws Exception {
561 if (logger.isDebugEnabled()) {
562 logger.debug(testBanner(testName, CLASS_NAME));
565 setupCreateWithWrongXmlSchema();
567 // Submit the request to the service and store the response.
568 String method = REQUEST_TYPE.httpMethodName();
569 String url = getServiceRootURL();
570 String mediaType = MediaType.APPLICATION_XML;
571 final String entity = WRONG_XML_SCHEMA_DATA;
572 int statusCode = submitRequest(method, url, mediaType, entity);
574 // Check the status code of the response: does it match
575 // the expected response(s)?
576 if(logger.isDebugEnabled()){
577 logger.debug(testName + ": url=" + url +
578 " status=" + statusCode);
580 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
581 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
582 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
587 * Attempts to create an authority with an short identifier that contains
588 * non-word characters.
590 * @param testName the test name
592 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
593 groups = {"create", "nonWordCharsInShortId"})
594 public void createWithShortIdNonWordChars(String testName) throws Exception {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
598 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
599 REQUEST_TYPE = ServiceRequestType.CREATE;
600 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
602 // Create the payload to be included in the body of the request
603 PersonAuthorityClient client = new PersonAuthorityClient();
604 String shortId = createIdentifier() + "*" + createIdentifier();
605 String displayName = "displayName-" + shortId;
606 PoxPayloadOut multipart =
607 PersonAuthorityClientUtils.createPersonAuthorityInstance(
608 displayName, shortId, client.getCommonPartName());
610 // Submit the request to the service and store the response.
611 ClientResponse<Response> res = client.create(multipart);
613 // Check the status code of the response: does it match
614 // the expected response(s)?
616 int statusCode = res.getStatus();
617 if(logger.isDebugEnabled()){
618 logger.debug(testName + ": status = " + statusCode);
620 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
621 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
622 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
624 res.releaseConnection();
630 * Attempts to create an item with an short identifier that contains
631 * non-word characters.
633 * @param testName the test name
635 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
636 groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"})
637 public void createItemWithShortIdNonWordChars(String testName) {
638 if (logger.isDebugEnabled()) {
639 logger.debug(testBanner(testName, CLASS_NAME));
641 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
642 REQUEST_TYPE = ServiceRequestType.CREATE;
643 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
645 PersonAuthorityClient client = new PersonAuthorityClient();
647 // Create the payload to be included in the body of the request
648 String shortId = "7-Eleven";
649 Map<String, String> fieldProperties = new HashMap<String,String>();
650 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
651 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, shortId);
652 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
653 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, shortId);
654 fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
655 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
656 PoxPayloadOut multipart =
657 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
658 knownResourceRefName, fieldProperties,
659 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
661 // Send the request and receive a response
662 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
664 // Check the status code of the response: does it match
665 // the expected response(s)?
667 int statusCode = res.getStatus();
668 // Check the status code of the response: does it match
669 // the expected response(s)?
670 if(logger.isDebugEnabled()){
671 logger.debug(testName + ": status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
677 res.releaseConnection();
682 // ---------------------------------------------------------------
683 // CRUD tests : CREATE LIST tests
684 // ---------------------------------------------------------------
687 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
690 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
691 groups = {"createList"}, dependsOnGroups = {"create"})
692 public void createList(String testName) throws Exception {
693 if (logger.isDebugEnabled()) {
694 logger.debug(testBanner(testName, CLASS_NAME));
696 for (int i = 0; i < nItemsToCreateInList; i++) {
702 * Creates the item list.
704 * @param testName the test name
705 * @throws Exception the exception
707 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
708 groups = {"createList"}, dependsOnMethods = {"createList"})
709 public void createItemList(String testName) throws Exception {
710 if (logger.isDebugEnabled()) {
711 logger.debug(testBanner(testName, CLASS_NAME));
713 // Add items to the initially-created, known parent record.
714 for (int j = 0; j < nItemsToCreateInList; j++) {
715 createItem(testName);
720 * Creates the contact list.
722 * @param testName the test name
723 * @throws Exception the exception
725 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726 groups = {"createList"}, dependsOnMethods = {"createItemList"})
727 public void createContactList(String testName) throws Exception {
728 // Add contacts to the initially-created, known item record.
729 for (int j = 0; j < nItemsToCreateInList; j++) {
730 createContact(testName);
734 // ---------------------------------------------------------------
735 // CRUD tests : READ tests
736 // ---------------------------------------------------------------
739 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
742 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
743 groups = {"read"}, dependsOnGroups = {"create"})
744 public void read(String testName) throws Exception {
745 readInternal(testName, knownResourceId, null);
751 * @param testName the test name
752 * @throws Exception the exception
754 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
755 groups = {"read"}, dependsOnMethods = {"read"})
756 public void readByName(String testName) throws Exception {
757 readInternal(testName, null, knownResourceShortIdentifer);
760 protected void readInternal(String testName, String CSID, String shortId) {
761 if (logger.isDebugEnabled()) {
762 logger.debug(testBanner(testName, CLASS_NAME));
767 // Submit the request to the service and store the response.
768 PersonAuthorityClient client = new PersonAuthorityClient();
769 ClientResponse<String> res = null;
771 res = client.read(CSID);
772 } else if(shortId!=null) {
773 res = client.readByName(shortId);
775 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
778 int statusCode = res.getStatus();
779 // Check the status code of the response: does it match
780 // the expected response(s)?
781 if(logger.isDebugEnabled()){
782 logger.debug(testName + ": status = " + statusCode);
784 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
785 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
786 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
787 //FIXME: remove the following try catch once Aron fixes signatures
789 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
790 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
791 client.getCommonPartName(), PersonauthoritiesCommon.class);
792 Assert.assertNotNull(personAuthority);
793 } catch (Exception e) {
794 throw new RuntimeException(e);
797 res.releaseConnection();
804 * @param testName the test name
805 * @throws Exception the exception
807 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
808 groups = {"readItem"}, dependsOnGroups = {"read"})
809 public void readItem(String testName) throws Exception {
810 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
814 * Read item in Named Auth.
816 * @param testName the test name
817 * @throws Exception the exception
819 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
820 groups = {"readItem"}, dependsOnMethods = {"readItem"})
821 public void readItemInNamedAuth(String testName) throws Exception {
822 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
828 * @param testName the test name
829 * @throws Exception the exception
831 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
832 groups = {"readItem"}, dependsOnMethods = {"readItem"})
833 public void readNamedItem(String testName) throws Exception {
834 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
838 * Read Named item in Named Auth.
840 * @param testName the test name
841 * @throws Exception the exception
843 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
844 groups = {"readItem"}, dependsOnMethods = {"readItem"})
845 public void readNamedItemInNamedAuth(String testName) throws Exception {
846 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
849 protected void readItemInternal(String testName,
850 String authCSID, String authShortId, String itemCSID, String itemShortId)
853 if (logger.isDebugEnabled()) {
854 logger.debug(testBanner(testName, CLASS_NAME));
855 logger.debug("Reading:"+((authCSID!=null)?authCSID:authShortId)+"/"+
856 ((itemCSID!=null)?authCSID:itemShortId));
861 // Submit the request to the service and store the response.
862 PersonAuthorityClient client = new PersonAuthorityClient();
863 ClientResponse<String> res = null;
866 res = client.readItem(authCSID, itemCSID);
867 } else if(itemShortId!=null) {
868 res = client.readNamedItem(authCSID, itemShortId);
870 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
872 } else if(authShortId!=null) {
874 res = client.readItemInNamedAuthority(authShortId, itemCSID);
875 } else if(itemShortId!=null) {
876 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
878 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
881 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
884 int statusCode = res.getStatus();
886 // Check the status code of the response: does it match
887 // the expected response(s)?
888 if(logger.isDebugEnabled()){
889 logger.debug(testName + ": status = " + statusCode);
891 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
892 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
893 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
895 // Check whether we've received a person.
896 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
897 PersonsCommon person = (PersonsCommon) extractPart(input,
898 client.getItemCommonPartName(), PersonsCommon.class);
899 Assert.assertNotNull(person);
900 boolean showFull = true;
901 if(showFull && logger.isDebugEnabled()){
902 logger.debug(testName + ": returned payload:");
903 logger.debug(objectAsXmlString(person, PersonsCommon.class));
906 // Check that the person item is within the expected Person Authority.
907 Assert.assertEquals(person.getInAuthority(), knownResourceId);
909 // Verify the number and contents of values in a repeatable field,
910 // as created in the instance record used for testing.
911 List<String> groups = person.getGroups().getGroup();
912 Assert.assertTrue(groups.size() > 0);
913 Assert.assertNotNull(groups.get(0));
916 res.releaseConnection();
921 * Verify item display name.
923 * @param testName the test name
924 * @throws Exception the exception
926 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
927 groups = {"update"}, dependsOnMethods = {"updateItem"})
928 public void verifyItemDisplayNames(String testName) throws Exception {
930 if (logger.isDebugEnabled()) {
931 logger.debug(testBanner(testName, CLASS_NAME));
936 // Submit the request to the service and store the response.
937 PersonAuthorityClient client = new PersonAuthorityClient();
938 PoxPayloadIn input =null;
939 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
941 int statusCode = res.getStatus();
943 // Check the status code of the response: does it match
944 // the expected response(s)?
945 if(logger.isDebugEnabled()){
946 logger.debug(testName + ": status = " + statusCode);
948 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
949 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
950 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
952 // Check whether person has expected displayName.
953 input = new PoxPayloadIn(res.getEntity());
955 res.releaseConnection();
958 PersonsCommon person = (PersonsCommon) extractPart(input,
959 client.getItemCommonPartName(), PersonsCommon.class);
960 Assert.assertNotNull(person);
961 String displayName = person.getDisplayName();
962 // Make sure displayName matches computed form
963 String expectedDisplayName =
964 PersonAuthorityClientUtils.prepareDefaultDisplayName(
965 TEST_FORE_NAME, null, TEST_SUR_NAME,
966 TEST_BIRTH_DATE, TEST_DEATH_DATE);
967 Assert.assertFalse(displayName.equals(expectedDisplayName));
969 String shortDisplayName = person.getShortDisplayName();
970 // Make sure displayName matches computed form
971 String expectedShortDisplayName =
972 PersonAuthorityClientUtils.prepareDefaultDisplayName(
973 TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
974 Assert.assertFalse(expectedShortDisplayName.equals(shortDisplayName));
976 // Update the forename and verify the computed name is updated.
977 person.setCsid(null);
978 person.setDisplayNameComputed(true);
979 person.setShortDisplayNameComputed(true);
980 person.setForeName("updated-" + TEST_FORE_NAME);
981 expectedDisplayName =
982 PersonAuthorityClientUtils.prepareDefaultDisplayName(
983 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
984 TEST_BIRTH_DATE, TEST_DEATH_DATE);
985 expectedShortDisplayName =
986 PersonAuthorityClientUtils.prepareDefaultDisplayName(
987 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,null, null);
989 // Submit the updated resource to the service and store the response.
990 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
991 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
992 commonPart.setLabel(client.getItemCommonPartName());
993 res = client.updateItem(knownResourceId, knownItemResourceId, output);
995 int statusCode = res.getStatus();
997 // Check the status code of the response: does it match the expected response(s)?
998 if(logger.isDebugEnabled()){
999 logger.debug("updateItem: status = " + statusCode);
1001 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1002 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1003 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1005 // Retrieve the updated resource and verify that its contents exist.
1006 input = new PoxPayloadIn(res.getEntity());
1008 res.releaseConnection();
1011 PersonsCommon updatedPerson =
1012 (PersonsCommon) extractPart(input,
1013 client.getItemCommonPartName(), PersonsCommon.class);
1014 Assert.assertNotNull(updatedPerson);
1016 // Verify that the updated resource received the correct data.
1017 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
1018 "Updated ForeName in Person did not match submitted data.");
1019 // Verify that the updated resource computes the right displayName.
1020 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
1021 "Updated ForeName in Person not reflected in computed DisplayName.");
1022 // Verify that the updated resource computes the right displayName.
1023 Assert.assertEquals(updatedPerson.getShortDisplayName(), expectedShortDisplayName,
1024 "Updated ForeName in Person not reflected in computed ShortDisplayName.");
1026 // Now Update the displayName, not computed and verify the computed name is overriden.
1027 person.setDisplayNameComputed(false);
1028 expectedDisplayName = "TestName";
1029 person.setDisplayName(expectedDisplayName);
1030 person.setShortDisplayNameComputed(false);
1031 person.setShortDisplayName(expectedDisplayName);
1033 // Submit the updated resource to the service and store the response.
1034 output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1035 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1036 commonPart.setLabel(client.getItemCommonPartName());
1037 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1039 int statusCode = res.getStatus();
1041 // Check the status code of the response: does it match the expected response(s)?
1042 if(logger.isDebugEnabled()){
1043 logger.debug("updateItem: status = " + statusCode);
1045 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1046 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1047 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1049 // Retrieve the updated resource and verify that its contents exist.
1050 input = new PoxPayloadIn(res.getEntity());
1052 res.releaseConnection();
1056 (PersonsCommon) extractPart(input,
1057 client.getItemCommonPartName(), PersonsCommon.class);
1058 Assert.assertNotNull(updatedPerson);
1060 // Verify that the updated resource received the correct data.
1061 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
1062 "Updated displayNameComputed in Person did not match submitted data.");
1063 // Verify that the updated resource computes the right displayName.
1064 Assert.assertEquals(updatedPerson.getDisplayName(),
1065 expectedDisplayName,
1066 "Updated DisplayName (not computed) in Person not stored.");
1067 // Verify that the updated resource received the correct data.
1068 Assert.assertEquals(updatedPerson.isShortDisplayNameComputed(), false,
1069 "Updated shortDisplayNameComputed in Person did not match submitted data.");
1070 // Verify that the updated resource computes the right displayName.
1071 Assert.assertEquals(updatedPerson.getShortDisplayName(),
1072 expectedDisplayName,
1073 "Updated ShortDisplayName (not computed) in Person not stored.");
1077 * Verify illegal item display name.
1079 * @param testName the test name
1080 * @throws Exception the exception
1082 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1083 groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"})
1084 public void verifyIllegalItemDisplayName(String testName) throws Exception {
1086 if (logger.isDebugEnabled()) {
1087 logger.debug(testBanner(testName, CLASS_NAME));
1090 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
1091 // setupUpdateWithWrongXmlSchema(testName);
1093 // Submit the request to the service and store the response.
1094 PersonAuthorityClient client = new PersonAuthorityClient();
1095 PoxPayloadIn input = null;
1096 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
1098 int statusCode = res.getStatus();
1100 // Check the status code of the response: does it match
1101 // the expected response(s)?
1102 if(logger.isDebugEnabled()){
1103 logger.debug(testName + ": status = " + statusCode);
1105 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1106 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1107 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
1109 // Check whether Person has expected displayName.
1110 input = new PoxPayloadIn(res.getEntity());
1112 res.releaseConnection();
1115 PersonsCommon person = (PersonsCommon) extractPart(input,
1116 client.getItemCommonPartName(), PersonsCommon.class);
1117 Assert.assertNotNull(person);
1118 // Try to Update with computed false and no displayName
1119 person.setDisplayNameComputed(false);
1120 person.setDisplayName(null);
1122 // Submit the updated resource to the service and store the response.
1123 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1124 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1125 commonPart.setLabel(client.getItemCommonPartName());
1126 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1128 int statusCode = res.getStatus();
1130 // Check the status code of the response: does it match the expected response(s)?
1131 if(logger.isDebugEnabled()){
1132 logger.debug("updateItem: status = " + statusCode);
1134 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1135 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1136 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1138 res.releaseConnection();
1145 * @param testName the test name
1146 * @throws Exception the exception
1148 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1149 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1150 public void readContact(String testName) throws Exception {
1152 if (logger.isDebugEnabled()) {
1153 logger.debug(testBanner(testName, CLASS_NAME));
1158 // Submit the request to the service and store the response.
1159 PersonAuthorityClient client = new PersonAuthorityClient();
1160 PoxPayloadIn input = null;
1161 ClientResponse<String> res =
1162 client.readContact(knownResourceId, knownItemResourceId,
1163 knownContactResourceId);
1165 int statusCode = res.getStatus();
1167 // Check the status code of the response: does it match
1168 // the expected response(s)?
1169 if(logger.isDebugEnabled()){
1170 logger.debug(testName + ": status = " + statusCode);
1172 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1173 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1174 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1176 // Check whether we've received a contact.
1177 input = new PoxPayloadIn(res.getEntity());
1179 res.releaseConnection();
1182 ContactsCommon contact = (ContactsCommon) extractPart(input,
1183 new ContactClient().getCommonPartName(), ContactsCommon.class);
1184 Assert.assertNotNull(contact);
1185 boolean showFull = true;
1186 if(showFull && logger.isDebugEnabled()){
1187 logger.debug(testName + ": returned payload:");
1188 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
1190 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
1191 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
1197 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
1200 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1201 groups = {"read"}, dependsOnMethods = {"read"})
1202 public void readNonExistent(String testName) {
1204 if (logger.isDebugEnabled()) {
1205 logger.debug(testBanner(testName, CLASS_NAME));
1208 setupReadNonExistent();
1210 // Submit the request to the service and store the response.
1211 PersonAuthorityClient client = new PersonAuthorityClient();
1212 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
1214 int statusCode = res.getStatus();
1215 // Check the status code of the response: does it match
1216 // the expected response(s)?
1217 if(logger.isDebugEnabled()){
1218 logger.debug(testName + ": status = " + statusCode);
1220 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1221 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1222 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1224 res.releaseConnection();
1229 * Read item non existent.
1231 * @param testName the test name
1233 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1234 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1235 public void readItemNonExistent(String testName) {
1237 if (logger.isDebugEnabled()) {
1238 logger.debug(testBanner(testName, CLASS_NAME));
1241 setupReadNonExistent();
1243 // Submit the request to the service and store the response.
1244 PersonAuthorityClient client = new PersonAuthorityClient();
1245 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1247 int statusCode = res.getStatus();
1249 // Check the status code of the response: does it match
1250 // the expected response(s)?
1251 if(logger.isDebugEnabled()){
1252 logger.debug(testName + ": status = " + statusCode);
1254 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1255 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1256 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1258 res.releaseConnection();
1263 * Read contact non existent.
1265 * @param testName the test name
1267 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1268 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1269 public void readContactNonExistent(String testName) {
1271 if (logger.isDebugEnabled()) {
1272 logger.debug(testBanner(testName, CLASS_NAME));
1275 setupReadNonExistent();
1277 // Submit the request to the service and store the response.
1278 PersonAuthorityClient client = new PersonAuthorityClient();
1279 ClientResponse<String> res =
1280 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1282 int statusCode = res.getStatus();
1284 // Check the status code of the response: does it match
1285 // the expected response(s)?
1286 if(logger.isDebugEnabled()){
1287 logger.debug(testName + ": status = " + statusCode);
1289 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1290 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1291 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1293 res.releaseConnection();
1297 // ---------------------------------------------------------------
1298 // CRUD tests : READ_LIST tests
1299 // ---------------------------------------------------------------
1303 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1306 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1307 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1308 public void readList(String testName) throws Exception {
1310 if (logger.isDebugEnabled()) {
1311 logger.debug(testBanner(testName, CLASS_NAME));
1316 // Submit the request to the service and store the response.
1317 PersonAuthorityClient client = new PersonAuthorityClient();
1318 PersonauthoritiesCommonList list = null;
1319 ClientResponse<PersonauthoritiesCommonList> res = client.readList();
1321 int statusCode = res.getStatus();
1323 // Check the status code of the response: does it match
1324 // the expected response(s)?
1325 if(logger.isDebugEnabled()){
1326 logger.debug(testName + ": status = " + statusCode);
1328 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1329 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1330 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1332 list = res.getEntity();
1334 res.releaseConnection();
1337 // Optionally output additional data about list members for debugging.
1338 boolean iterateThroughList = false;
1339 if (iterateThroughList && logger.isDebugEnabled()) {
1340 List<PersonauthoritiesCommonList.PersonauthorityListItem> items =
1341 list.getPersonauthorityListItem();
1343 for (PersonauthoritiesCommonList.PersonauthorityListItem item : items) {
1344 String csid = item.getCsid();
1345 logger.debug(testName + ": list-item[" + i + "] csid=" +
1347 logger.debug(testName + ": list-item[" + i + "] displayName=" +
1348 item.getDisplayName());
1349 logger.debug(testName + ": list-item[" + i + "] URI=" +
1351 readItemList(csid, null, testName);
1360 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1361 groups = {"readList"}, dependsOnMethods = {"readList"})
1362 public void readItemList(String testName) {
1363 readItemList(knownResourceId, null, testName);
1367 * Read item list by authority name.
1369 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1370 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1371 public void readItemListByAuthorityName(String testName) {
1372 readItemList(null, knownResourceShortIdentifer, testName);
1378 * @param vcsid the vcsid
1379 * @param name the name
1381 private void readItemList(String vcsid, String name, String testName) {
1386 // Submit the request to the service and store the response.
1387 PersonAuthorityClient client = new PersonAuthorityClient();
1388 ClientResponse<PersonsCommonList> res = null;
1390 res = client.readItemList(vcsid, null, null);
1391 } else if (name!= null) {
1392 res = client.readItemListForNamedAuthority(name, null, null);
1394 Assert.fail("readItemList passed null csid and name!");
1396 PersonsCommonList list = null;
1398 int statusCode = res.getStatus();
1400 // Check the status code of the response: does it match
1401 // the expected response(s)?
1402 if(logger.isDebugEnabled()){
1403 logger.debug(testName + ": status = " + statusCode);
1405 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1406 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1407 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1409 list = res.getEntity();
1411 res.releaseConnection();
1414 List<PersonsCommonList.PersonListItem> items =
1415 list.getPersonListItem();
1416 int nItemsReturned = items.size();
1417 // There will be one item created, associated with a
1418 // known parent resource, by the createItem test.
1420 // In addition, there will be 'nItemsToCreateInList'
1421 // additional items created by the createItemList test,
1422 // all associated with the same parent resource.
1423 int nExpectedItems = nItemsToCreateInList + 1;
1424 if(logger.isDebugEnabled()){
1425 logger.debug(testName + ": Expected "
1426 + nExpectedItems +" items; got: "+nItemsReturned);
1428 Assert.assertEquals(nItemsReturned, nExpectedItems);
1431 for (PersonsCommonList.PersonListItem item : items) {
1432 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
1433 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
1434 // Optionally output additional data about list members for debugging.
1435 boolean showDetails = true;
1436 if (showDetails && logger.isDebugEnabled()) {
1437 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1439 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
1441 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
1442 item.getDisplayName());
1443 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1451 * Read contact list.
1453 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1454 public void readContactList() {
1455 readContactList(knownResourceId, knownItemResourceId);
1459 * Read contact list.
1461 * @param parentcsid the parentcsid
1462 * @param itemcsid the itemcsid
1464 private void readContactList(String parentcsid, String itemcsid) {
1465 final String testName = "readContactList";
1470 // Submit the request to the service and store the response.
1471 PersonAuthorityClient client = new PersonAuthorityClient();
1472 ContactsCommonList list = null;
1473 ClientResponse<ContactsCommonList> res =
1474 client.readContactList(parentcsid, itemcsid);
1476 int statusCode = res.getStatus();
1478 // Check the status code of the response: does it match
1479 // the expected response(s)?
1480 if(logger.isDebugEnabled()){
1481 logger.debug(testName + ": status = " + statusCode);
1483 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1484 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1485 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1487 list = res.getEntity();
1489 res.releaseConnection();
1492 List<ContactsCommonList.ContactListItem> listitems =
1493 list.getContactListItem();
1494 int nItemsReturned = listitems.size();
1495 // There will be one item created, associated with a
1496 // known parent resource, by the createItem test.
1498 // In addition, there will be 'nItemsToCreateInList'
1499 // additional items created by the createItemList test,
1500 // all associated with the same parent resource.
1501 int nExpectedItems = nItemsToCreateInList + 1;
1502 if(logger.isDebugEnabled()){
1503 logger.debug(testName + ": Expected "
1504 + nExpectedItems +" items; got: "+nItemsReturned);
1506 Assert.assertEquals(nItemsReturned, nExpectedItems);
1509 for (ContactsCommonList.ContactListItem listitem : listitems) {
1510 // Optionally output additional data about list members for debugging.
1511 boolean showDetails = false;
1512 if (showDetails && logger.isDebugEnabled()) {
1513 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
1514 listitem.getCsid());
1515 logger.debug(" " + testName + ": list-item[" + i + "] addressPlace=" +
1516 listitem.getAddressPlace());
1517 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
1526 // There are no failure outcome tests at present.
1528 // ---------------------------------------------------------------
1529 // CRUD tests : UPDATE tests
1530 // ---------------------------------------------------------------
1533 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1536 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1537 groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
1538 public void update(String testName) throws Exception {
1540 if (logger.isDebugEnabled()) {
1541 logger.debug(testBanner(testName, CLASS_NAME));
1546 // Retrieve the contents of a resource to update.
1547 PersonAuthorityClient client = new PersonAuthorityClient();
1548 PoxPayloadIn input = null;
1549 ClientResponse<String> res = client.read(knownResourceId);
1551 if(logger.isDebugEnabled()){
1552 logger.debug(testName + ": read status = " + res.getStatus());
1554 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1556 if(logger.isDebugEnabled()){
1557 logger.debug("got PersonAuthority to update with ID: " + knownResourceId);
1559 input = new PoxPayloadIn(res.getEntity());
1561 res.releaseConnection();
1564 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1565 client.getCommonPartName(), PersonauthoritiesCommon.class);
1566 Assert.assertNotNull(personAuthority);
1568 // Update the contents of this resource.
1569 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1570 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1571 if(logger.isDebugEnabled()){
1572 logger.debug("to be updated PersonAuthority");
1573 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1576 // Submit the updated resource to the service and store the response.
1577 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
1578 PayloadOutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1579 commonPart.setLabel(client.getCommonPartName());
1580 res = client.update(knownResourceId, output);
1582 int statusCode = res.getStatus();
1584 // Check the status code of the response: does it match the expected response(s)?
1585 if(logger.isDebugEnabled()){
1586 logger.debug(testName + ": status = " + statusCode);
1588 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1589 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1590 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1592 // Retrieve the updated resource and verify that its contents exist.
1593 input = new PoxPayloadIn(res.getEntity());
1595 res.releaseConnection();
1598 PersonauthoritiesCommon updatedPersonAuthority =
1599 (PersonauthoritiesCommon) extractPart(input,
1600 client.getCommonPartName(), PersonauthoritiesCommon.class);
1601 Assert.assertNotNull(updatedPersonAuthority);
1603 // Verify that the updated resource received the correct data.
1604 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1605 personAuthority.getDisplayName(),
1606 "Data in updated object did not match submitted data.");
1612 * @param testName the test name
1613 * @throws Exception the exception
1615 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1616 groups = {"update"}, dependsOnMethods = {"update"})
1617 public void updateItem(String testName) throws Exception {
1619 if (logger.isDebugEnabled()) {
1620 logger.debug(testBanner(testName, CLASS_NAME));
1625 // Retrieve the contents of a resource to update.
1626 PersonAuthorityClient client = new PersonAuthorityClient();
1627 PoxPayloadIn input = null;
1628 ClientResponse<String> res =
1629 client.readItem(knownResourceId, knownItemResourceId);
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 Person to update with ID: " +
1638 knownItemResourceId +
1639 " in PersonAuthority: " + knownResourceId );
1641 input = new PoxPayloadIn(res.getEntity());
1643 res.releaseConnection();
1646 PersonsCommon person = (PersonsCommon) extractPart(input,
1647 client.getItemCommonPartName(), PersonsCommon.class);
1648 Assert.assertNotNull(person);
1650 if (logger.isDebugEnabled() == true) {
1651 logger.debug("About to update the following person...");
1652 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1655 // Update the contents of this resource.
1656 person.setCsid(null);
1657 person.setForeName("updated-" + person.getForeName());
1658 if(logger.isDebugEnabled()){
1659 logger.debug("to be updated Person");
1660 logger.debug(objectAsXmlString(person,
1661 PersonsCommon.class));
1664 // Submit the updated resource to the service and store the response.
1665 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1666 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1667 commonPart.setLabel(client.getItemCommonPartName());
1668 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1670 int statusCode = res.getStatus();
1672 // Check the status code of the response: does it match the expected response(s)?
1673 if(logger.isDebugEnabled()){
1674 logger.debug(testName + ": status = " + statusCode);
1676 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1677 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1678 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1680 // Retrieve the updated resource and verify that its contents exist.
1681 input = new PoxPayloadIn(res.getEntity());
1683 res.releaseConnection();
1686 PersonsCommon updatedPerson =
1687 (PersonsCommon) extractPart(input,
1688 client.getItemCommonPartName(), PersonsCommon.class);
1689 Assert.assertNotNull(updatedPerson);
1691 if (logger.isDebugEnabled() == true) {
1692 logger.debug("Updated to following person to:");
1693 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1696 // Verify that the updated resource received the correct data.
1697 Assert.assertEquals(updatedPerson.getForeName(),
1698 person.getForeName(),
1699 "Data in updated Person did not match submitted data.");
1705 * @param testName the test name
1706 * @throws Exception the exception
1708 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1709 groups = {"update"}, dependsOnMethods = {"updateItem"})
1710 public void updateContact(String testName) throws Exception {
1712 if (logger.isDebugEnabled()) {
1713 logger.debug(testBanner(testName, CLASS_NAME));
1718 // Retrieve the contents of a resource to update.
1719 PersonAuthorityClient client = new PersonAuthorityClient();
1720 PoxPayloadIn input = null;
1721 ClientResponse<String> res =
1722 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1724 if(logger.isDebugEnabled()){
1725 logger.debug(testName + ": read status = " + res.getStatus());
1727 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
1729 if(logger.isDebugEnabled()){
1730 logger.debug("got Contact to update with ID: " +
1731 knownContactResourceId +
1732 " in item: " + knownItemResourceId +
1733 " in parent: " + knownResourceId );
1735 input = new PoxPayloadIn(res.getEntity());
1737 res.releaseConnection();
1740 ContactsCommon contact = (ContactsCommon) extractPart(input,
1741 new ContactClient().getCommonPartName(), ContactsCommon.class);
1742 Assert.assertNotNull(contact);
1744 // Update the contents of this resource.
1745 contact.setAddressPlace("updated-" + contact.getAddressPlace());
1746 if(logger.isDebugEnabled()){
1747 logger.debug("to be updated Contact");
1748 logger.debug(objectAsXmlString(contact,
1749 ContactsCommon.class));
1752 // Submit the updated resource to the service and store the response.
1753 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1754 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); //FIXME: REM - Replace with output.addPart(contact, client.getCommonPartName())
1755 commonPart.setLabel(client.getCommonPartName());
1756 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1758 int statusCode = res.getStatus();
1760 // Check the status code of the response: does it match the expected response(s)?
1761 if(logger.isDebugEnabled()){
1762 logger.debug(testName + ": status = " + statusCode);
1764 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1765 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1766 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1768 // Retrieve the updated resource and verify that its contents exist.
1769 input = new PoxPayloadIn(res.getEntity());;
1771 res.releaseConnection();
1773 ContactsCommon updatedContact =
1774 (ContactsCommon) extractPart(input,
1775 new ContactClient().getCommonPartName(), ContactsCommon.class);
1776 Assert.assertNotNull(updatedContact);
1778 // Verify that the updated resource received the correct data.
1779 Assert.assertEquals(updatedContact.getAddressPlace(),
1780 contact.getAddressPlace(),
1781 "Data in updated Contact did not match submitted data.");
1785 // Placeholders until the three tests below can be uncommented.
1786 // See Issue CSPACE-401.
1788 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1791 public void updateWithEmptyEntityBody(String testName) throws Exception {
1792 //Should this really be empty?
1796 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1799 public void updateWithMalformedXml(String testName) throws Exception {
1800 //Should this really be empty?
1804 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1807 public void updateWithWrongXmlSchema(String testName) throws Exception {
1808 //Should this really be empty?
1811 /* //FIXME: REM - Can we kill all this dead code please?
1813 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1814 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1815 public void updateWithEmptyEntityBody(String testName) throws Exception {
1817 if (logger.isDebugEnabled()) {
1818 logger.debug(testBanner(testName, CLASS_NAME));
1821 setupUpdateWithEmptyEntityBody(testName, logger);
1823 // Submit the request to the service and store the response.
1824 String method = REQUEST_TYPE.httpMethodName();
1825 String url = getResourceURL(knownResourceId);
1826 String mediaType = MediaType.APPLICATION_XML;
1827 final String entity = "";
1828 int statusCode = submitRequest(method, url, mediaType, entity);
1830 // Check the status code of the response: does it match
1831 // the expected response(s)?
1832 if(logger.isDebugEnabled()){
1833 logger.debug(testName + ": url=" + url +
1834 " status=" + statusCode);
1836 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1837 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1838 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1842 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1843 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1844 public void updateWithMalformedXml(String testName) throws Exception {
1846 if (logger.isDebugEnabled()) {
1847 logger.debug(testBanner(testName, CLASS_NAME));
1850 setupUpdateWithMalformedXml();
1852 // Submit the request to the service and store the response.
1853 String method = REQUEST_TYPE.httpMethodName();
1854 String url = getResourceURL(knownResourceId);
1855 String mediaType = MediaType.APPLICATION_XML;
1856 final String entity = MALFORMED_XML_DATA;
1857 int statusCode = submitRequest(method, url, mediaType, entity);
1859 // Check the status code of the response: does it match
1860 // the expected response(s)?
1861 if(logger.isDebugEnabled()){
1862 logger.debug(testName + ": url=" + url +
1863 " status=" + statusCode);
1865 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1866 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1867 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1871 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1872 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1873 public void updateWithWrongXmlSchema(String testName) throws Exception {
1875 if (logger.isDebugEnabled()) {
1876 logger.debug(testBanner(testName, CLASS_NAME));
1879 setupUpdateWithWrongXmlSchema();
1881 // Submit the request to the service and store the response.
1882 String method = REQUEST_TYPE.httpMethodName();
1883 String url = getResourceURL(knownResourceId);
1884 String mediaType = MediaType.APPLICATION_XML;
1885 final String entity = WRONG_XML_SCHEMA_DATA;
1886 int statusCode = submitRequest(method, url, mediaType, entity);
1888 // Check the status code of the response: does it match
1889 // the expected response(s)?
1890 if(logger.isDebugEnabled()){
1891 logger.debug("updateWithWrongXmlSchema: url=" + url +
1892 " status=" + statusCode);
1894 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1895 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1896 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1901 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1904 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1905 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1906 public void updateNonExistent(String testName) throws Exception {
1908 if (logger.isDebugEnabled()) {
1909 logger.debug(testBanner(testName, CLASS_NAME));
1912 setupUpdateNonExistent();
1914 // Submit the request to the service and store the response.
1915 // Note: The ID(s) used when creating the request payload may be arbitrary.
1916 // The only relevant ID may be the one used in update(), below.
1917 PersonAuthorityClient client = new PersonAuthorityClient();
1918 String displayName = "displayName-NON_EXISTENT_ID";
1919 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1920 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1921 ClientResponse<String> res =
1922 client.update(NON_EXISTENT_ID, multipart);
1924 int statusCode = res.getStatus();
1926 // Check the status code of the response: does it match
1927 // the expected response(s)?
1928 if(logger.isDebugEnabled()){
1929 logger.debug(testName + ": status = " + statusCode);
1931 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1932 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1933 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1935 res.releaseConnection();
1940 * Update non existent item.
1942 * @param testName the test name
1943 * @throws Exception the exception
1945 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1946 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1947 public void updateNonExistentItem(String testName) throws Exception {
1949 if (logger.isDebugEnabled()) {
1950 logger.debug(testBanner(testName, CLASS_NAME));
1953 setupUpdateNonExistent();
1955 // Submit the request to the service and store the response.
1956 // Note: The ID used in this 'create' call may be arbitrary.
1957 // The only relevant ID may be the one used in update(), below.
1958 PersonAuthorityClient client = new PersonAuthorityClient();
1959 Map<String, String> nonexMap = new HashMap<String,String>();
1960 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1961 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1962 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1963 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1964 Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1965 PoxPayloadOut multipart =
1966 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1967 PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1968 nonexMap, nonexRepeatablesMap, client.getItemCommonPartName() );
1969 ClientResponse<String> res =
1970 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1972 int statusCode = res.getStatus();
1974 // Check the status code of the response: does it match
1975 // the expected response(s)?
1976 if(logger.isDebugEnabled()){
1977 logger.debug(testName + ": status = " + statusCode);
1979 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1980 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1981 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1983 res.releaseConnection();
1988 * Update non existent contact.
1990 * @param testName the test name
1991 * @throws Exception the exception
1993 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1994 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1995 public void updateNonExistentContact(String testName) throws Exception {
1996 // Currently a no-op test
1999 // ---------------------------------------------------------------
2000 // CRUD tests : DELETE tests
2001 // ---------------------------------------------------------------
2004 // Note: delete sub-resources in ascending hierarchical order,
2005 // before deleting their parents.
2010 * @param testName the test name
2011 * @throws Exception the exception
2013 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2014 groups = {"delete"}, dependsOnGroups = {"update"})
2015 public void deleteContact(String testName) throws Exception {
2017 if (logger.isDebugEnabled()) {
2018 logger.debug(testBanner(testName, CLASS_NAME));
2023 if(logger.isDebugEnabled()){
2024 logger.debug("parentcsid =" + knownResourceId +
2025 " itemcsid = " + knownItemResourceId +
2026 " csid = " + knownContactResourceId);
2029 // Submit the request to the service and store the response.
2030 PersonAuthorityClient client = new PersonAuthorityClient();
2031 ClientResponse<Response> res =
2032 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
2034 int statusCode = res.getStatus();
2036 // Check the status code of the response: does it match
2037 // the expected response(s)?
2038 if(logger.isDebugEnabled()){
2039 logger.debug(testName + ": status = " + statusCode);
2041 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2042 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2043 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2045 res.releaseConnection();
2052 * @param testName the test name
2053 * @throws Exception the exception
2055 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2056 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2057 public void deleteItem(String testName) throws Exception {
2059 if (logger.isDebugEnabled()) {
2060 logger.debug(testBanner(testName, CLASS_NAME));
2065 if(logger.isDebugEnabled()){
2066 logger.debug("parentcsid =" + knownResourceId +
2067 " itemcsid = " + knownItemResourceId);
2070 // Submit the request to the service and store the response.
2071 PersonAuthorityClient client = new PersonAuthorityClient();
2072 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
2074 int statusCode = res.getStatus();
2076 // Check the status code of the response: does it match
2077 // the expected response(s)?
2078 if(logger.isDebugEnabled()){
2079 logger.debug(testName + ": status = " + statusCode);
2081 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2082 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2083 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2085 res.releaseConnection();
2090 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
2093 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2094 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2095 public void delete(String testName) throws Exception {
2097 if (logger.isDebugEnabled()) {
2098 logger.debug(testBanner(testName, CLASS_NAME));
2103 if(logger.isDebugEnabled()){
2104 logger.debug("parentcsid =" + knownResourceId);
2107 // Submit the request to the service and store the response.
2108 PersonAuthorityClient client = new PersonAuthorityClient();
2109 ClientResponse<Response> res = client.delete(knownResourceId);
2111 int statusCode = res.getStatus();
2113 // Check the status code of the response: does it match
2114 // the expected response(s)?
2115 if(logger.isDebugEnabled()){
2116 logger.debug(testName + ": status = " + statusCode);
2118 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2119 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2120 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2122 res.releaseConnection();
2128 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
2131 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2132 groups = {"delete"}, dependsOnMethods = {"delete"})
2133 public void deleteNonExistent(String testName) throws Exception {
2135 if (logger.isDebugEnabled()) {
2136 logger.debug(testBanner(testName, CLASS_NAME));
2139 setupDeleteNonExistent();
2141 // Submit the request to the service and store the response.
2142 PersonAuthorityClient client = new PersonAuthorityClient();
2143 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
2145 int statusCode = res.getStatus();
2147 // Check the status code of the response: does it match
2148 // the expected response(s)?
2149 if(logger.isDebugEnabled()){
2150 logger.debug(testName + ": status = " + statusCode);
2152 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2153 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2154 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2156 res.releaseConnection();
2161 * Delete non existent item.
2163 * @param testName the test name
2165 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2166 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
2167 public void deleteNonExistentItem(String testName) {
2169 if (logger.isDebugEnabled()) {
2170 logger.debug(testBanner(testName, CLASS_NAME));
2173 setupDeleteNonExistent();
2175 // Submit the request to the service and store the response.
2176 PersonAuthorityClient client = new PersonAuthorityClient();
2177 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
2179 int statusCode = res.getStatus();
2181 // Check the status code of the response: does it match
2182 // the expected response(s)?
2183 if(logger.isDebugEnabled()){
2184 logger.debug(testName + ": status = " + statusCode);
2186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2190 res.releaseConnection();
2195 * Delete non existent contact.
2197 * @param testName the test name
2199 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
2200 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2201 public void deleteNonExistentContact(String testName) {
2203 if (logger.isDebugEnabled()) {
2204 logger.debug(testBanner(testName, CLASS_NAME));
2207 setupDeleteNonExistent();
2209 // Submit the request to the service and store the response.
2210 PersonAuthorityClient client = new PersonAuthorityClient();
2211 ClientResponse<Response> res =
2212 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2214 int statusCode = res.getStatus();
2216 // Check the status code of the response: does it match
2217 // the expected response(s)?
2218 if(logger.isDebugEnabled()){
2219 logger.debug(testName + ": status = " + statusCode);
2221 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2222 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2223 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2225 res.releaseConnection();
2229 // ---------------------------------------------------------------
2230 // Utility tests : tests of code used in tests above
2231 // ---------------------------------------------------------------
2233 * Tests the code for manually submitting data that is used by several
2234 * of the methods above.
2236 @Test(dependsOnMethods = {"create", "read"})
2237 public void testSubmitRequest() {
2239 // Expected status code: 200 OK
2240 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2242 // Submit the request to the service and store the response.
2243 String method = ServiceRequestType.READ.httpMethodName();
2244 String url = getResourceURL(knownResourceId);
2245 int statusCode = submitRequest(method, url);
2247 // Check the status code of the response: does it match
2248 // the expected response(s)?
2249 if(logger.isDebugEnabled()){
2250 logger.debug("testSubmitRequest: url=" + url +
2251 " status=" + statusCode);
2253 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2258 * Test item submit request.
2260 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2261 public void testItemSubmitRequest() {
2263 // Expected status code: 200 OK
2264 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2266 // Submit the request to the service and store the response.
2267 String method = ServiceRequestType.READ.httpMethodName();
2268 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2269 int statusCode = submitRequest(method, url);
2271 // Check the status code of the response: does it match
2272 // the expected response(s)?
2273 if(logger.isDebugEnabled()){
2274 logger.debug("testItemSubmitRequest: url=" + url +
2275 " status=" + statusCode);
2277 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2282 * Test contact submit request.
2284 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2285 public void testContactSubmitRequest() {
2287 // Expected status code: 200 OK
2288 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2290 // Submit the request to the service and store the response.
2291 String method = ServiceRequestType.READ.httpMethodName();
2292 String url = getContactResourceURL(knownResourceId,
2293 knownItemResourceId, knownContactResourceId);
2294 int statusCode = submitRequest(method, url);
2296 // Check the status code of the response: does it match
2297 // the expected response(s)?
2298 if(logger.isDebugEnabled()){
2299 logger.debug("testItemSubmitRequest: url=" + url +
2300 " status=" + statusCode);
2302 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2307 // ---------------------------------------------------------------
2308 // Cleanup of resources created during testing
2309 // ---------------------------------------------------------------
2312 * Deletes all resources created by tests, after all tests have been run.
2314 * This cleanup method will always be run, even if one or more tests fail.
2315 * For this reason, it attempts to remove all resources created
2316 * at any point during testing, even if some of those resources
2317 * may be expected to be deleted by certain tests.
2320 @AfterClass(alwaysRun=true)
2322 public void cleanUp() {
2323 String noTest = System.getProperty("noTestCleanup");
2324 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2325 if (logger.isDebugEnabled()) {
2326 logger.debug("Skipping Cleanup phase ...");
2330 if (logger.isDebugEnabled()) {
2331 logger.debug("Cleaning up temporary resources created for testing ...");
2333 String parentResourceId;
2334 String itemResourceId;
2335 String contactResourceId;
2336 // Clean up contact resources.
2337 PersonAuthorityClient client = new PersonAuthorityClient();
2338 parentResourceId = knownResourceId;
2339 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2340 contactResourceId = entry.getKey();
2341 itemResourceId = entry.getValue();
2342 // Note: Any non-success responses from the delete operation
2343 // below are ignored and not reported.
2344 ClientResponse<Response> res =
2345 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2346 res.releaseConnection();
2348 // Clean up item resources.
2349 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2350 itemResourceId = entry.getKey();
2351 parentResourceId = entry.getValue();
2352 // Note: Any non-success responses from the delete operation
2353 // below are ignored and not reported.
2354 ClientResponse<Response> res =
2355 client.deleteItem(parentResourceId, itemResourceId);
2356 res.releaseConnection();
2358 // Clean up parent resources.
2362 // ---------------------------------------------------------------
2363 // Utility methods used by tests above
2364 // ---------------------------------------------------------------
2366 * Gets the contact service path component.
2368 * @return the contact service path component
2370 public String getContactServicePathComponent() {
2371 return ContactClient.SERVICE_PATH_COMPONENT;
2375 * Returns the root URL for the item service.
2377 * This URL consists of a base URL for all services, followed by
2378 * a path component for the owning parent, followed by the
2379 * path component for the items.
2381 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2382 * parent authority resource of the relevant item resource.
2384 * @return The root URL for the item service.
2386 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2387 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2391 * Returns the URL of a specific item resource managed by a service, and
2392 * designated by an identifier (such as a universally unique ID, or UUID).
2394 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2395 * parent authority resource of the relevant item resource.
2397 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2400 * @return The URL of a specific item resource managed by a service.
2402 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2403 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2408 * Returns the root URL for the contact service.
2410 * This URL consists of a base URL for all services, followed by
2411 * a path component for the owning authority, followed by the
2412 * path component for the owning item, followed by the path component
2413 * for the contact service.
2415 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2416 * parent authority resource of the relevant item resource.
2418 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2421 * @return The root URL for the contact service.
2423 protected String getContactServiceRootURL(String parentResourceIdentifier,
2424 String itemResourceIdentifier) {
2425 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/" +
2426 getContactServicePathComponent();
2430 * Returns the URL of a specific contact resource managed by a service, and
2431 * designated by an identifier (such as a universally unique ID, or UUID).
2433 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2434 * parent resource of the relevant item resource.
2436 * @param resourceIdentifier An identifier (such as a UUID) for an
2439 * @return The URL of a specific resource managed by a service.
2441 protected String getContactResourceURL(String parentResourceIdentifier,
2442 String itemResourceIdentifier, String contactResourceIdentifier) {
2443 return getContactServiceRootURL(parentResourceIdentifier,
2444 itemResourceIdentifier) + "/" + contactResourceIdentifier;