mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-19 07:53:08 +00:00
[DS-3832] Recast test support classes.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.statistics;
|
package org.dspace.statistics;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -24,15 +25,25 @@ import com.maxmind.geoip2.record.Postal;
|
|||||||
import com.maxmind.geoip2.record.RepresentedCountry;
|
import com.maxmind.geoip2.record.RepresentedCountry;
|
||||||
import com.maxmind.geoip2.record.Subdivision;
|
import com.maxmind.geoip2.record.Subdivision;
|
||||||
import com.maxmind.geoip2.record.Traits;
|
import com.maxmind.geoip2.record.Traits;
|
||||||
|
import mockit.Deencapsulation;
|
||||||
import mockit.Mock;
|
import mockit.Mock;
|
||||||
import mockit.MockUp;
|
import mockit.MockUp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock service to mock the location Lookup Service used by the SOLR statistics logger
|
* Mock service to mock the location Lookup Service used by the SOLR statistics
|
||||||
|
* logger.
|
||||||
*/
|
*/
|
||||||
public class MockLookupService extends MockUp<DatabaseReader> {
|
public class FakeDatabaseReader
|
||||||
|
extends MockUp<DatabaseReader> {
|
||||||
|
|
||||||
public MockLookupService() throws IOException {
|
FakeDatabaseReader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeDatabaseReader(Object object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeDatabaseReader $init(Builder builder) {
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -84,4 +95,24 @@ public class MockLookupService extends MockUp<DatabaseReader> {
|
|||||||
subdivisions, traits);
|
subdivisions, traits);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder
|
||||||
|
extends MockUp<DatabaseReader.Builder> {
|
||||||
|
|
||||||
|
public Builder() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake constructor.
|
||||||
|
* @param file ignored.
|
||||||
|
*/
|
||||||
|
@Mock
|
||||||
|
public void $init(File file) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
public DatabaseReader build()
|
||||||
|
throws IOException {
|
||||||
|
return Deencapsulation.newUninitializedInstance(DatabaseReader.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -15,18 +15,29 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock service that uses an embedded SOLR server for the statistics core
|
* Mock service that uses an embedded SOLR server for the statistics core.
|
||||||
*/
|
*/
|
||||||
public class MockSolrLoggerServiceImpl extends SolrLoggerServiceImpl implements InitializingBean {
|
public class MockSolrLoggerServiceImpl
|
||||||
|
extends SolrLoggerServiceImpl
|
||||||
|
implements InitializingBean {
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
private ConfigurationService configurationService;
|
private ConfigurationService configurationService;
|
||||||
|
|
||||||
|
public MockSolrLoggerServiceImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
//We don't use SOLR in the tests of this module
|
//We don't use SOLR in the tests of this module
|
||||||
solr = null;
|
solr = null;
|
||||||
locationService = new DatabaseReader.Builder(new File(".")).build();
|
|
||||||
|
new FakeDatabaseReader(); // Activate fake
|
||||||
|
new FakeDatabaseReader.Builder(); // Activate fake
|
||||||
|
String locationDbPath = configurationService.getProperty("usage-statistics.dbfile");
|
||||||
|
File locationDb = new File(locationDbPath);
|
||||||
|
locationDb.createNewFile();
|
||||||
|
locationService = new DatabaseReader.Builder(locationDb).build();
|
||||||
useProxies = configurationService.getBooleanProperty("useProxies");
|
useProxies = configurationService.getBooleanProperty("useProxies");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.statistics;
|
package org.dspace.statistics;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -23,15 +25,28 @@ import com.maxmind.geoip2.record.Postal;
|
|||||||
import com.maxmind.geoip2.record.RepresentedCountry;
|
import com.maxmind.geoip2.record.RepresentedCountry;
|
||||||
import com.maxmind.geoip2.record.Subdivision;
|
import com.maxmind.geoip2.record.Subdivision;
|
||||||
import com.maxmind.geoip2.record.Traits;
|
import com.maxmind.geoip2.record.Traits;
|
||||||
|
import mockit.Deencapsulation;
|
||||||
import mockit.Mock;
|
import mockit.Mock;
|
||||||
import mockit.MockUp;
|
import mockit.MockUp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock service to mock the location Lookup Service used by the SOLR statistics logger
|
* Mock service to mock the location Lookup Service used by the SOLR statistics
|
||||||
|
* logger.
|
||||||
*/
|
*/
|
||||||
public class MockLookupService
|
public class FakeDatabaseReader
|
||||||
extends MockUp<DatabaseReader> {
|
extends MockUp<DatabaseReader> {
|
||||||
/*
|
|
||||||
|
FakeDatabaseReader() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeDatabaseReader(Object object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FakeDatabaseReader $init(Builder builder) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
public Location getLocation(String str) {
|
public Location getLocation(String str) {
|
||||||
Location location = new Location();
|
Location location = new Location();
|
||||||
@@ -48,7 +63,7 @@ public class MockLookupService
|
|||||||
|
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
public CityResponse city(InetAddress address) {
|
public CityResponse city(InetAddress address) {
|
||||||
@@ -80,4 +95,24 @@ public class MockLookupService
|
|||||||
subdivisions, traits);
|
subdivisions, traits);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Builder
|
||||||
|
extends MockUp<DatabaseReader.Builder> {
|
||||||
|
|
||||||
|
public Builder() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fake constructor.
|
||||||
|
* @param file ignored.
|
||||||
|
*/
|
||||||
|
@Mock
|
||||||
|
public void $init(File file) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
public DatabaseReader build()
|
||||||
|
throws IOException {
|
||||||
|
return Deencapsulation.newUninitializedInstance(DatabaseReader.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -17,20 +17,31 @@ import org.springframework.beans.factory.InitializingBean;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock service that uses an embedded SOLR server for the statistics core
|
* Mock service that uses an embedded SOLR server for the statistics core.
|
||||||
*/
|
*/
|
||||||
public class MockSolrLoggerServiceImpl extends SolrLoggerServiceImpl implements InitializingBean, DisposableBean {
|
public class MockSolrLoggerServiceImpl
|
||||||
|
extends SolrLoggerServiceImpl
|
||||||
|
implements InitializingBean, DisposableBean {
|
||||||
|
|
||||||
private MockSolrServer mockSolrServer;
|
private MockSolrServer mockSolrServer;
|
||||||
|
|
||||||
@Autowired(required = true)
|
@Autowired(required = true)
|
||||||
private ConfigurationService configurationService;
|
private ConfigurationService configurationService;
|
||||||
|
|
||||||
|
public MockSolrLoggerServiceImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
mockSolrServer = new MockSolrServer("statistics");
|
mockSolrServer = new MockSolrServer("statistics");
|
||||||
solr = mockSolrServer.getSolrServer();
|
solr = mockSolrServer.getSolrServer();
|
||||||
locationService = new DatabaseReader.Builder(new File(".")).build();
|
|
||||||
|
new FakeDatabaseReader(); // Activate fake
|
||||||
|
new FakeDatabaseReader.Builder(); // Activate fake
|
||||||
|
String locationDbPath = configurationService.getProperty("usage-statistics.dbfile");
|
||||||
|
File locationDb = new File(locationDbPath);
|
||||||
|
locationDb.createNewFile();
|
||||||
|
locationService = new DatabaseReader.Builder(locationDb).build();
|
||||||
useProxies = configurationService.getBooleanProperty("useProxies");
|
useProxies = configurationService.getBooleanProperty("useProxies");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user