mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Fix some ORCID mock / test usage
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
<bean id="dspace.DSpaceAuthorityIndexer" class="org.dspace.authority.indexer.DSpaceAuthorityIndexer"/>
|
<bean id="dspace.DSpaceAuthorityIndexer" class="org.dspace.authority.indexer.DSpaceAuthorityIndexer"/>
|
||||||
|
|
||||||
<alias name="OrcidSource" alias="AuthoritySource"/>
|
<alias name="OrcidSource" alias="AuthoritySource"/>
|
||||||
<bean name="OrcidSource" class="org.dspace.authority.orcid.MockOrcid" />
|
<bean name="OrcidSource" class="org.dspace.authority.orcid.MockOrcid" init-method="init" />
|
||||||
|
|
||||||
<bean name="AuthorityTypes" class="org.dspace.authority.AuthorityTypes">
|
<bean name="AuthorityTypes" class="org.dspace.authority.AuthorityTypes">
|
||||||
<property name="types">
|
<property name="types">
|
||||||
|
@@ -26,25 +26,19 @@ import org.mockito.stubbing.Answer;
|
|||||||
*/
|
*/
|
||||||
public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
||||||
|
|
||||||
public MockOrcid() {
|
OrcidRestConnector orcidRestConnector;
|
||||||
setupMockConnector();
|
|
||||||
setAccessToken("mock-access-token");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
// Empty implementation as setup is now done in constructor
|
initializeAccessToken();
|
||||||
|
orcidRestConnector = Mockito.mock(OrcidRestConnector.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void initializeAccessToken() {
|
* Call this to set up mocking for any test classes that need it. We don't set it in init()
|
||||||
if (getAccessToken() == null) {
|
* or other AbstractIntegrationTest implementations will complain of unnecessary Mockito stubbing
|
||||||
setAccessToken("mock-access-token");
|
*/
|
||||||
}
|
public void setupNoResultsSearch() {
|
||||||
}
|
|
||||||
|
|
||||||
private void setupMockConnector() {
|
|
||||||
OrcidRestConnector orcidRestConnector = Mockito.mock(OrcidRestConnector.class);
|
|
||||||
when(orcidRestConnector.get(ArgumentMatchers.startsWith("search?"), ArgumentMatchers.any()))
|
when(orcidRestConnector.get(ArgumentMatchers.startsWith("search?"), ArgumentMatchers.any()))
|
||||||
.thenAnswer(new Answer<InputStream>() {
|
.thenAnswer(new Answer<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -52,6 +46,12 @@ public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
|||||||
return this.getClass().getResourceAsStream("orcid-search-noresults.xml");
|
return this.getClass().getResourceAsStream("orcid-search-noresults.xml");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Call this to set up mocking for any test classes that need it. We don't set it in init()
|
||||||
|
* or other AbstractIntegrationTest implementations will complain of unnecessary Mockito stubbing
|
||||||
|
*/
|
||||||
|
public void setupSingleSearch() {
|
||||||
when(orcidRestConnector.get(ArgumentMatchers.startsWith("search?q=Bollini"), ArgumentMatchers.any()))
|
when(orcidRestConnector.get(ArgumentMatchers.startsWith("search?q=Bollini"), ArgumentMatchers.any()))
|
||||||
.thenAnswer(new Answer<InputStream>() {
|
.thenAnswer(new Answer<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -59,6 +59,12 @@ public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
|||||||
return this.getClass().getResourceAsStream("orcid-search.xml");
|
return this.getClass().getResourceAsStream("orcid-search.xml");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Call this to set up mocking for any test classes that need it. We don't set it in init()
|
||||||
|
* or other AbstractIntegrationTest implementations will complain of unnecessary Mockito stubbing
|
||||||
|
*/
|
||||||
|
public void setupSearchWithResults() {
|
||||||
when(orcidRestConnector.get(ArgumentMatchers.endsWith("/person"), ArgumentMatchers.any()))
|
when(orcidRestConnector.get(ArgumentMatchers.endsWith("/person"), ArgumentMatchers.any()))
|
||||||
.thenAnswer(new Answer<InputStream>() {
|
.thenAnswer(new Answer<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -69,4 +75,11 @@ public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
|||||||
|
|
||||||
setOrcidRestConnector(orcidRestConnector);
|
setOrcidRestConnector(orcidRestConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initializeAccessToken() {
|
||||||
|
if (getAccessToken() == null) {
|
||||||
|
setAccessToken("mock-access-token");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
|
|||||||
import org.dspace.authority.AuthorityValueServiceImpl;
|
import org.dspace.authority.AuthorityValueServiceImpl;
|
||||||
import org.dspace.authority.PersonAuthorityValue;
|
import org.dspace.authority.PersonAuthorityValue;
|
||||||
import org.dspace.authority.factory.AuthorityServiceFactory;
|
import org.dspace.authority.factory.AuthorityServiceFactory;
|
||||||
|
import org.dspace.authority.orcid.MockOrcid;
|
||||||
import org.dspace.builder.CollectionBuilder;
|
import org.dspace.builder.CollectionBuilder;
|
||||||
import org.dspace.builder.CommunityBuilder;
|
import org.dspace.builder.CommunityBuilder;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
@@ -29,11 +30,13 @@ import org.dspace.content.authority.DCInputAuthority;
|
|||||||
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
import org.dspace.content.authority.service.ChoiceAuthorityService;
|
||||||
import org.dspace.core.service.PluginService;
|
import org.dspace.core.service.PluginService;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class handles all Authority related IT. It alters some config to run the tests, but it gets cleared again
|
* This class handles all Authority related IT. It alters some config to run the tests, but it gets cleared again
|
||||||
@@ -56,6 +59,17 @@ public class VocabularyRestRepositoryIT extends AbstractControllerIntegrationTes
|
|||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
// Explicitly set stubbing for the MockOrcid class. We don't do it in the init() or constructor
|
||||||
|
// of the MockOrcid class itself or Mockito will complain of unnecessary stubbing in certain other
|
||||||
|
// AbstractIntegrationTest implementations (depending on how config is (re)loaded)
|
||||||
|
ApplicationContext applicationContext = DSpaceServicesFactory.getInstance()
|
||||||
|
.getServiceManager().getApplicationContext();
|
||||||
|
MockOrcid mockOrcid = applicationContext.getBean(MockOrcid.class);
|
||||||
|
mockOrcid.setupNoResultsSearch();
|
||||||
|
mockOrcid.setupSingleSearch();
|
||||||
|
mockOrcid.setupSearchWithResults();
|
||||||
|
|
||||||
configurationService.setProperty("plugin.named.org.dspace.content.authority.ChoiceAuthority",
|
configurationService.setProperty("plugin.named.org.dspace.content.authority.ChoiceAuthority",
|
||||||
new String[] {
|
new String[] {
|
||||||
"org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority",
|
"org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority",
|
||||||
|
Reference in New Issue
Block a user