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