From 087246d1691f2c08fabc6afe91f2e0bf1e9c1b42 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Fri, 20 Dec 2019 21:13:21 +0100 Subject: [PATCH] Fix Springer fetcher tests --- .../logic/importer/fetcher/SpringerLink.java | 17 +++++++++-------- .../importer/fetcher/SpringerLinkTest.java | 3 +++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java index 28f2357efc5..98e313078dd 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java @@ -20,14 +20,14 @@ /** * FulltextFetcher implementation that attempts to find a PDF URL at SpringerLink. - * + *

* 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 @@ -45,13 +45,14 @@ public Optional 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); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerLinkTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerLinkTest.java index 22d5964c6b6..275a5fb6761 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerLinkTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerLinkTest.java @@ -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; @@ -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"); @@ -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");