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.client.PoxPayloadOut;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.person.PersonsCommonList;
42 import org.jboss.resteasy.client.ClientResponse;
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);
63 public String getServicePathComponent() {
64 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
68 protected String getServiceName() {
69 return PersonAuthorityClient.SERVICE_NAME;
72 final String UTF8_CHARSET_NAME = "UTF-8";
74 // Test name for partial term matching: Lech Wałęsa
76 // For details regarding the łę characters in the last name, see:
77 // http://en.wikipedia.org/wiki/L_with_stroke
78 // http://en.wikipedia.org/wiki/%C4%98
81 final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
83 // Surname (contains single quote character)
84 final String TEST_PARTIAL_TERM_SUR_NAME_QUOTE = "O'Hara";
86 // Surname (contains two non-USASCII range Unicode UTF-8 characters)
87 final String TEST_PARTIAL_TERM_SUR_NAME_UNICODE = "Wałęsa";
88 // Wrong: "Wa" + "\u0142" + "\u0119" + "sa";
89 // Should also work: "Wa" + '\u0142' + '\u0119' + "sa";
90 // Should also work: "Wa\u0142\u0119sa";
94 final String TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE =
95 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
98 final String TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE =
99 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
102 final String TEST_SHORT_ID_UNICODE = "lechWalesa";
105 final String TEST_SHORT_ID_QUOTE = "lechOHara";
107 final String TEST_KWD_BIRTH_PLACE = "Popowo, Poland";
109 final String TEST_KWD_UTF8_STYLE = "Appliqu"+'\u00e8'+"d Arts";
111 final String TEST_KWD_BIO_NOTE_NO_QUOTES =
112 "This is a silly bionote with no so-called quotes.";
114 final String TEST_KWD_BIO_NOTE_DBL_QUOTES =
115 "This is a silly \"bionote\" for testing so called quote_handling";
117 final String TEST_KWD_NO_MATCH = "Foobar";
119 // Non-existent partial term name (first letters of each of the words
120 // in a pangram for the English alphabet).
121 private static final String TEST_PARTIAL_TERM_NON_EXISTENT = "jlmbsoq";
123 /** The known resource id. */
124 private String knownResourceId = null;
126 /** The known resource ref name. */
127 private String knownResourceRefName = null;
129 /** The known item resource id. */
130 private String knownItemResourceId = null;
132 // The resource ID of an item resource used for partial term matching tests.
133 private String knownItemPartialTermResourceId = null;
135 private List<String> allResourceIdsCreated = new ArrayList<String>();
137 /** The all item resource ids created. */
138 private Map<String, String> allItemResourceIdsCreated =
139 new HashMap<String, String>();
141 // The number of matches expected on each partial term.
142 final int NUM_MATCHES_EXPECTED_COMMON = 2;
143 final int NUM_MATCHES_EXPECTED_SPECIFIC = 1;
145 // The minimum number of characters that must be included
146 // a partial term, in order to permit matching to occur.
147 final int PARTIAL_TERM_MIN_LENGTH = 1;
150 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
153 protected CollectionSpaceClient getClientInstance() {
154 return new PersonAuthorityClient();
158 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
161 protected AbstractCommonList getAbstractCommonList(
162 ClientResponse<AbstractCommonList> response) {
163 return response.getEntity(PersonsCommonList.class);
166 private String getPartialTermCommon() {
167 return TEST_PARTIAL_TERM_FORE_NAME;
170 private String getPartialTermUtf8() {
171 return TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
174 private String getPartialTermQuote() {
175 return TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
178 private String getPartialTermNonExistent() {
179 return TEST_PARTIAL_TERM_NON_EXISTENT;
182 private String getPartialTermMinimumLength() {
183 String partialTerm = getPartialTermCommon();
184 if (partialTerm == null || partialTerm.trim().isEmpty()) {
187 if (partialTerm.length() > PARTIAL_TERM_MIN_LENGTH) {
188 return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH);
194 private String getKwdTerm() {
195 return TEST_KWD_BIRTH_PLACE;
198 private String getKwdTermUTF8() {
199 return TEST_KWD_UTF8_STYLE;
202 private String getKwdTermNonExistent() {
203 return TEST_KWD_NO_MATCH;
207 public void setup() {
210 } catch (Exception e) {
211 Assert.fail("Could not create new Authority for search tests.", e);
214 createItemsInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
215 } catch (Exception e) {
216 Assert.fail("Could not create new item in Authority for search tests.", e);
220 // ---------------------------------------------------------------
221 // CRUD tests : READ_LIST tests by partial term match.
222 // ---------------------------------------------------------------
227 * Reads an item list by partial term.
229 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
230 groups = {"readListByPartialTerm"})
231 public void partialTermMatch(String testName) {
232 if (logger.isDebugEnabled()) {
233 logger.debug(testBanner(testName, CLASS_NAME));
235 int numMatchesFound = 0;
236 String partialTerm = getPartialTermCommon();
237 if (logger.isDebugEnabled()) {
238 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
240 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
241 if (logger.isDebugEnabled()) {
242 logger.debug("Found " + numMatchesFound + " match(es), expected " +
243 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
245 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
249 * Reads an item list by partial term, with a partial term that consists
250 * of an all-lowercase variation of the expected match, to test case-insensitive
253 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
254 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
255 public void partialTermMatchCaseInsensitiveLowerCase(String testName) {
256 if (logger.isDebugEnabled()) {
257 logger.debug(testBanner(testName, CLASS_NAME));
259 int numMatchesFound = 0;
261 final String partialTerm = getPartialTermCommon().toLowerCase();
262 if (logger.isDebugEnabled()) {
263 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
266 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
267 if (logger.isDebugEnabled()) {
268 logger.debug("Found " + numMatchesFound + " match(es), expected " +
269 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
271 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
275 * Reads an item list by partial term, with a partial term that consists
276 * of an all-uppercase variation of the expected match, to test case-insensitive
279 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
280 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
281 public void partialTermMatchCaseInsensitiveUpperCase(String testName) {
282 if (logger.isDebugEnabled()) {
283 logger.debug(testBanner(testName, CLASS_NAME));
285 int numMatchesFound = 0;
287 final String partialTerm = getPartialTermCommon().toUpperCase();
288 if (logger.isDebugEnabled()) {
289 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
292 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
293 if (logger.isDebugEnabled()) {
294 logger.debug("Found " + numMatchesFound + " match(es), expected " +
295 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
297 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
301 * Reads an item list by partial term, with a partial term that is of
302 * the minimum character length that may be expected to be matched.
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
305 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
306 public void partialTermMatchMinimumLength(String testName) {
307 if (logger.isDebugEnabled()) {
308 logger.debug(testBanner(testName, CLASS_NAME));
310 int numMatchesFound = 0;
311 String partialTerm = getPartialTermMinimumLength();
312 if (logger.isDebugEnabled()) {
313 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
315 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
316 // Zero matches are expected on a non-existent term.
317 if (logger.isDebugEnabled()) {
318 logger.debug("Found " + numMatchesFound + " match(es), expected " +
319 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
321 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
325 * Reads an item list by partial term, with a partial term that contains
326 * at least one Unicode UTF-8 character (outside the USASCII range).
328 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
329 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
330 public void partialTermMatchUTF8(String testName) {
331 if (logger.isDebugEnabled()) {
332 logger.debug(testBanner(testName, CLASS_NAME));
334 int numMatchesFound = 0;
335 String partialTerm = getPartialTermUtf8();
338 ptEncoded = URLEncoder.encode(partialTerm, UTF8_CHARSET_NAME);
340 catch (UnsupportedEncodingException ex) {
341 throw new RuntimeException("Broken VM does not support UTF-8");
343 if (logger.isDebugEnabled()) {
344 logger.debug("Attempting match on partial term '" + partialTerm + "', Encoded:'"+ptEncoded+"' ...");
347 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
348 if (logger.isDebugEnabled()) {
349 logger.debug("Found " + numMatchesFound + " match(es), expected " +
350 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
352 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
356 * Reads an item list by partial term, with a partial term that contains
357 * at least one Unicode UTF-8 character (outside the USASCII range).
359 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
360 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
361 public void partialTermMatchQuote(String testName) {
362 if (logger.isDebugEnabled()) {
363 logger.debug(testBanner(testName, CLASS_NAME));
365 int numMatchesFound = 0;
366 String partialTerm = getPartialTermQuote();
367 if (logger.isDebugEnabled()) {
368 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
371 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
372 if (logger.isDebugEnabled()) {
373 logger.debug("Found " + numMatchesFound + " match(es), expected " +
374 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
376 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
380 * Finds terms by keywords.
382 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
383 groups = {"readListByKwdTerm"})
384 public void keywordTermMatch(String testName) {
385 if (logger.isDebugEnabled()) {
386 logger.debug(testBanner(testName, CLASS_NAME));
388 int numMatchesFound = 0;
389 String kwdTerm = getKwdTerm();
390 if (logger.isDebugEnabled()) {
391 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
393 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
394 if (logger.isDebugEnabled()) {
395 logger.debug("Found " + numMatchesFound + " match(es), expected " +
396 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
398 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
402 * Finds terms by keywords.
404 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
405 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
406 public void keywordTermMatchUTF8(String testName) {
407 if (logger.isDebugEnabled()) {
408 logger.debug(testBanner(testName, CLASS_NAME));
410 int numMatchesFound = 0;
411 String kwdTerm = getKwdTermUTF8();
412 if (logger.isDebugEnabled()) {
413 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
415 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
416 if (logger.isDebugEnabled()) {
417 logger.debug("Found " + numMatchesFound + " match(es), expected " +
418 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
420 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
428 * Reads an item list by partial term, with a partial term that is not
429 * expected to be matched by any term in any resource.
431 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
432 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
433 public void partialTermMatchOnNonexistentTerm(String testName) {
434 if (logger.isDebugEnabled()) {
435 logger.debug(testBanner(testName, CLASS_NAME));
437 int numMatchesFound = 0;
438 int ZERO_MATCHES_EXPECTED = 0;
439 String partialTerm = getPartialTermNonExistent();
440 if (logger.isDebugEnabled()) {
441 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
443 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
444 // Zero matches are expected on a non-existent term.
445 if (logger.isDebugEnabled()) {
446 logger.debug("Found " + numMatchesFound + " match(es), expected " +
447 ZERO_MATCHES_EXPECTED + " match(es).");
449 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
453 * Reads an item list by partial term, with a partial term that is not
454 * expected to be matched by any term in any resource.
456 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
457 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
458 public void keywordTermMatchOnNonexistentTerm(String testName) {
459 if (logger.isDebugEnabled()) {
460 logger.debug(testBanner(testName, CLASS_NAME));
462 int numMatchesFound = 0;
463 int ZERO_MATCHES_EXPECTED = 0;
464 String kwdTerm = getKwdTermNonExistent();
465 if (logger.isDebugEnabled()) {
466 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
468 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
469 // Zero matches are expected on a non-existent term.
470 if (logger.isDebugEnabled()) {
471 logger.debug("Found " + numMatchesFound + " match(es), expected " +
472 ZERO_MATCHES_EXPECTED + " match(es).");
474 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
478 * Reads an item list by partial term or keywords, given an authority and a term.
479 * Only one of partialTerm or keywords should be specified.
480 * If both are specified, keywords will be ignored.
482 * @param testName Calling test name
483 * @param authorityCsid The CSID of the authority within which partial term matching
485 * @param partialTerm A partial term to match item resources.
486 * @param partialTerm A keyword list to match item resources.
487 * @return The number of item resources matched by the partial term.
489 private int readItemListWithFilters(String testName,
490 String authorityCsid, String partialTerm, String keywords) {
493 int expectedStatusCode = Response.Status.OK.getStatusCode();
494 ServiceRequestType requestType = ServiceRequestType.READ_LIST;
495 testSetup(expectedStatusCode, requestType);
497 // Submit the request to the service and store the response.
498 PersonAuthorityClient client = new PersonAuthorityClient();
499 ClientResponse<PersonsCommonList> res = null;
500 if (authorityCsid != null) {
501 res = client.readItemList(authorityCsid, partialTerm, keywords);
503 Assert.fail("readItemListByPartialTerm passed null csid!");
505 PersonsCommonList list = null;
507 int statusCode = res.getStatus();
509 // Check the status code of the response: does it match
510 // the expected response(s)?
511 if(logger.isDebugEnabled()){
512 logger.debug(testName + ": status = " + statusCode);
514 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
515 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
516 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
518 list = res.getEntity();
520 res.releaseConnection();
523 List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
524 int nItemsReturned = items.size();
526 return nItemsReturned;
529 // ---------------------------------------------------------------
530 // Cleanup of resources created during testing
531 // ---------------------------------------------------------------
534 * Deletes all resources created by tests, after all tests have been run.
536 * This cleanup method will always be run, even if one or more tests fail.
537 * For this reason, it attempts to remove all resources created
538 * at any point during testing, even if some of those resources
539 * may be expected to be deleted by certain tests.
541 @AfterClass(alwaysRun=true)
542 public void cleanUp() {
543 String noTest = System.getProperty("noTestCleanup");
544 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
545 if (logger.isDebugEnabled()) {
546 logger.debug("Skipping Cleanup phase ...");
550 if (logger.isDebugEnabled()) {
551 logger.debug("Cleaning up temporary resources created for testing ...");
553 String parentResourceId;
554 String itemResourceId;
555 PersonAuthorityClient client = new PersonAuthorityClient();
556 parentResourceId = knownResourceId;
557 // Clean up item resources.
558 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
559 itemResourceId = entry.getKey();
560 parentResourceId = entry.getValue();
561 // Note: Any non-success responses from the delete operation
562 // below are ignored and not reported.
563 ClientResponse<Response> res =
564 client.deleteItem(parentResourceId, itemResourceId);
565 res.releaseConnection();
567 // Clean up authority resources.
568 for (String resourceId : allResourceIdsCreated) {
569 // Note: Any non-success responses are ignored and not reported.
570 client.delete(resourceId).releaseConnection();
574 // ---------------------------------------------------------------
575 // Utility methods used by tests above
576 // ---------------------------------------------------------------
578 // ---------------------------------------------------------------
579 // Utilities: setup routines for search tests
580 // ---------------------------------------------------------------
582 public void createAuthority() throws Exception {
584 String testName = "createAuthority";
585 if (logger.isDebugEnabled()) {
586 logger.debug(testBanner(testName, CLASS_NAME));
590 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
591 ServiceRequestType requestType = ServiceRequestType.CREATE;
592 testSetup(expectedStatusCode, requestType);
594 // Submit the request to the service and store the response.
595 PersonAuthorityClient client = new PersonAuthorityClient();
596 String shortId = createIdentifier();
597 String displayName = "displayName-" + shortId;
598 String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
599 PoxPayloadOut multipart =
600 PersonAuthorityClientUtils.createPersonAuthorityInstance(
601 displayName, shortId, client.getCommonPartName());
604 ClientResponse<Response> res = client.create(multipart);
606 int statusCode = res.getStatus();
607 // Check the status code of the response: does it match
608 // the expected response(s)?
609 if(logger.isDebugEnabled()){
610 logger.debug(testName + ": status = " + statusCode);
612 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
613 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
614 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
615 newID = PersonAuthorityClientUtils.extractId(res);
617 res.releaseConnection();
619 // Store the refname from the first resource created
620 // for additional tests below.
621 knownResourceRefName = baseRefName;
622 // Store the ID returned from the first resource created
623 // for additional tests below.
624 if (knownResourceId == null){
625 knownResourceId = newID;
626 knownResourceRefName = baseRefName;
629 // Store the IDs from every resource created by tests,
630 // so they can be deleted after tests have been run.
631 allResourceIdsCreated.add(newID);
635 * Creates an item in the authority, used for partial term matching tests.
637 * @param authorityCsid The CSID of the Authority in which the term will be created.
638 * @param authRefName The refName of the Authority in which the term will be created.
640 private void createItemsInAuthorityForPartialTermMatch(
641 String authorityCsid, String authRefName)
644 String testName = "createItemsInAuthorityForPartialTermMatch";
646 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
647 ServiceRequestType requestType = ServiceRequestType.CREATE;
648 testSetup(expectedStatusCode, requestType);
650 // Submit the request to the service and store the response.
651 PersonAuthorityClient client = new PersonAuthorityClient();
652 Map<String, String> partialTermPersonMap = new HashMap<String,String>();
654 // Fill the property map for the UNICODE item
656 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_UNICODE );
657 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
658 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
659 partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
660 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_UNICODE);
661 partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
662 partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
663 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_NO_QUOTES);
665 Map<String, List<String>> partialTermRepeatablesMap = new HashMap<String, List<String>>();
666 ArrayList<String> styles = new ArrayList<String>();
667 styles.add(TEST_KWD_UTF8_STYLE);
668 partialTermRepeatablesMap.put(PersonJAXBSchema.SCHOOLS_OR_STYLES, styles);
670 createItem(testName, authorityCsid, authRefName, client,
671 partialTermPersonMap, partialTermRepeatablesMap);
673 // Adjust the property map for the QUOTE item
675 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_QUOTE );
676 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE);
677 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_QUOTE);
678 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_DBL_QUOTES);
680 createItem(testName, authorityCsid, authRefName, client,
681 partialTermPersonMap, partialTermRepeatablesMap);
684 private void createItem(
686 String authorityCsid,
688 PersonAuthorityClient client,
689 Map<String, String> partialTermPersonMap,
690 Map<String, List<String>> partialTermRepeatablesMap) throws Exception {
691 PoxPayloadOut multipart =
692 PersonAuthorityClientUtils.createPersonInstance(authorityCsid, authRefName,
693 partialTermPersonMap, partialTermRepeatablesMap, client.getItemCommonPartName() );
696 ClientResponse<Response> res = client.createItem(authorityCsid, multipart);
698 int statusCode = res.getStatus();
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if(logger.isDebugEnabled()){
702 logger.debug(testName + ": status = " + statusCode);
704 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
708 newID = PersonAuthorityClientUtils.extractId(res);
710 res.releaseConnection();
713 // Store the ID returned from the first item resource created
714 // for additional tests below.
715 if (knownItemResourceId == null){
716 knownItemResourceId = newID;
717 if (logger.isDebugEnabled()) {
718 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
722 // Store the IDs from any item resources created
723 // by tests, along with the IDs of their parents, so these items
724 // can be deleted after all tests have been run.
725 allItemResourceIdsCreated.put(newID, authorityCsid);