]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
b010db4979256e66d6261b52bcb626fd3fb1d3be
[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.UnsupportedEncodingException;
26 import java.net.URLEncoder;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import javax.ws.rs.core.Response;
33
34 import org.collectionspace.services.PersonJAXBSchema;
35 import org.collectionspace.services.client.CollectionSpaceClient;
36 import org.collectionspace.services.client.PersonAuthorityClient;
37 import org.collectionspace.services.client.PersonAuthorityClientUtils;
38 import org.collectionspace.services.client.PoxPayloadOut;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.person.PersonTermGroup;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.testng.Assert;
44 import org.testng.annotations.AfterClass;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.Test;
47
48 /**
49  * PersonAuthoritySearchTest, carries out search (e.g. partial
50  * term matching) tests against a deployed and running PersonAuthority Service.
51  *
52  * $LastChangedRevision: 753 $
53  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
54  */
55 public class PersonAuthoritySearchTest extends BaseServiceTest<AbstractCommonList> {
56
57     private final String CLASS_NAME = PersonAuthoritySearchTest.class.getName();
58     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
59     
60         @Override
61         public String getServicePathComponent() {
62                 return PersonAuthorityClient.SERVICE_PATH_COMPONENT;
63         }
64
65         @Override
66         protected String getServiceName() {
67                 return PersonAuthorityClient.SERVICE_NAME;
68         }
69     
70     final String UTF8_CHARSET_NAME = "UTF-8";
71     
72     // Test name for partial term matching: Lech Wałęsa
73     //
74     // For details regarding the łę characters in the last name, see:
75     // http://en.wikipedia.org/wiki/L_with_stroke
76     // http://en.wikipedia.org/wiki/%C4%98
77     //
78     // Forename
79     final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
80     //
81     // Surname (contains single quote character)
82     final String TEST_PARTIAL_TERM_SUR_NAME_QUOTE = "O'Hara";
83     //
84     // Surname (contains two non-USASCII range Unicode UTF-8 characters)
85     final String TEST_PARTIAL_TERM_SUR_NAME_UNICODE = "Wałęsa";
86         // Wrong: "Wa" + "\u0142" + "\u0119" + "sa";
87         // Should also work: "Wa" + '\u0142' + '\u0119' + "sa";
88         // Should also work: "Wa\u0142\u0119sa";
89     //
90     //
91     // Displayname
92     final String TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE =
93             TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
94     //
95     // Displayname
96     final String TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE =
97             TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
98     //
99     // shortId
100     final String TEST_SHORT_ID_UNICODE = "lechWalesa";
101     //
102     // shortId
103     final String TEST_SHORT_ID_QUOTE = "lechOHara";
104     
105     final String TEST_KWD_BIRTH_PLACE = "Popowo, Poland";
106
107     final String TEST_KWD_UTF8_STYLE = "Appliqu"+'\u00e8'+"d Arts";
108     
109     final String TEST_KWD_BIO_NOTE_NO_QUOTES = 
110         "This is a silly bionote with no so-called quotes.";
111     
112     final String TEST_KWD_BIO_NOTE_DBL_QUOTES = 
113         "This is a silly \"bionote\" for testing so called quote_handling";
114
115     final String TEST_KWD_NO_MATCH = "Foobar";
116
117     // Non-existent partial term name (first letters of each of the words
118     // in a pangram for the English alphabet).
119     private static final String TEST_PARTIAL_TERM_NON_EXISTENT = "jlmbsoq";
120
121     /** The known resource id. */
122     private String knownResourceId = null;
123     
124     /** The known resource ref name. */
125     //private String knownResourceRefName = null;
126     
127     /** The known item resource id. */
128     private String knownItemResourceId = null;
129
130     // The resource ID of an item resource used for partial term matching tests.
131     private String knownItemPartialTermResourceId = null;
132
133     private List<String> allResourceIdsCreated = new ArrayList<String>();
134     
135     /** The all item resource ids created. */
136     private Map<String, String> allItemResourceIdsCreated =
137         new HashMap<String, String>();
138
139     // The number of matches expected on each partial term.
140     final int NUM_MATCHES_EXPECTED_COMMON = 2;
141     final int NUM_MATCHES_EXPECTED_SPECIFIC = 1;
142
143     // The minimum number of characters that must be included
144     // a partial term, in order to permit matching to occur.
145     final int PARTIAL_TERM_MIN_LENGTH = 1;
146
147     /* (non-Javadoc)
148      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
149      */
150     @Override
151     protected CollectionSpaceClient getClientInstance() throws Exception {
152         return new PersonAuthorityClient();
153     }
154
155         @Override
156         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
157         return new PersonAuthorityClient(clientPropertiesFilename);
158         }
159
160     /* (non-Javadoc)
161      * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
162      */
163     @Override
164     protected AbstractCommonList getCommonList(Response response) {
165         return response.readEntity(AbstractCommonList.class);
166     }
167
168     private String getPartialTermCommon() {
169         return TEST_PARTIAL_TERM_FORE_NAME;
170     }
171
172     private String getPartialTermUtf8() {
173         return TEST_PARTIAL_TERM_SUR_NAME_UNICODE;
174     }
175
176     private String getPartialTermQuote() {
177         return TEST_PARTIAL_TERM_SUR_NAME_QUOTE;
178     }
179
180     private String getPartialTermNonExistent() {
181         return TEST_PARTIAL_TERM_NON_EXISTENT;
182     }
183
184     private String getPartialTermMinimumLength() {
185         String partialTerm = getPartialTermCommon();
186         if (partialTerm == null || partialTerm.trim().isEmpty()) {
187             return partialTerm;
188         }
189         if (partialTerm.length() > PARTIAL_TERM_MIN_LENGTH) {
190             return partialTerm.substring(0, PARTIAL_TERM_MIN_LENGTH);
191         } else {
192           return partialTerm;
193         }
194     }
195
196     private String getKwdTerm() {
197         return TEST_KWD_BIRTH_PLACE;
198     }
199
200     private String getKwdTermUTF8() {
201         return TEST_KWD_UTF8_STYLE;
202     }
203
204     private String getKwdTermNonExistent() {
205         return TEST_KWD_NO_MATCH;
206     }
207
208     @BeforeClass
209     public void setup() {
210         try {
211             createAuthority();
212         } catch (Exception e) {
213             Assert.fail("Could not create new Authority for search tests.", e);
214         }
215         try {
216             createItemsInAuthorityForPartialTermMatch(knownResourceId, null ); //knownResourceRefName);
217         } catch (Exception e) {
218             Assert.fail("Could not create new item in Authority for search tests.", e);
219         }
220     }
221  
222     // ---------------------------------------------------------------
223     // CRUD tests : READ_LIST tests by partial term match.
224     // ---------------------------------------------------------------
225
226     // Success outcomes
227
228     /**
229      * Reads an item list by partial term.
230      * @throws Exception 
231      */
232     @Test(dataProvider="testName", groups = {"readListByPartialTerm"})
233     public void partialTermMatch(String testName) throws Exception {
234         int numMatchesFound = 0;
235         String partialTerm = getPartialTermCommon();
236         if (logger.isDebugEnabled()) {
237             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
238         }
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).");
243         }
244         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
245     }
246
247     /**
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
250      * matching.
251      * @throws Exception 
252      */
253     @Test(dataProvider="testName", groups = {"readListByPartialTerm"},
254                 dependsOnMethods = {"partialTermMatch"})
255     public void partialTermMatchCaseInsensitiveLowerCase(String testName) throws Exception {
256         int numMatchesFound = 0;
257
258         final String partialTerm = getPartialTermCommon().toLowerCase();
259         if (logger.isDebugEnabled()) {
260             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
261         }
262         numMatchesFound =
263                 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
264                 if (logger.isDebugEnabled()) {
265         logger.debug("Found " + numMatchesFound + " match(es), expected " +
266                         NUM_MATCHES_EXPECTED_COMMON + " match(es).");
267         }
268         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
269     }
270
271     /**
272      * Reads an item list by partial term, with a partial term that consists
273      * of an all-uppercase variation of the expected match, to test case-insensitive
274      * matching.
275      * @throws Exception 
276      */
277     @Test(dataProvider="testName",
278         groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
279     public void partialTermMatchCaseInsensitiveUpperCase(String testName) throws Exception {
280         int numMatchesFound = 0;
281
282         final String partialTerm = getPartialTermCommon().toUpperCase();
283         if (logger.isDebugEnabled()) {
284             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
285         }
286         numMatchesFound =
287                 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
288         if (logger.isDebugEnabled()) {
289             logger.debug("Found " + numMatchesFound + " match(es), expected " +
290                         NUM_MATCHES_EXPECTED_COMMON + " match(es).");
291         }
292         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
293     }
294
295     /**
296      * Reads an item list by partial term, with a partial term that is of
297      * the minimum character length that may be expected to be matched.
298      * @throws Exception 
299      */
300     @Test(dataProvider="testName",
301         groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
302     public void partialTermMatchMinimumLength(String testName) throws Exception {
303         int numMatchesFound = 0;
304         String partialTerm = getPartialTermMinimumLength();
305         if (logger.isDebugEnabled()) {
306             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
307         }
308         numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
309         // Zero matches are expected on a non-existent term.
310         if (logger.isDebugEnabled()) {
311             logger.debug("Found " + numMatchesFound + " match(es), expected " +
312                         NUM_MATCHES_EXPECTED_COMMON + " match(es).");
313         }
314         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
315     }
316
317     /**
318      * Reads an item list by partial term, with a partial term that contains
319      * at least one Unicode UTF-8 character (outside the USASCII range).
320      * @throws Exception 
321      */
322     @Test(dataProvider="testName",
323         groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
324     public void partialTermMatchUTF8(String testName) throws Exception {
325         int numMatchesFound = 0;
326         String partialTerm = getPartialTermUtf8();
327         String ptEncoded;
328         try {
329                 ptEncoded = URLEncoder.encode(partialTerm, UTF8_CHARSET_NAME);
330         }
331         catch (UnsupportedEncodingException ex) {
332           throw new RuntimeException("Broken VM does not support UTF-8");
333         }
334         if (logger.isDebugEnabled()) {
335             logger.debug("Attempting match on partial term '" + partialTerm + "', Encoded:'"+ptEncoded+"' ...");
336         }
337         numMatchesFound =
338                 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
339         if (logger.isDebugEnabled()) {
340             logger.debug("Found " + numMatchesFound + " match(es), expected " +
341                 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
342         }
343         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
344     }
345     
346     /**
347      * Reads an item list by partial term, with a partial term that contains
348      * at least one Unicode UTF-8 character (outside the USASCII range).
349      * @throws Exception 
350      */
351     @Test(dataProvider="testName",
352         groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
353     public void partialTermMatchQuote(String testName) throws Exception {
354         int numMatchesFound = 0;
355         String partialTerm = getPartialTermQuote();
356         if (logger.isDebugEnabled()) {
357             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
358         }
359         numMatchesFound =
360                 readItemListWithFilters(testName, knownResourceId, partialTerm, null);
361         if (logger.isDebugEnabled()) {
362             logger.debug("Found " + numMatchesFound + " match(es), expected " +
363                 NUM_MATCHES_EXPECTED_SPECIFIC + " match(es).");
364         }
365         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_SPECIFIC);
366     }
367
368     /**
369      * Finds terms by keywords.
370      * @throws Exception 
371      */
372     @Test(dataProvider="testName", groups = {"readListByKwdTerm"})
373     public void keywordTermMatch(String testName) throws Exception {
374         int numMatchesFound = 0;
375         String kwdTerm = getKwdTerm();
376         if (logger.isDebugEnabled()) {
377             logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
378         }
379         numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
380         if (logger.isDebugEnabled()) {
381             logger.debug("Found " + numMatchesFound + " match(es), expected " +
382                     NUM_MATCHES_EXPECTED_COMMON + " match(es).");
383         }
384         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
385     }
386
387     /**
388      * Finds terms by keywords.
389      * @throws Exception 
390      */
391     @Test(dataProvider="testName",
392         groups = {"readListByKwdTerm"}, dependsOnMethods = {"keywordTermMatch"})
393     public void keywordTermMatchUTF8(String testName) throws Exception {
394         int numMatchesFound = 0;
395         String kwdTerm = getKwdTermUTF8();
396         if (logger.isDebugEnabled()) {
397             logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
398         }
399         numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
400         if (logger.isDebugEnabled()) {
401             logger.debug("Found " + numMatchesFound + " match(es), expected " +
402                 NUM_MATCHES_EXPECTED_COMMON + " match(es).");
403         }
404         Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED_COMMON);
405     }
406
407     
408     
409     // Failure outcomes
410
411     /**
412      * Reads an item list by partial term, with a partial term that is not
413      * expected to be matched by any term in any resource.
414      * @throws Exception 
415      */
416     @Test(dataProvider="testName",
417         groups = {"readListByPartialTerm"}, dependsOnMethods = {"partialTermMatch"})
418     public void partialTermMatchOnNonexistentTerm(String testName) throws Exception {
419         int numMatchesFound = 0;
420         int ZERO_MATCHES_EXPECTED = 0;
421         String partialTerm = getPartialTermNonExistent();
422         if (logger.isDebugEnabled()) {
423             logger.debug("Attempting match on partial term '" + partialTerm + "' ...");
424         }
425         numMatchesFound = readItemListWithFilters(testName, knownResourceId, partialTerm, null);
426         // Zero matches are expected on a non-existent term.
427         if (logger.isDebugEnabled()) {
428             logger.debug("Found " + numMatchesFound + " match(es), expected " +
429                 ZERO_MATCHES_EXPECTED + " match(es).");
430         }
431         Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
432     }
433
434     /**
435      * Reads an item list by partial term, with a partial term that is not
436      * expected to be matched by any term in any resource.
437      * @throws Exception 
438      */
439     @Test(dataProvider="testName", groups = {"readListByKwdTerm"},
440                 dependsOnMethods = {"keywordTermMatch"})
441     public void keywordTermMatchOnNonexistentTerm(String testName) throws Exception {
442         int numMatchesFound = 0;
443         int ZERO_MATCHES_EXPECTED = 0;
444         String kwdTerm = getKwdTermNonExistent();
445         if (logger.isDebugEnabled()) {
446             logger.debug("Attempting match on kwd term '" + kwdTerm + "' ...");
447         }
448         numMatchesFound = readItemListWithFilters(testName, knownResourceId, null, kwdTerm);
449         // Zero matches are expected on a non-existent term.
450         if (logger.isDebugEnabled()) {
451             logger.debug("Found " + numMatchesFound + " match(es), expected " +
452                 ZERO_MATCHES_EXPECTED + " match(es).");
453         }
454         Assert.assertEquals(numMatchesFound, ZERO_MATCHES_EXPECTED);
455     }
456
457     /**
458      * Reads an item list by partial term or keywords, given an authority and a term.
459      * Only one of partialTerm or keywords should be specified. 
460      * If both are specified, keywords will be ignored.
461      * 
462      * @param testName Calling test name
463      * @param authorityCsid The CSID of the authority within which partial term matching
464      *     will be performed.
465      * @param partialTerm A partial term to match item resources.
466      * @param partialTerm A keyword list to match item resources.
467      * @return The number of item resources matched by the partial term.
468      * @throws Exception 
469      */
470     private int readItemListWithFilters(String testName, 
471                 String authorityCsid, String partialTerm, String keywords) throws Exception {
472
473         // Perform setup.
474         int expectedStatusCode = Response.Status.OK.getStatusCode();
475         ServiceRequestType requestType = ServiceRequestType.READ_LIST;
476         testSetup(expectedStatusCode, requestType);
477
478         // Submit the request to the service and store the response.
479         PersonAuthorityClient client = new PersonAuthorityClient();
480         Response res = null;
481         if (authorityCsid != null) {
482                 res = client.readItemList(authorityCsid, partialTerm, keywords);
483         } else {
484             Assert.fail("readItemListByPartialTerm passed null csid!");
485         }
486         AbstractCommonList list = null;
487         try {
488             assertStatusCode(res, testName);
489             list = res.readEntity(AbstractCommonList.class);
490         } finally {
491                 if (res != null) {
492                 res.close();
493             }
494         }
495
496         List<AbstractCommonList.ListItem> items = list.getListItem();
497         int nItemsReturned = items.size();
498
499         return nItemsReturned;
500     }
501     
502     // ---------------------------------------------------------------
503     // Cleanup of resources created during testing
504     // ---------------------------------------------------------------
505     
506     /**
507      * Deletes all resources created by tests, after all tests have been run.
508      *
509      * This cleanup method will always be run, even if one or more tests fail.
510      * For this reason, it attempts to remove all resources created
511      * at any point during testing, even if some of those resources
512      * may be expected to be deleted by certain tests.
513      * @throws Exception 
514      */
515     @AfterClass(alwaysRun=true)
516     public void cleanUp() throws Exception {
517         String noTest = System.getProperty("noTestCleanup");
518         if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
519             if (logger.isDebugEnabled()) {
520                 logger.debug("Skipping Cleanup phase ...");
521             }
522             return;
523         }
524         if (logger.isDebugEnabled()) {
525             logger.debug("Cleaning up temporary resources created for testing ...");
526         }
527         String parentResourceId;
528         String itemResourceId;
529         PersonAuthorityClient client = new PersonAuthorityClient();
530         parentResourceId = knownResourceId;
531         // Clean up item resources.
532         for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
533             itemResourceId = entry.getKey();
534             parentResourceId = entry.getValue();
535             // Note: Any non-success responses from the delete operation
536             // below are ignored and not reported.
537             Response res = client.deleteItem(parentResourceId, itemResourceId);
538             res.close();
539         }
540         // Clean up authority resources.
541         for (String resourceId : allResourceIdsCreated) {
542             // Note: Any non-success responses are ignored and not reported.
543             client.delete(resourceId).close();
544         }
545     }
546
547     // ---------------------------------------------------------------
548     // Utility methods used by tests above
549     // ---------------------------------------------------------------
550
551     // ---------------------------------------------------------------
552     // Utilities: setup routines for search tests
553     // ---------------------------------------------------------------
554
555     public void createAuthority() throws Exception {
556
557         String testName = "createAuthority";
558         if (logger.isDebugEnabled()) {
559             logger.debug(getTestBanner(testName, CLASS_NAME));
560         }
561
562         // Perform setup.
563         int expectedStatusCode = Response.Status.CREATED.getStatusCode();
564         ServiceRequestType requestType = ServiceRequestType.CREATE;
565         testSetup(expectedStatusCode, requestType);
566
567         // Submit the request to the service and store the response.
568         PersonAuthorityClient client = new PersonAuthorityClient();
569         String shortId = createIdentifier();
570         String displayName = "displayName-" + shortId;
571         //String baseRefName = PersonAuthorityClientUtils.createPersonAuthRefName(shortId, null);
572         PoxPayloadOut multipart =
573             PersonAuthorityClientUtils.createPersonAuthorityInstance(
574             displayName, shortId, client.getCommonPartName());
575
576         String newID = null;
577         Response res = client.create(multipart);
578         try {
579             assertStatusCode(res, testName);
580             newID = PersonAuthorityClientUtils.extractId(res);
581         } finally {
582                 if (res != null) {
583                 res.close();
584             }
585         }
586         // Store the refname from the first resource created
587         // for additional tests below.
588         //knownResourceRefName = baseRefName;
589         // Store the ID returned from the first resource created
590         // for additional tests below.
591         if (knownResourceId == null){
592             knownResourceId = newID;
593             //knownResourceRefName = baseRefName;
594         }
595
596         // Store the IDs from every resource created by tests,
597         // so they can be deleted after tests have been run.
598         allResourceIdsCreated.add(newID);
599     }
600
601      /**
602      * Creates an item in the authority, used for partial term matching tests.
603      *
604      * @param authorityCsid The CSID of the Authority in which the term will be created.
605      * @param authRefName The refName of the Authority in which the term will be created.
606      */
607     private void createItemsInAuthorityForPartialTermMatch(
608                 String authorityCsid, String authRefName)
609         throws Exception {
610             
611         String testName = "createItemsInAuthorityForPartialTermMatch";
612
613         int expectedStatusCode = Response.Status.CREATED.getStatusCode();
614         ServiceRequestType requestType = ServiceRequestType.CREATE;
615         testSetup(expectedStatusCode, requestType);
616
617         // Submit the request to the service and store the response.
618         PersonAuthorityClient client = new PersonAuthorityClient();
619         Map<String, String> partialTermPersonMap = new HashMap<String,String>();
620         //
621         // Fill values for the UNICODE item
622         //
623         partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_UNICODE );
624         partialTermPersonMap.put(PersonJAXBSchema.BIRTH_PLACE, TEST_KWD_BIRTH_PLACE);
625         partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
626         partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_NO_QUOTES);
627         
628         List<PersonTermGroup> partialTerms = new ArrayList<PersonTermGroup>();
629         PersonTermGroup term = new PersonTermGroup();
630         term.setTermDisplayName(TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
631         term.setTermName(TEST_PARTIAL_TERM_DISPLAY_NAME_UNICODE);
632         term.setForeName(TEST_PARTIAL_TERM_FORE_NAME);
633         term.setSurName(TEST_PARTIAL_TERM_SUR_NAME_UNICODE);
634         partialTerms.add(term);
635
636         Map<String, List<String>> partialTermRepeatablesMap = new HashMap<String, List<String>>();
637         ArrayList<String> styles = new ArrayList<String>();
638         styles.add(TEST_KWD_UTF8_STYLE);
639         partialTermRepeatablesMap.put(PersonJAXBSchema.SCHOOLS_OR_STYLES, styles);
640
641         createItem(testName, authorityCsid, null /*authRefName*/, client, 
642                 partialTermPersonMap, partialTerms, partialTermRepeatablesMap);
643         //
644         // Adjust values for the QUOTE item
645         //
646         partialTermPersonMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, TEST_SHORT_ID_QUOTE );
647         partialTermPersonMap.put(PersonJAXBSchema.BIO_NOTE, TEST_KWD_BIO_NOTE_DBL_QUOTES);
648         
649         partialTerms.get(0).setTermDisplayName(TEST_PARTIAL_TERM_DISPLAY_NAME_QUOTE);
650         partialTerms.get(0).setSurName(TEST_PARTIAL_TERM_SUR_NAME_QUOTE);
651
652         createItem(testName, authorityCsid, null /*authRefName*/, client, 
653                 partialTermPersonMap, partialTerms, partialTermRepeatablesMap);
654     }
655     
656     private void createItem(
657                 String testName, 
658                 String authorityCsid, 
659                 String authRefName,
660                 PersonAuthorityClient client,
661                 Map<String, String> partialTermPersonMap,
662                 List<PersonTermGroup> partialTerms,
663                 Map<String, List<String>> partialTermRepeatablesMap) throws Exception {
664         PoxPayloadOut multipart =
665             PersonAuthorityClientUtils.createPersonInstance(authorityCsid, null, //authRefName, 
666                 partialTermPersonMap, partialTerms, partialTermRepeatablesMap, client.getItemCommonPartName() );
667
668         String newID = null;
669         Response res = client.createItem(authorityCsid, multipart);
670         try {
671             newID = PersonAuthorityClientUtils.extractId(res);
672         } finally {
673                 if (res != null) {
674                 res.close();
675             }
676         }
677
678         // Store the ID returned from the first item resource created
679         // for additional tests below.
680         if (knownItemResourceId == null){
681             knownItemResourceId = newID;
682             if (logger.isDebugEnabled()) {
683                 logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
684             }
685         }
686
687         // Store the IDs from any item resources created
688         // by tests, along with the IDs of their parents, so these items
689         // can be deleted after all tests have been run.
690         allItemResourceIdsCreated.put(newID, authorityCsid);
691     }
692 }