Reorganise test system via Downloader/Cache
authorNiki Roo <niki@nikiroo.be>
Wed, 26 Sep 2018 07:26:38 +0000 (09:26 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 26 Sep 2018 07:26:38 +0000 (09:26 +0200)
31 files changed:
src/be/nikiroo/gofetch/test/TestBase.java
src/be/nikiroo/gofetch/test/TestLWN.java
src/be/nikiroo/gofetch/test/TestSlashdot.java
test/source/LWN/lwn.net/__/_null [moved from test/source/LWN/index.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_763252_/_null [moved from test/source/LWN/Articles/763252.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_763987_/_null [moved from test/source/LWN/Articles/763987.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764046/_null [moved from test/source/LWN/Articles/764046.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764055/_null [moved from test/source/LWN/Articles/764055.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764130/_null [moved from test/source/LWN/Articles/764130.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764182/_null [moved from test/source/LWN/Articles/764182.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764184_/_null [moved from test/source/LWN/Articles/764184.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764202_/_null [moved from test/source/LWN/Articles/764202.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764219/_null [moved from test/source/LWN/Articles/764219.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764300/_null [moved from test/source/LWN/Articles/764300.html with 100% similarity]
test/source/LWN/lwn.net/__Articles_764321_/_null [moved from test/source/LWN/Articles/764321.html with 100% similarity]
test/source/SLASHDOT/developers.slashdot.org/__story_18_09_06_2024232_software-developers-are-now-more-valuable-to-companies-than-money-says-survey/_null [moved 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 with 100% similarity]
test/source/SLASHDOT/games.slashdot.org/__story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker/_null [moved from test/source/SLASHDOT/games.slashdot.org/story_18_09_06_1921222_eve-online-studio-acquired-by-korean-mmo-maker.html with 100% similarity]
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 [moved 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 with 100% similarity]
test/source/SLASHDOT/hardware.slashdot.org/__story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing/_null [moved from test/source/SLASHDOT/hardware.slashdot.org/story_18_09_06_1719243_robot-boat-sails-into-history-by-finishing-atlantic-crossing.html with 100% similarity]
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 [moved 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 with 100% similarity]
test/source/SLASHDOT/it.slashdot.org/__story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach/_null [moved from test/source/SLASHDOT/it.slashdot.org/story_18_09_07_0247228_380000-card-payments-compromised-in-british-airways-breach.html with 100% similarity]
test/source/SLASHDOT/mobile.slashdot.org/__story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free/_null [moved from test/source/SLASHDOT/mobile.slashdot.org/story_18_09_06_235254_icelanders-seek-to-keep-remote-nordic-peninsula-digital-free.html with 100% similarity]
test/source/SLASHDOT/news.slashdot.org/__story_18_09_06_1558206_computer-chips-are-still-made-in-usa/_null [moved from test/source/SLASHDOT/news.slashdot.org/story_18_09_06_1558206_computer-chips-are-still-made-in-usa.html with 100% similarity]
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 [moved 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 with 100% similarity]
test/source/SLASHDOT/politics.slashdot.org/__story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report/_null [moved from test/source/SLASHDOT/politics.slashdot.org/story_18_09_06_2137245_blockchains-are-not-safe-for-voting-concludes-nap-report.html with 100% similarity]
test/source/SLASHDOT/science.slashdot.org/__story_18_09_06_2153223_study-finds-probiotics-not-as-beneficial-for-gut-health-as-previously-thought/_null [moved 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 with 100% similarity]
test/source/SLASHDOT/slashdot.org/__/_null [moved from test/source/SLASHDOT/index.html with 100% similarity]
test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69/_null [moved from test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1839242_google-investigating-issue-with-blurry-fonts-on-new-chrome-69.html with 100% similarity]
test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories/_null [moved from test/source/SLASHDOT/tech.slashdot.org/story_18_09_06_1954253_400000-websites-vulnerable-through-exposed-git-directories.html with 100% similarity]
test/source/SLASHDOT/tech.slashdot.org/__story_18_09_06_205221_ive-seen-the-future-of-consumer-ai-and-it-doesnt-have-one/_null [moved 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 with 100% similarity]
test/source/SLASHDOT/yro.slashdot.org/__story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine/_null [moved from test/source/SLASHDOT/yro.slashdot.org/story_18_09_06_1651255_tor-browser-gets-a-redesign-switches-to-new-firefox-quantum-engine.html with 100% similarity]

index 65074ca7b577f9de79ca384225f863a75acbe239..dbc6952a6e03c1a2db2a244175b83655cf9c1a75 100644 (file)
@@ -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;
  * <p>
  * It will use the paths:
  * <ul>
- * <li><tt>test/XXX/source</tt>: the html source files</li>
- * <li><tt>test/XXX/expected</tt>: the expected output</li>
- * <li><tt>test/XXX/actual</tt>: the actual output of the last test</li>
+ * <li><tt>test/???/source</tt>: the html source files</li>
+ * <li><tt>test/???/expected</tt>: the expected output</li>
+ * <li><tt>test/???/actual</tt>: the actual output of the last test</li>
  * </ul>
  * 
  * @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,
index 1025813c36aed7725e189ae6de2b92adfe0a6f77..a7012b27e8710045589320b9a76c0a8dbb9d6312 100644 (file)
@@ -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<URL, File> getMap() throws MalformedURLException {
-               Map<URL, File> map = new HashMap<URL, File>();
-
-               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;
        }
 }
index d9660c4d72e5ae363776d3e87bdc7a2dbd14c8a1..81413b3ec5fbddb5174668d6c09e533cb23087d4 100644 (file)
@@ -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<URL, File> getMap() throws MalformedURLException {
-               Map<URL, File> map = new HashMap<URL, File>();
-
-               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;
        }
 }