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;
38 import org.collectionspace.services.client.ContactClient;
39 import org.collectionspace.services.client.ContactClientUtils;
40 import org.collectionspace.services.common.AbstractCommonListUtils;
41 import org.collectionspace.services.contact.AddressGroup;
42 import org.collectionspace.services.contact.AddressGroupList;
43 import org.collectionspace.services.contact.ContactsCommon;
45 import org.collectionspace.services.client.PersonAuthorityClient;
46 import org.collectionspace.services.client.PersonAuthorityClientUtils;
47 import org.collectionspace.services.jaxb.AbstractCommonList;
48 import org.collectionspace.services.PersonJAXBSchema;
49 import org.collectionspace.services.person.PersonauthoritiesCommon;
50 import org.collectionspace.services.person.PersonsCommon;
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);
72 private final String REFNAME = "refName";
73 private final String DISPLAYNAME = "displayName";
76 public String getServicePathComponent() {
77 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
81 protected String getServiceName() {
82 return PersonAuthorityClient.SERVICE_NAME;
85 public String getItemServicePathComponent() {
86 return AuthorityClient.ITEMS;
88 /** The test forename. */
89 final String TEST_FORE_NAME = "John";
90 /** The test middle name. */
91 final String TEST_MIDDLE_NAME = null;
92 /** The test surname. */
93 final String TEST_SUR_NAME = "Wayne";
94 /** The test birthdate. */
95 final String TEST_BIRTH_DATE = "May 26, 1907";
96 /** The test death date. */
97 final String TEST_DEATH_DATE = "June 11, 1979";
98 // Hold some values for a recently created item to verify upon read.
99 private String knownResourceId = null;
100 private String knownResourceShortIdentifer = null;
101 //private String knownResourceRefName = null;
102 private String knownItemResourceId = null;
103 private String knownItemResourceShortIdentifer = null;
104 // The resource ID of an item resource used for partial term matching tests.
105 private String knownItemPartialTermResourceId = null;
106 /** The known contact resource id. */
107 private String knownContactResourceId = null;
108 /** The n items to create in list. */
109 private int nItemsToCreateInList = 3;
110 /** The all item resource ids created. */
111 private Map<String, String> allItemResourceIdsCreated =
112 new HashMap<String, String>();
113 /** The all contact resource ids created. */
114 private Map<String, String> allContactResourceIdsCreated =
115 new HashMap<String, String>();
117 protected void setKnownResource(String id, String shortIdentifer,
119 knownResourceId = id;
120 knownResourceShortIdentifer = shortIdentifer;
121 //knownResourceRefName = refName;
124 protected void setKnownItemResource(String id, String shortIdentifer) {
125 knownItemResourceId = id;
126 knownItemResourceShortIdentifer = shortIdentifer;
130 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
133 protected CollectionSpaceClient getClientInstance() {
134 return new PersonAuthorityClient();
137 // ---------------------------------------------------------------
138 // CRUD tests : CREATE tests
139 // ---------------------------------------------------------------
142 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
145 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
147 public void create(String testName) throws Exception {
149 if (logger.isDebugEnabled()) {
150 logger.debug(testBanner(testName, CLASS_NAME));
152 // Perform setup, such as initializing the type of service request
153 // (e.g. CREATE, DELETE), its valid and expected status codes, and
154 // its associated HTTP method name (e.g. POST, DELETE).
157 // Submit the request to the service and store the response.
158 PersonAuthorityClient client = new PersonAuthorityClient();
159 String shortId = createIdentifier();
160 String displayName = "displayName-" + shortId;
161 //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
162 PoxPayloadOut multipart =
163 PersonAuthorityClientUtils.createPersonAuthorityInstance(
164 displayName, shortId, client.getCommonPartName());
167 ClientResponse<Response> res = client.create(multipart);
169 int statusCode = res.getStatus();
171 // Check the status code of the response: does it match
172 // the expected response(s)?
175 // Does it fall within the set of valid status codes?
176 // Does it exactly match the expected status code?
177 if (logger.isDebugEnabled()) {
178 logger.debug(testName + ": status = " + statusCode);
180 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
181 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
182 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
184 newID = PersonAuthorityClientUtils.extractId(res);
186 res.releaseConnection();
188 // Save values for additional tests
189 if (knownResourceId == null) {
190 setKnownResource(newID, shortId, null ); //baseRefName);
191 if (logger.isDebugEnabled()) {
192 logger.debug(testName + ": knownResourceId=" + knownResourceId);
195 // Store the IDs from every resource created by tests,
196 // so they can be deleted after tests have been run.
197 allResourceIdsCreated.add(newID);
201 protected PoxPayloadOut createInstance(String identifier) {
202 PersonAuthorityClient client = new PersonAuthorityClient();
203 String displayName = "displayName-" + identifier;
204 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
205 displayName, identifier, client.getCommonPartName());
210 protected PoxPayloadOut createItemInstance(String parentCsid, String identifier) {
211 String headerLabel = new PersonAuthorityClient().getItemCommonPartName();
212 HashMap<String, String> personInfo = new HashMap<String, String>();
213 String shortId = "johnWayneTempActor";
214 personInfo.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
215 personInfo.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne Temp");
216 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
217 personInfo.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayneTemp");
218 personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
220 return PersonAuthorityClientUtils.createPersonInstance(parentCsid, identifier, personInfo, headerLabel);
226 * @param testName the test name
228 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
229 groups = {"create"}, dependsOnMethods = {"create"})
230 public void createItem(String testName) {
231 if (logger.isDebugEnabled()) {
232 logger.debug(testBanner(testName, CLASS_NAME));
235 String newID = createItemInAuthority(knownResourceId, null ); //knownResourceRefName);
239 * Creates the item with an empty short identifier.
241 * @param testName the test name
244 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
245 groups = {"create"}, dependsOnMethods = {"create"})
246 public void createItemWithEmptyShortId(String testName) {
247 if (logger.isDebugEnabled()) {
248 logger.debug(testBanner(testName, CLASS_NAME));
252 // Fill the property map
254 Map<String, String> fieldProperties = new HashMap<String,String>();
255 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
256 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck");
257 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
258 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck");
260 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
261 String newID = createItemInAuthority(knownResourceId, knownResourceRefName,
262 shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES);
263 allResourceIdsCreated.add(newID);
267 * Creates an item in an authority, using test data.
269 * @param vcsid the vcsid
270 * @param authRefName the auth ref name
273 private String createItemInAuthority(String vcsid, String authRefName) {
275 final String testName = "createItemInAuthority";
276 if (logger.isDebugEnabled()) {
277 logger.debug(testName + ":" + vcsid + "...");
280 Map<String, String> johnWayneMap = new HashMap<String, String>();
282 // Fill the property map
284 String shortId = "johnWayneActor";
285 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
286 johnWayneMap.put(PersonJAXBSchema.DISPLAY_NAME, "John Wayne");
287 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
288 johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayne");
289 johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
291 johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
292 johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
293 johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
294 johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, TEST_BIRTH_DATE);
295 johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
296 johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, TEST_DEATH_DATE);
297 johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better"
298 + "known by his stage name John Wayne, was an American film actor, director "
299 + "and producer. He epitomized rugged masculinity and has become an enduring "
300 + "American icon. He is famous for his distinctive voice, walk and height. "
301 + "He was also known for his conservative political views and his support in "
302 + "the 1950s for anti-communist positions.");
304 Map<String, List<String>> johnWayneRepeatablesMap = new HashMap<String, List<String>>();
305 List<String> johnWayneGroups = new ArrayList<String>();
306 johnWayneGroups.add("Irish");
307 johnWayneGroups.add("Scottish");
308 johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
310 return createItemInAuthority(vcsid, null /*authRefName*/, shortId, johnWayneMap, johnWayneRepeatablesMap);
315 * Creates an item in an authority.
317 * @param vcsid the vcsid
318 * @param authRefName the auth ref name
319 * @param itemFieldProperties a set of properties specifying the values of fields.
320 * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
323 private String createItemInAuthority(String vcsid, String authRefName, String shortId,
324 Map itemFieldProperties, Map itemRepeatableFieldProperties) {
326 final String testName = "createItemInAuthority";
327 if (logger.isDebugEnabled()) {
328 logger.debug(testName + ":" + vcsid + "...");
331 // Submit the request to the service and store the response.
332 PersonAuthorityClient client = new PersonAuthorityClient();
334 PoxPayloadOut multipart =
335 PersonAuthorityClientUtils.createPersonInstance(vcsid, null /*authRefName*/, itemFieldProperties,
336 itemRepeatableFieldProperties, client.getItemCommonPartName());
339 ClientResponse<Response> res = client.createItem(vcsid, multipart);
341 int statusCode = res.getStatus();
342 // Check the status code of the response: does it match
343 // the expected response(s)?
344 if (logger.isDebugEnabled()) {
345 logger.debug(testName + ": status = " + statusCode);
347 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
348 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
349 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
351 newID = PersonAuthorityClientUtils.extractId(res);
353 res.releaseConnection();
356 // Store the ID returned from the first item resource created
357 // for additional tests below.
358 if (knownItemResourceId == null) {
359 setKnownItemResource(newID, shortId);
360 if (logger.isDebugEnabled()) {
361 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
364 if (logger.isDebugEnabled()) {
365 logger.debug(testName + " (created):" + vcsid + "/(" + newID + "," + shortId + ")");
368 // Store the IDs from any item resources created
369 // by tests, along with the IDs of their parents, so these items
370 // can be deleted after all tests have been run.
371 allItemResourceIdsCreated.put(newID, vcsid);
377 * Creates the contact.
379 * @param testName the test name
381 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
382 groups = {"create"}, dependsOnMethods = {"createItem"})
383 public void createContact(String testName) {
384 if (logger.isDebugEnabled()) {
385 logger.debug(testBanner(testName, CLASS_NAME));
388 String newID = createContactInItem(knownResourceId, knownItemResourceId);
392 * Creates the contact in item.
394 * @param parentcsid the parentcsid
395 * @param itemcsid the itemcsid
398 private String createContactInItem(String parentcsid, String itemcsid) {
400 final String testName = "createContactInItem";
401 if (logger.isDebugEnabled()) {
402 logger.debug(testName + ":...");
407 // Submit the request to the service and store the response.
408 PersonAuthorityClient client = new PersonAuthorityClient();
409 String identifier = createIdentifier();
410 PoxPayloadOut multipart = ContactClientUtils.createContactInstance(parentcsid,
411 itemcsid, identifier, new ContactClient().getCommonPartName());
414 ClientResponse<Response> res =
415 client.createContact(parentcsid, itemcsid, multipart);
417 int statusCode = res.getStatus();
418 // Check the status code of the response: does it match
419 // the expected response(s)?
420 if (logger.isDebugEnabled()) {
421 logger.debug(testName + ": status = " + statusCode);
423 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
424 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
425 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
427 newID = PersonAuthorityClientUtils.extractId(res);
429 res.releaseConnection();
432 // Store the ID returned from the first contact resource created
433 // for additional tests below.
434 if (knownContactResourceId == null) {
435 knownContactResourceId = newID;
436 if (logger.isDebugEnabled()) {
437 logger.debug(testName + ": knownContactResourceId=" + knownContactResourceId);
441 // Store the IDs from any contact resources created
442 // by tests, along with the IDs of their parent items,
443 // so these items can be deleted after all tests have been run.
444 allContactResourceIdsCreated.put(newID, itemcsid);
450 // Placeholders until the three tests below can be uncommented.
451 // See Issue CSPACE-401.
453 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
456 public void createWithEmptyEntityBody(String testName) throws Exception {
457 //Should this really be empty?
461 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
464 public void createWithMalformedXml(String testName) throws Exception {
465 //Should this really be empty?
469 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
472 public void createWithWrongXmlSchema(String testName) throws Exception {
473 //Should this really be empty?
478 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
479 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
480 public void createWithEmptyEntityBody(String testName) throws Exception {
482 if (logger.isDebugEnabled()) {
483 logger.debug(testBanner(testName, CLASS_NAME));
486 setupCreateWithEmptyEntityBody();
488 // Submit the request to the service and store the response.
489 String method = REQUEST_TYPE.httpMethodName();
490 String url = getServiceRootURL();
491 String mediaType = MediaType.APPLICATION_XML;
492 final String entity = "";
493 int statusCode = submitRequest(method, url, mediaType, entity);
495 // Check the status code of the response: does it match
496 // the expected response(s)?
497 if(logger.isDebugEnabled()) {
498 logger.debug(testName + ": url=" + url +
499 " status=" + statusCode);
501 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
502 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
503 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
507 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
508 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
509 public void createWithMalformedXml(String testName) throws Exception {
511 if (logger.isDebugEnabled()) {
512 logger.debug(testBanner(testName, CLASS_NAME));
515 setupCreateWithMalformedXml();
517 // Submit the request to the service and store the response.
518 String method = REQUEST_TYPE.httpMethodName();
519 String url = getServiceRootURL();
520 String mediaType = MediaType.APPLICATION_XML;
521 final String entity = MALFORMED_XML_DATA; // Constant from base class.
522 int statusCode = submitRequest(method, url, mediaType, entity);
524 // Check the status code of the response: does it match
525 // the expected response(s)?
526 if(logger.isDebugEnabled()){
527 logger.debug(testName + ": url=" + url +
528 " status=" + statusCode);
530 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
531 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
532 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
536 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
537 groups = {"create"}, dependsOnMethods = {"create", "testSubmitRequest"})
538 public void createWithWrongXmlSchema(String testName) throws Exception {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
544 setupCreateWithWrongXmlSchema();
546 // Submit the request to the service and store the response.
547 String method = REQUEST_TYPE.httpMethodName();
548 String url = getServiceRootURL();
549 String mediaType = MediaType.APPLICATION_XML;
550 final String entity = WRONG_XML_SCHEMA_DATA;
551 int statusCode = submitRequest(method, url, mediaType, entity);
553 // Check the status code of the response: does it match
554 // the expected response(s)?
555 if(logger.isDebugEnabled()){
556 logger.debug(testName + ": url=" + url +
557 " status=" + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565 * Attempts to create an authority with an short identifier that contains
566 * non-word characters.
568 * @param testName the test name
570 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
571 groups = {"create", "nonWordCharsInShortId"})
572 public void createWithShortIdNonWordChars(String testName) throws Exception {
573 if (logger.isDebugEnabled()) {
574 logger.debug(testBanner(testName, CLASS_NAME));
576 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
577 REQUEST_TYPE = ServiceRequestType.CREATE;
578 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
580 // Create the payload to be included in the body of the request
581 PersonAuthorityClient client = new PersonAuthorityClient();
582 String shortId = createIdentifier() + "*" + createIdentifier();
583 String displayName = "displayName-" + shortId;
584 PoxPayloadOut multipart =
585 PersonAuthorityClientUtils.createPersonAuthorityInstance(
586 displayName, shortId, client.getCommonPartName());
588 // Submit the request to the service and store the response.
589 ClientResponse<Response> res = client.create(multipart);
591 // Check the status code of the response: does it match
592 // the expected response(s)?
594 int statusCode = res.getStatus();
595 if (logger.isDebugEnabled()) {
596 logger.debug(testName + ": status = " + statusCode);
598 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
599 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
600 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
602 res.releaseConnection();
608 * Attempts to create an item with an short identifier that contains
609 * non-word characters.
611 * @param testName the test name
613 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
614 groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"})
615 public void createItemWithShortIdNonWordChars(String testName) {
616 if (logger.isDebugEnabled()) {
617 logger.debug(testBanner(testName, CLASS_NAME));
619 EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
620 REQUEST_TYPE = ServiceRequestType.CREATE;
621 testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
623 PersonAuthorityClient client = new PersonAuthorityClient();
625 // Create the payload to be included in the body of the request
626 String shortId = "7-Eleven";
627 Map<String, String> fieldProperties = new HashMap<String, String>();
628 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
629 fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, shortId);
630 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
631 fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, shortId);
632 fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
633 final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
634 PoxPayloadOut multipart =
635 PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
636 null /*knownResourceRefName*/, fieldProperties,
637 NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
639 // Send the request and receive a response
640 ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
642 // Check the status code of the response: does it match
643 // the expected response(s)?
645 int statusCode = res.getStatus();
646 // Check the status code of the response: does it match
647 // the expected response(s)?
648 if (logger.isDebugEnabled()) {
649 logger.debug(testName + ": status = " + statusCode);
651 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
655 res.releaseConnection();
660 // ---------------------------------------------------------------
661 // CRUD tests : CREATE LIST tests
662 // ---------------------------------------------------------------
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
668 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
669 groups = {"createList"}, dependsOnGroups = {"create"})
670 public void createList(String testName) throws Exception {
671 if (logger.isDebugEnabled()) {
672 logger.debug(testBanner(testName, CLASS_NAME));
674 for (int i = 0; i < nItemsToCreateInList; i++) {
680 * Creates the item list.
682 * @param testName the test name
683 * @throws Exception the exception
685 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
686 groups = {"createList"}, dependsOnMethods = {"createList"})
687 public void createItemList(String testName) throws Exception {
688 if (logger.isDebugEnabled()) {
689 logger.debug(testBanner(testName, CLASS_NAME));
691 // Add items to the initially-created, known parent record.
692 for (int j = 0; j < nItemsToCreateInList; j++) {
693 createItem(testName);
698 * Creates the contact list.
700 * @param testName the test name
701 * @throws Exception the exception
703 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
704 groups = {"createList"}, dependsOnMethods = {"createItemList"})
705 public void createContactList(String testName) throws Exception {
706 // Add contacts to the initially-created, known item record.
707 for (int j = 0; j < nItemsToCreateInList; j++) {
708 createContact(testName);
712 // ---------------------------------------------------------------
713 // CRUD tests : READ tests
714 // ---------------------------------------------------------------
717 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
720 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
721 groups = {"read"}, dependsOnGroups = {"create"})
722 public void read(String testName) throws Exception {
723 readInternal(testName, knownResourceId, null);
729 * @param testName the test name
730 * @throws Exception the exception
732 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
733 groups = {"read"}, dependsOnMethods = {"read"})
734 public void readByName(String testName) throws Exception {
735 readInternal(testName, null, knownResourceShortIdentifer);
738 protected void readInternal(String testName, String CSID, String shortId) {
739 if (logger.isDebugEnabled()) {
740 logger.debug(testBanner(testName, CLASS_NAME));
745 // Submit the request to the service and store the response.
746 PersonAuthorityClient client = new PersonAuthorityClient();
747 ClientResponse<String> res = null;
749 res = client.read(CSID);
750 } else if (shortId != null) {
751 res = client.readByName(shortId);
753 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
755 assertStatusCode(res, testName);
757 //FIXME: remove the following try catch once Aron fixes signatures
759 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
760 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
761 client.getCommonPartName(), PersonauthoritiesCommon.class);
762 Assert.assertNotNull(personAuthority);
763 } catch (Exception e) {
764 throw new RuntimeException(e);
767 res.releaseConnection();
774 * @param testName the test name
775 * @throws Exception the exception
777 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
778 groups = {"readItem"}, dependsOnGroups = {"read"})
779 public void readItem(String testName) throws Exception {
780 readItemInternal(testName, knownResourceId, null, knownItemResourceId, null);
784 * Read item in Named Auth.
786 * @param testName the test name
787 * @throws Exception the exception
789 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
790 groups = {"readItem"}, dependsOnMethods = {"readItem"})
791 public void readItemInNamedAuth(String testName) throws Exception {
792 readItemInternal(testName, null, knownResourceShortIdentifer, knownItemResourceId, null);
798 * @param testName the test name
799 * @throws Exception the exception
801 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
802 groups = {"readItem"}, dependsOnMethods = {"readItem"})
803 public void readNamedItem(String testName) throws Exception {
804 readItemInternal(testName, knownResourceId, null, null, knownItemResourceShortIdentifer);
808 * Read Named item in Named Auth.
810 * @param testName the test name
811 * @throws Exception the exception
813 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
814 groups = {"readItem"}, dependsOnMethods = {"readItem"})
815 public void readNamedItemInNamedAuth(String testName) throws Exception {
816 readItemInternal(testName, null, knownResourceShortIdentifer, null, knownItemResourceShortIdentifer);
819 protected void readItemInternal(String testName,
820 String authCSID, String authShortId, String itemCSID, String itemShortId)
823 if (logger.isDebugEnabled()) {
824 logger.debug(testBanner(testName, CLASS_NAME));
825 logger.debug("Reading:" + ((authCSID != null) ? authCSID : authShortId) + "/"
826 + ((itemCSID != null) ? authCSID : itemShortId));
831 // Submit the request to the service and store the response.
832 PersonAuthorityClient client = new PersonAuthorityClient();
833 ClientResponse<String> res = null;
834 if (authCSID != null) {
835 if (itemCSID != null) {
836 res = client.readItem(authCSID, itemCSID);
837 } else if (itemShortId != null) {
838 res = client.readNamedItem(authCSID, itemShortId);
840 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
842 } else if (authShortId != null) {
843 if (itemCSID != null) {
844 res = client.readItemInNamedAuthority(authShortId, itemCSID);
845 } else if (itemShortId != null) {
846 res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
848 Assert.fail("readInternal: Internal error. One of CSID or shortId must be non-null");
851 Assert.fail("readInternal: Internal error. One of authCSID or authShortId must be non-null");
853 assertStatusCode(res, testName);
855 // Check whether we've received a person.
856 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
857 PersonsCommon person = (PersonsCommon) extractPart(input,
858 client.getItemCommonPartName(), PersonsCommon.class);
859 Assert.assertNotNull(person);
860 boolean showFull = true;
861 if (showFull && logger.isDebugEnabled()) {
862 logger.debug(testName + ": returned payload:");
863 logger.debug(objectAsXmlString(person, PersonsCommon.class));
866 // Check that the person item is within the expected Person Authority.
867 Assert.assertEquals(person.getInAuthority(), knownResourceId);
869 // Verify the number and contents of values in a repeatable field,
870 // as created in the instance record used for testing.
871 List<String> groups = person.getGroups().getGroup();
872 Assert.assertTrue(groups.size() > 0);
873 Assert.assertNotNull(groups.get(0));
876 res.releaseConnection();
881 * Verify item display name.
883 * @param testName the test name
884 * @throws Exception the exception
886 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
887 groups = {"update"}, dependsOnMethods = {"updateItem"})
888 public void verifyItemDisplayNames(String testName) throws Exception {
890 if (logger.isDebugEnabled()) {
891 logger.debug(testBanner(testName, CLASS_NAME));
896 // Submit the request to the service and store the response.
897 PersonAuthorityClient client = new PersonAuthorityClient();
898 PoxPayloadIn input = null;
899 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
900 assertStatusCode(res, testName);
902 input = new PoxPayloadIn(res.getEntity());
904 res.releaseConnection();
907 PersonsCommon person = (PersonsCommon) extractPart(input,
908 client.getItemCommonPartName(), PersonsCommon.class);
909 Assert.assertNotNull(person);
910 // Check whether person has expected displayName.
911 // Make sure displayName matches computed form
912 String displayName = person.getDisplayName();
913 String expectedDisplayName =
914 PersonAuthorityClientUtils.prepareDefaultDisplayName(
915 TEST_FORE_NAME, null, TEST_SUR_NAME,
916 TEST_BIRTH_DATE, TEST_DEATH_DATE);
917 Assert.assertFalse(displayName.equals(expectedDisplayName));
919 // Make sure short displayName matches computed form
920 String shortDisplayName = person.getShortDisplayName();
921 String expectedShortDisplayName =
922 PersonAuthorityClientUtils.prepareDefaultDisplayName(
923 TEST_FORE_NAME, null, TEST_SUR_NAME, null, null);
924 Assert.assertFalse(expectedShortDisplayName.equals(shortDisplayName));
926 // Update the forename and verify the computed name is updated.
927 person.setCsid(null);
928 person.setDisplayNameComputed(true);
929 person.setShortDisplayNameComputed(true);
930 person.setForeName("updated-" + TEST_FORE_NAME);
931 expectedDisplayName =
932 PersonAuthorityClientUtils.prepareDefaultDisplayName(
933 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME,
934 TEST_BIRTH_DATE, TEST_DEATH_DATE);
935 expectedShortDisplayName =
936 PersonAuthorityClientUtils.prepareDefaultDisplayName(
937 "updated-" + TEST_FORE_NAME, null, TEST_SUR_NAME, null, null);
939 // Submit the updated resource to the service and store the response.
940 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
941 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
942 commonPart.setLabel(client.getItemCommonPartName());
943 res = client.updateItem(knownResourceId, knownItemResourceId, output);
944 assertStatusCode(res, testName);
946 // Retrieve the updated resource and verify that its contents exist.
947 input = new PoxPayloadIn(res.getEntity());
949 res.releaseConnection();
952 PersonsCommon updatedPerson =
953 (PersonsCommon) extractPart(input,
954 client.getItemCommonPartName(), PersonsCommon.class);
955 Assert.assertNotNull(updatedPerson);
957 // Verify that the updated resource received the correct data.
958 Assert.assertEquals(updatedPerson.getForeName(), person.getForeName(),
959 "Updated ForeName in Person did not match submitted data.");
960 // Verify that the updated resource computes the right displayName.
961 Assert.assertEquals(updatedPerson.getDisplayName(), expectedDisplayName,
962 "Updated ForeName in Person not reflected in computed DisplayName.");
963 // Verify that the updated resource computes the right displayName.
964 Assert.assertEquals(updatedPerson.getShortDisplayName(), expectedShortDisplayName,
965 "Updated ForeName in Person not reflected in computed ShortDisplayName.");
967 // Now Update the displayName, not computed and verify the computed name is overriden.
968 person.setDisplayNameComputed(false);
969 expectedDisplayName = "TestName";
970 person.setDisplayName(expectedDisplayName);
971 person.setShortDisplayNameComputed(false);
972 person.setShortDisplayName(expectedDisplayName);
974 // Submit the updated resource to the service and store the response.
975 output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
976 commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
977 commonPart.setLabel(client.getItemCommonPartName());
978 res = client.updateItem(knownResourceId, knownItemResourceId, output);
979 assertStatusCode(res, testName);
981 // Retrieve the updated resource and verify that its contents exist.
982 input = new PoxPayloadIn(res.getEntity());
984 res.releaseConnection();
988 (PersonsCommon) extractPart(input,
989 client.getItemCommonPartName(), PersonsCommon.class);
990 Assert.assertNotNull(updatedPerson);
992 // Verify that the updated resource received the correct data.
993 Assert.assertEquals(updatedPerson.isDisplayNameComputed(), false,
994 "Updated displayNameComputed in Person did not match submitted data.");
995 // Verify that the updated resource computes the right displayName.
996 Assert.assertEquals(updatedPerson.getDisplayName(),
998 "Updated DisplayName (not computed) in Person not stored.");
999 // Verify that the updated resource received the correct data.
1000 Assert.assertEquals(updatedPerson.isShortDisplayNameComputed(), false,
1001 "Updated shortDisplayNameComputed in Person did not match submitted data.");
1002 // Verify that the updated resource computes the right displayName.
1003 Assert.assertEquals(updatedPerson.getShortDisplayName(),
1004 expectedDisplayName,
1005 "Updated ShortDisplayName (not computed) in Person not stored.");
1009 * Verify illegal item display name.
1011 * @param testName the test name
1012 * @throws Exception the exception
1014 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1015 groups = {"update"}, dependsOnMethods = {"verifyItemDisplayNames"})
1016 public void verifyIllegalItemDisplayName(String testName) throws Exception {
1018 if (logger.isDebugEnabled()) {
1019 logger.debug(testBanner(testName, CLASS_NAME));
1022 // Perform setup for read.
1025 // Submit the request to the service and store the response.
1026 PersonAuthorityClient client = new PersonAuthorityClient();
1027 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
1028 assertStatusCode(res, testName);
1030 // Perform setup for update.
1031 testSetup(STATUS_BAD_REQUEST, ServiceRequestType.UPDATE);
1033 PoxPayloadIn input = null;
1035 input = new PoxPayloadIn(res.getEntity());
1037 res.releaseConnection();
1040 PersonsCommon person = (PersonsCommon) extractPart(input,
1041 client.getItemCommonPartName(), PersonsCommon.class);
1042 Assert.assertNotNull(person);
1043 // Try to Update with computed false and no displayName
1044 person.setDisplayNameComputed(false);
1045 person.setDisplayName(null);
1047 // Submit the updated resource to the service and store the response.
1048 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1049 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1050 commonPart.setLabel(client.getItemCommonPartName());
1051 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1052 assertStatusCode(res, testName);
1054 // intentionally empty try block
1056 res.releaseConnection();
1063 * @param testName the test name
1064 * @throws Exception the exception
1066 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1067 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1068 public void readContact(String testName) throws Exception {
1070 if (logger.isDebugEnabled()) {
1071 logger.debug(testBanner(testName, CLASS_NAME));
1076 // Submit the request to the service and store the response.
1077 PersonAuthorityClient client = new PersonAuthorityClient();
1078 PoxPayloadIn input = null;
1079 ClientResponse<String> res =
1080 client.readContact(knownResourceId, knownItemResourceId,
1081 knownContactResourceId);
1082 assertStatusCode(res, testName);
1084 // Check whether we've received a contact.
1085 input = new PoxPayloadIn(res.getEntity());
1087 res.releaseConnection();
1090 ContactsCommon contact = (ContactsCommon) extractPart(input,
1091 new ContactClient().getCommonPartName(), ContactsCommon.class);
1092 Assert.assertNotNull(contact);
1093 boolean showFull = true;
1094 if (showFull && logger.isDebugEnabled()) {
1095 logger.debug(testName + ": returned payload:");
1096 logger.debug(objectAsXmlString(contact, ContactsCommon.class));
1098 Assert.assertEquals(contact.getInAuthority(), knownResourceId);
1099 Assert.assertEquals(contact.getInItem(), knownItemResourceId);
1105 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
1108 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1109 groups = {"read"}, dependsOnMethods = {"read"})
1110 public void readNonExistent(String testName) {
1112 if (logger.isDebugEnabled()) {
1113 logger.debug(testBanner(testName, CLASS_NAME));
1116 setupReadNonExistent();
1118 // Submit the request to the service and store the response.
1119 PersonAuthorityClient client = new PersonAuthorityClient();
1120 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
1122 int statusCode = res.getStatus();
1123 // Check the status code of the response: does it match
1124 // the expected response(s)?
1125 if (logger.isDebugEnabled()) {
1126 logger.debug(testName + ": status = " + statusCode);
1128 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1129 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1130 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1132 res.releaseConnection();
1137 * Read item non existent.
1139 * @param testName the test name
1141 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1142 groups = {"readItem"}, dependsOnMethods = {"readItem"})
1143 public void readItemNonExistent(String testName) {
1145 if (logger.isDebugEnabled()) {
1146 logger.debug(testBanner(testName, CLASS_NAME));
1149 setupReadNonExistent();
1151 // Submit the request to the service and store the response.
1152 PersonAuthorityClient client = new PersonAuthorityClient();
1153 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
1155 int statusCode = res.getStatus();
1157 // Check the status code of the response: does it match
1158 // the expected response(s)?
1159 if (logger.isDebugEnabled()) {
1160 logger.debug(testName + ": status = " + statusCode);
1162 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1163 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1164 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1166 res.releaseConnection();
1171 * Read contact non existent.
1173 * @param testName the test name
1175 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1176 groups = {"readItem"}, dependsOnMethods = {"readContact"})
1177 public void readContactNonExistent(String testName) {
1179 if (logger.isDebugEnabled()) {
1180 logger.debug(testBanner(testName, CLASS_NAME));
1183 setupReadNonExistent();
1185 // Submit the request to the service and store the response.
1186 PersonAuthorityClient client = new PersonAuthorityClient();
1187 ClientResponse<String> res =
1188 client.readContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
1190 int statusCode = res.getStatus();
1192 // Check the status code of the response: does it match
1193 // the expected response(s)?
1194 if (logger.isDebugEnabled()) {
1195 logger.debug(testName + ": status = " + statusCode);
1197 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1198 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1199 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1201 res.releaseConnection();
1205 // ---------------------------------------------------------------
1206 // CRUD tests : READ_LIST tests
1207 // ---------------------------------------------------------------
1211 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
1214 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1215 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
1216 public void readList(String testName) throws Exception {
1218 if (logger.isDebugEnabled()) {
1219 logger.debug(testBanner(testName, CLASS_NAME));
1224 // Submit the request to the service and store the response.
1225 PersonAuthorityClient client = new PersonAuthorityClient();
1226 AbstractCommonList list = null;
1227 ClientResponse<AbstractCommonList> res = client.readList();
1228 assertStatusCode(res, testName);
1230 list = res.getEntity();
1232 res.releaseConnection();
1235 // Optionally output additional data about list members for debugging.
1236 if (logger.isTraceEnabled()) {
1237 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1244 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1245 groups = {"readList"}, dependsOnMethods = {"readList"})
1246 public void readItemList(String testName) {
1247 readItemList(knownResourceId, null, testName);
1251 * Read item list by authority name.
1253 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1254 groups = {"readList"}, dependsOnMethods = {"readItemList"})
1255 public void readItemListByAuthorityName(String testName) {
1256 readItemList(null, knownResourceShortIdentifer, testName);
1262 * @param vcsid the vcsid
1263 * @param name the name
1265 private void readItemList(String vcsid, String name, String testName) {
1270 // Submit the request to the service and store the response.
1271 PersonAuthorityClient client = new PersonAuthorityClient();
1272 ClientResponse<AbstractCommonList> res = null;
1273 if (vcsid != null) {
1274 res = client.readItemList(vcsid, null, null);
1275 } else if (name != null) {
1276 res = client.readItemListForNamedAuthority(name, null, null);
1278 Assert.fail("readItemList passed null csid and name!");
1280 assertStatusCode(res, testName);
1281 AbstractCommonList list = null;
1283 list = res.getEntity();
1285 res.releaseConnection();
1288 List<AbstractCommonList.ListItem> items =
1290 int nItemsReturned = items.size();
1291 // There will be one item created, associated with a
1292 // known parent resource, by the createItem test.
1294 // In addition, there will be 'nItemsToCreateInList'
1295 // additional items created by the createItemList test,
1296 // all associated with the same parent resource.
1297 int nExpectedItems = nItemsToCreateInList + 1;
1298 if (logger.isDebugEnabled()) {
1299 logger.debug(testName + ": Expected "
1300 + nExpectedItems + " items; got: " + nItemsReturned);
1302 Assert.assertEquals(nItemsReturned, nExpectedItems);
1304 for (AbstractCommonList.ListItem item : items) {
1306 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
1307 Assert.assertTrue((null != value), "Item refName is null!");
1309 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
1310 Assert.assertTrue((null != value), "Item displayName is null!");
1312 if (logger.isTraceEnabled()) {
1313 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1318 * Read contact list.
1320 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
1321 public void readContactList() {
1322 readContactList(knownResourceId, knownItemResourceId);
1326 * Read contact list.
1328 * @param parentcsid the parentcsid
1329 * @param itemcsid the itemcsid
1331 private void readContactList(String parentcsid, String itemcsid) {
1332 final String testName = "readContactList";
1337 // Submit the request to the service and store the response.
1338 PersonAuthorityClient client = new PersonAuthorityClient();
1339 AbstractCommonList list = null;
1340 ClientResponse<AbstractCommonList> res =
1341 client.readContactList(parentcsid, itemcsid);
1342 assertStatusCode(res, testName);
1344 list = res.getEntity();
1346 res.releaseConnection();
1349 List<AbstractCommonList.ListItem> listitems =
1351 int nItemsReturned = listitems.size();
1352 // There will be one item created, associated with a
1353 // known parent resource, by the createItem test.
1355 // In addition, there will be 'nItemsToCreateInList'
1356 // additional items created by the createItemList test,
1357 // all associated with the same parent resource.
1358 int nExpectedItems = nItemsToCreateInList + 1;
1359 if (logger.isDebugEnabled()) {
1360 logger.debug(testName + ": Expected "
1361 + nExpectedItems + " items; got: " + nItemsReturned);
1363 Assert.assertEquals(nItemsReturned, nExpectedItems);
1365 // Optionally output additional data about list members for debugging.
1366 boolean iterateThroughList = false;
1367 if (iterateThroughList && logger.isDebugEnabled()) {
1368 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1373 // There are no failure outcome tests at present.
1374 // ---------------------------------------------------------------
1375 // CRUD tests : UPDATE tests
1376 // ---------------------------------------------------------------
1379 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
1382 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1383 groups = {"update"}, dependsOnGroups = {"readItem", "readList"})
1384 public void update(String testName) throws Exception {
1386 if (logger.isDebugEnabled()) {
1387 logger.debug(testBanner(testName, CLASS_NAME));
1392 // Retrieve the contents of a resource to update.
1393 PersonAuthorityClient client = new PersonAuthorityClient();
1394 PoxPayloadIn input = null;
1395 ClientResponse<String> res = client.read(knownResourceId);
1396 assertStatusCode(res, testName);
1398 input = new PoxPayloadIn(res.getEntity());
1400 res.releaseConnection();
1403 PersonauthoritiesCommon personAuthority = (PersonauthoritiesCommon) extractPart(input,
1404 client.getCommonPartName(), PersonauthoritiesCommon.class);
1405 Assert.assertNotNull(personAuthority);
1407 // Update the contents of this resource.
1408 personAuthority.setDisplayName("updated-" + personAuthority.getDisplayName());
1409 personAuthority.setVocabType("updated-" + personAuthority.getVocabType());
1410 if (logger.isDebugEnabled()) {
1411 logger.debug("to be updated PersonAuthority");
1412 logger.debug(objectAsXmlString(personAuthority, PersonauthoritiesCommon.class));
1415 // Submit the updated resource to the service and store the response.
1416 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_PAYLOAD_NAME);
1417 PayloadOutputPart commonPart = output.addPart(personAuthority, MediaType.APPLICATION_XML_TYPE);
1418 commonPart.setLabel(client.getCommonPartName());
1419 res = client.update(knownResourceId, output);
1420 assertStatusCode(res, testName);
1422 // Retrieve the updated resource and verify that its contents exist.
1423 input = new PoxPayloadIn(res.getEntity());
1425 res.releaseConnection();
1428 PersonauthoritiesCommon updatedPersonAuthority =
1429 (PersonauthoritiesCommon) extractPart(input,
1430 client.getCommonPartName(), PersonauthoritiesCommon.class);
1431 Assert.assertNotNull(updatedPersonAuthority);
1433 // Verify that the updated resource received the correct data.
1434 Assert.assertEquals(updatedPersonAuthority.getDisplayName(),
1435 personAuthority.getDisplayName(),
1436 "Data in updated object did not match submitted data.");
1442 * @param testName the test name
1443 * @throws Exception the exception
1445 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1446 groups = {"update"}, dependsOnMethods = {"update"})
1447 public void updateItem(String testName) throws Exception {
1449 if (logger.isDebugEnabled()) {
1450 logger.debug(testBanner(testName, CLASS_NAME));
1455 // Retrieve the contents of a resource to update.
1456 PersonAuthorityClient client = new PersonAuthorityClient();
1457 PoxPayloadIn input = null;
1458 ClientResponse<String> res =
1459 client.readItem(knownResourceId, knownItemResourceId);
1460 assertStatusCode(res, testName);
1462 input = new PoxPayloadIn(res.getEntity());
1464 res.releaseConnection();
1467 PersonsCommon person = (PersonsCommon) extractPart(input,
1468 client.getItemCommonPartName(), PersonsCommon.class);
1469 Assert.assertNotNull(person);
1471 if (logger.isDebugEnabled() == true) {
1472 logger.debug("About to update the following person...");
1473 logger.debug(objectAsXmlString(person, PersonsCommon.class));
1476 // Update the contents of this resource.
1477 person.setCsid(null);
1478 person.setForeName("updated-" + person.getForeName());
1479 if (logger.isDebugEnabled()) {
1480 logger.debug("to be updated Person");
1481 logger.debug(objectAsXmlString(person,
1482 PersonsCommon.class));
1485 // Submit the updated resource to the service and store the response.
1486 PoxPayloadOut output = new PoxPayloadOut(PersonAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1487 PayloadOutputPart commonPart = output.addPart(person, MediaType.APPLICATION_XML_TYPE);
1488 commonPart.setLabel(client.getItemCommonPartName());
1489 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1490 assertStatusCode(res, testName);
1492 // Retrieve the updated resource and verify that its contents exist.
1493 input = new PoxPayloadIn(res.getEntity());
1495 res.releaseConnection();
1498 PersonsCommon updatedPerson =
1499 (PersonsCommon) extractPart(input,
1500 client.getItemCommonPartName(), PersonsCommon.class);
1501 Assert.assertNotNull(updatedPerson);
1503 if (logger.isDebugEnabled() == true) {
1504 logger.debug("Updated to following person to:");
1505 logger.debug(objectAsXmlString(updatedPerson, PersonsCommon.class));
1508 // Verify that the updated resource received the correct data.
1509 Assert.assertEquals(updatedPerson.getForeName(),
1510 person.getForeName(),
1511 "Data in updated Person did not match submitted data.");
1517 * @param testName the test name
1518 * @throws Exception the exception
1520 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1521 groups = {"update"}, dependsOnMethods = {"updateItem"})
1522 public void updateContact(String testName) throws Exception {
1524 if (logger.isDebugEnabled()) {
1525 logger.debug(testBanner(testName, CLASS_NAME));
1530 // Retrieve the contents of a resource to update.
1531 PersonAuthorityClient client = new PersonAuthorityClient();
1532 PoxPayloadIn input = null;
1533 ClientResponse<String> res =
1534 client.readContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1535 assertStatusCode(res, testName);
1537 input = new PoxPayloadIn(res.getEntity());
1539 res.releaseConnection();
1542 ContactsCommon contact = (ContactsCommon) extractPart(input,
1543 new ContactClient().getCommonPartName(), ContactsCommon.class);
1544 Assert.assertNotNull(contact);
1546 // Verify the contents of this resource
1547 AddressGroupList addressGroupList = contact.getAddressGroupList();
1548 Assert.assertNotNull(addressGroupList);
1549 List<AddressGroup> addressGroups = addressGroupList.getAddressGroup();
1550 Assert.assertNotNull(addressGroups);
1551 Assert.assertTrue(addressGroups.size() > 0);
1552 String addressPlace1 = addressGroups.get(0).getAddressPlace1();
1553 Assert.assertNotNull(addressPlace1);
1555 // Update the contents of this resource.
1556 addressGroups.get(0).setAddressPlace1("updated-" + addressPlace1);
1557 contact.setAddressGroupList(addressGroupList);
1558 if (logger.isDebugEnabled()) {
1559 logger.debug("to be updated Contact");
1560 logger.debug(objectAsXmlString(contact,
1561 ContactsCommon.class));
1564 // Submit the updated resource to the service and store the response.
1565 PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME);
1566 PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); //FIXME: REM - Replace with output.addPart(contact, client.getCommonPartName())
1567 commonPart.setLabel(client.getCommonPartName());
1568 res = client.updateContact(knownResourceId, knownItemResourceId, knownContactResourceId, output);
1569 assertStatusCode(res, testName);
1571 // Retrieve the updated resource and verify that its contents exist.
1572 input = new PoxPayloadIn(res.getEntity());;
1574 res.releaseConnection();
1576 ContactsCommon updatedContact =
1577 (ContactsCommon) extractPart(input,
1578 new ContactClient().getCommonPartName(), ContactsCommon.class);
1579 Assert.assertNotNull(updatedContact);
1581 // Verify that the updated resource received the correct data.
1582 Assert.assertEquals(updatedContact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1583 contact.getAddressGroupList().getAddressGroup().get(0).getAddressPlace1(),
1584 "Data in updated object did not match submitted data.");
1588 // Placeholders until the three tests below can be uncommented.
1589 // See Issue CSPACE-401.
1591 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1594 public void updateWithEmptyEntityBody(String testName) throws Exception {
1595 //Should this really be empty?
1599 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1602 public void updateWithMalformedXml(String testName) throws Exception {
1603 //Should this really be empty?
1607 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1610 public void updateWithWrongXmlSchema(String testName) throws Exception {
1611 //Should this really be empty?
1614 /* //FIXME: REM - Can we kill all this dead code please?
1616 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1617 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1618 public void updateWithEmptyEntityBody(String testName) throws Exception {
1620 if (logger.isDebugEnabled()) {
1621 logger.debug(testBanner(testName, CLASS_NAME));
1624 setupUpdateWithEmptyEntityBody(testName, logger);
1626 // Submit the request to the service and store the response.
1627 String method = REQUEST_TYPE.httpMethodName();
1628 String url = getResourceURL(knownResourceId);
1629 String mediaType = MediaType.APPLICATION_XML;
1630 final String entity = "";
1631 int statusCode = submitRequest(method, url, mediaType, entity);
1633 // Check the status code of the response: does it match
1634 // the expected response(s)?
1635 if(logger.isDebugEnabled()){
1636 logger.debug(testName + ": url=" + url +
1637 " status=" + statusCode);
1639 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1640 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1641 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1645 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1646 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1647 public void updateWithMalformedXml(String testName) throws Exception {
1649 if (logger.isDebugEnabled()) {
1650 logger.debug(testBanner(testName, CLASS_NAME));
1653 setupUpdateWithMalformedXml();
1655 // Submit the request to the service and store the response.
1656 String method = REQUEST_TYPE.httpMethodName();
1657 String url = getResourceURL(knownResourceId);
1658 String mediaType = MediaType.APPLICATION_XML;
1659 final String entity = MALFORMED_XML_DATA;
1660 int statusCode = submitRequest(method, url, mediaType, entity);
1662 // Check the status code of the response: does it match
1663 // the expected response(s)?
1664 if(logger.isDebugEnabled()){
1665 logger.debug(testName + ": url=" + url +
1666 " status=" + statusCode);
1668 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1669 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1670 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1674 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
1675 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1676 public void updateWithWrongXmlSchema(String testName) throws Exception {
1678 if (logger.isDebugEnabled()) {
1679 logger.debug(testBanner(testName, CLASS_NAME));
1682 setupUpdateWithWrongXmlSchema();
1684 // Submit the request to the service and store the response.
1685 String method = REQUEST_TYPE.httpMethodName();
1686 String url = getResourceURL(knownResourceId);
1687 String mediaType = MediaType.APPLICATION_XML;
1688 final String entity = WRONG_XML_SCHEMA_DATA;
1689 int statusCode = submitRequest(method, url, mediaType, entity);
1691 // Check the status code of the response: does it match
1692 // the expected response(s)?
1693 if(logger.isDebugEnabled()){
1694 logger.debug("updateWithWrongXmlSchema: url=" + url +
1695 " status=" + statusCode);
1697 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1698 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1699 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1704 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1707 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1708 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1709 public void updateNonExistent(String testName) throws Exception {
1711 if (logger.isDebugEnabled()) {
1712 logger.debug(testBanner(testName, CLASS_NAME));
1715 setupUpdateNonExistent();
1717 // Submit the request to the service and store the response.
1718 // Note: The ID(s) used when creating the request payload may be arbitrary.
1719 // The only relevant ID may be the one used in update(), below.
1720 PersonAuthorityClient client = new PersonAuthorityClient();
1721 String displayName = "displayName-NON_EXISTENT_ID";
1722 PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(
1723 displayName, "NON_EXISTENT_SHORT_ID", client.getCommonPartName());
1724 ClientResponse<String> res =
1725 client.update(NON_EXISTENT_ID, multipart);
1727 int statusCode = res.getStatus();
1729 // Check the status code of the response: does it match
1730 // the expected response(s)?
1731 if (logger.isDebugEnabled()) {
1732 logger.debug(testName + ": status = " + statusCode);
1734 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1735 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1736 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1738 res.releaseConnection();
1743 * Update non existent item.
1745 * @param testName the test name
1746 * @throws Exception the exception
1748 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1749 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1750 public void updateNonExistentItem(String testName) throws Exception {
1752 if (logger.isDebugEnabled()) {
1753 logger.debug(testBanner(testName, CLASS_NAME));
1756 setupUpdateNonExistent();
1758 // Submit the request to the service and store the response.
1759 // Note: The ID used in this 'create' call may be arbitrary.
1760 // The only relevant ID may be the one used in update(), below.
1761 PersonAuthorityClient client = new PersonAuthorityClient();
1762 Map<String, String> nonexMap = new HashMap<String, String>();
1763 nonexMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, "nonEX");
1764 nonexMap.put(PersonJAXBSchema.FORE_NAME, "John");
1765 nonexMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
1766 nonexMap.put(PersonJAXBSchema.GENDER, "male");
1767 Map<String, List<String>> nonexRepeatablesMap = new HashMap<String, List<String>>();
1768 PoxPayloadOut multipart =
1769 PersonAuthorityClientUtils.createPersonInstance(NON_EXISTENT_ID,
1770 null, //PersonAuthorityClientUtils.createPersonAuthRefName(NON_EXISTENT_ID, null),
1771 nonexMap, nonexRepeatablesMap, client.getItemCommonPartName());
1772 ClientResponse<String> res =
1773 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1775 int statusCode = res.getStatus();
1777 // Check the status code of the response: does it match
1778 // the expected response(s)?
1779 if (logger.isDebugEnabled()) {
1780 logger.debug(testName + ": status = " + statusCode);
1782 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1783 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1784 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1786 res.releaseConnection();
1791 * Update non existent contact.
1793 * @param testName the test name
1794 * @throws Exception the exception
1796 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1797 groups = {"update"}, dependsOnMethods = {"updateContact", "testContactSubmitRequest"})
1798 public void updateNonExistentContact(String testName) throws Exception {
1799 // Currently a no-op test
1802 // ---------------------------------------------------------------
1803 // CRUD tests : DELETE tests
1804 // ---------------------------------------------------------------
1806 // Note: delete sub-resources in ascending hierarchical order,
1807 // before deleting their parents.
1811 * @param testName the test name
1812 * @throws Exception the exception
1814 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1815 groups = {"delete"}, dependsOnGroups = {"update"})
1816 public void deleteContact(String testName) throws Exception {
1818 if (logger.isDebugEnabled()) {
1819 logger.debug(testBanner(testName, CLASS_NAME));
1824 if (logger.isDebugEnabled()) {
1825 logger.debug("parentcsid =" + knownResourceId
1826 + " itemcsid = " + knownItemResourceId
1827 + " csid = " + knownContactResourceId);
1830 // Submit the request to the service and store the response.
1831 PersonAuthorityClient client = new PersonAuthorityClient();
1832 ClientResponse<Response> res =
1833 client.deleteContact(knownResourceId, knownItemResourceId, knownContactResourceId);
1835 int statusCode = res.getStatus();
1837 // Check the status code of the response: does it match
1838 // the expected response(s)?
1839 if (logger.isDebugEnabled()) {
1840 logger.debug(testName + ": status = " + statusCode);
1842 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1843 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1844 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1846 res.releaseConnection();
1853 * @param testName the test name
1854 * @throws Exception the exception
1856 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1857 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
1858 public void deleteItem(String testName) throws Exception {
1860 if (logger.isDebugEnabled()) {
1861 logger.debug(testBanner(testName, CLASS_NAME));
1866 if (logger.isDebugEnabled()) {
1867 logger.debug("parentcsid =" + knownResourceId
1868 + " itemcsid = " + knownItemResourceId);
1871 // Submit the request to the service and store the response.
1872 PersonAuthorityClient client = new PersonAuthorityClient();
1873 ClientResponse<Response> res = client.deleteItem(knownResourceId, knownItemResourceId);
1875 int statusCode = res.getStatus();
1877 // Check the status code of the response: does it match
1878 // the expected response(s)?
1879 if (logger.isDebugEnabled()) {
1880 logger.debug(testName + ": status = " + statusCode);
1882 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1883 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1884 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1886 res.releaseConnection();
1891 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1894 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1895 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1896 public void delete(String testName) throws Exception {
1898 if (logger.isDebugEnabled()) {
1899 logger.debug(testBanner(testName, CLASS_NAME));
1904 if (logger.isDebugEnabled()) {
1905 logger.debug("parentcsid =" + knownResourceId);
1908 // Submit the request to the service and store the response.
1909 PersonAuthorityClient client = new PersonAuthorityClient();
1910 ClientResponse<Response> res = client.delete(knownResourceId);
1912 int statusCode = res.getStatus();
1914 // Check the status code of the response: does it match
1915 // the expected response(s)?
1916 if (logger.isDebugEnabled()) {
1917 logger.debug(testName + ": status = " + statusCode);
1919 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1920 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1921 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1923 res.releaseConnection();
1929 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1932 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1933 groups = {"delete"}, dependsOnMethods = {"delete"})
1934 public void deleteNonExistent(String testName) throws Exception {
1936 if (logger.isDebugEnabled()) {
1937 logger.debug(testBanner(testName, CLASS_NAME));
1940 setupDeleteNonExistent();
1942 // Submit the request to the service and store the response.
1943 PersonAuthorityClient client = new PersonAuthorityClient();
1944 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1946 int statusCode = res.getStatus();
1948 // Check the status code of the response: does it match
1949 // the expected response(s)?
1950 if (logger.isDebugEnabled()) {
1951 logger.debug(testName + ": status = " + statusCode);
1953 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1954 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1955 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1957 res.releaseConnection();
1962 * Delete non existent item.
1964 * @param testName the test name
1966 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1967 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1968 public void deleteNonExistentItem(String testName) {
1970 if (logger.isDebugEnabled()) {
1971 logger.debug(testBanner(testName, CLASS_NAME));
1974 setupDeleteNonExistent();
1976 // Submit the request to the service and store the response.
1977 PersonAuthorityClient client = new PersonAuthorityClient();
1978 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1980 int statusCode = res.getStatus();
1982 // Check the status code of the response: does it match
1983 // the expected response(s)?
1984 if (logger.isDebugEnabled()) {
1985 logger.debug(testName + ": status = " + statusCode);
1987 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1988 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1989 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1991 res.releaseConnection();
1996 * Delete non existent contact.
1998 * @param testName the test name
2000 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
2001 groups = {"delete"}, dependsOnMethods = {"deleteContact"})
2002 public void deleteNonExistentContact(String testName) {
2004 if (logger.isDebugEnabled()) {
2005 logger.debug(testBanner(testName, CLASS_NAME));
2008 setupDeleteNonExistent();
2010 // Submit the request to the service and store the response.
2011 PersonAuthorityClient client = new PersonAuthorityClient();
2012 ClientResponse<Response> res =
2013 client.deleteContact(knownResourceId, knownItemResourceId, NON_EXISTENT_ID);
2015 int statusCode = res.getStatus();
2017 // Check the status code of the response: does it match
2018 // the expected response(s)?
2019 if (logger.isDebugEnabled()) {
2020 logger.debug(testName + ": status = " + statusCode);
2022 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
2023 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
2024 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
2026 res.releaseConnection();
2030 // ---------------------------------------------------------------
2031 // Utility tests : tests of code used in tests above
2032 // ---------------------------------------------------------------
2034 * Tests the code for manually submitting data that is used by several
2035 * of the methods above.
2037 @Test(dependsOnMethods = {"create", "read"})
2038 public void testSubmitRequest() {
2040 // Expected status code: 200 OK
2041 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2043 // Submit the request to the service and store the response.
2044 String method = ServiceRequestType.READ.httpMethodName();
2045 String url = getResourceURL(knownResourceId);
2046 int statusCode = submitRequest(method, url);
2048 // Check the status code of the response: does it match
2049 // the expected response(s)?
2050 if (logger.isDebugEnabled()) {
2051 logger.debug("testSubmitRequest: url=" + url
2052 + " status=" + statusCode);
2054 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2059 * Test item submit request.
2061 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
2062 public void testItemSubmitRequest() {
2064 // Expected status code: 200 OK
2065 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2067 // Submit the request to the service and store the response.
2068 String method = ServiceRequestType.READ.httpMethodName();
2069 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
2070 int statusCode = submitRequest(method, url);
2072 // Check the status code of the response: does it match
2073 // the expected response(s)?
2074 if (logger.isDebugEnabled()) {
2075 logger.debug("testItemSubmitRequest: url=" + url
2076 + " status=" + statusCode);
2078 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2083 * Test contact submit request.
2085 @Test(dependsOnMethods = {"createContact", "readContact", "testItemSubmitRequest"})
2086 public void testContactSubmitRequest() {
2088 // Expected status code: 200 OK
2089 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
2091 // Submit the request to the service and store the response.
2092 String method = ServiceRequestType.READ.httpMethodName();
2093 String url = getContactResourceURL(knownResourceId,
2094 knownItemResourceId, knownContactResourceId);
2095 int statusCode = submitRequest(method, url);
2097 // Check the status code of the response: does it match
2098 // the expected response(s)?
2099 if (logger.isDebugEnabled()) {
2100 logger.debug("testItemSubmitRequest: url=" + url
2101 + " status=" + statusCode);
2103 Assert.assertEquals(statusCode, EXPECTED_STATUS);
2107 // ---------------------------------------------------------------
2108 // Cleanup of resources created during testing
2109 // ---------------------------------------------------------------
2111 * Deletes all resources created by tests, after all tests have been run.
2113 * This cleanup method will always be run, even if one or more tests fail.
2114 * For this reason, it attempts to remove all resources created
2115 * at any point during testing, even if some of those resources
2116 * may be expected to be deleted by certain tests.
2118 @AfterClass(alwaysRun = true)
2120 public void cleanUp() {
2121 String noTest = System.getProperty("noTestCleanup");
2122 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
2123 if (logger.isDebugEnabled()) {
2124 logger.debug("Skipping Cleanup phase ...");
2128 if (logger.isDebugEnabled()) {
2129 logger.debug("Cleaning up temporary resources created for testing ...");
2131 String parentResourceId;
2132 String itemResourceId;
2133 String contactResourceId;
2134 // Clean up contact resources.
2135 PersonAuthorityClient client = new PersonAuthorityClient();
2136 parentResourceId = knownResourceId;
2137 for (Map.Entry<String, String> entry : allContactResourceIdsCreated.entrySet()) {
2138 contactResourceId = entry.getKey();
2139 itemResourceId = entry.getValue();
2140 // Note: Any non-success responses from the delete operation
2141 // below are ignored and not reported.
2142 ClientResponse<Response> res =
2143 client.deleteContact(parentResourceId, itemResourceId, contactResourceId);
2144 res.releaseConnection();
2146 // Clean up item resources.
2147 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
2148 itemResourceId = entry.getKey();
2149 parentResourceId = entry.getValue();
2150 // Note: Any non-success responses from the delete operation
2151 // below are ignored and not reported.
2152 ClientResponse<Response> res =
2153 client.deleteItem(parentResourceId, itemResourceId);
2154 res.releaseConnection();
2156 // Clean up parent resources.
2160 // ---------------------------------------------------------------
2161 // Utility methods used by tests above
2162 // ---------------------------------------------------------------
2164 * Gets the contact service path component.
2166 * @return the contact service path component
2168 public String getContactServicePathComponent() {
2169 return ContactClient.SERVICE_PATH_COMPONENT;
2173 * Returns the root URL for the item service.
2175 * This URL consists of a base URL for all services, followed by
2176 * a path component for the owning parent, followed by the
2177 * path component for the items.
2179 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2180 * parent authority resource of the relevant item resource.
2182 * @return The root URL for the item service.
2184 protected String getItemServiceRootURL(String parentResourceIdentifier) {
2185 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
2189 * Returns the URL of a specific item resource managed by a service, and
2190 * designated by an identifier (such as a universally unique ID, or UUID).
2192 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2193 * parent authority resource of the relevant item resource.
2195 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2198 * @return The URL of a specific item resource managed by a service.
2200 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
2201 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;
2205 * Returns the root URL for the contact service.
2207 * This URL consists of a base URL for all services, followed by
2208 * a path component for the owning authority, followed by the
2209 * path component for the owning item, followed by the path component
2210 * for the contact service.
2212 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2213 * parent authority resource of the relevant item resource.
2215 * @param itemResourceIdentifier An identifier (such as a UUID) for an
2218 * @return The root URL for the contact service.
2220 protected String getContactServiceRootURL(String parentResourceIdentifier,
2221 String itemResourceIdentifier) {
2222 return getItemResourceURL(parentResourceIdentifier, itemResourceIdentifier) + "/"
2223 + getContactServicePathComponent();
2227 * Returns the URL of a specific contact resource managed by a service, and
2228 * designated by an identifier (such as a universally unique ID, or UUID).
2230 * @param parentResourceIdentifier An identifier (such as a UUID) for the
2231 * parent resource of the relevant item resource.
2233 * @param resourceIdentifier An identifier (such as a UUID) for an
2236 * @return The URL of a specific resource managed by a service.
2238 protected String getContactResourceURL(String parentResourceIdentifier,
2239 String itemResourceIdentifier, String contactResourceIdentifier) {
2240 return getContactServiceRootURL(parentResourceIdentifier,
2241 itemResourceIdentifier) + "/" + contactResourceIdentifier;