Merge branch 'main' into CST-6761-NewUsersMightBeRegisteredInMassiveWayByRobot

This commit is contained in:
Davide Negretti
2022-09-26 15:47:01 +02:00
4 changed files with 22 additions and 4 deletions

View File

@@ -52,6 +52,9 @@ public class SearchUtils {
*/
private SearchUtils() { }
/**
* Return an instance of the {@link SearchService}.
*/
public static SearchService getSearchService() {
if (searchService == null) {
org.dspace.kernel.ServiceManager manager = DSpaceServicesFactory.getInstance().getServiceManager();
@@ -60,6 +63,16 @@ public class SearchUtils {
return searchService;
}
/**
* Clear the cached {@link SearchService} instance, forcing it to be retrieved from the service manager again
* next time {@link SearchUtils#getSearchService} is called.
* In practice, this is only necessary for integration tests in some environments
* where the cached version may no longer be up to date between tests.
*/
public static void clearCachedSearchService() {
searchService = null;
}
public static DiscoveryConfiguration getDiscoveryConfiguration() {
return getDiscoveryConfiguration(null, null);
}

View File

@@ -18,6 +18,7 @@ import java.util.TimeZone;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.builder.AbstractBuilder;
import org.dspace.discovery.SearchUtils;
import org.dspace.servicemanager.DSpaceKernelImpl;
import org.dspace.servicemanager.DSpaceKernelInit;
import org.junit.AfterClass;
@@ -104,6 +105,7 @@ public class AbstractDSpaceIntegrationTest {
// Unload DSpace services
AbstractBuilder.destroy();
SearchUtils.clearCachedSearchService();
// NOTE: We explicitly do NOT stop/destroy the kernel, as it is cached
// in the Spring ApplicationContext. By default, to speed up tests,

View File

@@ -39,10 +39,8 @@ import org.dspace.discovery.SearchUtils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class MetadataExportSearchIT extends AbstractIntegrationTestWithDatabase {
private String subject1 = "subject1";
@@ -55,13 +53,15 @@ public class MetadataExportSearchIT extends AbstractIntegrationTestWithDatabase
private Collection collection;
private Logger logger = Logger.getLogger(MetadataExportSearchIT.class);
private ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
private SearchService searchService = SearchUtils.getSearchService();
private SearchService searchService;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
searchService = SearchUtils.getSearchService();
// dummy search so that the SearchService gets called in a test context first
DiscoverQuery query = new DiscoverQuery();
query.setMaxResults(0);

View File

@@ -60,6 +60,7 @@ import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
import org.dspace.xmlworkflow.storedcomponents.PoolTask;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.service.ClaimedTaskService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
@@ -69,7 +70,7 @@ import org.springframework.mock.web.MockHttpServletRequest;
public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
protected SearchService searchService = SearchUtils.getSearchService();
protected SearchService searchService;
XmlWorkflowService workflowService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService();
@@ -92,9 +93,11 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
.getMetadataAuthorityService();
@Override
@Before
public void setUp() throws Exception {
super.setUp();
configurationService.setProperty("solr-database-resync.time-until-reindex", 1);
searchService = SearchUtils.getSearchService();
}
@Test