Skip to content

Added api keys from default build file #12816

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

Merged
merged 6 commits into from
May 9, 2025
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 @@ -9,6 +9,7 @@
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.PagedSearchBasedFetcher;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
Expand Down Expand Up @@ -67,9 +68,11 @@ public class AstrophysicsDataSystemTest implements PagedSearchFetcherTest {

@BeforeEach
void setUp() {
Optional<String> apiKey = Optional.of(new BuildInfo().astrophysicsDataSystemAPIKey);
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
ImporterPreferences importerPreferences = mock(ImporterPreferences.class);
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());
when(importerPreferences.getApiKey(AstrophysicsDataSystem.FETCHER_NAME)).thenReturn(apiKey);

fetcher = new AstrophysicsDataSystem(importFormatPreferences, importerPreferences);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.Optional;

import javafx.collections.FXCollections;

Expand Down Expand Up @@ -29,14 +30,14 @@
class BiodiversityLibraryTest {
private final String RESPONSE_FORMAT = "&format=json";

private String apiKey;
private final String apiKey = new BuildInfo().biodiversityHeritageApiKey;
private BiodiversityLibrary fetcher;

@BeforeEach
void setUp() {
apiKey = new BuildInfo().biodiversityHeritageApiKey;
ImporterPreferences importerPreferences = mock(ImporterPreferences.class);
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());
when(importerPreferences.getApiKey(BiodiversityLibrary.FETCHER_NAME)).thenReturn(Optional.of(apiKey));
fetcher = new BiodiversityLibrary(importerPreferences);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import org.jabref.logic.bibtex.FieldPreferences;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportCleanup;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.importer.WebFetcher;
import org.jabref.logic.importer.fetcher.citation.semanticscholar.SemanticScholarFetcher;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.support.DisabledOnCIServer;
Expand All @@ -30,6 +35,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -71,12 +77,16 @@ void performSearchOnEmptyQuery(Set<SearchBasedFetcher> fetchers) throws FetcherE
"Fetchers: {arguments}")
@MethodSource("performSearchParameters")
void performSearchOnNonEmptyQuery(Set<SearchBasedFetcher> fetchers) throws FetcherException {
List fetcherNames = fetchers.stream().map(WebFetcher::getName).toList();
ObservableList<String> observableList = FXCollections.observableArrayList(fetcherNames);
when(importerPreferences.getCatalogs()).thenReturn(observableList);
CompositeSearchBasedFetcher compositeFetcher = new CompositeSearchBasedFetcher(fetchers, importerPreferences, Integer.MAX_VALUE);
FieldPreferences fieldPreferences = mock(FieldPreferences.class);
when(fieldPreferences.getNonWrappableFields()).thenReturn(FXCollections.observableArrayList());
ImportCleanup cleanup = ImportCleanup.targeting(BibDatabaseMode.BIBTEX, fieldPreferences);

List<BibEntry> compositeResult = compositeFetcher.performSearch("quantum");
compositeResult.forEach(cleanup::doPostCleanup);
for (SearchBasedFetcher fetcher : fetchers) {
try {
List<BibEntry> fetcherResult = fetcher.performSearch("quantum");
Expand All @@ -100,7 +110,15 @@ void performSearchOnNonEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Fetch
static Stream<Arguments> performSearchParameters() {
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
ImporterPreferences importerPreferences = mock(ImporterPreferences.class);
BuildInfo buildInfo = new BuildInfo();
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());
when(importerPreferences.getApiKey(eq(AstrophysicsDataSystem.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.astrophysicsDataSystemAPIKey));
when(importerPreferences.getApiKey(eq(SemanticScholarFetcher.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.semanticScholarApiKey));
when(importerPreferences.getApiKey(eq(BiodiversityLibrary.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.biodiversityHeritageApiKey));
when(importerPreferences.getApiKey(eq(ScienceDirect.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.scienceDirectApiKey));
when(importerPreferences.getApiKey(eq(SpringerFetcher.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.springerNatureAPIKey));
when(importerPreferences.getApiKey(eq(IEEE.FETCHER_NAME))).thenReturn(Optional.of(buildInfo.ieeeAPIKey));

List<Set<SearchBasedFetcher>> fetcherParameters = new ArrayList<>();

List<SearchBasedFetcher> list = List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.PagedSearchBasedFetcher;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.URLUtil;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -35,6 +36,8 @@ class IEEETest implements SearchBasedFetcherCapabilityTest, PagedSearchFetcherTe

private static ImporterPreferences importerPreferences;

private static final Optional<String> API_KEY = Optional.of(new BuildInfo().ieeeAPIKey);

private static final BibEntry IGOR_NEWCOMERS = new BibEntry(StandardEntryType.InProceedings)
.withField(StandardField.AUTHOR, "Igor Steinmacher and Tayana Uchoa Conte and Christoph Treude and Marco Aurélio Gerosa")
.withField(StandardField.DATE, "14-22 May 2016")
Expand All @@ -61,14 +64,15 @@ static void ensureIeeeIsAvailable() throws FetcherException {

importerPreferences = mock(ImporterPreferences.class);
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());

when(importerPreferences.getApiKey(IEEE.FETCHER_NAME)).thenReturn(API_KEY);
IEEE ieee = new IEEE(importFormatPreferences, importerPreferences);

assumeFalse(List.of().equals(ieee.performSearch("article_number:8801912")));
}

@BeforeEach
void setUp() {
when(importerPreferences.getApiKey(IEEE.FETCHER_NAME)).thenReturn(API_KEY);
fetcher = new IEEE(importFormatPreferences, importerPreferences);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.collections.FXCollections;

import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.URLUtil;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -25,10 +26,11 @@ class ScienceDirectTest {
private final ImporterPreferences importerPreferences = mock(ImporterPreferences.class);
private ScienceDirect finder;
private BibEntry entry;

@BeforeEach
void setUp() {
Optional<String> apiKey = Optional.of(new BuildInfo().scienceDirectApiKey);
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());
when(importerPreferences.getApiKey(ScienceDirect.FETCHER_NAME)).thenReturn(apiKey);
finder = new ScienceDirect(importerPreferences);
entry = new BibEntry();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.importer.PagedSearchBasedFetcher;
import org.jabref.logic.importer.fetcher.citation.semanticscholar.SemanticScholarFetcher;
import org.jabref.logic.util.BuildInfo;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.types.StandardEntryType;
Expand All @@ -26,6 +28,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@FetcherTest
public class SemanticScholarTest implements PagedSearchFetcherTest {
Expand All @@ -43,9 +46,11 @@ public class SemanticScholarTest implements PagedSearchFetcherTest {
.withField(StandardField.VENUE, "International Conference on Software Engineering");

private SemanticScholar fetcher;
private final Optional<String> apiKey = Optional.of(new BuildInfo().semanticScholarApiKey);

@BeforeEach
void setUp() {
when(importerPreferences.getApiKey(SemanticScholarFetcher.FETCHER_NAME)).thenReturn(apiKey);
fetcher = new SemanticScholar(importerPreferences);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javafx.collections.FXCollections;

import org.jabref.logic.importer.ImporterPreferences;
import org.jabref.logic.util.BuildInfo;
import org.jabref.logic.util.URLUtil;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
Expand All @@ -29,6 +30,8 @@ class SpringerLinkTest {

@BeforeEach
void setUp() {
Optional<String> apiKey = Optional.of(new BuildInfo().springerNatureAPIKey);
when(importerPreferences.getApiKey(SpringerLink.FETCHER_NAME)).thenReturn(apiKey);
when(importerPreferences.getApiKeys()).thenReturn(FXCollections.emptyObservableSet());
finder = new SpringerLink(importerPreferences);
entry = new BibEntry();
Expand Down
Loading