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.jboss.resteasy.client.ClientResponse;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44 import org.testng.Assert;
45 import org.testng.annotations.AfterClass;
46 import org.testng.annotations.BeforeClass;
47 import org.testng.annotations.Test;
50 * PersonAuthoritySearchTest, carries out search (e.g. partial
51 * term matching) tests against a deployed and running PersonAuthority Service.
53 * $LastChangedRevision: 753 $
54 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
56 public class PersonAuthoritySearchTest extends BaseServiceTest {
58 private final String CLASS_NAME = PersonAuthoritySearchTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 public String getServicePathComponent() {
63 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
67 protected String getServiceName() {
68 return PersonAuthorityClient.SERVICE_NAME;
71 final String UTF8_CHARSET_NAME = "UTF-8";
73 // Test name for partial term matching: Lech Wałęsa
75 // For details regarding the łę characters in the last name, see:
76 // http://en.wikipedia.org/wiki/L_with_stroke
77 // http://en.wikipedia.org/wiki/%C4%98
80 final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
82 // Surname (contains single quote character)
83 final String TEST_PARTIAL_TERM_SUR_NAME_QUOTE = "O'Hara";
85 // Surname (contains two non-USASCII range Unicode UTF-8 characters)
86 final String TEST_PARTIAL_TERM_SUR_NAME_UNICODE = "Wałęsa";
87 // Wrong: "Wa" + "\u0142" + "\u0119" + "sa";
88 // Should also work: "Wa" + '\u0142' + '\u0119' + "sa";
89 // Should also work: "Wa\u0142\u0119sa";
93 final String TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE =
94 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
97 final String TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE =
98 TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
101 final String TEST_SHORT_ID_UNICODE = "lechWalesa";
104 final String TEST_SHORT_ID_QUOTE = "lechOHara";
106 final String TEST_KWD_BIRTH_PLACE = "Popowo, Poland";
108 final String TEST_KWD_UTF8_STYLE = "Appliqu"+'\u00e8'+"d Arts";
110 final String TEST_KWD_BIO_NOTE_NO_QUOTES =
111 "This is a silly bionote with no so-called quotes.";
113 final String TEST_KWD_BIO_NOTE_DBL_QUOTES =
114 "This is a silly \"bionote\" for testing so called quote_handling";
116 final String TEST_KWD_NO_MATCH = "Foobar";
118 // Non-existent partial term name (first letters of each of the words
119 // in a pangram for the English alphabet).
120 private static final String TEST_PARTIAL_TERM_NON_EXISTENT = "jlmbsoq";
122 /** The known resource id. */
123 private String knownResourceId = null;
125 /** The known resource ref name. */
126 //private String knownResourceRefName = null;
128 /** The known item resource id. */
129 private String knownItemResourceId = null;
131 // The resource ID of an item resource used for partial term matching tests.
132 private String knownItemPartialTermResourceId = null;
134 private List<String> allResourceIdsCreated = new ArrayList<String>();
136 /** The all item resource ids created. */
137 private Map<String, String> allItemResourceIdsCreated =
138 new HashMap<String, String>();
140 // The number of matches expected on each partial term.
141 final int NUM_MATCHES_EXPECTED_COMMON = 2;
142 final int NUM_MATCHES_EXPECTED_SPECIFIC = 1;
144 // The minimum number of characters that must be included
145 // a partial term, in order to permit matching to occur.
146 final int PARTIAL_TERM_MIN_LENGTH = 1;
149 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
152 protected CollectionSpaceClient getClientInstance() {
153 return new PersonAuthorityClient();
157 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
160 protected AbstractCommonList getAbstractCommonList(
161 ClientResponse<AbstractCommonList> response) {
162 return response.getEntity(AbstractCommonList.class);
165 private String getPartialTermCommon() {
166 return TEST_PARTIAL_TERM_FORE_NAME;
169 private String getPartialTermUtf8() {
170 return TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
173 private String getPartialTermQuote() {
174 return TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
177 private String getPartialTermNonExistent() {
178 return TEST_PARTIAL_TERM_NON_EXISTENT;
181 private String getPartialTermMinimumLength() {
182 String partialTerm = getPartialTermCommon();
183 if (partialTerm == null || partialTerm.trim().isEmpty()) {
186 if (partialTerm.length() > PARTIAL_TERM_MIN_LENGTH) {
187 return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH);
193 private String getKwdTerm() {
194 return TEST_KWD_BIRTH_PLACE;
197 private String getKwdTermUTF8() {
198 return TEST_KWD_UTF8_STYLE;
201 private String getKwdTermNonExistent() {
202 return TEST_KWD_NO_MATCH;
206 public void setup() {
209 } catch (Exception e) {
210 Assert.fail("Could not create new Authority for search tests.", e);
213 createItemsInAuthorityForPartialTermMatch(knownResourceId, null ); //knownResourceRefName);
214 } catch (Exception e) {
215 Assert.fail("Could not create new item in Authority for search tests.", e);
219 // ---------------------------------------------------------------
220 // CRUD tests : READ_LIST tests by partial term match.
221 // ---------------------------------------------------------------
226 * Reads an item list by partial term.
228 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
229 groups = {"readListByPartialTerm"})
230 public void partialTermMatch(String testName) {
231 if (logger.isDebugEnabled()) {
232 logger.debug(testBanner(testName, CLASS_NAME));
234 int numMatchesFound = 0;
235 String partialTerm = getPartialTermCommon();
236 if (logger.isDebugEnabled()) {
237 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
239 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
240 if (logger.isDebugEnabled()) {
241 logger.debug("Found " + numMatchesFound + " match(es), expected " +
242 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
244 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
248 * Reads an item list by partial term, with a partial term that consists
249 * of an all-lowercase variation of the expected match, to test case-insensitive
252 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
253 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
254 public void partialTermMatchCaseInsensitiveLowerCase(String testName) {
255 if (logger.isDebugEnabled()) {
256 logger.debug(testBanner(testName, CLASS_NAME));
258 int numMatchesFound = 0;
260 final String partialTerm = getPartialTermCommon().toLowerCase();
261 if (logger.isDebugEnabled()) {
262 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
265 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
266 if (logger.isDebugEnabled()) {
267 logger.debug("Found " + numMatchesFound + " match(es), expected " +
268 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
270 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
274 * Reads an item list by partial term, with a partial term that consists
275 * of an all-uppercase variation of the expected match, to test case-insensitive
278 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
279 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
280 public void partialTermMatchCaseInsensitiveUpperCase(String testName) {
281 if (logger.isDebugEnabled()) {
282 logger.debug(testBanner(testName, CLASS_NAME));
284 int numMatchesFound = 0;
286 final String partialTerm = getPartialTermCommon().toUpperCase();
287 if (logger.isDebugEnabled()) {
288 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
291 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
292 if (logger.isDebugEnabled()) {
293 logger.debug("Found " + numMatchesFound + " match(es), expected " +
294 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
296 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
300 * Reads an item list by partial term, with a partial term that is of
301 * the minimum character length that may be expected to be matched.
303 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
304 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
305 public void partialTermMatchMinimumLength(String testName) {
306 if (logger.isDebugEnabled()) {
307 logger.debug(testBanner(testName, CLASS_NAME));
309 int numMatchesFound = 0;
310 String partialTerm = getPartialTermMinimumLength();
311 if (logger.isDebugEnabled()) {
312 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
314 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
315 // Zero matches are expected on a non-existent term.
316 if (logger.isDebugEnabled()) {
317 logger.debug("Found " + numMatchesFound + " match(es), expected " +
318 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
320 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
324 * Reads an item list by partial term, with a partial term that contains
325 * at least one Unicode UTF-8 character (outside the USASCII range).
327 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
328 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
329 public void partialTermMatchUTF8(String testName) {
330 if (logger.isDebugEnabled()) {
331 logger.debug(testBanner(testName, CLASS_NAME));
333 int numMatchesFound = 0;
334 String partialTerm = getPartialTermUtf8();
337 ptEncoded = URLEncoder.encode(partialTerm, UTF8_CHARSET_NAME);
339 catch (UnsupportedEncodingException ex) {
340 throw new RuntimeException("Broken VM does not support UTF-8");
342 if (logger.isDebugEnabled()) {
343 logger.debug("Attempting match on partial term '" + partialTerm + "', Encoded:'"+ptEncoded+"' ...");
346 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
347 if (logger.isDebugEnabled()) {
348 logger.debug("Found " + numMatchesFound + " match(es), expected " +
349 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
351 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
355 * Reads an item list by partial term, with a partial term that contains
356 * at least one Unicode UTF-8 character (outside the USASCII range).
358 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
359 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
360 public void partialTermMatchQuote(String testName) {
361 if (logger.isDebugEnabled()) {
362 logger.debug(testBanner(testName, CLASS_NAME));
364 int numMatchesFound = 0;
365 String partialTerm = getPartialTermQuote();
366 if (logger.isDebugEnabled()) {
367 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
370 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
371 if (logger.isDebugEnabled()) {
372 logger.debug("Found " + numMatchesFound + " match(es), expected " +
373 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
375 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
379 * Finds terms by keywords.
381 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
382 groups = {"readListByKwdTerm"})
383 public void keywordTermMatch(String testName) {
384 if (logger.isDebugEnabled()) {
385 logger.debug(testBanner(testName, CLASS_NAME));
387 int numMatchesFound = 0;
388 String kwdTerm = getKwdTerm();
389 if (logger.isDebugEnabled()) {
390 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
392 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
393 if (logger.isDebugEnabled()) {
394 logger.debug("Found " + numMatchesFound + " match(es), expected " +
395 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
397 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
401 * Finds terms by keywords.
403 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
404 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
405 public void keywordTermMatchUTF8(String testName) {
406 if (logger.isDebugEnabled()) {
407 logger.debug(testBanner(testName, CLASS_NAME));
409 int numMatchesFound = 0;
410 String kwdTerm = getKwdTermUTF8();
411 if (logger.isDebugEnabled()) {
412 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
414 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
415 if (logger.isDebugEnabled()) {
416 logger.debug("Found " + numMatchesFound + " match(es), expected " +
417 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
419 Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
427 * Reads an item list by partial term, with a partial term that is not
428 * expected to be matched by any term in any resource.
430 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
431 groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
432 public void partialTermMatchOnNonexistentTerm(String testName) {
433 if (logger.isDebugEnabled()) {
434 logger.debug(testBanner(testName, CLASS_NAME));
436 int numMatchesFound = 0;
437 int ZERO_MATCHES_EXPECTED = 0;
438 String partialTerm = getPartialTermNonExistent();
439 if (logger.isDebugEnabled()) {
440 logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
442 numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
443 // Zero matches are expected on a non-existent term.
444 if (logger.isDebugEnabled()) {
445 logger.debug("Found " + numMatchesFound + " match(es), expected " +
446 ZERO_MATCHES_EXPECTED + " match(es).");
448 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
452 * Reads an item list by partial term, with a partial term that is not
453 * expected to be matched by any term in any resource.
455 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
456 groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
457 public void keywordTermMatchOnNonexistentTerm(String testName) {
458 if (logger.isDebugEnabled()) {
459 logger.debug(testBanner(testName, CLASS_NAME));
461 int numMatchesFound = 0;
462 int ZERO_MATCHES_EXPECTED = 0;
463 String kwdTerm = getKwdTermNonExistent();
464 if (logger.isDebugEnabled()) {
465 logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
467 numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
468 // Zero matches are expected on a non-existent term.
469 if (logger.isDebugEnabled()) {
470 logger.debug("Found " + numMatchesFound + " match(es), expected " +
471 ZERO_MATCHES_EXPECTED + " match(es).");
473 Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
477 * Reads an item list by partial term or keywords, given an authority and a term.
478 * Only one of partialTerm or keywords should be specified.
479 * If both are specified, keywords will be ignored.
481 * @param testName Calling test name
482 * @param authorityCsid The CSID of the authority within which partial term matching
484 * @param partialTerm A partial term to match item resources.
485 * @param partialTerm A keyword list to match item resources.
486 * @return The number of item resources matched by the partial term.
488 private int readItemListWithFilters(String testName,
489 String authorityCsid, String partialTerm, String keywords) {
492 int expectedStatusCode = Response.Status.OK.getStatusCode();
493 ServiceRequestType requestType = ServiceRequestType.READ_LIST;
494 testSetup(expectedStatusCode, requestType);
496 // Submit the request to the service and store the response.
497 PersonAuthorityClient client = new PersonAuthorityClient();
498 ClientResponse<AbstractCommonList> res = null;
499 if (authorityCsid != null) {
500 res = client.readItemList(authorityCsid, partialTerm, keywords);
502 Assert.fail("readItemListByPartialTerm passed null csid!");
504 assertStatusCode(res, testName);
505 AbstractCommonList list = null;
507 list = res.getEntity();
509 res.releaseConnection();
512 List<AbstractCommonList.ListItem> items = list.getListItem();
513 int nItemsReturned = items.size();
515 return nItemsReturned;
518 // ---------------------------------------------------------------
519 // Cleanup of resources created during testing
520 // ---------------------------------------------------------------
523 * Deletes all resources created by tests, after all tests have been run.
525 * This cleanup method will always be run, even if one or more tests fail.
526 * For this reason, it attempts to remove all resources created
527 * at any point during testing, even if some of those resources
528 * may be expected to be deleted by certain tests.
530 @AfterClass(alwaysRun=true)
531 public void cleanUp() {
532 String noTest = System.getProperty("noTestCleanup");
533 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
534 if (logger.isDebugEnabled()) {
535 logger.debug("Skipping Cleanup phase ...");
539 if (logger.isDebugEnabled()) {
540 logger.debug("Cleaning up temporary resources created for testing ...");
542 String parentResourceId;
543 String itemResourceId;
544 PersonAuthorityClient client = new PersonAuthorityClient();
545 parentResourceId = knownResourceId;
546 // Clean up item resources.
547 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
548 itemResourceId = entry.getKey();
549 parentResourceId = entry.getValue();
550 // Note: Any non-success responses from the delete operation
551 // below are ignored and not reported.
552 ClientResponse<Response> res =
553 client.deleteItem(parentResourceId, itemResourceId);
554 res.releaseConnection();
556 // Clean up authority resources.
557 for (String resourceId : allResourceIdsCreated) {
558 // Note: Any non-success responses are ignored and not reported.
559 client.delete(resourceId).releaseConnection();
563 // ---------------------------------------------------------------
564 // Utility methods used by tests above
565 // ---------------------------------------------------------------
567 // ---------------------------------------------------------------
568 // Utilities: setup routines for search tests
569 // ---------------------------------------------------------------
571 public void createAuthority() throws Exception {
573 String testName = "createAuthority";
574 if (logger.isDebugEnabled()) {
575 logger.debug(testBanner(testName, CLASS_NAME));
579 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
580 ServiceRequestType requestType = ServiceRequestType.CREATE;
581 testSetup(expectedStatusCode, requestType);
583 // Submit the request to the service and store the response.
584 PersonAuthorityClient client = new PersonAuthorityClient();
585 String shortId = createIdentifier();
586 String displayName = "displayName-" + shortId;
587 //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
588 PoxPayloadOut multipart =
589 PersonAuthorityClientUtils.createPersonAuthorityInstance(
590 displayName, shortId, client.getCommonPartName());
593 ClientResponse<Response> res = client.create(multipart);
595 int statusCode = res.getStatus();
596 // Check the status code of the response: does it match
597 // the expected response(s)?
598 if(logger.isDebugEnabled()){
599 logger.debug(testName + ": status = " + statusCode);
601 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
602 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
603 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
604 newID = PersonAuthorityClientUtils.extractId(res);
606 res.releaseConnection();
608 // Store the refname from the first resource created
609 // for additional tests below.
610 //knownResourceRefName = baseRefName;
611 // Store the ID returned from the first resource created
612 // for additional tests below.
613 if (knownResourceId == null){
614 knownResourceId = newID;
615 //knownResourceRefName = baseRefName;
618 // Store the IDs from every resource created by tests,
619 // so they can be deleted after tests have been run.
620 allResourceIdsCreated.add(newID);
624 * Creates an item in the authority, used for partial term matching tests.
626 * @param authorityCsid The CSID of the Authority in which the term will be created.
627 * @param authRefName The refName of the Authority in which the term will be created.
629 private void createItemsInAuthorityForPartialTermMatch(
630 String authorityCsid, String authRefName)
633 String testName = "createItemsInAuthorityForPartialTermMatch";
635 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
636 ServiceRequestType requestType = ServiceRequestType.CREATE;
637 testSetup(expectedStatusCode, requestType);
639 // Submit the request to the service and store the response.
640 PersonAuthorityClient client = new PersonAuthorityClient();
641 Map<String, String> partialTermPersonMap = new HashMap<String,String>();
643 // Fill the property map for the UNICODE item
645 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_UNICODE );
646 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
647 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
648 partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
649 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_UNICODE);
650 partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
651 partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
652 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_NO_QUOTES);
654 Map<String, List<String>> partialTermRepeatablesMap = new HashMap<String, List<String>>();
655 ArrayList<String> styles = new ArrayList<String>();
656 styles.add(TEST_KWD_UTF8_STYLE);
657 partialTermRepeatablesMap.put(PersonJAXBSchema.SCHOOLS_OR_STYLES, styles);
659 createItem(testName, authorityCsid, null /*authRefName*/, client,
660 partialTermPersonMap, partialTermRepeatablesMap);
662 // Adjust the property map for the QUOTE item
664 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_QUOTE );
665 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE);
666 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_QUOTE);
667 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_DBL_QUOTES);
669 createItem(testName, authorityCsid, null /*authRefName*/, client,
670 partialTermPersonMap, partialTermRepeatablesMap);
673 private void createItem(
675 String authorityCsid,
677 PersonAuthorityClient client,
678 Map<String, String> partialTermPersonMap,
679 Map<String, List<String>> partialTermRepeatablesMap) throws Exception {
680 PoxPayloadOut multipart =
681 PersonAuthorityClientUtils.createPersonInstance(authorityCsid, null, //authRefName,
682 partialTermPersonMap, partialTermRepeatablesMap, client.getItemCommonPartName() );
685 ClientResponse<Response> res = client.createItem(authorityCsid, multipart);
687 int statusCode = res.getStatus();
688 // Check the status code of the response: does it match
689 // the expected response(s)?
690 if(logger.isDebugEnabled()){
691 logger.debug(testName + ": status = " + statusCode);
693 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
694 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
695 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
697 newID = PersonAuthorityClientUtils.extractId(res);
699 res.releaseConnection();
702 // Store the ID returned from the first item resource created
703 // for additional tests below.
704 if (knownItemResourceId == null){
705 knownItemResourceId = newID;
706 if (logger.isDebugEnabled()) {
707 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
711 // Store the IDs from any item resources created
712 // by tests, along with the IDs of their parents, so these items
713 // can be deleted after all tests have been run.
714 allItemResourceIdsCreated.put(newID, authorityCsid);