]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2508: Explicitly tests sorting of results from keyword searches. Lays groundwo...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 20 Jul 2010 22:48:36 +0000 (22:48 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 20 Jul 2010 22:48:36 +0000 (22:48 +0000)
services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java
services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java
services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java
services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java

index 7d8d8007c3a26ab34f03355fa745b48082001e8e..5b7077b7a2d4e6cdb1227bdba7f3135f8a9fe942 100644 (file)
@@ -1,6 +1,33 @@
+/**\r
+ * This document is a part of the source code and related artifacts\r
+ * for CollectionSpace, an open source collections management system\r
+ * for museums and related institutions:\r
+ *\r
+ * http://www.collectionspace.org\r
+ * http://wiki.collectionspace.org\r
+ *\r
+ * Copyright © 2009 Regents of the University of California\r
+ *\r
+ * Licensed under the Educational Community License (ECL), Version 2.0.\r
+ * You may not use this file except in compliance with this License.\r
+ *\r
+ * You may obtain a copy of the ECL 2.0 License at\r
+ * https://source.collectionspace.org/collection-space/LICENSE.txt\r
+ */\r
+\r
 package org.collectionspace.services.client;\r
 \r
+/**\r
+ * IClientQueryParams.java\r
+ *\r
+ * Specifies contants used as query parameters in client requests to services.\r
+ *\r
+ * $LastChangedBy: $\r
+ * $LastChangedRevision: $\r
+ */\r
+\r
 public interface IClientQueryParams {\r
+\r
     public static final String PAGE_SIZE_PARAM = "pgSz";\r
     public static final String START_PAGE_PARAM = "pgNum";\r
     public static final String SORT_BY_PARAM = "sortBy";\r
index 26bb7df7f910b5332a1649929e06ad17bf6127f5..09338dfcc2192cc456b6fe7d38acd4dd5524e1ea 100644 (file)
@@ -6,7 +6,7 @@
  * http://www.collectionspace.org
  * http://wiki.collectionspace.org
  *
- * Copyright (c) 2009 Regents of the University of California
+ * Copyright © 2009 Regents of the University of California
  *
  * Licensed under the Educational Community License (ECL), Version 2.0.
  * You may not use this file except in compliance with this License.
  * You may obtain a copy of the ECL 2.0 License at
  * https://source.collectionspace.org/collection-space/LICENSE.txt
  */
+
 package org.collectionspace.services.client;
 
-import javax.ws.rs.PathParam;
 import javax.ws.rs.core.Response;
 
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-//import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.movement.MovementsCommonList;
 
 import org.jboss.resteasy.client.ProxyFactory;
@@ -42,6 +41,7 @@ public class MovementClient extends AbstractServiceClientImpl {
     /* (non-Javadoc)
      * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent()
      */
+    @Override
     public String getServicePathComponent() {
         return "movements";
     }
@@ -73,6 +73,7 @@ public class MovementClient extends AbstractServiceClientImpl {
     /**
      * allow to reset proxy as per security needs
      */
+    @Override
     public void setProxy() {
         if (useAuth()) {
             movementProxy = ProxyFactory.create(MovementProxy.class,
@@ -108,6 +109,16 @@ public class MovementClient extends AbstractServiceClientImpl {
     public ClientResponse<MovementsCommonList> readListSortedBy(String sortFieldName) {
         return movementProxy.readListSortedBy(sortFieldName);
     }
+
+    /**
+     * @param sortFieldName
+     * @param keywords
+     * @return
+     * @see org.collectionspace.services.client.MovementProxy#keywordSearchSortedBy(java.lang.String, java.lang.String)
+     */
+    public ClientResponse<MovementsCommonList> keywordSearchSortedBy(String keywords, String sortFieldName) {
+        return movementProxy.keywordSearchSortedBy(keywords, sortFieldName);
+    }
     
     /**
      * @param csid
index 7395539465d886d9de7b587d7c2b933a35677dbb..3bd9e3443334460bd08d1dd4b693498c523f08d6 100644 (file)
@@ -1,3 +1,20 @@
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+ *
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+ *
+ * Copyright © 2009 Regents of the University of California
+ *
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+ *
+ * You may obtain a copy of the ECL 2.0 License at
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+
 package org.collectionspace.services.client;
 
 import javax.ws.rs.Consumes;
@@ -11,6 +28,7 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Response;
 
+import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.movement.MovementsCommonList;
 import org.jboss.resteasy.client.ClientResponse;
@@ -18,7 +36,10 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 /**
- * @version $Revision$
+ * MovementClient.java
+ *
+ * $LastChangedRevision$
+ * $LastChangedDate$
  */
 @Path("/movements/")
 @Produces({"multipart/mixed"})
@@ -53,7 +74,13 @@ public interface MovementProxy extends CollectionSpaceProxy {
     @GET
     @Produces({"application/xml"})
     ClientResponse<MovementsCommonList> readListSortedBy(
-        @QueryParam("sortBy") String sortFieldName);
+        @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName);
+
+    @GET
+    @Produces({"application/xml"})
+    ClientResponse<MovementsCommonList> keywordSearchSortedBy(
+        @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
+        @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName);
 
     // List Authority References
     @GET
index ffd0ee3c9c4755fab61dffd57757a24f14413536..7602981dad9b8a1b20ce7fbcd24d7fcdd24df92d 100644 (file)
@@ -61,10 +61,12 @@ public class MovementSortByTest extends BaseServiceTest {
 
     private final String CLASS_NAME = MovementSortByTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
+
+    // Instance variables specific to this test.
     final String DELIMITER_SCHEMA_AND_FIELD = ":";
     final String KEYWORD_DESCENDING_SEARCH = "DESC";
-    // Instance variables specific to this test.
     final String SERVICE_PATH_COMPONENT = "movements";
+    final String TEST_SPECIFIC_KEYWORD = "msotebstpfscn";
     private List<String> movementIdsCreated = new ArrayList<String>();
 
     /* (non-Javadoc)
@@ -140,6 +142,59 @@ public class MovementSortByTest extends BaseServiceTest {
 
     }
 
+    /*
+     * Tests whether a list of records, obtained by a keyword search, and
+     * sorted by a String field in ascending order, is returned in the expected order.
+     *
+     * This verifies that summary list results from keyword searches, in
+     * addition to 'read list' requests, can be returned in sorted order.
+     */
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+    dependsOnMethods = {"createList"})
+    public void sortKeywordSearchResultsByStringFieldAscending(String testName) throws Exception {
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+
+        String sortFieldName = qualifySortFieldName(MovementJAXBSchema.MOVEMENT_NOTE);
+        if (logger.isDebugEnabled()) {
+            logger.debug("Sorting on field name=" + sortFieldName);
+        }
+        MovementsCommonList list = keywordSearchSortedBy(TEST_SPECIFIC_KEYWORD, sortFieldName);
+        List<MovementsCommonList.MovementListItem> items =
+                list.getMovementListItem();
+
+        String[] values = new String[100];
+        Collator usEnglishCollator = Collator.getInstance(Locale.US);
+        int i = 0;
+        for (MovementsCommonList.MovementListItem item : items) {
+            // Because movementNote is not currently a summary field
+            // (returned in summary list items), we will need to verify
+            // sort order by retrieving full records, using the
+            // IDs provided in the summary list items. amd then retriving
+            // the value of that field from each of those records.
+            MovementsCommon movement = read(item.getCsid());
+            values[i] = movement.getMovementNote();
+            if (logger.isDebugEnabled()) {
+                logger.debug("list-item[" + i + "] movementNote=" + values[i]);
+            }
+            // Verify that the value of the specified field in the current record
+            // is equal to or greater than its value in the previous record,
+            // using a locale-specific collator.
+            //
+            // (Note: when used with certain text, this test case could potentially
+            // reflect inconsistencies, if any, between Java's collator and the
+            // collator used for ordering by the database.  To help avoid this,
+            // it might be useful to keep test strings fairly generic.)
+            if (i > 0) {
+                Assert.assertTrue(usEnglishCollator.compare(values[i], values[i - 1]) >= 0);
+            }
+            i++;
+        }
+
+    }
+
     /*
      * Tests whether a list of records, sorted by a String field in
      * descending order, is returned in the expected order.
@@ -419,7 +474,7 @@ public class MovementSortByTest extends BaseServiceTest {
     public Object[][] unsortedValues() {
         // Add a test record-specific string so we have the option of
         // constraining tests to only test records, in list or search results.
-        final String TEST_RECORD_SPECIFIC_STRING = CLASS_NAME + " " + "jlmbsoq";
+        final String TEST_RECORD_SPECIFIC_STRING = CLASS_NAME + " " + TEST_SPECIFIC_KEYWORD;
         return new Object[][]{
                     {1, "Aardvark and plumeria. " + TEST_RECORD_SPECIFIC_STRING, "2009-01-29T00:00:05Z"},
                     {4, "Bat fling off wall. " + TEST_RECORD_SPECIFIC_STRING, "2010-08-30T00:00:00Z"},
@@ -547,4 +602,31 @@ public class MovementSortByTest extends BaseServiceTest {
 
     }
 
+    private MovementsCommonList keywordSearchSortedBy(String keywords,
+            String sortFieldName) throws Exception {
+
+        String testName = "keywordSearchSortedBy";
+        testSetup(STATUS_OK, ServiceRequestType.READ);
+
+        // Submit the request to the service and store the response.
+        MovementClient client = new MovementClient();
+
+        ClientResponse<MovementsCommonList> res =
+                client.keywordSearchSortedBy(keywords, sortFieldName);
+        MovementsCommonList list = res.getEntity();
+        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);
+
+        return list;
+
+    }
+
 }