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

Added api keys from default build file #12816

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jnchin314
Copy link
Contributor

Closes #12803
Added api keys from BuildInfo where applicable for the fetcher tests. Needed to do proper mocking for the ImporterPrefereces.getApiKey($IMPORTER_NAME)

CompositeSearchBasedFetcher updated with proper mocks as well to use api keys for the different fetchers.

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • [/] Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • [/] Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • [/] Screenshots added in PR description (if change is visible to the user)
  • [/] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [/] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

updated CompositeSearchBasedFetcher as well to use api keys where applicable
@@ -72,12 +78,16 @@ void performSearchOnEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Exceptio
"Fetchers: {arguments}")
@MethodSource("performSearchParameters")
void performSearchOnNonEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Exception {
List fetcherNames = fetchers.stream().map(fetcher-> fetcher.getName()).collect(Collectors.toUnmodifiableList());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lambda expression has unnecessary parentheses and arrow syntax could be replaced with method reference: fetcher::getName for better readability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use IntelliJ IDEA, it should propose you these changes, and you can just click on hint

@jabref-machine
Copy link
Collaborator

Your code currently does not meet JabRef's code guidelines. We use Checkstyle to identify issues. Please carefully follow the setup guide for the codestyle. Afterwards, please run checkstyle locally and fix the issues.

In case of issues with the import order, double check that you activated Auto Import. You can trigger fixing imports by pressing Ctrl+Alt+O to trigger Optimize Imports.

changed to use optional variable where applicable
Copy link

trag-bot bot commented Mar 25, 2025

@trag-bot didn't find any issues in the code! ✅✨

@koppor
Copy link
Member

koppor commented Mar 28, 2025

JabRef CI uses (tests-fetchers.yml):

env:
  SpringerNatureAPIKey: ${{ secrets.SPRINGERNATUREAPIKEY_FOR_TESTS }}
  AstrophysicsDataSystemAPIKey: ${{ secrets.AstrophysicsDataSystemAPIKey_FOR_TESTS }}
  IEEEAPIKey: ${{ secrets.IEEEAPIKey_FOR_TESTS }}
  BiodiversityHeritageApiKey: ${{ secrets.BiodiversityHeritageApiKey_FOR_TESTS}}

This is put into build.properties - see build.gradle:

"ieeeAPIKey": System.getenv('IEEEAPIKey') ? System.getenv('IEEEAPIKey') : '',

Which seems to be read by org.jabref.logic.util.BuildInfo#BuildInfo().

Thus, reading that in fetcher tests seems to be right.

@koppor
Copy link
Member

koppor commented Mar 28, 2025

I wonder why the fetcher tests worked before - haha

@@ -25,10 +26,11 @@ class ScienceDirectTest {
private final ImporterPreferences importerPreferences = mock(ImporterPreferences.class);
private ScienceDirect finder;
private BibEntry entry;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not remove empty lines separating blocks.

Comment on lines +83 to +84
ObservableList<String> observableList = FXCollections.observableArrayList(fetcherNames);
when(importerPreferences.getCatalogs()).thenReturn(observableList);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge these two lines - the name obsevableList is not good.

@@ -72,12 +79,16 @@ void performSearchOnEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Exceptio
"Fetchers: {arguments}")
@MethodSource("performSearchParameters")
void performSearchOnNonEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Exception {
List fetcherNames = fetchers.stream().map(WebFetcher::getName).collect(Collectors.toUnmodifiableList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use .toList() instead of .collect...

@@ -101,7 +112,15 @@ void performSearchOnNonEmptyQuery(Set<SearchBasedFetcher> fetchers) throws Excep
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove this line to cause an error when an unknown key is retrieved? To catch errors early when a new fetcher is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by this comment. If I remove it the parameterized tests will start failing.

Should i create a whole new set of tests?

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is OK for consistency reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Tests with fetchers to use assumeTrue()
4 participants