mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-09-10 14:11:25 +00:00
[MNT-24778] Added test case and overflow handling for int conversion
This commit is contained in:
@@ -3849,7 +3849,8 @@ public class SolrInformationServer implements InformationServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private NamedList<Integer> getFacets(SolrQueryRequest request, String query, String field, int minCount, long maxCount)
|
NamedList<Integer> getFacets(SolrQueryRequest request, String query, String field, int minCount,
|
||||||
|
long maxCount)
|
||||||
{
|
{
|
||||||
ModifiableSolrParams params =
|
ModifiableSolrParams params =
|
||||||
new ModifiableSolrParams(request.getParams())
|
new ModifiableSolrParams(request.getParams())
|
||||||
@@ -3857,7 +3858,7 @@ public class SolrInformationServer implements InformationServer
|
|||||||
.set(CommonParams.ROWS, 0)
|
.set(CommonParams.ROWS, 0)
|
||||||
.set(FacetParams.FACET, true)
|
.set(FacetParams.FACET, true)
|
||||||
.set(FacetParams.FACET_FIELD, field)
|
.set(FacetParams.FACET_FIELD, field)
|
||||||
.set(FacetParams.FACET_LIMIT, (int)maxCount)
|
.set(FacetParams.FACET_LIMIT, Math.toIntExact(Math.min(maxCount, Integer.MAX_VALUE)))
|
||||||
.set(FacetParams.FACET_MINCOUNT, minCount);
|
.set(FacetParams.FACET_MINCOUNT, minCount);
|
||||||
|
|
||||||
SolrQueryResponse response = cloud.getResponse(nativeRequestHandler, request, params);
|
SolrQueryResponse response = cloud.getResponse(nativeRequestHandler, request, params);
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
package org.alfresco.solr;
|
package org.alfresco.solr;
|
||||||
|
|
||||||
import static java.util.Optional.ofNullable;
|
import static java.util.Optional.ofNullable;
|
||||||
|
|
||||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ANY;
|
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ANY;
|
||||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ASSOC_REF;
|
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ASSOC_REF;
|
||||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.BOOLEAN;
|
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.BOOLEAN;
|
||||||
@@ -71,11 +70,11 @@ import static org.mockito.Mockito.when;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -533,5 +532,38 @@ public class SolrInformationServerTest
|
|||||||
// verifies if the method was called
|
// verifies if the method was called
|
||||||
verify(updateRequestProcessor).processAdd(any());
|
verify(updateRequestProcessor).processAdd(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetFacets() {
|
||||||
|
|
||||||
|
SimpleOrderedMap<Object> responseContent = new SimpleOrderedMap<>();
|
||||||
|
// Create facet_fields (TXID) as SimpleOrderedMap with Integer as value type
|
||||||
|
SimpleOrderedMap<Object> txidFacet = new SimpleOrderedMap<>();
|
||||||
|
txidFacet.add("1", 1);
|
||||||
|
txidFacet.add("2", 1);
|
||||||
|
txidFacet.add("3", 1);
|
||||||
|
// Create and populate the NamedList to simulate facet_counts
|
||||||
|
NamedList<Object> facetCounts = new NamedList<>();
|
||||||
|
facetCounts.add("facet_queries", new SimpleOrderedMap<>());
|
||||||
|
facetCounts.add("facet_fields", new SimpleOrderedMap<>());
|
||||||
|
// Add TXID facet to facet_fields
|
||||||
|
SimpleOrderedMap<Object> facetFields = (SimpleOrderedMap<Object>) facetCounts.get("facet_fields");
|
||||||
|
facetFields.add("TXID", txidFacet);
|
||||||
|
// Add the facet_counts to the main facetMap
|
||||||
|
responseContent.add("facet_counts", facetCounts);
|
||||||
|
// Set up the request handler to return the fake response.
|
||||||
|
doAnswer(invocation -> {
|
||||||
|
SolrQueryResponse solrQueryResponse = invocation.getArgument(1);
|
||||||
|
solrQueryResponse.setAllValues(responseContent);
|
||||||
|
return null;
|
||||||
|
}).when(handler).handleRequest(any(SolrQueryRequest.class), any(SolrQueryResponse.class));
|
||||||
|
NamedList<Integer> actualResult = infoServer.getFacets(request, "TXID:[1 TO 411]", "TXID", 1, 3);
|
||||||
|
assertEquals(new NamedList<>() {
|
||||||
|
{
|
||||||
|
add("1", 1);
|
||||||
|
add("2", 1);
|
||||||
|
add("3", 1);
|
||||||
|
}
|
||||||
|
}, actualResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user