From 56ca5c9340f2c3949cbba646484c16d7cb3c34d4 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Sun, 14 Jul 2019 11:04:01 -0300 Subject: [PATCH 01/10] fetcher ottobib --- .../logic/importer/fetcher/IsbnFetcher.java | 9 +- .../fetcher/IsbnViaOttoBibFetcher.java | 91 +++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java index ac74cec7aca..63d83f3267d 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java @@ -18,7 +18,7 @@ import org.slf4j.LoggerFactory; /** - * Fetcher for ISBN trying ebook.de first and then chimbori.com + * Fetcher for ISBN trying ebook.de first, chimbori.com and then ottobib */ public class IsbnFetcher implements EntryBasedFetcher, IdBasedFetcher { @@ -47,12 +47,19 @@ public Optional performSearchById(String identifier) throws FetcherExc IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences); Optional bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier); + // nothing found at ebook.de, try chimbori.com if (!bibEntry.isPresent()) { LOGGER.debug("No entry found at ebook.de try chimbori.com"); IsbnViaChimboriFetcher isbnViaChimboriFetcher = new IsbnViaChimboriFetcher(importFormatPreferences); bibEntry = isbnViaChimboriFetcher.performSearchById(identifier); + } + //nothing found at ebook.de and chimbori.com, try ottobib + if (!bibEntry.isPresent()) { + LOGGER.debug("No entry found at ebook.de and chimbori.com try ottobib"); + IsbnViaOttoBibFetcher isbnViaOttoBibFetcher = new IsbnViaOttoBibFetcher(importFormatPreferences); + bibEntry = isbnViaOttoBibFetcher.performSearchById(identifier); } return bibEntry; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java new file mode 100644 index 00000000000..5ae3967be34 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java @@ -0,0 +1,91 @@ +package org.jabref.logic.importer.fetcher; + +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.List; +import java.util.Optional; + +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ParseException; +import org.jabref.model.entry.BibEntry; +import org.jabref.model.strings.StringUtil; + +import com.mashape.unirest.http.HttpResponse; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.exceptions.UnirestException; + +/** + * Fetcher for ISBN using https://www.ottobib.com + */ +public class IsbnViaOttoBibFetcher extends AbstractIsbnFetcher { + + public IsbnViaOttoBibFetcher(ImportFormatPreferences importFormatPreferences) { + super(importFormatPreferences); + } + + @Override + public String getName() { + return "ISBN (OttoBib)"; + } + + /** + * @return null, because the identifier is passed using form data. This method is not used. + */ + @Override + public URL getURLForID(String identifier) throws URISyntaxException, MalformedURLException, FetcherException { + return null; + } + + @Override + public Optional performSearchById(String identifier) throws FetcherException { + if (StringUtil.isBlank(identifier)) { + return Optional.empty(); + } + + this.ensureThatIsbnIsValid(identifier); + + HttpResponse postResponse; + + String BASE_URL = "https://www.ottobib.com/isbn/" + identifier + "/bibtex"; + + try { + postResponse = Unirest.post(BASE_URL) + .asString(); + } catch (UnirestException e) { + throw new FetcherException("Could not retrieve data from ottobib.com", e); + } + if (postResponse.getStatus() != 200) { + throw new FetcherException("Error while retrieving data from ottobib.com: " + postResponse.getBody()); + } + + List fetchedEntries; + try { + fetchedEntries = getParser().parseEntries(postResponse.getRawBody()); + } catch (ParseException e) { + throw new FetcherException("An internal parser error occurred", e); + } + if (fetchedEntries.isEmpty()) { + return Optional.empty(); + } else if (fetchedEntries.size() > 1) { + LOGGER.info("Fetcher " + getName() + "found more than one result for identifier " + identifier + + ". We will use the first entry."); + } + + BibEntry entry = fetchedEntries.get(0); + + // ottobib does not return an ISBN. + entry.setField("isbn", identifier); + + doPostCleanup(entry); + + return Optional.of(entry); + } + + @Override + public void doPostCleanup(BibEntry entry) { + + } + +} From ce4ae96af9651c68f91af96c41c66069b5f604d1 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Sun, 14 Jul 2019 17:45:09 -0300 Subject: [PATCH 02/10] removed new fetcher ottobib from the list of expected fetchers --- src/test/java/org/jabref/logic/importer/WebFetchersTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 7e9107ce061..23d3b36a46e 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -5,6 +5,7 @@ import java.util.stream.Collectors; import org.jabref.logic.importer.fetcher.AbstractIsbnFetcher; +import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.IsbnViaChimboriFetcher; import org.jabref.logic.importer.fetcher.IsbnViaEbookDeFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; @@ -34,6 +35,7 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exce expected.remove(AbstractIsbnFetcher.class); expected.remove(IdBasedParserFetcher.class); // Remove special ISBN fetcher since we don't want to expose them to the user + expected.remove(IsbnViaOttoBibFetcher.class); expected.remove(IsbnViaChimboriFetcher.class); expected.remove(IsbnViaEbookDeFetcher.class); assertEquals(expected, getClasses(idFetchers)); From 46b1bfc582e0a4dac9755a7f43b3a203bcd52db0 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Sun, 14 Jul 2019 18:02:51 -0300 Subject: [PATCH 03/10] changed the order of the importer --- src/test/java/org/jabref/logic/importer/WebFetchersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 23d3b36a46e..664e83c761a 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -5,8 +5,8 @@ import java.util.stream.Collectors; import org.jabref.logic.importer.fetcher.AbstractIsbnFetcher; -import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.IsbnViaChimboriFetcher; +import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.IsbnViaEbookDeFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; From 7c90f7a71b4bf1a3bcec7e78c5f078523e2457c1 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Sun, 14 Jul 2019 18:11:12 -0300 Subject: [PATCH 04/10] changed the order of the importer --- src/test/java/org/jabref/logic/importer/WebFetchersTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 664e83c761a..d57e6661835 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -6,7 +6,6 @@ import org.jabref.logic.importer.fetcher.AbstractIsbnFetcher; import org.jabref.logic.importer.fetcher.IsbnViaChimboriFetcher; -import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.IsbnViaEbookDeFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; @@ -17,6 +16,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; +import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; + class WebFetchersTest { Reflections reflections = new Reflections("org.jabref"); From 477432a81e5adab5b955510276d37e373c859445 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Sun, 14 Jul 2019 18:36:13 -0300 Subject: [PATCH 05/10] import --- src/test/java/org/jabref/logic/importer/WebFetchersTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index d57e6661835..0655257e133 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -7,6 +7,7 @@ import org.jabref.logic.importer.fetcher.AbstractIsbnFetcher; import org.jabref.logic.importer.fetcher.IsbnViaChimboriFetcher; import org.jabref.logic.importer.fetcher.IsbnViaEbookDeFetcher; +import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; import org.junit.jupiter.api.BeforeEach; @@ -16,8 +17,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; - class WebFetchersTest { Reflections reflections = new Reflections("org.jabref"); @@ -36,9 +35,9 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exce expected.remove(AbstractIsbnFetcher.class); expected.remove(IdBasedParserFetcher.class); // Remove special ISBN fetcher since we don't want to expose them to the user - expected.remove(IsbnViaOttoBibFetcher.class); expected.remove(IsbnViaChimboriFetcher.class); expected.remove(IsbnViaEbookDeFetcher.class); + expected.remove(IsbnViaOttoBibFetcher.class); assertEquals(expected, getClasses(idFetchers)); } From 10f14506e1b4d979e80de010d9dba514ae177885 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Mon, 15 Jul 2019 08:26:47 -0300 Subject: [PATCH 06/10] Removed unused method --- .../logic/importer/fetcher/IsbnViaOttoBibFetcher.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java index 5ae3967be34..b026018d1d2 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java @@ -82,10 +82,4 @@ public Optional performSearchById(String identifier) throws FetcherExc return Optional.of(entry); } - - @Override - public void doPostCleanup(BibEntry entry) { - - } - } From 72776ccd704b2e7067fe99f043d25cc277454263 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Mon, 15 Jul 2019 08:29:36 -0300 Subject: [PATCH 07/10] removed method call --- .../jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java index b026018d1d2..42ae03126f6 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java @@ -78,8 +78,6 @@ public Optional performSearchById(String identifier) throws FetcherExc // ottobib does not return an ISBN. entry.setField("isbn", identifier); - doPostCleanup(entry); - return Optional.of(entry); } } From 77606faa5103dfa103e2e231d311db72b2053dbb Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Mon, 15 Jul 2019 17:12:49 -0300 Subject: [PATCH 08/10] added a unit test --- .../fetcher/IsbnViaOttoBibFetcherTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java new file mode 100644 index 00000000000..74421a055b9 --- /dev/null +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java @@ -0,0 +1,83 @@ +package org.jabref.logic.importer.fetcher; + +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.BiblatexEntryTypes; +import org.jabref.testutils.category.FetcherTest; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Answers; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.Mockito.mock; + +@FetcherTest +public class IsbnViaOttoBibFetcherTest extends AbstractIsbnFetcherTest { + + @BeforeEach + public void setUp() { + bibEntry = new BibEntry(); + bibEntry.setType(BiblatexEntryTypes.BOOK); + bibEntry.setField("bibtexkey", "9782819502746"); + bibEntry.setField("title", "Les mots du passé : roman"); + bibEntry.setField("publisher", "́Éd. les Nouveaux auteurs"); + bibEntry.setField("year", "2012"); + bibEntry.setField("author", "Denis"); + bibEntry.setField("isbn", "978-2-8195-02746"); + bibEntry.setField("url", "https://www.ottobib.com/isbn/9782819502746/bibtex"); + + fetcher = new IsbnViaOttoBibFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); + } + + @Test + @Override + public void testName() { + assertEquals("ISBN (OttoBib)", fetcher.getName()); + } + + @Test + @Override + public void testHelpPage() { + assertEquals("ISBNtoBibTeX", fetcher.getHelpPage().get().getPageName()); + } + + @Test + @Override + public void searchByIdSuccessfulWithShortISBN() throws FetcherException { + Optional fetchedEntry = fetcher.performSearchById("0321356683"); + bibEntry.setField("bibtexkey", "0321356683"); + bibEntry.setField("isbn", "0321356683"); + assertEquals(Optional.of(bibEntry), fetchedEntry); + } + + @Test + @Override + public void searchByIdSuccessfulWithLongISBN() throws FetcherException { + Optional fetchedEntry = fetcher.performSearchById("9780321356680"); + bibEntry.setField("bibtexkey", "9780321356680"); + bibEntry.setField("isbn", "9780321356680"); + assertEquals(Optional.of(bibEntry), fetchedEntry); + } + + @Test + @Override + public void authorsAreCorrectlyFormatted() throws Exception { + BibEntry bibEntry = new BibEntry(); + bibEntry.setType(BiblatexEntryTypes.BOOK); + bibEntry.setField("bibtexkey", "9782819502746"); + bibEntry.setField("title", "Les mots du passé : roman"); + bibEntry.setField("publisher", "́Éd. les Nouveaux auteurs"); + bibEntry.setField("year", "2012"); + bibEntry.setField("author", "Denis"); + bibEntry.setField("isbn", "978-2-8195-02746"); + bibEntry.setField("url", "https://www.ottobib.com/isbn/9782819502746/bibtex"); + + Optional fetchedEntry = fetcher.performSearchById("9782819502746"); + assertEquals(Optional.of(bibEntry), fetchedEntry); + } +} From 236d62245a7274c6969b4baf4b3d25a97aecdfa6 Mon Sep 17 00:00:00 2001 From: Allison Sampaio Date: Mon, 15 Jul 2019 17:20:10 -0300 Subject: [PATCH 09/10] added a unit test --- .../jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java index 74421a055b9..e5045e7a991 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java @@ -13,7 +13,6 @@ import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.Mockito.mock; @FetcherTest From 526fcf6465ea1690c3b6c6b6c4fa3b089042df16 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sun, 18 Aug 2019 18:24:16 +0200 Subject: [PATCH 10/10] Implement ottobib fetcher Fetcher does not return bibtex data in plain text, instead it's part of an html text area Fix ISBN tests Update user agent Follow up from #5125 --- .../fetcher/IsbnViaOttoBibFetcher.java | 47 +++++--------- .../org/jabref/logic/net/URLDownload.java | 2 +- .../fetcher/IsbnViaChimboriFetcherTest.java | 4 +- .../fetcher/IsbnViaEbookDeFetcherTest.java | 19 +++--- .../fetcher/IsbnViaOttoBibFetcherTest.java | 63 ++++++++++++------- 5 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java index 42ae03126f6..dfc1e8597bf 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcher.java @@ -1,26 +1,31 @@ package org.jabref.logic.importer.fetcher; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; -import java.util.List; import java.util.Optional; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.ParseException; +import org.jabref.logic.importer.fileformat.BibtexParser; +import org.jabref.logic.net.URLDownload; import org.jabref.model.entry.BibEntry; import org.jabref.model.strings.StringUtil; +import org.jabref.model.util.DummyFileUpdateMonitor; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; /** * Fetcher for ISBN using https://www.ottobib.com */ public class IsbnViaOttoBibFetcher extends AbstractIsbnFetcher { + private static final String BASE_URL = "https://www.ottobib.com/isbn/"; + public IsbnViaOttoBibFetcher(ImportFormatPreferences importFormatPreferences) { super(importFormatPreferences); } @@ -46,38 +51,20 @@ public Optional performSearchById(String identifier) throws FetcherExc this.ensureThatIsbnIsValid(identifier); - HttpResponse postResponse; - - String BASE_URL = "https://www.ottobib.com/isbn/" + identifier + "/bibtex"; - + Document html; try { - postResponse = Unirest.post(BASE_URL) - .asString(); - } catch (UnirestException e) { - throw new FetcherException("Could not retrieve data from ottobib.com", e); + html = Jsoup.connect(BASE_URL + identifier + "/bibtex").userAgent(URLDownload.USER_AGENT).get(); + } catch (IOException e) { + throw new FetcherException("Could not ", e); } - if (postResponse.getStatus() != 200) { - throw new FetcherException("Error while retrieving data from ottobib.com: " + postResponse.getBody()); - } - - List fetchedEntries; + Element textArea = html.select("textarea").first(); + Optional entry = Optional.empty(); try { - fetchedEntries = getParser().parseEntries(postResponse.getRawBody()); + entry = BibtexParser.singleFromString(textArea.text(), importFormatPreferences, new DummyFileUpdateMonitor()); } catch (ParseException e) { throw new FetcherException("An internal parser error occurred", e); } - if (fetchedEntries.isEmpty()) { - return Optional.empty(); - } else if (fetchedEntries.size() > 1) { - LOGGER.info("Fetcher " + getName() + "found more than one result for identifier " + identifier - + ". We will use the first entry."); - } - - BibEntry entry = fetchedEntries.get(0); - - // ottobib does not return an ISBN. - entry.setField("isbn", identifier); + return entry; - return Optional.of(entry); } } diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index e569adfa1b6..0eb2508cf13 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -58,7 +58,7 @@ */ public class URLDownload { - public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0"; + public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0"; private static final Logger LOGGER = LoggerFactory.getLogger(URLDownload.class); private final URL source; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java index 9b2c311695a..29a168fec02 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcherTest.java @@ -31,7 +31,7 @@ public void setUp() { bibEntry.setField(StandardField.AUTHOR, "Joshua Bloch"); bibEntry.setField(StandardField.ISBN, "978-0321356680"); bibEntry.setField(StandardField.URL, - "https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683?SubscriptionId=AKIAIOBINVZYXZQZ2U3A&tag=chimbori05-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=0321356683"); + "https://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683?SubscriptionId=AKIAIOBINVZYXZQZ2U3A&tag=chimbori05-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=0321356683"); fetcher = new IsbnViaChimboriFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); } @@ -78,7 +78,7 @@ public void authorsAreCorrectlyFormatted() throws Exception { bibEntry.setField(StandardField.AUTHOR, "Marlon Dumas and Marcello La Rosa and Jan Mendling and Hajo A. Reijers"); bibEntry.setField(StandardField.ISBN, "3642434738"); bibEntry.setField(StandardField.URL, - "https://www.amazon.com/Fundamentals-Business-Process-Management-Marlon/dp/3642434738?SubscriptionId=AKIAIOBINVZYXZQZ2U3A&tag=chimbori05-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=3642434738"); + "https://www.amazon.com/Fundamentals-Business-Process-Management-Marlon/dp/3642434738?SubscriptionId=AKIAIOBINVZYXZQZ2U3A&tag=chimbori05-20&linkCode=xm2&camp=2025&creative=165953&creativeASIN=3642434738"); Optional fetchedEntry = fetcher.performSearchById("3642434738"); assertEquals(Optional.of(bibEntry), fetchedEntry); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java index 104f309879e..d292d0ac3de 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java @@ -29,7 +29,7 @@ public void setUp() { bibEntry.setField(StandardField.PUBLISHER, "Addison Wesley"); bibEntry.setField(StandardField.YEAR, "2018"); bibEntry.setField(StandardField.AUTHOR, "Bloch, Joshua"); - bibEntry.setField(StandardField.DATE, "2018-01-11"); + bibEntry.setField(StandardField.DATE, "2018-01-01"); bibEntry.setField(new UnknownField("ean"), "9780134685991"); bibEntry.setField(StandardField.ISBN, "0134685997"); bibEntry.setField(StandardField.URL, "https://www.ebook.de/de/product/28983211/joshua_bloch_effective_java.html"); @@ -68,26 +68,29 @@ public void searchByIdSuccessfulWithLongISBN() throws FetcherException { public void authorsAreCorrectlyFormatted() throws Exception { BibEntry bibEntry = new BibEntry(); bibEntry.setType(StandardEntryType.Book); - bibEntry.setCiteKey("9783662565094"); + bibEntry.setCiteKey("9783662585856"); bibEntry.setField(StandardField.TITLE, "Fundamentals of Business Process Management"); bibEntry.setField(StandardField.PUBLISHER, "Springer Berlin Heidelberg"); - bibEntry.setField(StandardField.YEAR, "2018"); + bibEntry.setField(StandardField.YEAR, "2019"); bibEntry.setField(StandardField.AUTHOR, "Dumas, Marlon and Rosa, Marcello La and Mendling, Jan and Reijers, Hajo A."); - bibEntry.setField(StandardField.DATE, "2018-03-23"); - bibEntry.setField(new UnknownField("ean"), "9783662565094"); - bibEntry.setField(StandardField.URL, "https://www.ebook.de/de/product/33399253/marlon_dumas_marcello_la_rosa_jan_mendling_hajo_a_reijers_fundamentals_of_business_process_management.html"); + bibEntry.setField(StandardField.DATE, "2019-02-01"); + bibEntry.setField(StandardField.PAGETOTAL, "560"); + bibEntry.setField(new UnknownField("ean"), "9783662585856"); + bibEntry.setField(StandardField.ISBN, "3662585855"); + bibEntry.setField(StandardField.URL, "https://www.ebook.de/de/product/35805105/marlon_dumas_marcello_la_rosa_jan_mendling_hajo_a_reijers_fundamentals_of_business_process_management.html"); - Optional fetchedEntry = fetcher.performSearchById("978-3-662-56509-4"); + Optional fetchedEntry = fetcher.performSearchById("3662585855"); assertEquals(Optional.of(bibEntry), fetchedEntry); } /** * This test searches for a valid ISBN. See https://www.amazon.de/dp/3728128155/?tag=jabref-21 However, this ISBN is - * not available on ebook.de. The fetcher should return nothing rather than throwing an exeption. + * not available on ebook.de. The fetcher should return nothing rather than throwing an exception. */ @Test public void searchForValidButNotFoundISBN() throws Exception { Optional fetchedEntry = fetcher.performSearchById("3728128155"); assertEquals(Optional.empty(), fetchedEntry); } + } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java index e5045e7a991..9076b123f68 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaOttoBibFetcherTest.java @@ -5,7 +5,8 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.BiblatexEntryTypes; +import org.jabref.model.entry.StandardEntryType; +import org.jabref.model.entry.field.StandardField; import org.jabref.testutils.category.FetcherTest; import org.junit.jupiter.api.BeforeEach; @@ -21,14 +22,14 @@ public class IsbnViaOttoBibFetcherTest extends AbstractIsbnFetcherTest { @BeforeEach public void setUp() { bibEntry = new BibEntry(); - bibEntry.setType(BiblatexEntryTypes.BOOK); - bibEntry.setField("bibtexkey", "9782819502746"); - bibEntry.setField("title", "Les mots du passé : roman"); - bibEntry.setField("publisher", "́Éd. les Nouveaux auteurs"); - bibEntry.setField("year", "2012"); - bibEntry.setField("author", "Denis"); - bibEntry.setField("isbn", "978-2-8195-02746"); - bibEntry.setField("url", "https://www.ottobib.com/isbn/9782819502746/bibtex"); + bibEntry.setType(StandardEntryType.Book); + bibEntry.setCiteKey("bloch2008effective"); + bibEntry.setField(StandardField.TITLE, "Effective Java"); + bibEntry.setField(StandardField.PUBLISHER, "Addison-Wesley"); + bibEntry.setField(StandardField.YEAR, "2008"); + bibEntry.setField(StandardField.AUTHOR, "Bloch, Joshua"); + bibEntry.setField(StandardField.ISBN, "9780321356680"); + bibEntry.setField(StandardField.ADDRESS, "Upper Saddle River, NJ"); fetcher = new IsbnViaOttoBibFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); } @@ -49,8 +50,7 @@ public void testHelpPage() { @Override public void searchByIdSuccessfulWithShortISBN() throws FetcherException { Optional fetchedEntry = fetcher.performSearchById("0321356683"); - bibEntry.setField("bibtexkey", "0321356683"); - bibEntry.setField("isbn", "0321356683"); + bibEntry.setField(StandardField.ISBN, "0321356683"); assertEquals(Optional.of(bibEntry), fetchedEntry); } @@ -58,8 +58,7 @@ public void searchByIdSuccessfulWithShortISBN() throws FetcherException { @Override public void searchByIdSuccessfulWithLongISBN() throws FetcherException { Optional fetchedEntry = fetcher.performSearchById("9780321356680"); - bibEntry.setField("bibtexkey", "9780321356680"); - bibEntry.setField("isbn", "9780321356680"); + bibEntry.setField(StandardField.ISBN, "9780321356680"); assertEquals(Optional.of(bibEntry), fetchedEntry); } @@ -67,16 +66,34 @@ public void searchByIdSuccessfulWithLongISBN() throws FetcherException { @Override public void authorsAreCorrectlyFormatted() throws Exception { BibEntry bibEntry = new BibEntry(); - bibEntry.setType(BiblatexEntryTypes.BOOK); - bibEntry.setField("bibtexkey", "9782819502746"); - bibEntry.setField("title", "Les mots du passé : roman"); - bibEntry.setField("publisher", "́Éd. les Nouveaux auteurs"); - bibEntry.setField("year", "2012"); - bibEntry.setField("author", "Denis"); - bibEntry.setField("isbn", "978-2-8195-02746"); - bibEntry.setField("url", "https://www.ottobib.com/isbn/9782819502746/bibtex"); - - Optional fetchedEntry = fetcher.performSearchById("9782819502746"); + bibEntry.setType(StandardEntryType.Book); + bibEntry.setCiteKey("dumas2018fundamentals"); + bibEntry.setField(StandardField.TITLE, "Fundamentals of business process management"); + bibEntry.setField(StandardField.PUBLISHER, "Springer"); + bibEntry.setField(StandardField.AUTHOR, "Dumas, Marlon"); + bibEntry.setField(StandardField.ADDRESS, "Berlin, Germany"); + bibEntry.setField(StandardField.ISBN, "9783662565094"); + bibEntry.setField(StandardField.YEAR, "2018"); + + Optional fetchedEntry = fetcher.performSearchById("978-3-662-56509-4"); assertEquals(Optional.of(bibEntry), fetchedEntry); } + + @Test + public void testISBNNotAvaiableOnEbookDeOrChimbori() throws Exception { + bibEntry = new BibEntry(); + bibEntry.setType(StandardEntryType.Book); + bibEntry.setCiteKey("denis2012les"); + bibEntry.setField(StandardField.TITLE, "Les mots du passé : roman"); + bibEntry.setField(StandardField.PUBLISHER, "Éd. les Nouveaux auteurs"); + bibEntry.setField(StandardField.ADDRESS, "Paris"); + bibEntry.setField(StandardField.YEAR, "2012"); + bibEntry.setField(StandardField.AUTHOR, "Denis, "); + bibEntry.setField(StandardField.ISBN, "9782819502746"); + + Optional fetchedEntry = fetcher.performSearchById("978-2-8195-02746"); + assertEquals(Optional.of(bibEntry), fetchedEntry); + + } + }