Skip to content

Commit

Permalink
Fix Springer fetcher tests (#5773)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor authored and Siedlerchr committed Dec 20, 2019
1 parent 9b0dd5d commit c19feb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit c19feb1

Please sign in to comment.