Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Springer fetcher tests #5773

Merged
merged 1 commit into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

/**
* FulltextFetcher implementation that attempts to find a PDF URL at SpringerLink.
*
* <p>
* Uses Springer API, see @link{https://dev.springer.com}
*/
public class SpringerLink implements FulltextFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(SpringerLink.class);

private static final String API_URL = "https://api.springer.com/meta/v1/json";
private static final String API_KEY = "b0c7151179b3d9c1119cf325bca8460d";
private static final String API_KEY = "a98b4a55181ffcd27259bea45edad12e";
private static final String CONTENT_HOST = "link.springer.com";

@Override
Expand All @@ -45,13 +45,14 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
.queryString("api_key", API_KEY)
.queryString("q", String.format("doi:%s", doi.get().getDOI()))
.asJson();
if (jsonResponse.getBody() != null) {
JSONObject json = jsonResponse.getBody().getObject();
int results = json.getJSONArray("result").getJSONObject(0).getInt("total");

JSONObject json = jsonResponse.getBody().getObject();
int results = json.getJSONArray("result").getJSONObject(0).getInt("total");

if (results > 0) {
LOGGER.info("Fulltext PDF found @ Springer.");
pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI())));
if (results > 0) {
LOGGER.info("Fulltext PDF found @ Springer.");
pdfLink = Optional.of(new URL("http", CONTENT_HOST, String.format("/content/pdf/%s.pdf", doi.get().getDOI())));
}
}
} catch (UnirestException e) {
LOGGER.warn("SpringerLink API request failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.support.DisabledOnCIServer;
import org.jabref.testutils.category.FetcherTest;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -36,6 +37,7 @@ public void doiNotPresent() throws IOException {
assertEquals(Optional.empty(), finder.findFullText(entry));
}

@DisabledOnCIServer("Disable on CI Server to not hit the API call limit")
@Test
public void findByDOI() throws IOException {
entry.setField(StandardField.DOI, "10.1186/s13677-015-0042-8");
Expand All @@ -44,6 +46,7 @@ public void findByDOI() throws IOException {
finder.findFullText(entry));
}

@DisabledOnCIServer("Disable on CI Server to not hit the API call limit")
@Test
public void notFoundByDOI() throws IOException {
entry.setField(StandardField.DOI, "10.1186/unknown-doi");
Expand Down