#2893 Move builders from dspace-server-webapp to dspace-api.

This commit is contained in:
Mark H. Wood
2020-07-21 16:22:07 -04:00
parent 15d2e16ff4
commit dd9c0b9999
104 changed files with 445 additions and 489 deletions

View File

@@ -27,27 +27,39 @@ import com.maxmind.geoip2.record.MaxMind;
import com.maxmind.geoip2.record.Postal;
import com.maxmind.geoip2.record.RepresentedCountry;
import com.maxmind.geoip2.record.Traits;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.solr.MockSolrServer;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;
/**
* Mock service that uses an embedded SOLR server for the statistics core.
*
* <p>
* <strong>NOTE:</strong> this class is overridden by one <em>of the same name</em>
* defined in dspace-server-webapp and declared as a bean there.
* <strong>NOTE:</strong> this class overrides one <em>of the same name</em>
* defined in dspace-api and declared as a bean there.
* See {@code test/data/dspaceFolder/config/spring/api/solr-services.xml}. Some kind of classpath
* magic makes this work.
*/
@Service
public class MockSolrLoggerServiceImpl
extends SolrLoggerServiceImpl
implements InitializingBean {
implements InitializingBean, DisposableBean {
private static final Logger log = LogManager.getLogger();
private MockSolrServer mockSolrServer;
public MockSolrLoggerServiceImpl() {
}
@Override
public void afterPropertiesSet() throws Exception {
//We don't use SOLR in the tests of this module
solr = null;
// Initialize our service with a Mock Solr statistics core
mockSolrServer = new MockSolrServer("statistics");
solr = mockSolrServer.getSolrServer();
// Mock GeoIP's DatabaseReader
DatabaseReader reader = mock(DatabaseReader.class);
@@ -62,10 +74,10 @@ public class MockSolrLoggerServiceImpl
* @return faked CityResponse
*/
private CityResponse mockCityResponse() {
List<String> cityNames = new ArrayList<String>(Collections.singleton("New York"));
List<String> cityNames = new ArrayList<>(Collections.singleton("New York"));
City city = new City(cityNames, 1, 1, new HashMap());
List<String> countryNames = new ArrayList<String>(Collections.singleton("United States"));
List<String> countryNames = new ArrayList<>(Collections.singleton("United States"));
Country country = new Country(countryNames, 1, 1, "US", new HashMap());
Location location = new Location(1, 1, 40.760498D, -73.9933D, 501, 1, "EST");
@@ -73,7 +85,17 @@ public class MockSolrLoggerServiceImpl
Postal postal = new Postal("10036", 1);
return new CityResponse(city, new Continent(), country, location, new MaxMind(), postal,
country, new RepresentedCountry(), new ArrayList<>(0),
new Traits());
country, new RepresentedCountry(), new ArrayList<>(0),
new Traits());
}
/** Remove all records. */
public void reset() {
mockSolrServer.reset();
}
@Override
public void destroy() throws Exception {
mockSolrServer.destroy();
}
}