From 43d0c7df6150f9d78d32b20ef35938f7e7572d7d Mon Sep 17 00:00:00 2001 From: stefan-kolb Date: Mon, 17 Aug 2015 20:37:58 +0200 Subject: [PATCH] Rename package to fetchers --- CHANGELOG | 2 +- .../jabref/export/layout/format/DOICheck.java | 2 +- .../jabref/export/layout/format/DOIStrip.java | 2 +- .../jabref/external/DownloadExternalFile.java | 11 ++-- .../net/sf/jabref/external/FindFullText.java | 8 +-- .../sf/jabref/external/FullTextFinder.java | 39 ------------- .../java/net/sf/jabref/gui/CleanUpAction.java | 2 +- .../sf/jabref/imports/PdfContentImporter.java | 2 +- .../jabref/logic/crawler/ScienceDirect.java | 51 ----------------- .../logic/{crawler => fetcher}/ACS.java | 21 +------ .../jabref/logic/fetcher/FullTextFinder.java | 24 ++++++++ .../{crawler => fetcher}/GoogleScholar.java | 22 +------ .../jabref/logic/fetcher/ScienceDirect.java | 57 +++++++++++++++++++ .../{crawler => fetcher}/SpringerLink.java | 24 +------- .../net/sf/jabref/{ => logic}/util/DOI.java | 7 ++- .../logic/crawler/ScienceDirectTest.java | 43 -------------- .../logic/{crawler => fetcher}/ACSTest.java | 5 +- .../GoogleScholarTest.java | 5 +- .../logic/fetcher/ScienceDirectTest.java | 43 ++++++++++++++ .../SpringerLinkTest.java | 5 +- .../sf/jabref/{ => logic}/util/DOITest.java | 3 +- .../java/net/sf/jabref/util/UtilTest.java | 2 +- 22 files changed, 154 insertions(+), 226 deletions(-) delete mode 100644 src/main/java/net/sf/jabref/external/FullTextFinder.java delete mode 100644 src/main/java/net/sf/jabref/logic/crawler/ScienceDirect.java rename src/main/java/net/sf/jabref/logic/{crawler => fetcher}/ACS.java (63%) create mode 100644 src/main/java/net/sf/jabref/logic/fetcher/FullTextFinder.java rename src/main/java/net/sf/jabref/logic/{crawler => fetcher}/GoogleScholar.java (68%) create mode 100644 src/main/java/net/sf/jabref/logic/fetcher/ScienceDirect.java rename src/main/java/net/sf/jabref/logic/{crawler => fetcher}/SpringerLink.java (68%) rename src/main/java/net/sf/jabref/{ => logic}/util/DOI.java (95%) delete mode 100644 src/test/java/net/sf/jabref/logic/crawler/ScienceDirectTest.java rename src/test/java/net/sf/jabref/logic/{crawler => fetcher}/ACSTest.java (87%) rename src/test/java/net/sf/jabref/logic/{crawler => fetcher}/GoogleScholarTest.java (92%) create mode 100644 src/test/java/net/sf/jabref/logic/fetcher/ScienceDirectTest.java rename src/test/java/net/sf/jabref/logic/{crawler => fetcher}/SpringerLinkTest.java (90%) rename src/test/java/net/sf/jabref/{ => logic}/util/DOITest.java (98%) diff --git a/CHANGELOG b/CHANGELOG index e158d8fc30ab..afc69e6301d6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ [master] - - Fix fulltext crawler for ScienceDirect, SpringerLink, and ACS + - Feature: PDF auto download from ACS, ScienceDirect, SpringerLink, and Google Scholar - Perform syntax improvements enabled by Java 1.7+ (diamond operator, try-with-resources) - List of authors is now auto generated `scripts/generate-authors.sh` and inserted into L10N About.html - Remove Mr.DLib support as MR.DLib will be shut down in 2015 diff --git a/src/main/java/net/sf/jabref/export/layout/format/DOICheck.java b/src/main/java/net/sf/jabref/export/layout/format/DOICheck.java index 7583bcae7801..a22e5d7e38b0 100644 --- a/src/main/java/net/sf/jabref/export/layout/format/DOICheck.java +++ b/src/main/java/net/sf/jabref/export/layout/format/DOICheck.java @@ -15,7 +15,7 @@ */ package net.sf.jabref.export.layout.format; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import net.sf.jabref.export.layout.LayoutFormatter; /** diff --git a/src/main/java/net/sf/jabref/export/layout/format/DOIStrip.java b/src/main/java/net/sf/jabref/export/layout/format/DOIStrip.java index 9c1293774336..51a2bfc5deed 100644 --- a/src/main/java/net/sf/jabref/export/layout/format/DOIStrip.java +++ b/src/main/java/net/sf/jabref/export/layout/format/DOIStrip.java @@ -15,7 +15,7 @@ */ package net.sf.jabref.export.layout.format; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import net.sf.jabref.export.layout.LayoutFormatter; /** diff --git a/src/main/java/net/sf/jabref/external/DownloadExternalFile.java b/src/main/java/net/sf/jabref/external/DownloadExternalFile.java index b5efb5f07d25..0a0b3e45d348 100644 --- a/src/main/java/net/sf/jabref/external/DownloadExternalFile.java +++ b/src/main/java/net/sf/jabref/external/DownloadExternalFile.java @@ -159,8 +159,6 @@ public void run() { if (mimeType != null) { System.out.println("mimetype:" + mimeType); suggestedType = Globals.prefs.getExternalFileTypeByMimeType(mimeType); - /*if (suggestedType != null) - System.out.println("Found type '"+suggestedType.getName()+"' by MIME type '"+udl.getMimeType()+"'");*/ } // Then, while the download is proceeding, let the user choose the details of the file: String suffix; @@ -286,7 +284,7 @@ private void downloadFinished() { editor.setOkEnabled(true); editor.getProgressBar().setValue(editor.getProgressBar().getMaximum()); } - + // FIXME: will break download if no bibtexkey is present! private String getSuggestedFileName(String suffix) { String plannedName = bibtexKey; @@ -298,7 +296,10 @@ private String getSuggestedFileName(String suffix) { * [ 1548875 ] download pdf produces unsupported filename * * http://sourceforge.net/tracker/index.php?func=detail&aid=1548875&group_id=92314&atid=600306 - * + * FIXME: rework this! just allow alphanumeric stuff or so? + * https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions + * http://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os + * https://support.apple.com/en-us/HT202808 */ if (OS.WINDOWS) { plannedName = plannedName.replaceAll( @@ -311,7 +312,7 @@ private String getSuggestedFileName(String suffix) { } /** - * Look for the last '.' in the link, and returnthe following characters. + * Look for the last '.' in the link, and return the following characters. * This gives the extension for most reasonably named links. * * @param link The link diff --git a/src/main/java/net/sf/jabref/external/FindFullText.java b/src/main/java/net/sf/jabref/external/FindFullText.java index a21c00b667ad..d4159315f3a5 100644 --- a/src/main/java/net/sf/jabref/external/FindFullText.java +++ b/src/main/java/net/sf/jabref/external/FindFullText.java @@ -15,8 +15,6 @@ */ package net.sf.jabref.external; -import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; @@ -29,11 +27,7 @@ import java.util.Optional; import net.sf.jabref.BibtexEntry; -import net.sf.jabref.logic.crawler.ACS; -import net.sf.jabref.logic.crawler.GoogleScholar; -import net.sf.jabref.logic.crawler.ScienceDirect; -import net.sf.jabref.logic.crawler.SpringerLink; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.fetcher.*; import net.sf.jabref.logic.net.URLDownload; /** diff --git a/src/main/java/net/sf/jabref/external/FullTextFinder.java b/src/main/java/net/sf/jabref/external/FullTextFinder.java deleted file mode 100644 index c3ab0f5215c7..000000000000 --- a/src/main/java/net/sf/jabref/external/FullTextFinder.java +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2003-2011 JabRef contributors. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.external; - -import net.sf.jabref.BibtexEntry; - -import java.net.URL; -import java.io.IOException; -import java.util.Optional; - -/** - * This interface is used for classes that try to resolve a full-text PDF url for a BibTex entry. - * Implementing classes should specialize on specific article sites. - * See e.g. @link{http://libguides.mit.edu/apis}. - */ -public interface FullTextFinder { - /** - * Tries to find a fulltext URL for a given BibTex entry. - * - * @param entry The Bibtex entry - * @return The fulltext PDF URL Optional, if found, or an empty Optional if not found. - * @throws NullPointerException if no BibTex entry is given - * @throws java.io.IOException - */ - Optional findFullText(BibtexEntry entry) throws IOException; -} diff --git a/src/main/java/net/sf/jabref/gui/CleanUpAction.java b/src/main/java/net/sf/jabref/gui/CleanUpAction.java index 1ac7bd0aef43..eabbe88d492c 100644 --- a/src/main/java/net/sf/jabref/gui/CleanUpAction.java +++ b/src/main/java/net/sf/jabref/gui/CleanUpAction.java @@ -43,7 +43,7 @@ import com.jgoodies.forms.layout.CellConstraints; import com.jgoodies.forms.layout.FormLayout; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import net.sf.jabref.util.FileUtil; import net.sf.jabref.logic.util.MonthUtil; import net.sf.jabref.util.Util; diff --git a/src/main/java/net/sf/jabref/imports/PdfContentImporter.java b/src/main/java/net/sf/jabref/imports/PdfContentImporter.java index eaedd139f7e4..fe8380b941e4 100644 --- a/src/main/java/net/sf/jabref/imports/PdfContentImporter.java +++ b/src/main/java/net/sf/jabref/imports/PdfContentImporter.java @@ -30,7 +30,7 @@ of the License, or (at your option) any later version. import net.sf.jabref.*; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.pdfbox.pdmodel.PDDocument; diff --git a/src/main/java/net/sf/jabref/logic/crawler/ScienceDirect.java b/src/main/java/net/sf/jabref/logic/crawler/ScienceDirect.java deleted file mode 100644 index c084acbbc176..000000000000 --- a/src/main/java/net/sf/jabref/logic/crawler/ScienceDirect.java +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2003-2011 JabRef contributors. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.logic.crawler; - -import net.sf.jabref.BibtexEntry; -import net.sf.jabref.external.FindFullText; -import net.sf.jabref.external.FullTextFinder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; - -import java.net.URL; -import java.net.MalformedURLException; -import java.io.IOException; -import java.util.Objects; -import java.util.Optional; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * FullTextFinder implementation that attempts to find a PDF URL from a ScienceDirect article page. - */ -public class ScienceDirect implements FullTextFinder { - private static final Log LOGGER = LogFactory.getLog(ScienceDirect.class); - - private static final String URL_EXP = "sciencedirect.com"; - - @Override - public Optional findFullText(BibtexEntry entry) throws IOException { - Objects.requireNonNull(entry); - // TODO: http://dev.elsevier.com/ - // https://github.com/Mashape/unirest-java - return Optional.empty(); - } -} diff --git a/src/main/java/net/sf/jabref/logic/crawler/ACS.java b/src/main/java/net/sf/jabref/logic/fetcher/ACS.java similarity index 63% rename from src/main/java/net/sf/jabref/logic/crawler/ACS.java rename to src/main/java/net/sf/jabref/logic/fetcher/ACS.java index 3af796184072..b3637c1d399a 100644 --- a/src/main/java/net/sf/jabref/logic/crawler/ACS.java +++ b/src/main/java/net/sf/jabref/logic/fetcher/ACS.java @@ -1,30 +1,13 @@ -/* Copyright (C) 2014 Commonwealth Scientific and Industrial Research Organisation - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import net.sf.jabref.BibtexEntry; -import net.sf.jabref.external.FullTextFinder; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import java.net.HttpURLConnection; import java.net.URL; import java.io.IOException; import java.util.Objects; diff --git a/src/main/java/net/sf/jabref/logic/fetcher/FullTextFinder.java b/src/main/java/net/sf/jabref/logic/fetcher/FullTextFinder.java new file mode 100644 index 000000000000..c4e8b5b6c2b1 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/fetcher/FullTextFinder.java @@ -0,0 +1,24 @@ +package net.sf.jabref.logic.fetcher; + +import net.sf.jabref.BibtexEntry; + +import java.net.URL; +import java.io.IOException; +import java.util.Optional; + +/** + * This interface is used for classes that try to resolve a full-text PDF url for a BibTex entry. + * Implementing classes should specialize on specific article sites. + * See e.g. @link{http://libguides.mit.edu/apis}. + */ +public interface FullTextFinder { + /** + * Tries to find a fulltext URL for a given BibTex entry. + * + * @param entry The Bibtex entry + * @return The fulltext PDF URL Optional, if found, or an empty Optional if not found. + * @throws NullPointerException if no BibTex entry is given + * @throws java.io.IOException + */ + Optional findFullText(BibtexEntry entry) throws IOException; +} diff --git a/src/main/java/net/sf/jabref/logic/crawler/GoogleScholar.java b/src/main/java/net/sf/jabref/logic/fetcher/GoogleScholar.java similarity index 68% rename from src/main/java/net/sf/jabref/logic/crawler/GoogleScholar.java rename to src/main/java/net/sf/jabref/logic/fetcher/GoogleScholar.java index 9afe8cc6573d..da4fd72be51e 100644 --- a/src/main/java/net/sf/jabref/logic/crawler/GoogleScholar.java +++ b/src/main/java/net/sf/jabref/logic/fetcher/GoogleScholar.java @@ -1,22 +1,6 @@ -/* Copyright (C) 2003-2011 JabRef contributors. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import net.sf.jabref.BibtexEntry; -import net.sf.jabref.external.FullTextFinder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jsoup.Jsoup; @@ -24,8 +8,6 @@ import org.jsoup.select.Elements; import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; import java.util.Objects; @@ -55,7 +37,7 @@ public Optional findFullText(BibtexEntry entry) throws IOException { String url = String.format(SEARCH_URL, URLEncoder.encode(entryTitle, "UTF-8")); Document doc = Jsoup.connect(url) - .userAgent("Mozilla") // don't identify as a crawler + .userAgent("Mozilla") // don't identify as a crawler FIXME: still gets blocked in tests .get(); // Check results for PDF link // TODO: link always on first result or none? diff --git a/src/main/java/net/sf/jabref/logic/fetcher/ScienceDirect.java b/src/main/java/net/sf/jabref/logic/fetcher/ScienceDirect.java new file mode 100644 index 000000000000..92f7ae3aa783 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/fetcher/ScienceDirect.java @@ -0,0 +1,57 @@ +package net.sf.jabref.logic.fetcher; + +import com.mashape.unirest.http.HttpResponse; +import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.exceptions.UnirestException; +import net.sf.jabref.BibtexEntry; +import net.sf.jabref.logic.util.DOI; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.InputStream; +import java.net.URL; +import java.io.IOException; +import java.util.Objects; +import java.util.Optional; + +/** + * FullTextFinder implementation that attempts to find a PDF URL from a ScienceDirect article page. + * + * @see http://dev.elsevier.com/ + */ +public class ScienceDirect implements FullTextFinder { + private static final Log LOGGER = LogFactory.getLog(ScienceDirect.class); + + private static final String API_URL = "http://api.elsevier.com/content/article/doi/"; + private static final String API_KEY = "fb82f2e692b3c72dafe5f4f1fa0ac00b"; + @Override + public Optional findFullText(BibtexEntry entry) throws IOException { + Objects.requireNonNull(entry); + Optional pdfLink = Optional.empty(); + + // Try unique DOI first + Optional doi = DOI.build(entry.getField("doi")); + + if(doi.isPresent()) { + // Available in catalog? + try { + String request = API_URL + doi.get().getDOI(); + HttpResponse response = Unirest.get(request) + .header("X-ELS-APIKey", API_KEY) + .queryString("httpAccept", "application/pdf") + .asBinary(); + + if (response.getStatus() == 200) { + LOGGER.info("Fulltext PDF found @ ScienceDirect."); + pdfLink = Optional.of(new URL(request + "?httpAccept=application/pdf")); + } + } catch(UnirestException e) { + LOGGER.warn("Elsevier API request failed: " + e.getMessage()); + } + } + + // TODO: title search + // We can also get abstract automatically! + return pdfLink; + } +} diff --git a/src/main/java/net/sf/jabref/logic/crawler/SpringerLink.java b/src/main/java/net/sf/jabref/logic/fetcher/SpringerLink.java similarity index 68% rename from src/main/java/net/sf/jabref/logic/crawler/SpringerLink.java rename to src/main/java/net/sf/jabref/logic/fetcher/SpringerLink.java index 90a297633154..d1af71371cba 100644 --- a/src/main/java/net/sf/jabref/logic/crawler/SpringerLink.java +++ b/src/main/java/net/sf/jabref/logic/fetcher/SpringerLink.java @@ -1,36 +1,16 @@ -/* Copyright (C) 2003-2011 JabRef contributors. - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.JsonNode; import com.mashape.unirest.http.Unirest; import com.mashape.unirest.http.exceptions.UnirestException; import net.sf.jabref.BibtexEntry; -import net.sf.jabref.external.FullTextFinder; -import net.sf.jabref.util.DOI; +import net.sf.jabref.logic.util.DOI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONObject; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; import java.net.URL; -import java.net.MalformedURLException; import java.io.*; import java.util.Objects; import java.util.Optional; diff --git a/src/main/java/net/sf/jabref/util/DOI.java b/src/main/java/net/sf/jabref/logic/util/DOI.java similarity index 95% rename from src/main/java/net/sf/jabref/util/DOI.java rename to src/main/java/net/sf/jabref/logic/util/DOI.java index aa48550459b0..5208418d4aa4 100644 --- a/src/main/java/net/sf/jabref/util/DOI.java +++ b/src/main/java/net/sf/jabref/logic/util/DOI.java @@ -1,4 +1,4 @@ -package net.sf.jabref.util; +package net.sf.jabref.logic.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -10,6 +10,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Class for working with Digital object identifiers (DOIs) + * + * @see https://en.wikipedia.org/wiki/Digital_object_identifier + */ public class DOI { private static final Log LOGGER = LogFactory.getLog(DOI.class); diff --git a/src/test/java/net/sf/jabref/logic/crawler/ScienceDirectTest.java b/src/test/java/net/sf/jabref/logic/crawler/ScienceDirectTest.java deleted file mode 100644 index b5143c650038..000000000000 --- a/src/test/java/net/sf/jabref/logic/crawler/ScienceDirectTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.sf.jabref.logic.crawler; - -import net.sf.jabref.BibtexEntry; -import net.sf.jabref.logic.crawler.ScienceDirect; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; - -public class ScienceDirectTest { - ScienceDirect finder; - BibtexEntry entry; - - @Before - public void setup() { - finder = new ScienceDirect(); - entry = new BibtexEntry(); - } - - - @Test(expected = NullPointerException.class) - public void rejectNullParameter() throws IOException { - finder.findFullText(null); - } - - /* - @Test - public void findFullTextURL() throws IOException { - Assert.assertEquals( - new URL("http://www.sciencedirect.com/science/article/pii/S2212671614001024/pdf?md5=4e2e9a369b4d5b3db5100aba599bef8b&pid=1-s2.0-S2212671614001024-main.pdf"), - finder.findFullTextURL(new URL("http://www.sciencedirect.com/science/article/pii/S2212671614001024")) - ); - } - - @Test - public void nullWithNoFullTextURL() throws IOException { - Assert.assertNull(finder.findFullTextURL(new URL("http://www.sciencedirect.com/science/journals"))); - } - */ -} diff --git a/src/test/java/net/sf/jabref/logic/crawler/ACSTest.java b/src/test/java/net/sf/jabref/logic/fetcher/ACSTest.java similarity index 87% rename from src/test/java/net/sf/jabref/logic/crawler/ACSTest.java rename to src/test/java/net/sf/jabref/logic/fetcher/ACSTest.java index 779f436beb67..53dc0ffc3e11 100644 --- a/src/test/java/net/sf/jabref/logic/crawler/ACSTest.java +++ b/src/test/java/net/sf/jabref/logic/fetcher/ACSTest.java @@ -1,15 +1,12 @@ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import net.sf.jabref.BibtexEntry; import net.sf.jabref.BibtexEntryType; -import net.sf.jabref.external.FullTextFinder; -import net.sf.jabref.logic.crawler.ACS; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.util.Optional; diff --git a/src/test/java/net/sf/jabref/logic/crawler/GoogleScholarTest.java b/src/test/java/net/sf/jabref/logic/fetcher/GoogleScholarTest.java similarity index 92% rename from src/test/java/net/sf/jabref/logic/crawler/GoogleScholarTest.java rename to src/test/java/net/sf/jabref/logic/fetcher/GoogleScholarTest.java index 6ce1137001ba..4f97c8a25f72 100644 --- a/src/test/java/net/sf/jabref/logic/crawler/GoogleScholarTest.java +++ b/src/test/java/net/sf/jabref/logic/fetcher/GoogleScholarTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import net.sf.jabref.BibtexEntry; import org.junit.Assert; @@ -6,12 +6,9 @@ import org.junit.Test; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.util.Optional; -import static org.junit.Assert.*; - public class GoogleScholarTest { GoogleScholar finder; BibtexEntry entry; diff --git a/src/test/java/net/sf/jabref/logic/fetcher/ScienceDirectTest.java b/src/test/java/net/sf/jabref/logic/fetcher/ScienceDirectTest.java new file mode 100644 index 000000000000..e75413055e4f --- /dev/null +++ b/src/test/java/net/sf/jabref/logic/fetcher/ScienceDirectTest.java @@ -0,0 +1,43 @@ +package net.sf.jabref.logic.fetcher; + +import net.sf.jabref.BibtexEntry; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.URL; +import java.util.Optional; + +public class ScienceDirectTest { + ScienceDirect finder; + BibtexEntry entry; + + @Before + public void setup() { + finder = new ScienceDirect(); + entry = new BibtexEntry(); + } + + @Test(expected = NullPointerException.class) + public void rejectNullParameter() throws IOException { + finder.findFullText(null); + } + + @Test + public void findByDOI() throws IOException { + entry.setField("doi", "10.1016/j.aasri.2014.09.002"); + + Assert.assertEquals( + Optional.of(new URL("http://api.elsevier.com/content/article/doi/10.1016/j.aasri.2014.09.002?httpAccept=application/pdf")), + finder.findFullText(entry) + ); + } + + @Test + public void notFoundByDOI() throws IOException { + entry.setField("doi", "10.1016/j.aasri.2014.0559.002"); + + Assert.assertEquals(Optional.empty(), finder.findFullText(entry)); + } +} diff --git a/src/test/java/net/sf/jabref/logic/crawler/SpringerLinkTest.java b/src/test/java/net/sf/jabref/logic/fetcher/SpringerLinkTest.java similarity index 90% rename from src/test/java/net/sf/jabref/logic/crawler/SpringerLinkTest.java rename to src/test/java/net/sf/jabref/logic/fetcher/SpringerLinkTest.java index fde34d247a98..2ed334d83d45 100644 --- a/src/test/java/net/sf/jabref/logic/crawler/SpringerLinkTest.java +++ b/src/test/java/net/sf/jabref/logic/fetcher/SpringerLinkTest.java @@ -1,4 +1,4 @@ -package net.sf.jabref.logic.crawler; +package net.sf.jabref.logic.fetcher; import net.sf.jabref.BibtexEntry; import org.junit.Assert; @@ -6,12 +6,9 @@ import org.junit.Test; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import java.util.Optional; -import static org.junit.Assert.*; - public class SpringerLinkTest { SpringerLink finder; BibtexEntry entry; diff --git a/src/test/java/net/sf/jabref/util/DOITest.java b/src/test/java/net/sf/jabref/logic/util/DOITest.java similarity index 98% rename from src/test/java/net/sf/jabref/util/DOITest.java rename to src/test/java/net/sf/jabref/logic/util/DOITest.java index af4eba2c59b5..5a86d68ca493 100644 --- a/src/test/java/net/sf/jabref/util/DOITest.java +++ b/src/test/java/net/sf/jabref/logic/util/DOITest.java @@ -1,5 +1,6 @@ -package net.sf.jabref.util; +package net.sf.jabref.logic.util; +import net.sf.jabref.logic.util.DOI; import org.junit.Assert; import org.junit.Test; diff --git a/src/test/java/net/sf/jabref/util/UtilTest.java b/src/test/java/net/sf/jabref/util/UtilTest.java index 201598c31cd9..95964c801252 100644 --- a/src/test/java/net/sf/jabref/util/UtilTest.java +++ b/src/test/java/net/sf/jabref/util/UtilTest.java @@ -7,6 +7,7 @@ import net.sf.jabref.imports.BibtexParser; import net.sf.jabref.imports.ParserResult; +import net.sf.jabref.logic.util.DOI; import net.sf.jabref.logic.util.StringUtil; import org.junit.Assert; import org.junit.Before; @@ -17,7 +18,6 @@ import java.awt.*; import java.io.StringReader; -import java.net.URI; import java.util.*; import java.util.List;