]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
9948d5202a6cd57e09d70dd2b2c829ca0b707b02
[tmp/jakarta-migration.git] /
1 /**
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:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright (c)) 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
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.
22  */
23 package org.collectionspace.services.client.test;
24
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;
32 import java.util.Map;
33 import javax.ws.rs.core.Response;
34
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;
49
50 /**
51  * PersonAuthoritySearchTest, carries out search (e.g. partial
52  * term matching) tests against a deployed and running PersonAuthority Service.
53  *
54  * $LastChangedRevision: 753 $
55  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
56  */
57 public class PersonAuthoritySearchTest extends BaseServiceTest {
58
59     private final String CLASS_NAME = PersonAuthoritySearchTest.class.getName();
60     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61     
62         @Override
63         public String getServicePathComponent() {
64                 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
65         }
66
67         @Override
68         protected String getServiceName() {
69                 return PersonAuthorityClient.SERVICE_NAME;
70         }
71     
72     final String UTF8_CHARSET_NAME = "UTF-8";
73     
74     // Test name for partial term matching: Lech Wałęsa
75     //
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
79     //
80     // Forename
81     final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
82     //
83     // Surname (contains single quote character)
84     final String TEST_PARTIAL_TERM_SUR_NAME_QUOTE = "O'Hara";
85     //
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";
91     //
92     //
93     // Displayname
94     final String TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE =
95             TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
96     //
97     // Displayname
98     final String TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE =
99             TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
100     //
101     // shortId
102     final String TEST_SHORT_ID_UNICODE = "lechWalesa";
103     //
104     // shortId
105     final String TEST_SHORT_ID_QUOTE = "lechOHara";
106     
107     final String TEST_KWD_BIRTH_PLACE = "Popowo, Poland";
108
109     final String TEST_KWD_UTF8_STYLE = "Appliqu"+'\u00e8'+"d Arts";
110     
111     final String TEST_KWD_BIO_NOTE_NO_QUOTES = 
112         "This is a silly bionote with no so-called quotes.";
113     
114     final String TEST_KWD_BIO_NOTE_DBL_QUOTES = 
115         "This is a silly \"bionote\" for testing so called quote_handling";
116
117     final String TEST_KWD_NO_MATCH = "Foobar";
118
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";
122
123     /** The known resource id. */
124     private String knownResourceId = null;
125     
126     /** The known resource ref name. */
127     private String knownResourceRefName = null;
128     
129     /** The known item resource id. */
130     private String knownItemResourceId = null;
131
132     // The resource ID of an item resource used for partial term matching tests.
133     private String knownItemPartialTermResourceId = null;
134
135     private List<String> allResourceIdsCreated = new ArrayList<String>();
136     
137     /** The all item resource ids created. */
138     private Map<String, String> allItemResourceIdsCreated =
139         new HashMap<String, String>();
140
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;
144
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;
148
149     /* (non-Javadoc)
150      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
151      */
152     @Override
153     protected CollectionSpaceClient getClientInstance() {
154         return new PersonAuthorityClient();
155     }
156     
157     /* (non-Javadoc)
158      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
159      */
160     @Override
161     protected AbstractCommonList getAbstractCommonList(
162                     ClientResponse<AbstractCommonList> response) {
163     return response.getEntity(PersonsCommonList.class);
164     }
165
166     private String getPartialTermCommon() {
167         return TEST_PARTIAL_TERM_FORE_NAME;
168     }
169
170     private String getPartialTermUtf8() {
171         return TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
172     }
173
174     private String getPartialTermQuote() {
175         return TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
176     }
177
178     private String getPartialTermNonExistent() {
179         return TEST_PARTIAL_TERM_NON_EXISTENT;
180     }
181
182     private String getPartialTermMinimumLength() {
183         String partialTerm = getPartialTermCommon();
184         if (partialTerm == null || partialTerm.trim().isEmpty()) {
185             return partialTerm;
186         }
187         if (partialTerm.length() > PARTIAL_TERM_MIN_LENGTH) {
188             return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH);
189         } else {
190           return partialTerm;
191         }
192     }
193
194     private String getKwdTerm() {
195         return TEST_KWD_BIRTH_PLACE;
196     }
197
198     private String getKwdTermUTF8() {
199         return TEST_KWD_UTF8_STYLE;
200     }
201
202     private String getKwdTermNonExistent() {
203         return TEST_KWD_NO_MATCH;
204     }
205
206     @BeforeClass
207     public void setup() {
208         try {
209             createAuthority();
210         } catch (Exception e) {
211             Assert.fail("Could not create new Authority for search tests.", e);
212         }
213         try {
214             createItemsInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
215         } catch (Exception e) {
216             Assert.fail("Could not create new item in Authority for search tests.", e);
217         }
218     }
219  
220     // ---------------------------------------------------------------
221     // CRUD tests : READ_LIST tests by partial term match.
222     // ---------------------------------------------------------------
223
224     // Success outcomes
225
226     /**
227      * Reads an item list by partial term.
228      */
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));
234         }
235         int numMatchesFound = 0;
236         String partialTerm = getPartialTermCommon();
237         if (logger.isDebugEnabled()) {
238             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
239         }
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).");
244         }
245         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
246     }
247
248     /**
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
251      * matching.
252      */
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));
258         }
259         int numMatchesFound = 0;
260
261         final String partialTerm = getPartialTermCommon().toLowerCase();
262         if (logger.isDebugEnabled()) {
263             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
264         }
265         numMatchesFound =
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).");
270         }
271         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
272     }
273
274     /**
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
277      * matching.
278      */
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));
284         }
285         int numMatchesFound = 0;
286
287         final String partialTerm = getPartialTermCommon().toUpperCase();
288         if (logger.isDebugEnabled()) {
289             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
290         }
291         numMatchesFound =
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).");
296         }
297         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
298     }
299
300     /**
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.
303      */
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));
309         }
310         int numMatchesFound = 0;
311         String partialTerm = getPartialTermMinimumLength();
312         if (logger.isDebugEnabled()) {
313             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
314         }
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).");
320         }
321         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
322     }
323
324     /**
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).
327      */
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));
333         }
334         int numMatchesFound = 0;
335         String partialTerm = getPartialTermUtf8();
336         String ptEncoded;
337         try {
338                 ptEncoded = URLEncoder.encode(partialTerm, UTF8_CHARSET_NAME);
339         }
340         catch (UnsupportedEncodingException ex) {
341           throw new RuntimeException("Broken VM does not support UTF-8");
342         }
343         if (logger.isDebugEnabled()) {
344             logger.debug("Attempting match on partial term '" + partialTerm + "', Encoded:'"+ptEncoded+"' ...");
345         }
346         numMatchesFound =
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).");
351         }
352         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
353     }
354     
355     /**
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).
358      */
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));
364         }
365         int numMatchesFound = 0;
366         String partialTerm = getPartialTermQuote();
367         if (logger.isDebugEnabled()) {
368             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
369         }
370         numMatchesFound =
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).");
375         }
376         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
377     }
378
379     /**
380      * Finds terms by keywords.
381      */
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));
387         }
388         int numMatchesFound = 0;
389         String kwdTerm = getKwdTerm();
390         if (logger.isDebugEnabled()) {
391             logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
392         }
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).");
397         }
398         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
399     }
400
401     /**
402      * Finds terms by keywords.
403      */
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));
409         }
410         int numMatchesFound = 0;
411         String kwdTerm = getKwdTermUTF8();
412         if (logger.isDebugEnabled()) {
413             logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
414         }
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).");
419         }
420         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
421     }
422
423     
424     
425     // Failure outcomes
426
427     /**
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.
430      */
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));
436         }
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 + "' ...");
442         }
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).");
448         }
449         Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
450     }
451
452     /**
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.
455      */
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));
461         }
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 + "' ...");
467         }
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).");
473         }
474         Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
475     }
476
477     /**
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.
481      * 
482      * @param testName Calling test name
483      * @param authorityCsid The CSID of the authority within which partial term matching
484      *     will be performed.
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.
488      */
489     private int readItemListWithFilters(String testName, 
490                 String authorityCsid, String partialTerm, String keywords) {
491
492         // Perform setup.
493         int expectedStatusCode = Response.Status.OK.getStatusCode();
494         ServiceRequestType requestType = ServiceRequestType.READ_LIST;
495         testSetup(expectedStatusCode, requestType);
496
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);
502         } else {
503             Assert.fail("readItemListByPartialTerm passed null csid!");
504         }
505         PersonsCommonList list = null;
506         try {
507             int statusCode = res.getStatus();
508
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);
513             }
514             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
515                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
516             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
517
518             list = res.getEntity();
519         } finally {
520             res.releaseConnection();
521         }
522
523         List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
524         int nItemsReturned = items.size();
525
526         return nItemsReturned;
527     }
528     
529     // ---------------------------------------------------------------
530     // Cleanup of resources created during testing
531     // ---------------------------------------------------------------
532     
533     /**
534      * Deletes all resources created by tests, after all tests have been run.
535      *
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.
540      */
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 ...");
547             }
548             return;
549         }
550         if (logger.isDebugEnabled()) {
551             logger.debug("Cleaning up temporary resources created for testing ...");
552         }
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();
566         }
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();
571         }
572     }
573
574     // ---------------------------------------------------------------
575     // Utility methods used by tests above
576     // ---------------------------------------------------------------
577
578     // ---------------------------------------------------------------
579     // Utilities: setup routines for search tests
580     // ---------------------------------------------------------------
581
582     public void createAuthority() throws Exception {
583
584         String testName = "createAuthority";
585         if (logger.isDebugEnabled()) {
586             logger.debug(testBanner(testName, CLASS_NAME));
587         }
588
589         // Perform setup.
590         int expectedStatusCode = Response.Status.CREATED.getStatusCode();
591         ServiceRequestType requestType = ServiceRequestType.CREATE;
592         testSetup(expectedStatusCode, requestType);
593
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());
602
603         String newID = null;
604         ClientResponse<Response> res = client.create(multipart);
605         try {
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);
611             }
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);
616         } finally {
617             res.releaseConnection();
618         }
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;
627         }
628
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);
632     }
633
634      /**
635      * Creates an item in the authority, used for partial term matching tests.
636      *
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.
639      */
640     private void createItemsInAuthorityForPartialTermMatch(
641                 String authorityCsid, String authRefName)
642         throws Exception {
643             
644         String testName = "createItemsInAuthorityForPartialTermMatch";
645
646         int expectedStatusCode = Response.Status.CREATED.getStatusCode();
647         ServiceRequestType requestType = ServiceRequestType.CREATE;
648         testSetup(expectedStatusCode, requestType);
649
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>();
653         //
654         // Fill the property map for the UNICODE item
655         //
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);
664
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);
669
670         createItem(testName, authorityCsid, authRefName, client, 
671                 partialTermPersonMap, partialTermRepeatablesMap);
672         //
673         // Adjust the property map for the QUOTE item
674         //
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);
679
680         createItem(testName, authorityCsid, authRefName, client, 
681                 partialTermPersonMap, partialTermRepeatablesMap);
682     }
683     
684     private void createItem(
685                 String testName, 
686                 String authorityCsid, 
687                 String authRefName,
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() );
694
695         String newID = null;
696         ClientResponse<Response> res = client.createItem(authorityCsid, multipart);
697         try {
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);
703             }
704             Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705                     invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706             Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
707
708             newID = PersonAuthorityClientUtils.extractId(res);
709         } finally {
710             res.releaseConnection();
711         }
712
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);
719             }
720         }
721
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);
726     }
727
728 }