mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
131073 gjames: SEARCH-189: Always return skipCount and maxItems git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132213 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -35,7 +35,8 @@ import org.junit.runners.Suite.SuiteClasses;
|
||||
* @author Gethin James
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ SearchMapperTests.class, ResultMapperTests.class,SearchQuerySerializerTests.class})
|
||||
@SuiteClasses({ SearchMapperTests.class, ResultMapperTests.class,SearchQuerySerializerTests.class,
|
||||
SearchApiWebscriptTests.class})
|
||||
public class AllSearchApiTests
|
||||
{
|
||||
}
|
||||
|
@@ -47,6 +47,7 @@ import org.alfresco.rest.api.search.impl.ResultMapper;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.api.search.context.SearchContext;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -63,6 +64,8 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.social.support.ParameterMap;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
@@ -84,6 +87,7 @@ public class ResultMapperTests
|
||||
+ "\"facet_fields\":{\"content.size\":[\"Big\",8,\"Brown\",3,\"Fox\",5,\"Jumped\",2,\"somewhere\",3]},\"facet_dates\":{},\"facet_ranges\":{},\"facet_intervals\":{}\n" + " },"
|
||||
+ "\"spellcheck\":{\"searchInsteadFor\":\"alfresco\"},"
|
||||
+ "\"processedDenies\":true, \"lastIndexedTx\":34}";
|
||||
public static final Params EMPTY_PARAMS = Params.valueOf((String)null,(String)null,(WebScriptRequest) null);
|
||||
|
||||
@BeforeClass
|
||||
public static void setupTests() throws Exception
|
||||
@@ -115,7 +119,7 @@ public class ResultMapperTests
|
||||
@Test
|
||||
public void testNoResults() throws Exception
|
||||
{
|
||||
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(SearchQuery.EMPTY,new EmptyResultSet());
|
||||
CollectionWithPagingInfo<Node> collection = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS,new EmptyResultSet());
|
||||
assertNotNull(collection);
|
||||
assertFalse(collection.hasMoreItems());
|
||||
assertTrue(collection.getTotalItems() < 1);
|
||||
@@ -126,7 +130,7 @@ public class ResultMapperTests
|
||||
public void testToCollectionWithPagingInfo() throws Exception
|
||||
{
|
||||
ResultSet results = mockResultset(Arrays.asList(514l));
|
||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(SearchQuery.EMPTY,results);
|
||||
CollectionWithPagingInfo<Node> collectionWithPage = mapper.toCollectionWithPagingInfo(EMPTY_PARAMS,results);
|
||||
assertNotNull(collectionWithPage);
|
||||
Long found = results.getNumberFound();
|
||||
assertEquals(found.intValue(), collectionWithPage.getTotalItems().intValue());
|
||||
|
@@ -0,0 +1,125 @@
|
||||
/*-
|
||||
* #%L
|
||||
* Alfresco Remote API
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.rest.api.search;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.alfresco.service.cmr.repository.StoreRef.PROTOCOL_DELETED;
|
||||
import static org.alfresco.service.cmr.repository.StoreRef.PROTOCOL_TEST;
|
||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_CMIS_ALFRESCO;
|
||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_FTS_ALFRESCO;
|
||||
import static org.alfresco.service.cmr.search.SearchService.LANGUAGE_LUCENE;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import org.alfresco.rest.api.search.impl.SearchMapper;
|
||||
import org.alfresco.rest.api.search.model.Default;
|
||||
import org.alfresco.rest.api.search.model.FacetField;
|
||||
import org.alfresco.rest.api.search.model.FacetFields;
|
||||
import org.alfresco.rest.api.search.model.FacetQuery;
|
||||
import org.alfresco.rest.api.search.model.FilterQuery;
|
||||
import org.alfresco.rest.api.search.model.Limits;
|
||||
import org.alfresco.rest.api.search.model.Query;
|
||||
import org.alfresco.rest.api.search.model.Scope;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.api.search.model.SortDef;
|
||||
import org.alfresco.rest.api.search.model.Spelling;
|
||||
import org.alfresco.rest.api.search.model.Template;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.LimitBy;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchParameters.FieldFacet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tests the SearchApiWebscript class
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class SearchApiWebscriptTests
|
||||
{
|
||||
static SearchApiWebscript webscript = new SearchApiWebscript();
|
||||
|
||||
@Test
|
||||
public void testPaging() throws Exception
|
||||
{
|
||||
Params params = webscript.getParams(null, null, null, null);
|
||||
//Defaults
|
||||
assertNotNull(params.getPaging());
|
||||
assertEquals(Paging.DEFAULT_MAX_ITEMS, params.getPaging().getMaxItems());
|
||||
assertEquals(Paging.DEFAULT_SKIP_COUNT,params.getPaging().getSkipCount());
|
||||
|
||||
params = webscript.getParams(null, null, null, Paging.valueOf(4,20));
|
||||
assertEquals(20, params.getPaging().getMaxItems());
|
||||
assertEquals(4,params.getPaging().getSkipCount());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() throws Exception
|
||||
{
|
||||
Params params = webscript.getParams(null, null, null, null);
|
||||
//Defaults
|
||||
assertNotNull(params.getFilter());
|
||||
|
||||
params = webscript.getParams(null, null, Arrays.asList("name", "size"), null);
|
||||
assertTrue("This isn't used until include is also specfied", params.getFilter().isAllowed("name"));
|
||||
|
||||
assertTrue("Anything is allowed if include hasn't been specfied", params.getFilter().isAllowed("horse"));
|
||||
|
||||
params = webscript.getParams(null, Arrays.asList("cat", "dog"), null, null);
|
||||
assertTrue(params.getFilter().isAllowed("cat"));
|
||||
assertTrue(params.getFilter().isAllowed("dog"));
|
||||
assertFalse(params.getFilter().isAllowed("horse"));
|
||||
|
||||
params = webscript.getParams(null, Arrays.asList("cat", "dog"), Arrays.asList("name", "size"), null);
|
||||
assertTrue(params.getFilter().isAllowed("cat"));
|
||||
assertFalse(params.getFilter().isAllowed("horse"));
|
||||
assertTrue("name and size should be automatically added to the filter list",params.getFilter().isAllowed("name"));
|
||||
assertTrue("name and size should be automatically added to the filter list",params.getFilter().isAllowed("size"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclude() throws Exception
|
||||
{
|
||||
Params params = webscript.getParams(null, null, null, null);
|
||||
//Defaults
|
||||
assertNotNull(params.getInclude());
|
||||
assertEquals(0, params.getInclude().size());
|
||||
|
||||
params = webscript.getParams(null, null, Arrays.asList("name", "size"), null);
|
||||
assertNotNull(params.getInclude());
|
||||
assertEquals(2, params.getInclude().size());
|
||||
}
|
||||
}
|
@@ -51,6 +51,7 @@ import org.alfresco.rest.api.search.model.Spelling;
|
||||
import org.alfresco.rest.api.search.model.Template;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Params;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.LimitBy;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
@@ -74,13 +75,13 @@ public class SearchMapperTests
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testMandatory() throws Exception
|
||||
{
|
||||
SearchParameters searchParameters = searchMapper.toSearchParameters(SearchQuery.EMPTY);
|
||||
SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, SearchQuery.EMPTY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toSearchParameters() throws Exception
|
||||
{
|
||||
SearchParameters searchParameters = searchMapper.toSearchParameters(minimalQuery());
|
||||
SearchParameters searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, minimalQuery());
|
||||
assertNotNull(searchParameters);
|
||||
|
||||
//Test defaults
|
||||
@@ -89,7 +90,7 @@ public class SearchMapperTests
|
||||
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
|
||||
assertEquals(100, searchParameters.getLimit());
|
||||
|
||||
searchParameters = searchMapper.toSearchParameters(helper.searchQueryFromJson());
|
||||
searchParameters = searchMapper.toSearchParameters(ResultMapperTests.EMPTY_PARAMS, helper.searchQueryFromJson());
|
||||
assertNotNull(searchParameters);
|
||||
}
|
||||
|
||||
@@ -488,12 +489,12 @@ public class SearchMapperTests
|
||||
|
||||
//Doesn't error
|
||||
searchMapper.fromLimits(searchParameters, null);
|
||||
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
|
||||
assertEquals(100, searchParameters.getLimit());
|
||||
assertEquals(500, searchParameters.getLimit());
|
||||
assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
|
||||
|
||||
searchMapper.fromLimits(searchParameters, new Limits(null, null));
|
||||
assertEquals(LimitBy.FINAL_SIZE, searchParameters.getLimitBy());
|
||||
assertEquals(100, searchParameters.getLimit());
|
||||
assertEquals(LimitBy.UNLIMITED, searchParameters.getLimitBy());
|
||||
assertEquals(500, searchParameters.getLimit());
|
||||
|
||||
searchMapper.fromLimits(searchParameters, new Limits(null, 34));
|
||||
assertEquals(LimitBy.NUMBER_OF_PERMISSION_EVALUATIONS, searchParameters.getLimitBy());
|
||||
|
Reference in New Issue
Block a user