From: Aron Roberts Date: Tue, 20 Jul 2010 22:48:36 +0000 (+0000) Subject: CSPACE-2508: Explicitly tests sorting of results from keyword searches. Lays groundwo... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=0c98e6ed94c091e1f1f695a80b87931ffea63d02;p=tmp%2Fjakarta-migration.git CSPACE-2508: Explicitly tests sorting of results from keyword searches. Lays groundwork for restricting the scope of sorting tests to temporary records created during client testing. --- diff --git a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java index 7d8d8007c..5b7077b7a 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IClientQueryParams.java @@ -1,6 +1,33 @@ +/** + * 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; +/** + * IClientQueryParams.java + * + * Specifies contants used as query parameters in client requests to services. + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + */ + public interface IClientQueryParams { + public static final String PAGE_SIZE_PARAM = "pgSz"; public static final String START_PAGE_PARAM = "pgNum"; public static final String SORT_BY_PARAM = "sortBy"; diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java index 26bb7df7f..09338dfcc 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java @@ -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. @@ -14,13 +14,12 @@ * 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 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 keywordSearchSortedBy(String keywords, String sortFieldName) { + return movementProxy.keywordSearchSortedBy(keywords, sortFieldName); + } /** * @param csid diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java index 739553946..3bd9e3443 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java @@ -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 readListSortedBy( - @QueryParam("sortBy") String sortFieldName); + @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); + + @GET + @Produces({"application/xml"}) + ClientResponse keywordSearchSortedBy( + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, + @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); // List Authority References @GET diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java index ffd0ee3c9..7602981da 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java @@ -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 movementIdsCreated = new ArrayList(); /* (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 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 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; + + } + }