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 AbstractCommonList list = null;
506 int statusCode = res.getStatus();
508 // Check the status code of the response: does it match
509 // the expected response(s)?
510 if(logger.isDebugEnabled()){
511 logger.debug(testName + ": status = " + statusCode);
513 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
514 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
515 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
517 list = res.getEntity();
519 res.releaseConnection();
522 List<AbstractCommonList.ListItem> items = list.getListItem();
523 int nItemsReturned = items.size();
525 return nItemsReturned;
528 // ---------------------------------------------------------------
529 // Cleanup of resources created during testing
530 // ---------------------------------------------------------------
533 * Deletes all resources created by tests, after all tests have been run.
535 * This cleanup method will always be run, even if one or more tests fail.
536 * For this reason, it attempts to remove all resources created
537 * at any point during testing, even if some of those resources
538 * may be expected to be deleted by certain tests.
540 @AfterClass(alwaysRun=true)
541 public void cleanUp() {
542 String noTest = System.getProperty("noTestCleanup");
543 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
544 if (logger.isDebugEnabled()) {
545 logger.debug("Skipping Cleanup phase ...");
549 if (logger.isDebugEnabled()) {
550 logger.debug("Cleaning up temporary resources created for testing ...");
552 String parentResourceId;
553 String itemResourceId;
554 PersonAuthorityClient client = new PersonAuthorityClient();
555 parentResourceId = knownResourceId;
556 // Clean up item resources.
557 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
558 itemResourceId = entry.getKey();
559 parentResourceId = entry.getValue();
560 // Note: Any non-success responses from the delete operation
561 // below are ignored and not reported.
562 ClientResponse<Response> res =
563 client.deleteItem(parentResourceId, itemResourceId);
564 res.releaseConnection();
566 // Clean up authority resources.
567 for (String resourceId : allResourceIdsCreated) {
568 // Note: Any non-success responses are ignored and not reported.
569 client.delete(resourceId).releaseConnection();
573 // ---------------------------------------------------------------
574 // Utility methods used by tests above
575 // ---------------------------------------------------------------
577 // ---------------------------------------------------------------
578 // Utilities: setup routines for search tests
579 // ---------------------------------------------------------------
581 public void createAuthority() throws Exception {
583 String testName = "createAuthority";
584 if (logger.isDebugEnabled()) {
585 logger.debug(testBanner(testName, CLASS_NAME));
589 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
590 ServiceRequestType requestType = ServiceRequestType.CREATE;
591 testSetup(expectedStatusCode, requestType);
593 // Submit the request to the service and store the response.
594 PersonAuthorityClient client = new PersonAuthorityClient();
595 String shortId = createIdentifier();
596 String displayName = "displayName-" + shortId;
597 //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
598 PoxPayloadOut multipart =
599 PersonAuthorityClientUtils.createPersonAuthorityInstance(
600 displayName, shortId, client.getCommonPartName());
603 ClientResponse<Response> res = client.create(multipart);
605 int statusCode = res.getStatus();
606 // Check the status code of the response: does it match
607 // the expected response(s)?
608 if(logger.isDebugEnabled()){
609 logger.debug(testName + ": status = " + statusCode);
611 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
612 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
613 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
614 newID = PersonAuthorityClientUtils.extractId(res);
616 res.releaseConnection();
618 // Store the refname from the first resource created
619 // for additional tests below.
620 //knownResourceRefName = baseRefName;
621 // Store the ID returned from the first resource created
622 // for additional tests below.
623 if (knownResourceId == null){
624 knownResourceId = newID;
625 //knownResourceRefName = baseRefName;
628 // Store the IDs from every resource created by tests,
629 // so they can be deleted after tests have been run.
630 allResourceIdsCreated.add(newID);
634 * Creates an item in the authority, used for partial term matching tests.
636 * @param authorityCsid The CSID of the Authority in which the term will be created.
637 * @param authRefName The refName of the Authority in which the term will be created.
639 private void createItemsInAuthorityForPartialTermMatch(
640 String authorityCsid, String authRefName)
643 String testName = "createItemsInAuthorityForPartialTermMatch";
645 int expectedStatusCode = Response.Status.CREATED.getStatusCode();
646 ServiceRequestType requestType = ServiceRequestType.CREATE;
647 testSetup(expectedStatusCode, requestType);
649 // Submit the request to the service and store the response.
650 PersonAuthorityClient client = new PersonAuthorityClient();
651 Map<String, String> partialTermPersonMap = new HashMap<String,String>();
653 // Fill the property map for the UNICODE item
655 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_UNICODE );
656 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
657 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
658 partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
659 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_UNICODE);
660 partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
661 partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
662 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_NO_QUOTES);
664 Map<String, List<String>> partialTermRepeatablesMap = new HashMap<String, List<String>>();
665 ArrayList<String> styles = new ArrayList<String>();
666 styles.add(TEST_KWD_UTF8_STYLE);
667 partialTermRepeatablesMap.put(PersonJAXBSchema.SCHOOLS_OR_STYLES, styles);
669 createItem(testName, authorityCsid, null /*authRefName*/, client,
670 partialTermPersonMap, partialTermRepeatablesMap);
672 // Adjust the property map for the QUOTE item
674 partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_QUOTE );
675 partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE);
676 partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME_QUOTE);
677 partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_DBL_QUOTES);
679 createItem(testName, authorityCsid, null /*authRefName*/, client,
680 partialTermPersonMap, partialTermRepeatablesMap);
683 private void createItem(
685 String authorityCsid,
687 PersonAuthorityClient client,
688 Map<String, String> partialTermPersonMap,
689 Map<String, List<String>> partialTermRepeatablesMap) throws Exception {
690 PoxPayloadOut multipart =
691 PersonAuthorityClientUtils.createPersonInstance(authorityCsid, null, //authRefName,
692 partialTermPersonMap, partialTermRepeatablesMap, client.getItemCommonPartName() );
695 ClientResponse<Response> res = client.createItem(authorityCsid, multipart);
697 int statusCode = res.getStatus();
698 // Check the status code of the response: does it match
699 // the expected response(s)?
700 if(logger.isDebugEnabled()){
701 logger.debug(testName + ": status = " + statusCode);
703 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
704 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
705 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
707 newID = PersonAuthorityClientUtils.extractId(res);
709 res.releaseConnection();
712 // Store the ID returned from the first item resource created
713 // for additional tests below.
714 if (knownItemResourceId == null){
715 knownItemResourceId = newID;
716 if (logger.isDebugEnabled()) {
717 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
721 // Store the IDs from any item resources created
722 // by tests, along with the IDs of their parents, so these items
723 // can be deleted after all tests have been run.
724 allItemResourceIdsCreated.put(newID, authorityCsid);