-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
SLR : Adding Routing Dispatch to StudyFetcher #16098
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
+175
−10
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f127214
added routing dispatch to StudyFetcher
faneeshh 01aed45
log uncaught raw query exceptions
faneeshh a896a70
page loop on raw path
faneeshh d061976
case insensitive lookup
faneeshh 1f2fe1f
scope exception to raw calls
faneeshh 77dd842
update tests
faneeshh efa8d0d
fix formatting
faneeshh f85a814
null value guard
faneeshh 1b98c7b
verify full page loop
faneeshh e48d353
fix formatting
faneeshh 39aad9e
added fetcher exceptions
faneeshh 2ec7af9
fix null guard order
faneeshh 4457c7d
switch to optional and split into sub methods
faneeshh 34a4bb3
fix null guard on catalogOverride filter
faneeshh fb4313f
Merge branch 'main' into slr-routing-dispatch
faneeshh 9067004
Merge branch 'main' into slr-routing-dispatch
faneeshh d5ea5c3
Update jablib/src/main/java/org/jabref/logic/crawler/StudyFetcher.java
faneeshh 7c5dfca
extract getCatalogOverride to dedicated method
faneeshh bf4f395
Merge branch 'slr-routing-dispatch' of https://github.com/faneeshh/ja…
faneeshh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
jablib/src/test/java/org/jabref/logic/crawler/StudyFetcherTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.jabref.logic.crawler; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.jabref.logic.importer.FetcherException; | ||
| import org.jabref.logic.importer.PagedSearchBasedFetcher; | ||
| import org.jabref.logic.importer.SearchBasedFetcher; | ||
| import org.jabref.model.entry.BibEntry; | ||
| import org.jabref.model.paging.Page; | ||
| import org.jabref.model.study.QueryResult; | ||
| import org.jabref.model.study.StudyQuery; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @NullMarked | ||
| class StudyFetcherTest { | ||
|
|
||
| @Test | ||
| void catalogSpecificOverrideUsesRawPathForPagedFetcher() throws FetcherException { | ||
| StudyQuery studyQuery = new StudyQuery("machine learning"); | ||
| studyQuery.setCatalogSpecific(Map.of("TestPagedFetcher", "native:query")); | ||
|
|
||
| PagedSearchBasedFetcher pagedFetcher = mock(PagedSearchBasedFetcher.class); | ||
| when(pagedFetcher.getName()).thenReturn("TestPagedFetcher"); | ||
| when(pagedFetcher.performRawSearchQueryPaged("native:query", 0)) | ||
| .thenReturn(new Page<>("native:query", 0, List.of(new BibEntry()))); | ||
|
|
||
|
Comment on lines
+39
to
+43
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The paged tests only page 0, so the multi-page loop (the thing that was fixed) isn't actually verified |
||
| StudyFetcher studyFetcher = new StudyFetcher(List.of(pagedFetcher), List.of(studyQuery), Map.of()); | ||
| List<QueryResult> results = studyFetcher.crawl(); | ||
|
|
||
| assertFalse(results.isEmpty()); | ||
| verify(pagedFetcher).performRawSearchQueryPaged("native:query", 0); | ||
| verify(pagedFetcher, never()).performSearchPaged(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyInt()); | ||
| } | ||
|
|
||
| @Test | ||
| void catalogSpecificOverrideUsesRawPathForPlainFetcher() throws FetcherException { | ||
| StudyQuery studyQuery = new StudyQuery("machine learning"); | ||
| studyQuery.setCatalogSpecific(Map.of("TestPlainFetcher", "native:query")); | ||
|
|
||
| SearchBasedFetcher plainFetcher = mock(SearchBasedFetcher.class); | ||
| when(plainFetcher.getName()).thenReturn("TestPlainFetcher"); | ||
| when(plainFetcher.performRawSearchQuery("native:query")).thenReturn(List.of(new BibEntry())); | ||
|
|
||
| StudyFetcher studyFetcher = new StudyFetcher(List.of(plainFetcher), List.of(studyQuery), Map.of()); | ||
| List<QueryResult> results = studyFetcher.crawl(); | ||
|
|
||
| assertFalse(results.isEmpty()); | ||
| verify(plainFetcher).performRawSearchQuery("native:query"); | ||
| verify(plainFetcher, never()).performSearch(org.mockito.ArgumentMatchers.anyString()); | ||
| } | ||
|
|
||
| @Test | ||
| void noOverrideFallsBackToStandardPath() throws FetcherException { | ||
| StudyQuery studyQuery = new StudyQuery("machine learning"); | ||
|
|
||
| PagedSearchBasedFetcher pagedFetcher = mock(PagedSearchBasedFetcher.class); | ||
| when(pagedFetcher.getName()).thenReturn("TestPagedFetcher"); | ||
| when(pagedFetcher.getPageSize()).thenReturn(10); | ||
| when(pagedFetcher.performSearchPaged(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyInt())) | ||
| .thenReturn(new Page<>("machine learning", 0, List.of())); | ||
| when(pagedFetcher.performSearchPaged("machine learning", 0)) | ||
| .thenReturn(new Page<>("machine learning", 0, List.of(new BibEntry()))); | ||
|
|
||
| StudyFetcher studyFetcher = new StudyFetcher(List.of(pagedFetcher), List.of(studyQuery), Map.of()); | ||
| studyFetcher.crawl(); | ||
|
|
||
| verify(pagedFetcher).performSearchPaged("machine learning", 0); | ||
| verify(pagedFetcher, never()).performRawSearchQueryPaged(org.mockito.ArgumentMatchers.anyString(), org.mockito.ArgumentMatchers.anyInt()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.