Address questions about dummy methods. This breaks tests. #2893

Merge more from dspace-server-webapp to make tests work again.
Tidy up XML layout.  Improve alignment of declared to actual dependencies.
This commit is contained in:
Mark H. Wood
2020-07-29 12:48:31 -04:00
parent ecd8a88633
commit 8ee4b7ab9d
7 changed files with 178 additions and 33 deletions

View File

@@ -170,6 +170,7 @@
install of DSpace, against which Tests can be run. --> install of DSpace, against which Tests can be run. -->
<plugin> <plugin>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<configuration> <configuration>
<outputDirectory>${project.build.directory}/testing</outputDirectory> <outputDirectory>${project.build.directory}/testing</outputDirectory>
<artifactItems> <artifactItems>
@@ -241,6 +242,7 @@
<dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir> <dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
<!-- Turn off any DSpace logging --> <!-- Turn off any DSpace logging -->
<dspace.log.init.disable>true</dspace.log.init.disable> <dspace.log.init.disable>true</dspace.log.init.disable>
<solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
@@ -255,6 +257,7 @@
<dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir> <dspace.dir>${agnostic.build.dir}/testing/dspace/</dspace.dir>
<!-- Turn off any DSpace logging --> <!-- Turn off any DSpace logging -->
<dspace.log.init.disable>true</dspace.log.init.disable> <dspace.log.init.disable>true</dspace.log.init.disable>
<solr.install.dir>${agnostic.build.dir}/testing/dspace/solr/</solr.install.dir>
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
@@ -323,6 +326,11 @@
<artifactId>apache-jena-libs</artifactId> <artifactId>apache-jena-libs</artifactId>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
<dependency> <dependency>
<groupId>commons-codec</groupId> <groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId> <artifactId>commons-codec</artifactId>
@@ -477,11 +485,86 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.client.version}</version>
</dependency>
<!-- Solr Core is needed for Integration Tests (to run a MockSolrServer) -->
<!-- The following Solr / Lucene dependencies also support integration tests -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<scope>test</scope>
<version>${solr.client.version}</version>
<exclusions>
<exclusion>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-continuation</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-http</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-rewrite</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency> <dependency>
<groupId>org.apache.solr</groupId> <groupId>org.apache.solr</groupId>
<artifactId>solr-cell</artifactId> <artifactId>solr-cell</artifactId>
<exclusions> <exclusions>
<!-- Newer versions provided in our parent POM --> <!-- Newer versions provided in our parent POM -->
<exclusion>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>org.ow2.asm</groupId> <groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId> <artifactId>asm-commons</artifactId>
@@ -536,6 +619,35 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>${solr.client.version}</version>
</dependency>
<!-- Reminder: Keep icu4j (in Parent POM) synced with version used by lucene-analyzers-icu below,
otherwise ICUFoldingFilterFactory may throw errors in tests. -->
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-icu</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-smartcn</artifactId>
<version>${solr.client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers-stempel</artifactId>
<version>${solr.client.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.6.0</version>
</dependency>
<dependency> <dependency>
<groupId>com.maxmind.geoip2</groupId> <groupId>com.maxmind.geoip2</groupId>
@@ -716,7 +828,7 @@
<dependency> <dependency>
<groupId>org.xmlunit</groupId> <groupId>org.xmlunit</groupId>
<artifactId>xmlunit-matchers</artifactId> <artifactId>xmlunit-core</artifactId>
<version>2.6.3</version> <version>2.6.3</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -19,19 +19,29 @@
<context:annotation-config/> <!-- allows us to use spring annotations in beans --> <context:annotation-config/> <!-- allows us to use spring annotations in beans -->
<bean class="org.dspace.discovery.SolrServiceImpl" id="org.dspace.discovery.SearchService"/> <bean class="org.dspace.discovery.SolrServiceImpl"
id="org.dspace.discovery.SearchService"/>
<alias name="org.dspace.discovery.SearchService" alias="org.dspace.discovery.IndexingService"/> <alias name="org.dspace.discovery.SearchService"
alias="org.dspace.discovery.IndexingService"/>
<!-- These beans have been added so that we can mock our AuthoritySearchService in the tests--> <!-- These beans have been added so that we can mock our AuthoritySearchService in the tests-->
<bean class="org.dspace.authority.MockAuthoritySolrServiceImpl" id="org.dspace.authority.AuthoritySearchService"/> <bean class="org.dspace.authority.MockAuthoritySolrServiceImpl"
<alias name="org.dspace.authority.AuthoritySearchService" alias="org.dspace.authority.indexer.AuthorityIndexingService"/> id="org.dspace.authority.AuthoritySearchService"/>
<alias name="org.dspace.authority.AuthoritySearchService"
alias="org.dspace.authority.indexer.AuthorityIndexingService"/>
<bean id="org.dspace.discovery.SolrSearchCore" class="org.dspace.discovery.MockSolrSearchCore" autowire-candidate="true"/> <bean id="org.dspace.discovery.MockSolrSearchCore"
class="org.dspace.discovery.MockSolrSearchCore"
autowire-candidate="true"/>
<!--<bean class="org.dspace.discovery.SolrServiceIndexOutputPlugin" id="solrServiceIndexOutputPlugin"/>--> <!--<bean class="org.dspace.discovery.SolrServiceIndexOutputPlugin"
id="solrServiceIndexOutputPlugin"/>-->
<!-- Statistics services are both lazy loaded (by name), as you are likely just using ONE of them and not both --> <!-- Statistics services are both lazy loaded (by name), as you are likely
<bean id="solrLoggerService" class="org.dspace.statistics.MockSolrLoggerServiceImpl" lazy-init="true"/> just using ONE of them and not both -->
<bean id="solrLoggerService"
class="org.dspace.statistics.MockSolrLoggerServiceImpl"
lazy-init="true"/>
</beans> </beans>

View File

@@ -0,0 +1,3 @@
<?xml version='1.0'?>
<!-- This empty configuration is required to start EmbeddedSolrServer for Integration Tests (see MockSolrServer) -->
<solr/>

View File

@@ -15,7 +15,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.dspace.app.launcher.ScriptLauncher; import org.dspace.app.launcher.ScriptLauncher;
import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler; import org.dspace.app.scripts.handler.impl.TestDSpaceRunnableHandler;
import org.dspace.authority.AuthoritySearchService;
import org.dspace.authority.MockAuthoritySolrServiceImpl; import org.dspace.authority.MockAuthoritySolrServiceImpl;
import org.dspace.authorize.AuthorizeException; import org.dspace.authorize.AuthorizeException;
import org.dspace.builder.AbstractBuilder; import org.dspace.builder.AbstractBuilder;
@@ -23,12 +22,12 @@ import org.dspace.content.Community;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.I18nUtil; import org.dspace.core.I18nUtil;
import org.dspace.discovery.MockSolrSearchCore; import org.dspace.discovery.MockSolrSearchCore;
import org.dspace.discovery.SolrSearchCore;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import org.dspace.eperson.Group; import org.dspace.eperson.Group;
import org.dspace.eperson.factory.EPersonServiceFactory; import org.dspace.eperson.factory.EPersonServiceFactory;
import org.dspace.eperson.service.EPersonService; import org.dspace.eperson.service.EPersonService;
import org.dspace.eperson.service.GroupService; import org.dspace.eperson.service.GroupService;
import org.dspace.kernel.ServiceManager;
import org.dspace.services.factory.DSpaceServicesFactory; import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.statistics.MockSolrLoggerServiceImpl; import org.dspace.statistics.MockSolrLoggerServiceImpl;
import org.dspace.storage.rdbms.DatabaseUtils; import org.dspace.storage.rdbms.DatabaseUtils;
@@ -181,21 +180,20 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati
parentCommunity = null; parentCommunity = null;
cleanupContext(); cleanupContext();
ServiceManager serviceManager = DSpaceServicesFactory.getInstance().getServiceManager();
// Clear the search core. // Clear the search core.
MockSolrSearchCore searchService = DSpaceServicesFactory.getInstance() MockSolrSearchCore searchService = serviceManager
.getServiceManager() .getServiceByName(null, MockSolrSearchCore.class);
.getServiceByName(SolrSearchCore.class.getName(), MockSolrSearchCore.class);
searchService.reset(); searchService.reset();
MockSolrLoggerServiceImpl statisticsService = DSpaceServicesFactory.getInstance() MockSolrLoggerServiceImpl statisticsService = serviceManager
.getServiceManager() .getServiceByName(null, MockSolrLoggerServiceImpl.class);
.getServiceByName("solrLoggerService", MockSolrLoggerServiceImpl.class);
statisticsService.reset(); statisticsService.reset();
MockAuthoritySolrServiceImpl authorityService = DSpaceServicesFactory.getInstance() MockAuthoritySolrServiceImpl authorityService = serviceManager
.getServiceManager() .getServiceByName(null, MockAuthoritySolrServiceImpl.class);
.getServiceByName(AuthoritySearchService.class.getName(), MockAuthoritySolrServiceImpl.class);
authorityService.reset(); authorityService.reset();
// Reload our ConfigurationService (to reset configs to defaults again) // Reload our ConfigurationService (to reset configs to defaults again)
DSpaceServicesFactory.getInstance().getConfigurationService().reloadConfig(); DSpaceServicesFactory.getInstance().getConfigurationService().reloadConfig();
@@ -209,6 +207,7 @@ public class AbstractIntegrationTestWithDatabase extends AbstractDSpaceIntegrati
/** /**
* Utility method to cleanup a created Context object (to save memory). * Utility method to cleanup a created Context object (to save memory).
* This can also be used by individual tests to cleanup context objects they create. * This can also be used by individual tests to cleanup context objects they create.
* @throws java.sql.SQLException passed through.
*/ */
protected void cleanupContext() throws SQLException { protected void cleanupContext() throws SQLException {
// If context still valid, flush all database changes and close it // If context still valid, flush all database changes and close it

View File

@@ -7,23 +7,35 @@
*/ */
package org.dspace.discovery; package org.dspace.discovery;
import org.dspace.solr.MockSolrServer;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
* Mock SOLR service for the Search Core * Mock SOLR service for the Search Core. Manages an in-process Solr server
* with an in-memory "search" core.
*/ */
@Service @Service
public class MockSolrSearchCore extends SolrSearchCore implements InitializingBean { public class MockSolrSearchCore extends SolrSearchCore
implements InitializingBean, DisposableBean {
private MockSolrServer mockSolrServer;
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
//We don't use SOLR in the tests of this module mockSolrServer = new MockSolrServer("search");
solr = null; solr = mockSolrServer.getSolrServer();
} }
/**
* Reset the core for the next test. See {@link MockSolrServer#reset()}.
*/
public void reset() { public void reset() {
// This method intentionally left blank. mockSolrServer.reset();
} }
@Override
public void destroy() throws Exception {
mockSolrServer.destroy();
}
} }

View File

@@ -60,7 +60,9 @@ public class MockSolrLoggerServiceImpl
} }
/** /**
* A mock/fake GeoIP CityResponse, which will be used for *all* test statistical requests * A mock/fake GeoIP CityResponse, which will be used for *all* test
* statistical requests.
*
* @return faked CityResponse * @return faked CityResponse
*/ */
private CityResponse mockCityResponse() { private CityResponse mockCityResponse() {
@@ -79,7 +81,7 @@ public class MockSolrLoggerServiceImpl
new Traits()); new Traits());
} }
/** Remove all records. */ /** Reset the core for the next test. See {@link MockSolrServer#reset()}. */
public void reset() { public void reset() {
mockSolrServer.reset(); mockSolrServer.reset();
} }

