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.io.PrintStream;
26 import java.io.UnsupportedEncodingException;
27 import java.net.URLEncoder;
28 import java.nio.charset.Charset;
29 import java.util.ArrayList;
30 import java.util.HashMap;
31 import java.util.List;
33 import javax.ws.rs.core.Response;
35 import org.collectionspace.services.PersonJAXBSchema;
36 import org.collectionspace.services.client.CollectionSpaceClient;
37 import org.collectionspace.services.client.PersonAuthorityClient;
38 import org.collectionspace.services.client.PersonAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonsCommonList;
41 import org.jboss.resteasy.client.ClientResponse;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.testng.Assert;
46 import org.testng.annotations.AfterClass;
47 import org.testng.annotations.BeforeClass;
48 import org.testng.annotations.Test;
51 * PersonAuthoritySearchTest, carries out search (e.g. partial
52 * term matching) tests against a deployed and running PersonAuthority Service.
54 * $LastChangedRevision: 753 $
55 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
57 public class PersonAuthoritySearchTest extends BaseServiceTest {
59 private final String CLASS_NAME = PersonAuthoritySearchTest.class.getName();
60 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 /** The service path component. */
63 final String SERVICE_PATH_COMPONENT = "personauthorities";
65 final String UTF8_CHARSET_NAME = "UTF-8";
67 // Test name for partial term matching: Lech Wałęsa
69 // For details regarding the łę characters in the last name, see:
70 // http://en.wikipedia.org/wiki/L_with_stroke
71 // http://en.wikipedia.org/wiki/%C4%98
74 final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
76 // Surname (contains single quote character)
77 final String TEST_PARTIAL_TERM_SUR_NAME_QUOTE = "O'Hara";
79 // Surname (contains two non-USASCII range Unicode UTF-8 characters)
80 final String TEST_PARTIAL_TERM_SUR_NAME_UNICODE = "Wałęsa";
81 // Wrong: "Wa" + "\u0142" + "\u0119" + "sa";
82 // Should also work: "Wa" + '\u0142' + '\u0119' + "sa";
83 // Should also work: "Wa\u0142\u0119sa";
87 final String TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE =
88 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
91 final String TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE =
92 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
95 final String TEST_SHORT_ID_UNICODE = "lechWalesa";
98 final String TEST_SHORT_ID_QUOTE = "lechOHara";
100 final String TEST_KWD_BIRTH_PLACE = "Popowo, Poland";
102 final String TEST_KWD_UTF8_STYLE = "Appliqu"+'\u00e8'+"d Arts";
104 final String TEST_KWD_BIO_NOTE_NO_QUOTES =
105 "This is a silly bionote with no so-called quotes.";
107 final String TEST_KWD_BIO_NOTE_DBL_QUOTES =
108 "This is a silly \"bionote\" for testing so called quote_handling";
110 final String TEST_KWD_NO_MATCH = "Foobar";
112 // Non-existent partial term name (first letters of each of the words
113 // in a pangram for the English alphabet).
114 private static final String TEST_PARTIAL_TERM_NON_EXISTENT = "jlmbsoq";
116 /** The known resource id. */
117 private String knownResourceId = null;
119 /** The known resource ref name. */
120 private String knownResourceRefName = null;
122 /** The known item resource id. */
123 private String knownItemResourceId = null;
125 // The resource ID of an item resource used for partial term matching tests.
126 private String knownItemPartialTermResourceId = null;
128 private List<String> allResourceIdsCreated = new ArrayList<String>();
130 /** The all item resource ids created. */
131 private Map<String, String> allItemResourceIdsCreated =
132 new HashMap<String, String>();
134 // The number of matches expected on each partial term.
135 final int NUM_MATCHES_EXPECTED_COMMON = 2;
136 final int NUM_MATCHES_EXPECTED_SPECIFIC = 1;
138 // The minimum number of characters that must be included
139 // a partial term, in order to permit matching to occur.
140 final int PARTIAL_TERM_MIN_LENGTH = 1;
143 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
146 protected CollectionSpaceClient getClientInstance() {
147 return new PersonAuthorityClient();
151 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
154 protected AbstractCommonList getAbstractCommonList(
155 ClientResponse<AbstractCommonList> response) {
156 return response.getEntity(PersonsCommonList.class);
159 private String getPartialTermCommon() {
160 return TEST_PARTIAL_TERM_FORE_NAME;
163 private String getPartialTermUtf8() {
164 return TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
167 private String getPartialTermQuote() {
168 return TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
171 private String getPartialTermNonExistent() {
172 return TEST_PARTIAL_TERM_NON_EXISTENT;
175 private String getPartialTermMinimumLength() {
176 String partialTerm = getPartialTermCommon();
177 if (partialTerm == null || partialTerm.trim().isEmpty()) {
180 if (partialTerm.length() > PARTIAL_TERM_MIN_LENGTH) {
181 return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH);
187 private String getKwdTerm() {
188 return TEST_KWD_BIRTH_PLACE;
191 private String getKwdTermUTF8() {
192 return TEST_KWD_UTF8_STYLE;
195 private String getKwdTermNonExistent() {
196 return TEST_KWD_NO_MATCH;
200 public void setup() {
203 } catch (Exception e) {
204 Assert.fail("Could not create new Authority for search tests.", e);
207 createItemsInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
208 } catch (Exception e) {
209 Assert.fail("Could not create new item in Authority for search tests.", e);
213 // ---------------------------------------------------------------
214 // CRUD tests : READ_LIST tests by partial term match.
215 // ---------------------------------------------------------------
220 * Reads an item list by partial term.
222 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
223 groups = {"readListByPartialTerm"})
224 public void partialTermMatch(String testName) {
225 if (logger.isDebugEnabled()) {
226 logger.debug(testBanner(testName, CLASS_NAME));
228 int numMatchesFound = 0;
229 String partialTerm = getPartialTermCommon();
230 if (logger.isDebugEnabled()) {
231 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
233 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
234 if (logger.isDebugEnabled()) {
235 logger.debug("Found " + numMatchesFound + " match(es), expected " +
236 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
238 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
242 * Reads an item list by partial term, with a partial term that consists
243 * of an all-lowercase variation of the expected match, to test case-insensitive
246 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
247 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
248 public void partialTermMatchCaseInsensitiveLowerCase(String testName) {
249 if (logger.isDebugEnabled()) {
250 logger.debug(testBanner(testName, CLASS_NAME));
252 int numMatchesFound = 0;
254 final String partialTerm = getPartialTermCommon().toLowerCase();
255 if (logger.isDebugEnabled()) {
256 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
259 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
260 if (logger.isDebugEnabled()) {
261 logger.debug("Found " + numMatchesFound + " match(es), expected " +
262 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
264 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
268 * Reads an item list by partial term, with a partial term that consists
269 * of an all-uppercase variation of the expected match, to test case-insensitive
272 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
273 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
274 public void partialTermMatchCaseInsensitiveUpperCase(String testName) {
275 if (logger.isDebugEnabled()) {
276 logger.debug(testBanner(testName, CLASS_NAME));
278 int numMatchesFound = 0;
280 final String partialTerm = getPartialTermCommon().toUpperCase();
281 if (logger.isDebugEnabled()) {
282 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
285 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
286 if (logger.isDebugEnabled()) {
287 logger.debug("Found " + numMatchesFound + " match(es), expected " +
288 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
290 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
294 * Reads an item list by partial term, with a partial term that is of
295 * the minimum character length that may be expected to be matched.
297 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
298 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
299 public void partialTermMatchMinimumLength(String testName) {
300 if (logger.isDebugEnabled()) {
301 logger.debug(testBanner(testName, CLASS_NAME));
303 int numMatchesFound = 0;
304 String partialTerm = getPartialTermMinimumLength();
305 if (logger.isDebugEnabled()) {
306 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
308 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
309 // Zero matches are expected on a non-existent term.
310 if (logger.isDebugEnabled()) {
311 logger.debug("Found " + numMatchesFound + " match(es), expected " +
312 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
314 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
318 * Reads an item list by partial term, with a partial term that contains
319 * at least one Unicode UTF-8 character (outside the USASCII range).
321 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
322 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
323 public void partialTermMatchUTF8(String testName) {
324 if (logger.isDebugEnabled()) {
325 logger.debug(testBanner(testName, CLASS_NAME));
327 int numMatchesFound = 0;
328 String partialTerm = getPartialTermUtf8();
331 ptEncoded = URLEncoder.encode(partialTerm, UTF8_CHARSET_NAME);
333 catch (UnsupportedEncodingException ex) {
334 throw new RuntimeException("Broken VM does not support UTF-8");
336 if (logger.isDebugEnabled()) {
337 logger.debug("Attempting match on partial term '" + partialTerm + "', Encoded:'"+ptEncoded+"' ...");
340 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
341 if (logger.isDebugEnabled()) {
342 logger.debug("Found " + numMatchesFound + " match(es), expected " +
343 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
345 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
349 * Reads an item list by partial term, with a partial term that contains
350 * at least one Unicode UTF-8 character (outside the USASCII range).
352 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
353 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
354 public void partialTermMatchQuote(String testName) {
355 if (logger.isDebugEnabled()) {
356 logger.debug(testBanner(testName, CLASS_NAME));
358 int numMatchesFound = 0;
359 String partialTerm = getPartialTermQuote();
360 if (logger.isDebugEnabled()) {
361 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
364 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
365 if (logger.isDebugEnabled()) {
366 logger.debug("Found " + numMatchesFound + " match(es), expected " +
367 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
369 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
373 * Finds terms by keywords.
375 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
376 groups = {"readListByKwdTerm"})
377 public void keywordTermMatch(String testName) {
378 if (logger.isDebugEnabled()) {
379 logger.debug(testBanner(testName, CLASS_NAME));
381 int numMatchesFound = 0;
382 String kwdTerm = getKwdTerm();
383 if (logger.isDebugEnabled()) {
384 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
386 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
387 if (logger.isDebugEnabled()) {
388 logger.debug("Found " + numMatchesFound + " match(es), expected " +
389 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
391 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
395 * Finds terms by keywords.
397 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
398 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
399 public void keywordTermMatchUTF8(String testName) {
400 if (logger.isDebugEnabled()) {
401 logger.debug(testBanner(testName, CLASS_NAME));
403 int numMatchesFound = 0;
404 String kwdTerm = getKwdTermUTF8();
405 if (logger.isDebugEnabled()) {
406 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
408 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
409 if (logger.isDebugEnabled()) {
410 logger.debug("Found " + numMatchesFound + " match(es), expected " +
411 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
413 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
421 * Reads an item list by partial term, with a partial term that is not
422 * expected to be matched by any term in any resource.
424 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
425 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
426 public void partialTermMatchOnNonexistentTerm(String testName) {
427 if (logger.isDebugEnabled()) {
428 logger.debug(testBanner(testName, CLASS_NAME));
430 int numMatchesFound = 0;
431 int ZERO_MATCHES_EXPECTED = 0;
432 String partialTerm = getPartialTermNonExistent();
433 if (logger.isDebugEnabled()) {
434 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
436 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
437 // Zero matches are expected on a non-existent term.
438 if (logger.isDebugEnabled()) {
439 logger.debug("Found " + numMatchesFound + " match(es), expected " +
440 ZERO_MATCHES_EXPECTED + " match(es).");
442 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
446 * Reads an item list by partial term, with a partial term that is not
447 * expected to be matched by any term in any resource.
449 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
450 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
451 public void keywordTermMatchOnNonexistentTerm(String testName) {
452 if (logger.isDebugEnabled()) {
453 logger.debug(testBanner(testName, CLASS_NAME));
455 int numMatchesFound = 0;
456 int ZERO_MATCHES_EXPECTED = 0;
457 String kwdTerm = getKwdTermNonExistent();
458 if (logger.isDebugEnabled()) {
459 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
461 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
462 // Zero matches are expected on a non-existent term.
463 if (logger.isDebugEnabled()) {
464 logger.debug("Found " + numMatchesFound + " match(es), expected " +
465 ZERO_MATCHES_EXPECTED + " match(es).");
467 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
471 * Reads an item list by partial term or keywords, given an authority and a term.
472 * Only one of partialTerm or keywords should be specified.
473 * If both are specified, keywords will be ignored.
475 * @param testName Calling test name
476 * @param authorityCsid The CSID of the authority within which partial term matching
478 * @param partialTerm A partial term to match item resources.
479 * @param partialTerm A keyword list to match item resources.
480 * @return The number of item resources matched by the partial term.
482 private int readItemListWithFilters(String testName,
483 String authorityCsid, String partialTerm, String keywords) {
486 int expectedStatusCode = Response.Status.OK.getStatusCode();
487 ServiceRequestType requestType = ServiceRequestType.READ_LIST;
488 testSetup(expectedStatusCode, requestType);
490 // Submit the request to the service and store the response.
491 PersonAuthorityClient client = new PersonAuthorityClient();
492 ClientResponse<PersonsCommonList> res = null;
493 if (authorityCsid != null) {
494 res = client.readItemList(authorityCsid, partialTerm, keywords);
496 Assert.fail("readItemListByPartialTerm passed null csid!");
498 PersonsCommonList list = null;
500 int statusCode = res.getStatus();
502 // Check the status code of the response: does it match
503 // the expected response(s)?
504 if(logger.isDebugEnabled()){
505 logger.debug(testName + ": status = " + statusCode);
507 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
508 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
509 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
511 list = res.getEntity();
513 res.releaseConnection();
516 List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
517 int nItemsReturned = items.size();
519 return nItemsReturned;
522 // ---------------------------------------------------------------
523 // Cleanup of resources created during testing
524 // ---------------------------------------------------------------
527 * Deletes all resources created by tests, after all tests have been run.
529 * This cleanup method will always be run, even if one or more tests fail.
530 * For this reason, it attempts to remove all resources created
531 * at any point during testing, even if some of those resources
532 * may be expected to be deleted by certain tests.
534 @AfterClass(alwaysRun=true)
535 public void cleanUp() {
536 String noTest = System.getProperty("noTestCleanup");
537 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
538 if (logger.isDebugEnabled()) {
539 logger.debug("Skipping Cleanup phase ...");
543 if (logger.isDebugEnabled()) {
544 logger.debug("Cleaning up temporary resources created for testing ...");
546 String parentResourceId;
547 String itemResourceId;
548 PersonAuthorityClient client = new PersonAuthorityClient();
549 parentResourceId = knownResourceId;
550 // Clean up item resources.
551 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
552 itemResourceId = entry.getKey();
553 parentResourceId = entry.getValue();
554 // Note: Any non-success responses from the delete operation
555 // below are ignored and not reported.
556 ClientResponse<Response> res =
557 client.deleteItem(parentResourceId, itemResourceId);
558 res.releaseConnection();
560 // Clean up authority resources.
561 for (String resourceId : allResourceIdsCreated) {
562 // Note: Any non-success responses are ignored and not reported.
563 client.delete(resourceId).releaseConnection();
567 // ---------------------------------------------------------------
568 // Utility methods used by tests above
569 // ---------------------------------------------------------------
571 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
574 public String getServicePathComponent() {
575 return SERVICE_PATH_COMPONENT;
579 // ---------------------------------------------------------------
580 // Utilities: setup routines for search tests
581 // ---------------------------------------------------------------
583 public void createAuthority() throws Exception {
585 String testName = "createAuthority";
586 if (logger.isDebugEnabled()) {
587 logger.debug(testBanner(testName, CLASS_NAME));
591 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
592 ServiceRequestType requestType = ServiceRequestType.CREATE;
593 testSetup(expectedStatusCode, requestType);
595 // Submit the request to the service and store the response.
596 PersonAuthorityClient client = new PersonAuthorityClient();
597 String shortId = createIdentifier();
598 String displayName = "displayName-" + shortId;
599 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
600 MultipartOutput multipart =
601 PersonAuthorityClientUtils.createPersonAuthorityInstance(
602 displayName, shortId, client.getCommonPartName());
605 ClientResponse<Response> res = client.create(multipart);
607 int statusCode = res.getStatus();
608 // Check the status code of the response: does it match
609 // the expected response(s)?
610 if(logger.isDebugEnabled()){
611 logger.debug(testName + ": status = " + statusCode);
613 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
614 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
615 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
616 newID = PersonAuthorityClientUtils.extractId(res);
618 res.releaseConnection();
620 // Store the refname from the first resource created
621 // for additional tests below.
622 knownResourceRefName = baseRefName;
623 // Store the ID returned from the first resource created
624 // for additional tests below.
625 if (knownResourceId == null){
626 knownResourceId = newID;
627 knownResourceRefName = baseRefName;
630 // Store the IDs from every resource created by tests,
631 // so they can be deleted after tests have been run.
632 allResourceIdsCreated.add(newID);
636 * Creates an item in the authority, used for partial term matching tests.
638 * @param authorityCsid The CSID of the Authority in which the term will be created.
639 * @param authRefName The refName of the Authority in which the term will be created.
641 private void createItemsInAuthorityForPartialTermMatch(
642 String authorityCsid, String authRefName)
645 String testName = "createItemsInAuthorityForPartialTermMatch";
647 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
648 ServiceRequestType requestType = ServiceRequestType.CREATE;
649 testSetup(expectedStatusCode, requestType);
651 // Submit the request to the service and store the response.
652 PersonAuthorityClient client = new PersonAuthorityClient();
653 Map<String, String> partialTermPersonMap = new HashMap<String,String>();
655 // Fill the property map for the UNICODE item
657 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_UNICODE );
658 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
659 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
660 partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
661 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_UNICODE);
662 partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
663 partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
664 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_NO_QUOTES);
666 Map<String, List<String>> partialTermRepeatablesMap = new HashMap<String, List<String>>();
667 ArrayList<String> styles = new ArrayList<String>();
668 styles.add(TEST_KWD_UTF8_STYLE);
669 partialTermRepeatablesMap.put(PersonJAXBSchema.SCHOOLS_OR_STYLES, styles);
671 createItem(testName, authorityCsid, authRefName, client,
672 partialTermPersonMap, partialTermRepeatablesMap);
674 // Adjust the property map for the QUOTE item
676 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_QUOTE );
677 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE);
678 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_QUOTE);
679 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_DBL_QUOTES);
681 createItem(testName, authorityCsid, authRefName, client,
682 partialTermPersonMap, partialTermRepeatablesMap);
685 private void createItem(
687 String authorityCsid,
689 PersonAuthorityClient client,
690 Map<String, String> partialTermPersonMap,
691 Map<String, List<String>> partialTermRepeatablesMap) throws Exception {
692 MultipartOutput multipart =
693 PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName,
694 partialTermPersonMap, partialTermRepeatablesMap, client.getItemCommonPartName() );
697 ClientResponse<Response> res = client.createItem(authorityCsid, multipart);
699 int statusCode = res.getStatus();
700 // Check the status code of the response: does it match
701 // the expected response(s)?
702 if(logger.isDebugEnabled()){
703 logger.debug(testName + ": status = " + statusCode);
705 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
706 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
707 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
709 newID = PersonAuthorityClientUtils.extractId(res);
711 res.releaseConnection();
714 // Store the ID returned from the first item resource created
715 // for additional tests below.
716 if (knownItemResourceId == null){
717 knownItemResourceId = newID;
718 if (logger.isDebugEnabled()) {
719 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
723 // Store the IDs from any item resources created
724 // by tests, along with the IDs of their parents, so these items
725 // can be deleted after all tests have been run.
726 allItemResourceIdsCreated.put(newID, authorityCsid);