mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 13:33:08 +00:00
mock authority control solr
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
import org.apache.solr.client.solrj.SolrQuery;
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
import org.apache.solr.client.solrj.impl.HttpSolrClient;
|
||||||
@@ -39,9 +40,9 @@ public class AuthoritySolrServiceImpl implements AuthorityIndexingService, Autho
|
|||||||
/**
|
/**
|
||||||
* Non-Static CommonsHttpSolrServer for processing indexing events.
|
* Non-Static CommonsHttpSolrServer for processing indexing events.
|
||||||
*/
|
*/
|
||||||
protected HttpSolrClient solr = null;
|
protected SolrClient solr = null;
|
||||||
|
|
||||||
protected HttpSolrClient getSolr()
|
protected SolrClient getSolr()
|
||||||
throws MalformedURLException, SolrServerException, IOException {
|
throws MalformedURLException, SolrServerException, IOException {
|
||||||
if (solr == null) {
|
if (solr == null) {
|
||||||
|
|
||||||
@@ -49,12 +50,14 @@ public class AuthoritySolrServiceImpl implements AuthorityIndexingService, Autho
|
|||||||
|
|
||||||
log.debug("Solr authority URL: " + solrService);
|
log.debug("Solr authority URL: " + solrService);
|
||||||
|
|
||||||
solr = new HttpSolrClient.Builder(solrService).build();
|
HttpSolrClient solrServer = new HttpSolrClient.Builder(solrService).build();
|
||||||
solr.setBaseURL(solrService);
|
solrServer.setBaseURL(solrService);
|
||||||
|
|
||||||
SolrQuery solrQuery = new SolrQuery().setQuery("*:*");
|
SolrQuery solrQuery = new SolrQuery().setQuery("*:*");
|
||||||
|
|
||||||
solr.query(solrQuery);
|
solrServer.query(solrQuery);
|
||||||
|
|
||||||
|
solr = solrServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return solr;
|
return solr;
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
The contents of this file are subject to the license and copyright
|
||||||
|
detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
tree and available online at
|
||||||
|
|
||||||
|
http://www.dspace.org/license/
|
||||||
|
|
||||||
|
-->
|
||||||
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns:context="http://www.springframework.org/schema/context"
|
||||||
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||||
|
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||||
|
http://www.springframework.org/schema/context
|
||||||
|
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
|
||||||
|
default-autowire-candidates="*Service,*DAO,javax.sql.DataSource">
|
||||||
|
|
||||||
|
<context:annotation-config/> <!-- allows us to use spring annotations in beans -->
|
||||||
|
|
||||||
|
<bean class="org.dspace.discovery.MockSolrServiceImpl" id="org.dspace.discovery.SearchService"/>
|
||||||
|
|
||||||
|
<alias name="org.dspace.discovery.SearchService" alias="org.dspace.discovery.IndexingService"/>
|
||||||
|
|
||||||
|
<bean class="org.dspace.authority.MockSolrServiceImpl" id="org.dspace.authority.indexer.AuthorityIndexingService"/>
|
||||||
|
<bean class="org.dspace.authority.MockSolrServiceImpl" id="org.dspace.authority.AuthoritySearchService"/>
|
||||||
|
|
||||||
|
<!--<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 -->
|
||||||
|
<bean id="solrLoggerService" class="org.dspace.statistics.MockSolrLoggerServiceImpl" lazy-init="true"/>
|
||||||
|
|
||||||
|
</beans>
|
@@ -11,6 +11,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.apache.solr.client.solrj.SolrQuery;
|
||||||
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
||||||
import org.dspace.authority.PersonAuthorityValue;
|
import org.dspace.authority.PersonAuthorityValue;
|
||||||
import org.dspace.authority.factory.AuthorityServiceFactory;
|
import org.dspace.authority.factory.AuthorityServiceFactory;
|
||||||
@@ -50,6 +52,13 @@ public class AuthorityRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
person1.setValue("Shirasaka, Seiko");
|
person1.setValue("Shirasaka, Seiko");
|
||||||
person1.setField("dc_contributor_author");
|
person1.setField("dc_contributor_author");
|
||||||
AuthorityServiceFactory.getInstance().getAuthorityIndexingService().indexContent(person1);
|
AuthorityServiceFactory.getInstance().getAuthorityIndexingService().indexContent(person1);
|
||||||
|
|
||||||
|
PersonAuthorityValue person2 = new PersonAuthorityValue();
|
||||||
|
person2.setLastName("Miller");
|
||||||
|
person2.setFirstName("Tyler E");
|
||||||
|
person2.setValue("Miller, Tyler E");
|
||||||
|
person2.setField("dc_contributor_author");
|
||||||
|
AuthorityServiceFactory.getInstance().getAuthorityIndexingService().indexContent(person2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -104,6 +113,18 @@ public class AuthorityRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void noResultsSolrQueryTest() throws Exception {
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(token).perform(
|
||||||
|
get("/api/integration/authorities/SolrAuthorAuthority/entries")
|
||||||
|
.param("metadata", "dc.contributor.author")
|
||||||
|
.param("query", "Smith")
|
||||||
|
.param("size", "1000"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(0)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveSrscValueTest() throws Exception {
|
public void retrieveSrscValueTest() throws Exception {
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -113,6 +134,19 @@ public class AuthorityRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
/**
|
||||||
|
* This functionality is currently broken, it an empty value
|
||||||
|
*/
|
||||||
|
public void noResultsSrscValueTest() throws Exception {
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
getClient(token).perform(
|
||||||
|
get("/api/integration/authorities/srsc/entryValues/DOESNTEXIST"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(0)));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void retrieveCommonTypesValueTest() throws Exception {
|
public void retrieveCommonTypesValueTest() throws Exception {
|
||||||
String token = getAuthToken(admin.getEmail(), password);
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
@@ -135,6 +169,21 @@ public class AuthorityRestRepositoryIT extends AbstractControllerIntegrationTest
|
|||||||
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retrieveSolrValueTest() throws Exception {
|
||||||
|
String token = getAuthToken(admin.getEmail(), password);
|
||||||
|
|
||||||
|
SolrQuery query = new SolrQuery();
|
||||||
|
query.setQuery("*:*");
|
||||||
|
QueryResponse queryResponse = AuthorityServiceFactory.getInstance().getAuthoritySearchService().search(query);
|
||||||
|
String id = String.valueOf(queryResponse.getResults().get(0).getFieldValue("id"));
|
||||||
|
|
||||||
|
getClient(token).perform(
|
||||||
|
get("/api/integration/authorities/SolrAuthorAuthority/entryValues/" + id))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() throws Exception {
|
public void destroy() throws Exception {
|
||||||
AuthorityServiceFactory.getInstance().getAuthorityIndexingService().cleanIndex();
|
AuthorityServiceFactory.getInstance().getAuthorityIndexingService().cleanIndex();
|
||||||
|
@@ -0,0 +1,44 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
|
package org.dspace.authority;
|
||||||
|
|
||||||
|
import org.dspace.solr.MockSolrServer;
|
||||||
|
import org.springframework.beans.factory.DisposableBean;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock SOLR service for the Search Core.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* <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 config/spring/api/Z-mock-services.xml}. Some kind of classpath
|
||||||
|
* magic makes this work.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MockSolrServiceImpl extends AuthoritySolrServiceImpl implements InitializingBean, DisposableBean {
|
||||||
|
|
||||||
|
private MockSolrServer mockSolrServer;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
mockSolrServer = new MockSolrServer("authority");
|
||||||
|
solr = mockSolrServer.getSolrServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Clear all records from the search core. */
|
||||||
|
public void reset() {
|
||||||
|
mockSolrServer.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() throws Exception {
|
||||||
|
mockSolrServer.destroy();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user