Skip to content

Commit

Permalink
added ITs for ORCID
Browse files Browse the repository at this point in the history
  • Loading branch information
Micheleboychuk committed Jun 16, 2020
1 parent 2ffde8e commit d77c505
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jdk:

before_install:
# Remove outdated settings.xml from Travis builds. Workaround for https://github.com/travis-ci/travis-ci/issues/4629
- sed -i 's/^orcid\.clientid.*/orcid.clientid='$ORCID_CLIENTID'/g' dspace-api/src/test/data/dspaceFolder/config/local.cfg
- sed -i 's/^orcid\.clientsecret.*/orcid.clientsecret='$ORCID_CLIENTSECRET'/g' dspace-api/src/test/data/dspaceFolder/config/local.cfg
- rm ~/.m2/settings.xml

# Skip install stage, as we'll do it below
Expand Down
3 changes: 3 additions & 0 deletions dspace-api/src/test/data/dspaceFolder/config/local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ rest.properties.exposed = configuration.not.existing
configuration.not.exposed = secret_value
configuration.exposed.single.value = public_value
configuration.exposed.array.value = public_value_1, public_value_2

orcid.clientid =
orcid.clientsecret =
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
<property name="sourceIdentifier" value="mock"/>

</bean>
<bean class="org.dspace.external.provider.impl.OrcidV3AuthorDataProvider" init-method="init">
<constructor-arg value="${orcid.api.url}"/>
<property name="sourceIdentifier" value="orcid"/>
<property name="orcidUrl" value="${orcid.url}" />
<property name="clientId" value="${orcid.clientid}" />
<property name="clientSecret" value="${orcid.clientsecret}" />
<property name="OAUTHUrl" value="${orcid.oauth.url}" />
</bean>
</beans>

Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public class ExternalSourcesRestControllerIT extends AbstractControllerIntegrati
public void findAllExternalSources() throws Exception {
getClient().perform(get("/api/integration/externalsources"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.externalsources", Matchers.hasItem(
ExternalSourceMatcher.matchExternalSource("mock", "mock", false)
.andExpect(jsonPath("$._embedded.externalsources", Matchers.hasItems(
ExternalSourceMatcher.matchExternalSource("mock", "mock", false),
ExternalSourceMatcher.matchExternalSource("orcid", "orcid", false)
)))
.andExpect(jsonPath("$.page.totalElements", Matchers.is(1)));
.andExpect(jsonPath("$.page.totalElements", Matchers.is(2)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* 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.app.rest;

import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.services.ConfigurationService;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
* This test suite includes end to end test to verify the integration with ORCID as an External Source.
* The test run only if the orcid.clientid property is configured.
*
* @author Mykhaylo Boychuk (4Science.it)
*
*/
public class OrcidExternalSourcesIT extends AbstractControllerIntegrationTest {

@Autowired
ConfigurationService configurationService;

@Before
public void onlyRunIfConfigExists() {
if (StringUtils.isBlank(configurationService.getProperty("orcid.clientid"))) {
Assume.assumeNoException(new IllegalStateException("Missing ORCID credentials"));
}
}

@Test
public void findOneExternalSourcesExistingSources() throws Exception {
getClient().perform(get("/api/integration/externalsources/orcid"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.id", is("orcid")),
hasJsonPath("$.name", is("orcid")),
hasJsonPath("$.hierarchical", is(false)),
hasJsonPath("$.type", is("externalsource"))
)));
}

@Test
public void findOneExternalSourcesExistingSourcesWithentryValueTest() throws Exception {
String entry = "0000-0002-9029-1854";
getClient().perform(get("/api/integration/externalsources/orcidV2/entryValues/" + entry))
.andExpect(status().isOk())
.andExpect(jsonPath("$", Matchers.allOf(
hasJsonPath("$.id", is(entry)),
hasJsonPath("$.display", is("Bollini, Andrea")),
hasJsonPath("$.value", is("Bollini, Andrea")),
hasJsonPath("$.externalSource", is("orcid")),
hasJsonPath("$.type", is("externalSourceEntry"))
)))
.andExpect(jsonPath("$.metadata['dc.identifier.uri'][0].value",is("https://orcid.org/" + entry)))
.andExpect(jsonPath("$.metadata['person.familyName'][0].value",is("Bollini")))
.andExpect(jsonPath("$.metadata['person.givenName'][0].value",is("Andrea")))
.andExpect(jsonPath("$.metadata['person.identifier.orcid'][0].value",is(entry)));
}

@Test
public void findOneExternalSourceEntriesApplicableQuery() throws Exception {
String q = "orcid:0000-0002-9029-1854";
getClient().perform(get("/api/integration/externalsources/orcid/entries")
.param("query", q))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.externalSourceEntries[0]", Matchers.allOf(
hasJsonPath("$.id", is("0000-0002-9029-1854")),
hasJsonPath("$.display", is("Bollini, Andrea")),
hasJsonPath("$.value", is("Bollini, Andrea")),
hasJsonPath("$.externalSource", is("orcid")),
hasJsonPath("$.type", is("externalSourceEntry"))
)))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['dc.identifier.uri'][0].value",
is("https://orcid.org/0000-0002-9029-1854")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.familyName'][0].value",
is("Bollini")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.givenName'][0].value",
is("Andrea")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.identifier.orcid'][0].value",
is("0000-0002-9029-1854")));
}

@Test
public void findOneExternalSourceEntriesApplicableQueryFamilyNameAndGivenNamesTest() throws Exception {
String q = "family-name:bollini AND given-names:andrea";
getClient().perform(get("/api/integration/externalsources/orcid/entries")
.param("query", q))
.andExpect(status().isOk())
.andExpect(jsonPath("$._embedded.externalSourceEntries[0]", Matchers.allOf(
hasJsonPath("$.id", is("0000-0002-9029-1854")),
hasJsonPath("$.display", is("Bollini, Andrea")),
hasJsonPath("$.value", is("Bollini, Andrea")),
hasJsonPath("$.externalSource", is("orcid")),
hasJsonPath("$.type", is("externalSourceEntry"))
)))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['dc.identifier.uri'][0].value",
is("https://orcid.org/0000-0002-9029-1854")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.familyName'][0].value",
is("Bollini")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.givenName'][0].value",
is("Andrea")))
.andExpect(jsonPath("$._embedded.externalSourceEntries[0].metadata['person.identifier.orcid'][0].value",
is("0000-0002-9029-1854")));
}
}

0 comments on commit d77c505

Please sign in to comment.