mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 18:14:26 +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"/>
|
||||
|
||||
<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">
|
||||
<property name="types">
|
||||
|
@@ -26,41 +26,47 @@ import org.mockito.stubbing.Answer;
|
||||
*/
|
||||
public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
||||
|
||||
public MockOrcid() {
|
||||
setupMockConnector();
|
||||
setAccessToken("mock-access-token");
|
||||
}
|
||||
OrcidRestConnector orcidRestConnector;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
// Empty implementation as setup is now done in constructor
|
||||
initializeAccessToken();
|
||||
orcidRestConnector = Mockito.mock(OrcidRestConnector.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeAccessToken() {
|
||||
if (getAccessToken() == null) {
|
||||
setAccessToken("mock-access-token");
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMockConnector() {
|
||||
OrcidRestConnector orcidRestConnector = Mockito.mock(OrcidRestConnector.class);
|
||||
/**
|
||||
* 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 setupNoResultsSearch() {
|
||||
when(orcidRestConnector.get(ArgumentMatchers.startsWith("search?"), ArgumentMatchers.any()))
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) {
|
||||
return this.getClass().getResourceAsStream("orcid-search-noresults.xml");
|
||||
}
|
||||
});
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) {
|
||||
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()))
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) {
|
||||
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()))
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
.thenAnswer(new Answer<InputStream>() {
|
||||
@Override
|
||||
public InputStream answer(InvocationOnMock invocation) {
|
||||
return this.getClass().getResourceAsStream("orcid-person-record.xml");
|
||||
@@ -69,4 +75,11 @@ public class MockOrcid extends Orcidv3SolrAuthorityImpl {
|
||||
|
||||
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.PersonAuthorityValue;
|
||||
import org.dspace.authority.factory.AuthorityServiceFactory;
|
||||
import org.dspace.authority.orcid.MockOrcid;
|
||||
import org.dspace.builder.CollectionBuilder;
|
||||
import org.dspace.builder.CommunityBuilder;
|
||||
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.core.service.PluginService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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
|
||||
@@ -56,6 +59,17 @@ public class VocabularyRestRepositoryIT extends AbstractControllerIntegrationTes
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
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",
|
||||
new String[] {
|
||||
"org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority",
|
||||
|
Reference in New Issue
Block a user