Skip to content

Commit

Permalink
fix spacing
Browse files Browse the repository at this point in the history
add test for empty terms
  • Loading branch information
Siedlerchr committed May 26, 2019
1 parent 1a25b47 commit 2fbfaf4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@
import org.jabref.preferences.JabRefPreferences;

import org.fxmisc.easybind.EasyBind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WebSearchPaneViewModel {

private static final Logger LOGGER = LoggerFactory.getLogger(WebSearchPaneViewModel.class);

private final ObjectProperty<SearchBasedFetcher> selectedFetcher = new SimpleObjectProperty<>();
private final ListProperty<SearchBasedFetcher> fetchers = new SimpleListProperty<>(FXCollections.observableArrayList());
private final StringProperty query = new SimpleStringProperty();
private final JabRefFrame frame;
private final DialogService dialogService;
private final DialogService dialogService;

public WebSearchPaneViewModel(ImportFormatPreferences importPreferences, JabRefFrame frame, JabRefPreferences preferences, DialogService dialogService) {
// TODO: Rework so that we don't rely on JabRefFrame and not the complete preferences
this.frame = frame;
Expand Down Expand Up @@ -92,16 +88,16 @@ public void search() {
}

if (frame.getCurrentBasePanel() == null) {
dialogService.notify(Localization.lang("Please open or start a new library before searching"));
dialogService.notify(Localization.lang("Please open or start a new library before searching"));
return;
}

SearchBasedFetcher activeFetcher = getSelectedFetcher();

BackgroundTask<List<BibEntry>> task = BackgroundTask.wrap(() -> activeFetcher.performSearch(getQuery().trim()))
.withInitialMessage(Localization.lang("Processing %0", getQuery()));
task.onFailure(ex->dialogService.showErrorDialogAndWait(ex));

task.onFailure(ex -> dialogService.showErrorDialogAndWait(ex));

ImportEntriesDialog dialog = new ImportEntriesDialog(frame.getCurrentBasePanel().getBibDatabaseContext(), task);
dialog.setTitle(activeFetcher.getName());
Expand Down
56 changes: 35 additions & 21 deletions src/test/java/org/jabref/logic/importer/fetcher/IEEETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import java.util.List;
import java.util.Optional;

import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.BibtexEntryTypes;
import org.jabref.model.entry.FieldName;
import org.jabref.support.DisabledOnCIServer;
import org.jabref.testutils.category.FetcherTest;

Expand Down Expand Up @@ -38,50 +40,40 @@ void setUp() {
void findByDOI() throws IOException {
entry.setField("doi", "10.1109/ACCESS.2016.2535486");

assertEquals(
Optional.of(
new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
assertEquals(Optional.of(new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
}

@Test
void findByDocumentUrl() throws IOException {
entry.setField("url", "https://ieeexplore.ieee.org/document/7421926/");
assertEquals(
Optional.of(
new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
assertEquals(Optional.of(new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
}

@Test
void findByURL() throws IOException {
entry.setField("url", "https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7421926&ref=");

assertEquals(
Optional.of(
new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
assertEquals(Optional.of(new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
}

@Test
void findByOldURL() throws IOException {
entry.setField("url", "https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=7421926");

assertEquals(
Optional.of(
new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
assertEquals(Optional.of(new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
}

@Test
void findByDOIButNotURL() throws IOException {
entry.setField("doi", "10.1109/ACCESS.2016.2535486");
entry.setField("url", "http://dx.doi.org/10.1109/ACCESS.2016.2535486");

assertEquals(
Optional.of(
new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
assertEquals(Optional.of(new URL("https://ieeexplore.ieee.org/ielx7/6287639/7419931/07421926.pdf?tp=&arnumber=7421926&isnumber=7419931&ref=")),
fetcher.findFullText(entry));
}

@Test
Expand All @@ -99,6 +91,28 @@ void notFoundByDOI() throws IOException {
assertEquals(Optional.empty(), fetcher.findFullText(entry));
}

@Test
void searchResultHasNoKeywordTerms() throws FetcherException {
BibEntry expected = new BibEntry(BibtexEntryTypes.ARTICLE);

expected.setField("author", "Shatakshi Jha and Ikhlaq Hussain and Bhim Singh and Sukumar Mishra");
expected.setField("date", "25 2 2019");
expected.setField("doi", "10.1049/iet-rpg.2018.5648");
expected.setField("file", ":https\\://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8636659:PDF");
expected.setField("issn", "1752-1416");
expected.setField("issue", "3");
expected.setField("journaltitle", "IET Renewable Power Generation");
expected.setField("pages", "418--426");
expected.setField("publisher", "IET");
expected.setField("title", "Optimal operation of PV-DG-battery based microgrid with power quality conditioner");
expected.setField("volume", "13");

List<BibEntry> fetchedEntries = fetcher.performSearch("8636659"); //article number
fetchedEntries.stream().forEach(entry -> entry.clearField(FieldName.ABSTRACT)); //Remove abstract due to copyright);
assertEquals(Collections.singletonList(expected), fetchedEntries);

}

@Test
void searchByQueryFindsEntry() throws Exception {
BibEntry expected = new BibEntry(BibtexEntryTypes.INPROCEEDINGS);
Expand All @@ -109,7 +123,7 @@ void searchByQueryFindsEntry() throws Exception {
expected.setField("location", "Austin, TX");
expected.setField("doi", "10.1145/2884781.2884806");
expected.setField("isbn", "978-1-4503-3900-1");
expected.setField("issn","1558-1225");
expected.setField("issn", "1558-1225");
expected.setField("journaltitle", "2016 IEEE/ACM 38th International Conference on Software Engineering (ICSE)");
expected.setField("pages", "273--284");
expected.setField("publisher", "IEEE");
Expand Down

0 comments on commit 2fbfaf4

Please sign in to comment.