mirror of
https://github.com/Alfresco/SearchServices.git
synced 2025-09-17 14:21:20 +00:00
SEARCH-2396: Create new test for several iterations on re-indexing the ANAME and APATH fields.
This commit is contained in:
@@ -26,8 +26,42 @@
|
||||
|
||||
package org.alfresco.solr;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import static java.util.Optional.ofNullable;
|
||||
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.BOOLEAN;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CATEGORY;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CHILD_ASSOC_REF;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CONTENT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.DOUBLE;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ENCRYPTED;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.FLOAT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.INT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.LOCALE;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.LONG;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.MLTEXT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.NODE_REF;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.PATH;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.PERIOD;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.QNAME;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.TEXT;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_DAY_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_HOUR_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MINUTE_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MONTH_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_QUARTER_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_SECOND_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_YEAR_FIELD_SUFFIX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -55,41 +89,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static java.util.Optional.ofNullable;
|
||||
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.BOOLEAN;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CATEGORY;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CHILD_ASSOC_REF;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.CONTENT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.DOUBLE;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.ENCRYPTED;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.FLOAT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.INT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.LOCALE;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.LONG;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.MLTEXT;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.NODE_REF;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.PATH;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.PERIOD;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.QNAME;
|
||||
import static org.alfresco.service.cmr.dictionary.DataTypeDefinition.TEXT;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_DAY_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_HOUR_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MINUTE_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_MONTH_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_SECOND_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_QUARTER_FIELD_SUFFIX;
|
||||
import static org.alfresco.solr.SolrInformationServer.UNIT_OF_TIME_YEAR_FIELD_SUFFIX;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link SolrInformationServer} class.
|
||||
*
|
||||
@@ -355,43 +354,65 @@ public class SolrInformationServerTest
|
||||
nodeMetaData.setAncestorPaths(List.of("/1/2/4/7/10", "/1/2/5/8/10", "/1/2/6/9/10"));
|
||||
nodeMetaData.setPaths(List.of());
|
||||
|
||||
// Repeat the operation 2 times to verify updating and existing document removes previous
|
||||
// information in ANAME and APATH fields
|
||||
List<String> expectedANames = Stream.of("0/10",
|
||||
"1/7/10", "1/8/10", "1/9/10",
|
||||
"2/4/7/10", "2/5/8/10", "2/6/9/10",
|
||||
"3/2/4/7/10", "3/2/5/8/10", "3/2/6/9/10",
|
||||
"4/1/2/4/7/10", "4/1/2/5/8/10", "4/1/2/6/9/10",
|
||||
"F/1/2/4/7/10", "F/1/2/5/8/10", "F/1/2/6/9/10")
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
List<String> expectedAPaths = Stream.of("0/1",
|
||||
"1/1/2",
|
||||
"2/1/2/4", "2/1/2/5", "2/1/2/6",
|
||||
"3/1/2/4/7", "3/1/2/5/8", "3/1/2/6/9",
|
||||
"4/1/2/4/7/10", "4/1/2/5/8/10", "4/1/2/6/9/10",
|
||||
"F/1/2/4/7/10", "F/1/2/5/8/10", "F/1/2/6/9/10")
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
infoServer.updatePathRelatedFields(nodeMetaData, doc);
|
||||
|
||||
List<String> anames = doc.getFieldValues(QueryConstants.FIELD_ANAME).stream()
|
||||
.map(aname -> aname.toString())
|
||||
.collect(Collectors.toList())
|
||||
.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedANames, anames);
|
||||
|
||||
List<String> apaths = doc.getFieldValues(QueryConstants.FIELD_APATH).stream()
|
||||
.map(aname -> aname.toString())
|
||||
.collect(Collectors.toList())
|
||||
.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedAPaths, apaths);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeat the indexing operation 2 times to verify that updating and existing document
|
||||
* removes previous information in ANAME and APATH fields
|
||||
*/
|
||||
@Test
|
||||
public void testPathsFieldStorageIterations()
|
||||
{
|
||||
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
NodeMetaData nodeMetaData = new NodeMetaData();
|
||||
nodeMetaData.setAncestorPaths(List.of("/1/2/4/7/10", "/1/2/5/8/10", "/1/2/6/9/10"));
|
||||
nodeMetaData.setPaths(List.of());
|
||||
|
||||
IntStream.range(0, 2).forEach(i ->
|
||||
{
|
||||
|
||||
infoServer.updatePathRelatedFields(nodeMetaData, doc);
|
||||
|
||||
List<String> anames = doc.getFieldValues(QueryConstants.FIELD_ANAME).stream()
|
||||
.map(aname -> aname.toString())
|
||||
.collect(Collectors.toList())
|
||||
.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals("Expecting only 1 aname for level 0 path: 0/10",
|
||||
anames.stream().filter(aname -> aname.startsWith("0/")).count(), 1);
|
||||
assertEquals(anames.stream().filter(aname -> aname.startsWith("1/")).count(), 3);
|
||||
assertEquals(anames.stream().filter(aname -> aname.startsWith("2/")).count(), 3);
|
||||
assertEquals(anames.stream().filter(aname -> aname.startsWith("3/")).count(), 3);
|
||||
assertEquals(anames.stream().filter(aname -> aname.startsWith("4/")).count(), 3);
|
||||
assertEquals(anames.stream().filter(aname -> aname.startsWith("F/")).count(), 3);
|
||||
|
||||
List<String> apaths = doc.getFieldValues(QueryConstants.FIELD_APATH).stream()
|
||||
.map(aname -> aname.toString())
|
||||
.collect(Collectors.toList())
|
||||
.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals("Expecting only 1 aname for level 0 path: 0/1",
|
||||
apaths.stream().filter(apath -> apath.startsWith("0/")).count(), 1);
|
||||
assertEquals("Expecting only 1 aname for level 0 path: 1/1/2",
|
||||
apaths.stream().filter(apath -> apath.startsWith("1/")).count(), 1);
|
||||
assertEquals(apaths.stream().filter(apath -> apath.startsWith("2/")).count(), 3);
|
||||
assertEquals(apaths.stream().filter(apath -> apath.startsWith("3/")).count(), 3);
|
||||
assertEquals(apaths.stream().filter(apath -> apath.startsWith("4/")).count(), 3);
|
||||
assertEquals(apaths.stream().filter(apath -> apath.startsWith("F/")).count(), 3);
|
||||
|
||||
assertEquals(doc.getFieldValues(QueryConstants.FIELD_ANAME).size(), 16);
|
||||
assertEquals(doc.getFieldValues(QueryConstants.FIELD_APATH).size(), 14);
|
||||
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user