View File

@@ -19,15 +19,22 @@
<context:annotation-config/> <!-- allows us to use spring annotations in beans --> <context:annotation-config/> <!-- allows us to use spring annotations in beans -->
<bean class="org.dspace.discovery.SolrServiceImpl" id="org.dspace.discovery.SearchService"/> <bean class="org.dspace.discovery.SolrServiceImpl"
id="org.dspace.discovery.SearchService"/>
<alias name="org.dspace.discovery.SearchService" alias="org.dspace.discovery.IndexingService"/> <alias name="org.dspace.discovery.SearchService"
alias="org.dspace.discovery.IndexingService"/>
<bean class="org.dspace.discovery.MockSolrSearchCore" autowire-candidate="true"/> <bean class="org.dspace.discovery.MockSolrSearchCore"
autowire-candidate="true"/>
<!--<bean class="org.dspace.discovery.SolrServiceIndexOutputPlugin" id="solrServiceIndexOutputPlugin"/>--> <!--<bean class="org.dspace.discovery.SolrServiceIndexOutputPlugin"
id="solrServiceIndexOutputPlugin"/>-->
<!-- Statistics services are both lazy loaded (by name), as you are likely just using ONE of them and not both --> <!-- Statistics services are both lazy loaded (by name), as you are likely
<bean id="solrLoggerService" class="org.dspace.statistics.MockSolrLoggerServiceImpl" lazy-init="true"/> just using ONE of them and not both -->
<bean id="solrLoggerService"
class="org.dspace.statistics.MockSolrLoggerServiceImpl"
lazy-init="true"/>
</beans> </beans>