mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
80669: Merged WAT1 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 78166: ACE-1582: Enhancements to the facet service to persist only the modified value(s) rather than the whole facet's properties. Also fixed facets cache and facets reordering NPE. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82966 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.repo.search;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
@@ -31,7 +30,6 @@ import org.alfresco.repo.search.impl.lucene.index.IndexInfoTest;
|
||||
import org.alfresco.repo.search.impl.parsers.CMISTest;
|
||||
import org.alfresco.repo.search.impl.parsers.CMIS_FTSTest;
|
||||
import org.alfresco.repo.search.impl.parsers.FTSTest;
|
||||
import org.alfresco.repo.search.impl.solr.facet.SolrFacetHelperTest;
|
||||
import org.alfresco.util.NumericEncodingTest;
|
||||
|
||||
/**
|
||||
@@ -63,11 +61,7 @@ public class SearchTestSuite extends TestSuite
|
||||
suite.addTestSuite(CMIS_FTSTest.class);
|
||||
suite.addTestSuite(CMISTest.class);
|
||||
suite.addTestSuite(FTSTest.class);
|
||||
suite.addTest(new JUnit4TestAdapter(SolrFacetHelperTest.class));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
@@ -34,15 +34,16 @@ public class SolrFacetComparatorTest
|
||||
{
|
||||
@Test public void simpleSortOfSortedFacets() throws Exception
|
||||
{
|
||||
List<String> expectedIds = Arrays.asList(new String[] { "a", "b", "c"});
|
||||
List<String> expectedIds = Arrays.asList(new String[] { "a", "b", "c", "d"});
|
||||
|
||||
SolrFacetProperties.Builder builder = new SolrFacetProperties.Builder();
|
||||
|
||||
List<SolrFacetProperties> facets = Arrays.asList(new SolrFacetProperties[]
|
||||
{
|
||||
builder.filterID("c").index(1).build(),
|
||||
builder.filterID("b").index(2).build(),
|
||||
builder.filterID("a").index(3).build(),
|
||||
builder.filterID("a").build(),
|
||||
builder.filterID("d").build(),
|
||||
builder.filterID("b").build(),
|
||||
builder.filterID("c").build(),
|
||||
});
|
||||
Collections.sort(facets, new SolrFacetComparator(expectedIds));
|
||||
|
||||
|
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.search.impl.solr.facet;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* This class contains tests for the class {@link SolrFacetConfig}
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
* @since 5.0
|
||||
*/
|
||||
public class SolrFacetConfigTest
|
||||
{
|
||||
private static ClassPathXmlApplicationContext context;
|
||||
private static Properties rawProperties;
|
||||
private static SolrFacetConfig facetConfig;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception
|
||||
{
|
||||
context = new ClassPathXmlApplicationContext(new String[] { "classpath:facets/test-facet-property-context.xml" },
|
||||
ApplicationContextHelper.getApplicationContext());
|
||||
|
||||
rawProperties = context.getBean("solrFacetRawPropertiesTest", Properties.class);
|
||||
facetConfig = context.getBean("solrFacetConfigsTest", SolrFacetConfig.class);
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws Exception
|
||||
{
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic() throws Exception
|
||||
{
|
||||
SolrFacetConfig config = null;
|
||||
try
|
||||
{
|
||||
config = new SolrFacetConfig(null, "");
|
||||
fail("Null properties should have been detected");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
try
|
||||
{
|
||||
config = new SolrFacetConfig(rawProperties, null);
|
||||
fail("Null properties should have been detected");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
config = new SolrFacetConfig(rawProperties, "default,custom");
|
||||
config.setNamespaceService(context.getBean("namespaceService", NamespaceService.class));
|
||||
try
|
||||
{
|
||||
config.getDefaultFacets();
|
||||
fail("Initialization should be done.");
|
||||
}
|
||||
catch (IllegalStateException e)
|
||||
{
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() throws Exception
|
||||
{
|
||||
Map<String, SolrFacetProperties> defaultProps = facetConfig.getDefaultFacets();
|
||||
assertNotNull(defaultProps);
|
||||
assertEquals("Incorrect number of properties", 4, defaultProps.size());
|
||||
|
||||
// loaded from /facets/facets-config-sample.properties
|
||||
SolrFacetProperties contentSizeFP = defaultProps.get("test_filter_content_size");
|
||||
assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}content.size", contentSizeFP.getFacetQName().toString());
|
||||
assertEquals("faceted-search.facet-menu.facet.size", contentSizeFP.getDisplayName());
|
||||
assertEquals("alfresco/search/FacetFilters", contentSizeFP.getDisplayControl());
|
||||
assertEquals(5, contentSizeFP.getMaxFilters());
|
||||
assertEquals(1, contentSizeFP.getHitThreshold());
|
||||
assertEquals(4, contentSizeFP.getMinFilterValueLength());
|
||||
assertEquals("ALPHABETICALLY", contentSizeFP.getSortBy());
|
||||
assertEquals("ALL", contentSizeFP.getScope());
|
||||
assertEquals(0, contentSizeFP.getScopedSites().size());
|
||||
assertEquals(true, contentSizeFP.isEnabled());
|
||||
assertEquals(1, contentSizeFP.getCustomProperties().size());
|
||||
String customValue = (String) contentSizeFP.getCustomProperties().iterator().next().getValue();
|
||||
assertTrue(Boolean.valueOf(customValue));
|
||||
|
||||
// loaded from /facets/extension/facets-config-custom-sample.properties
|
||||
SolrFacetProperties descFP = defaultProps.get("test_filter_description");
|
||||
assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}description", descFP.getFacetQName().toString());
|
||||
assertEquals("faceted-search.facet-menu.facet.description", descFP.getDisplayName());
|
||||
assertEquals("alfresco/search/FacetFilters", descFP.getDisplayControl());
|
||||
assertEquals(3, descFP.getMaxFilters());
|
||||
assertEquals(1, descFP.getHitThreshold());
|
||||
assertEquals(2, descFP.getMinFilterValueLength());
|
||||
assertEquals("DESCENDING", descFP.getSortBy());
|
||||
assertEquals("SCOPED_SITES", descFP.getScope());
|
||||
assertEquals(0, descFP.getScopedSites().size());
|
||||
assertEquals(true, descFP.isEnabled());
|
||||
|
||||
// See if the overrides worked
|
||||
SolrFacetProperties creatorFP = defaultProps.get("test_filter_creator");
|
||||
assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}creator.__.u", creatorFP.getFacetQName().toString());
|
||||
|
||||
String msg = "The value has not been overridden with the value from the custom properties";
|
||||
assertEquals(msg, 10, creatorFP.getMaxFilters());
|
||||
assertEquals(msg, 5, creatorFP.getHitThreshold());
|
||||
assertEquals(msg, 14, creatorFP.getMinFilterValueLength());
|
||||
assertEquals(msg, 1, creatorFP.getScopedSites().size());
|
||||
assertEquals("site1", creatorFP.getScopedSites().iterator().next());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideOrder() throws Exception
|
||||
{
|
||||
ApplicationEvent applicationEvent = new ApplicationEvent(this)
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
};
|
||||
|
||||
/*
|
||||
* Override order: default,custom
|
||||
*/
|
||||
SolrFacetConfig config = new SolrFacetConfig(rawProperties, "default,custom");
|
||||
config.setNamespaceService(context.getBean("namespaceService", NamespaceService.class));
|
||||
config.onBootstrap(applicationEvent);
|
||||
|
||||
SolrFacetProperties creatorFP = config.getDefaultFacets().get("test_filter_creator");
|
||||
assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}creator.__.u", creatorFP.getFacetQName().toString());
|
||||
assertEquals(10, creatorFP.getMaxFilters());
|
||||
assertEquals(5, creatorFP.getHitThreshold());
|
||||
assertEquals(14, creatorFP.getMinFilterValueLength());
|
||||
assertEquals(1, creatorFP.getScopedSites().size());
|
||||
assertEquals("site1", creatorFP.getScopedSites().iterator().next());
|
||||
|
||||
/*
|
||||
* Override order: custom,default
|
||||
*/
|
||||
config = new SolrFacetConfig(rawProperties, "custom,default");
|
||||
config.setNamespaceService(context.getBean("namespaceService", NamespaceService.class));
|
||||
config.onBootstrap(applicationEvent);
|
||||
|
||||
creatorFP = config.getDefaultFacets().get("test_filter_creator");
|
||||
assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}creator.__.u", creatorFP.getFacetQName().toString());
|
||||
assertEquals(5, creatorFP.getMaxFilters());
|
||||
assertEquals(1, creatorFP.getHitThreshold());
|
||||
assertEquals(4, creatorFP.getMinFilterValueLength());
|
||||
assertEquals(0, creatorFP.getScopedSites().size());
|
||||
}
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.search.impl.solr.facet;
|
||||
|
||||
import junit.framework.JUnit4TestAdapter;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
public class SolrFacetTestSuite extends TestSuite
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates the test suite
|
||||
*
|
||||
* @return the test suite
|
||||
*/
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
suite.addTest(new JUnit4TestAdapter(SolrFacetHelperTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(SolrFacetServiceImplTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(SolrFacetConfigTest.class));
|
||||
|
||||
return suite;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user