From: Niki Roo Date: Wed, 26 Sep 2018 07:26:38 +0000 (+0200) Subject: Reorganise test system via Downloader/Cache X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=6e234797ebb6bf2ba83e6e36d95c84cd176091db;p=gofetch.git Reorganise test system via Downloader/Cache --- diff --git a/src/be/nikiroo/gofetch/test/TestBase.java b/src/be/nikiroo/gofetch/test/TestBase.java index 65074ca..dbc6952 100644 --- a/src/be/nikiroo/gofetch/test/TestBase.java +++ b/src/be/nikiroo/gofetch/test/TestBase.java @@ -13,6 +13,8 @@ import be.nikiroo.gofetch.output.Gopher; import be.nikiroo.gofetch.output.Html; import be.nikiroo.gofetch.output.Output; import be.nikiroo.gofetch.support.BasicSupport; +import be.nikiroo.utils.Cache; +import be.nikiroo.utils.Downloader; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.test.TestCase; @@ -21,19 +23,32 @@ import be.nikiroo.utils.test.TestCase; *

* It will use the paths: *

* * @author niki */ abstract class TestBase extends TestCase { private BasicSupport support; + private Cache cache; + private Downloader downloader; public TestBase(BasicSupport support, String[] args) { super(support.getType().toString()); this.support = support; + try { + cache = new Cache(new File("test/source/" + support.getType()), -1, + -1); + downloader = new Downloader("gofetch", cache); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + protected InputStream download(URL url) throws IOException { + return downloader.open(url); } static protected InputStream doOpen(BasicSupport support, diff --git a/src/be/nikiroo/gofetch/test/TestLWN.java b/src/be/nikiroo/gofetch/test/TestLWN.java index 1025813..a7012b2 100644 --- a/src/be/nikiroo/gofetch/test/TestLWN.java +++ b/src/be/nikiroo/gofetch/test/TestLWN.java @@ -1,60 +1,29 @@ package be.nikiroo.gofetch.test; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; -import java.util.HashMap; -import java.util.Map; import be.nikiroo.gofetch.support.LWN; import be.nikiroo.gofetch.support.Type; public class TestLWN extends TestBase { - - static private Map getMap() throws MalformedURLException { - Map map = new HashMap(); - - map.put(new URL("https://lwn.net/"), new File("index.html")); - - map.put(new URL("https://lwn.net/Articles/763252/"), new File( - "Articles/763252.html")); - map.put(new URL("https://lwn.net/Articles/763987/"), new File( - "Articles/763987.html")); - map.put(new URL("https://lwn.net/Articles/764046"), new File( - "Articles/764046.html")); - map.put(new URL("https://lwn.net/Articles/764055"), new File( - "Articles/764055.html")); - map.put(new URL("https://lwn.net/Articles/764130"), new File( - "Articles/764130.html")); - map.put(new URL("https://lwn.net/Articles/764182"), new File( - "Articles/764182.html")); - map.put(new URL("https://lwn.net/Articles/764184/"), new File( - "Articles/764184.html")); - map.put(new URL("https://lwn.net/Articles/764202/"), new File( - "Articles/764202.html")); - map.put(new URL("https://lwn.net/Articles/764219"), new File( - "Articles/764219.html")); - map.put(new URL("https://lwn.net/Articles/764300"), new File( - "Articles/764300.html")); - map.put(new URL("https://lwn.net/Articles/764321/"), new File( - "Articles/764321.html")); - - return map; - } + static private Type type = Type.LWN; + static private TestBase base = null; public TestLWN(String[] args) { super(new LWN() { @Override protected InputStream open(URL url) throws IOException { - return doOpen(this, getMap(), url); + return base.download(url); } @Override public Type getType() { - return Type.LWN; + return type; } }, args); + + base = this; } } diff --git a/src/be/nikiroo/gofetch/test/TestSlashdot.java b/src/be/nikiroo/gofetch/test/TestSlashdot.java index d9660c4..81413b3 100644 --- a/src/be/nikiroo/gofetch/test/TestSlashdot.java +++ b/src/be/nikiroo/gofetch/test/TestSlashdot.java @@ -1,98 +1,29 @@ package be.nikiroo.gofetch.test; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; -import java.util.HashMap; -import java.util.Map; import be.nikiroo.gofetch.support.Slashdot; import be.nikiroo.gofetch.support.Type; public class TestSlashdot extends TestBase { - - static private Map getMap() throws MalformedURLException { - Map map = new HashMap(); - - map.put(new URL("https://slashdot.org/"), new File("index.html")); - - map.put(new URL( - "https://developers.slashdot.org/story/18/09/06/2024232/software-developers-are-now-more-valuable-to-companies-than-money-says-survey"), - new File( - "developers.slashdot.org/story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey.html")); - map.put(new URL( - "https://games.slashdot.org/story/18/09/06/1921222/eve-online-studio-acquired-by-korean-mmo-maker"), - new File( - "games.slashdot.org/story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker.html")); - map.put(new URL( - "https://games.slashdot.org/story/18/09/06/2146237/valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam"), - new File( - "games.slashdot.org/story_18_09_06_2146237_valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam.html")); - map.put(new URL( - "https://hardware.slashdot.org/story/18/09/06/1719243/robot-boat-sails-into-history-by-finishing-atlantic-crossing"), - new File( - "hardware.slashdot.org/story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing.html")); - map.put(new URL( - "https://hardware.slashdot.org/story/18/09/06/2058201/mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking"), - new File( - "hardware.slashdot.org/story_18_09_06_2058201_mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking.html")); - map.put(new URL( - "https://it.slashdot.org/story/18/09/07/0247228/380000-card-payments-compromised-in-british-airways-breach"), - new File( - "it.slashdot.org/story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach.html")); - map.put(new URL( - "https://mobile.slashdot.org/story/18/09/06/235254/icelanders-seek-to-keep-remote-nordic-peninsula-digital-free"), - new File( - "mobile.slashdot.org/story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free.html")); - map.put(new URL( - "https://news.slashdot.org/story/18/09/06/1558206/computer-chips-are-still-made-in-usa"), - new File( - "news.slashdot.org/story_18_09_06_1558206_computer-chips-are-still-made-in-usa.html")); - map.put(new URL( - "https://news.slashdot.org/story/18/09/06/2043213/professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook"), - new File( - "news.slashdot.org/story_18_09_06_2043213_professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook.html")); - map.put(new URL( - "https://politics.slashdot.org/story/18/09/06/2137245/blockchains-are-not-safe-for-voting-concludes-nap-report"), - new File( - "politics.slashdot.org/story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report.html")); - map.put(new URL( - "https://science.slashdot.org/story/18/09/06/2153223/study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought"), - new File( - "science.slashdot.org/story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought.html")); - map.put(new URL( - "https://tech.slashdot.org/story/18/09/06/1839242/google-investigating-issue-with-blurry-fonts-on-new-chrome-69"), - new File( - "tech.slashdot.org/story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69.html")); - map.put(new URL( - "https://tech.slashdot.org/story/18/09/06/1954253/400000-websites-vulnerable-through-exposed-git-directories"), - new File( - "tech.slashdot.org/story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories.html")); - map.put(new URL( - "https://tech.slashdot.org/story/18/09/06/205221/ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one"), - new File( - "tech.slashdot.org/story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one.html")); - map.put(new URL( - "https://yro.slashdot.org/story/18/09/06/1651255/tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine"), - new File( - "yro.slashdot.org/story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine.html")); - - return map; - } + static private Type type = Type.SLASHDOT; + static private TestBase base = null; public TestSlashdot(String[] args) { super(new Slashdot() { @Override protected InputStream open(URL url) throws IOException { - return doOpen(this, getMap(), url); + return base.download(url); } @Override public Type getType() { - return Type.SLASHDOT; + return type; } }, args); + + base = this; } } diff --git a/test/source/LWN/index.html b/test/source/LWN/lwn.net/__/_null similarity index 100% rename from test/source/LWN/index.html rename to test/source/LWN/lwn.net/__/_null diff --git a/test/source/LWN/Articles/763252.html b/test/source/LWN/lwn.net/__Articles_763252_/_null similarity index 100% rename from test/source/LWN/Articles/763252.html rename to test/source/LWN/lwn.net/__Articles_763252_/_null diff --git a/test/source/LWN/Articles/763987.html b/test/source/LWN/lwn.net/__Articles_763987_/_null similarity index 100% rename from test/source/LWN/Articles/763987.html rename to test/source/LWN/lwn.net/__Articles_763987_/_null diff --git a/test/source/LWN/Articles/764046.html b/test/source/LWN/lwn.net/__Articles_764046/_null similarity index 100% rename from test/source/LWN/Articles/764046.html rename to test/source/LWN/lwn.net/__Articles_764046/_null diff --git a/test/source/LWN/Articles/764055.html b/test/source/LWN/lwn.net/__Articles_764055/_null similarity index 100% rename from test/source/LWN/Articles/764055.html rename to test/source/LWN/lwn.net/__Articles_764055/_null diff --git a/test/source/LWN/Articles/764130.html b/test/source/LWN/lwn.net/__Articles_764130/_null similarity index 100% rename from test/source/LWN/Articles/764130.html rename to test/source/LWN/lwn.net/__Articles_764130/_null diff --git a/test/source/LWN/Articles/764182.html b/test/source/LWN/lwn.net/__Articles_764182/_null similarity index 100% rename from test/source/LWN/Articles/764182.html rename to test/source/LWN/lwn.net/__Articles_764182/_null diff --git a/test/source/LWN/Articles/764184.html b/test/source/LWN/lwn.net/__Articles_764184_/_null similarity index 100% rename from test/source/LWN/Articles/764184.html rename to test/source/LWN/lwn.net/__Articles_764184_/_null diff --git a/test/source/LWN/Articles/764202.html b/test/source/LWN/lwn.net/__Articles_764202_/_null similarity index 100% rename from test/source/LWN/Articles/764202.html rename to test/source/LWN/lwn.net/__Articles_764202_/_null diff --git a/test/source/LWN/Articles/764219.html b/test/source/LWN/lwn.net/__Articles_764219/_null similarity index 100% rename from test/source/LWN/Articles/764219.html rename to test/source/LWN/lwn.net/__Articles_764219/_null diff --git a/test/source/LWN/Articles/764300.html b/test/source/LWN/lwn.net/__Articles_764300/_null similarity index 100% rename from test/source/LWN/Articles/764300.html rename to test/source/LWN/lwn.net/__Articles_764300/_null diff --git a/test/source/LWN/Articles/764321.html b/test/source/LWN/lwn.net/__Articles_764321_/_null similarity index 100% rename from test/source/LWN/Articles/764321.html rename to test/source/LWN/lwn.net/__Articles_764321_/_null diff --git a/test/source/SLASHDOT/developers.slashdot.org/story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey.html b/test/source/SLASHDOT/developers.slashdot.org/__story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey/_null similarity index 100% rename from test/source/SLASHDOT/developers.slashdot.org/story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey.html rename to test/source/SLASHDOT/developers.slashdot.org/__story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey/_null diff --git a/test/source/SLASHDOT/games.slashdot.org/story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker.html b/test/source/SLASHDOT/games.slashdot.org/__story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker/_null similarity index 100% rename from test/source/SLASHDOT/games.slashdot.org/story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker.html rename to test/source/SLASHDOT/games.slashdot.org/__story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker/_null diff --git a/test/source/SLASHDOT/games.slashdot.org/story_18_09_06_2146237_valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam.html b/test/source/SLASHDOT/games.slashdot.org/__story_18_09_06_2146237_valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam/_null similarity index 100% rename from test/source/SLASHDOT/games.slashdot.org/story_18_09_06_2146237_valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam.html rename to test/source/SLASHDOT/games.slashdot.org/__story_18_09_06_2146237_valve-explains-how-it-decides-whos-a-straight-up-troll-publishing-video-games-on-steam/_null diff --git a/test/source/SLASHDOT/hardware.slashdot.org/story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing.html b/test/source/SLASHDOT/hardware.slashdot.org/__story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing/_null similarity index 100% rename from test/source/SLASHDOT/hardware.slashdot.org/story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing.html rename to test/source/SLASHDOT/hardware.slashdot.org/__story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing/_null diff --git a/test/source/SLASHDOT/hardware.slashdot.org/story_18_09_06_2058201_mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking.html b/test/source/SLASHDOT/hardware.slashdot.org/__story_18_09_06_2058201_mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking/_null similarity index 100% rename from test/source/SLASHDOT/hardware.slashdot.org/story_18_09_06_2058201_mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking.html rename to test/source/SLASHDOT/hardware.slashdot.org/__story_18_09_06_2058201_mit-graduate-creates-robot-that-swims-through-pipes-to-find-out-if-theyre-leaking/_null diff --git a/test/source/SLASHDOT/it.slashdot.org/story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach.html b/test/source/SLASHDOT/it.slashdot.org/__story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach/_null similarity index 100% rename from test/source/SLASHDOT/it.slashdot.org/story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach.html rename to test/source/SLASHDOT/it.slashdot.org/__story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach/_null diff --git a/test/source/SLASHDOT/mobile.slashdot.org/story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free.html b/test/source/SLASHDOT/mobile.slashdot.org/__story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free/_null similarity index 100% rename from test/source/SLASHDOT/mobile.slashdot.org/story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free.html rename to test/source/SLASHDOT/mobile.slashdot.org/__story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free/_null diff --git a/test/source/SLASHDOT/news.slashdot.org/story_18_09_06_1558206_computer-chips-are-still-made-in-usa.html b/test/source/SLASHDOT/news.slashdot.org/__story_18_09_06_1558206_computer-chips-are-still-made-in-usa/_null similarity index 100% rename from test/source/SLASHDOT/news.slashdot.org/story_18_09_06_1558206_computer-chips-are-still-made-in-usa.html rename to test/source/SLASHDOT/news.slashdot.org/__story_18_09_06_1558206_computer-chips-are-still-made-in-usa/_null diff --git a/test/source/SLASHDOT/news.slashdot.org/story_18_09_06_2043213_professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook.html b/test/source/SLASHDOT/news.slashdot.org/__story_18_09_06_2043213_professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook/_null similarity index 100% rename from test/source/SLASHDOT/news.slashdot.org/story_18_09_06_2043213_professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook.html rename to test/source/SLASHDOT/news.slashdot.org/__story_18_09_06_2043213_professor-who-coined-term-net-neutrality-thinks-its-time-to-break-up-facebook/_null diff --git a/test/source/SLASHDOT/politics.slashdot.org/story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report.html b/test/source/SLASHDOT/politics.slashdot.org/__story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report/_null similarity index 100% rename from test/source/SLASHDOT/politics.slashdot.org/story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report.html rename to test/source/SLASHDOT/politics.slashdot.org/__story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report/_null diff --git a/test/source/SLASHDOT/science.slashdot.org/story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought.html b/test/source/SLASHDOT/science.slashdot.org/__story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought/_null similarity index 100% rename from test/source/SLASHDOT/science.slashdot.org/story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought.html rename to test/source/SLASHDOT/science.slashdot.org/__story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought/_null diff --git a/test/source/SLASHDOT/index.html b/test/source/SLASHDOT/slashdot.org/__/_null similarity index 100% rename from test/source/SLASHDOT/index.html rename to test/source/SLASHDOT/slashdot.org/__/_null diff --git a/test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69.html b/test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69/_null similarity index 100% rename from test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69.html rename to test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69/_null diff --git a/test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories.html b/test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories/_null similarity index 100% rename from test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories.html rename to test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories/_null diff --git a/test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one.html b/test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one/_null similarity index 100% rename from test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one.html rename to test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one/_null diff --git a/test/source/SLASHDOT/yro.slashdot.org/story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine.html b/test/source/SLASHDOT/yro.slashdot.org/__story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine/_null similarity index 100% rename from test/source/SLASHDOT/yro.slashdot.org/story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine.html rename to test/source/SLASHDOT/yro.slashdot.org/__story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine/_null