tests: allow testing live URLs
authorNiki Roo <niki@nikiroo.be>
Wed, 18 Sep 2019 20:33:47 +0000 (22:33 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 18 Sep 2019 20:33:47 +0000 (22:33 +0200)
src/be/nikiroo/fanfix/test/ConversionTest.java
src/be/nikiroo/fanfix/test/Test.java

index 371c05aa25060a45cbb63e727a8c76b33d126c50..035a848948aa10708120fe9c12bf24742563fb68 100644 (file)
@@ -23,10 +23,11 @@ class ConversionTest extends TestLauncher {
        private String resultDir;
        private List<BasicOutput.OutputType> realTypes;
        private Map<String, List<String>> skipCompare;
+       private Map<String, List<String>> skipCompareCross;
 
-       public ConversionTest(final String testUri, final String expectedDir,
-                       final String resultDir, String[] args) {
-               super("Conversion", args);
+       public ConversionTest(String testName, final String testUri,
+                       final String expectedDir, final String resultDir, String[] args) {
+               super("Conversion - " + testName, args);
 
                this.testUri = testUri;
                this.expectedDir = expectedDir;
@@ -40,14 +41,16 @@ class ConversionTest extends TestLauncher {
                        }
                }
 
-               addTest(new TestCase("Read the test file") {
-                       @Override
-                       public void test() throws Exception {
-                               assertEquals("The test file \"" + testUri
-                                               + "\" cannot be found", true,
-                                               new File(testUri).exists());
-                       }
-               });
+               if (!testUri.startsWith("http://") && !testUri.startsWith("https://")) {
+                       addTest(new TestCase("Read the test file") {
+                               @Override
+                               public void test() throws Exception {
+                                       assertEquals("The test file \"" + testUri
+                                                       + "\" cannot be found", true,
+                                                       new File(testUri).exists());
+                               }
+                       });
+               }
 
                addTest(new TestCase("Assure directories exist") {
                        @Override
@@ -71,13 +74,27 @@ class ConversionTest extends TestLauncher {
        @Override
        protected void start() throws Exception {
                skipCompare = new HashMap<String, List<String>>();
+               skipCompareCross = new HashMap<String, List<String>>();
+               
                skipCompare.put("epb.ncx",
                                Arrays.asList("         <meta name=\"dtb:uid\" content="));
                skipCompare.put("epb.opf", Arrays.asList("      <dc:subject>",
                                "      <dc:identifier id=\"BookId\" opf:scheme=\"URI\">"));
                skipCompare.put(".info",
-                               Arrays.asList("CREATION_DATE=", "SUBJECT=", "URL=", "UUID="));
+                               Arrays.asList("CREATION_DATE=", "URL=\"file:/", "UUID="));
                skipCompare.put("URL", Arrays.asList("file:/"));
+               
+               for (String key : skipCompare.keySet()) {
+                       skipCompareCross.put(key, skipCompare.get(key));
+               }
+
+               skipCompareCross.put(".info", Arrays.asList(""));
+               skipCompareCross.put("epb.opf", Arrays.asList("      <dc:"));
+               skipCompareCross.put("title.xhtml",
+                               Arrays.asList("                 <div class=\"type\">"));
+               skipCompareCross.put("index.html",
+                               Arrays.asList("                 <div class=\"type\">"));
+               skipCompareCross.put("URL", Arrays.asList(""));
        }
 
        @Override
@@ -105,6 +122,7 @@ class ConversionTest extends TestLauncher {
                                for (BasicOutput.OutputType crossType : realTypes) {
                                        File crossDir = Test.tempFiles
                                                        .createTempDir("cross-result");
+
                                        generate(this, target.getAbsolutePath(), crossDir,
                                                        crossType);
                                        compareFiles(this, new File(resultDir), crossDir,
@@ -166,6 +184,10 @@ class ConversionTest extends TestLauncher {
        private void compareFiles(TestCase testCase, File expectedDir,
                        File resultDir, final BasicOutput.OutputType limitTiFiles,
                        final String errMess) throws Exception {
+
+               Map<String, List<String>> skipCompare = errMess.startsWith("Cross") ? this.skipCompareCross
+                               : this.skipCompare;
+
                FilenameFilter filter = null;
                if (limitTiFiles != null) {
                        filter = new FilenameFilter() {
index 7aac0cebd78cae0cc1b8bbc7788e52981986fef3..35fdec164c5ab8252a7f4a9aa05d96790c14aa71 100644 (file)
@@ -1,11 +1,10 @@
 package be.nikiroo.fanfix.test;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Properties;
 
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.bundles.ConfigBundle;
 import be.nikiroo.utils.IOUtils;
 import be.nikiroo.utils.TempFiles;
@@ -49,7 +48,7 @@ public class Test extends TestLauncher {
                addSeries(new BasicSupportUtilitiesTest(args));
                addSeries(new BasicSupportDeprecatedTest(args));
                addSeries(new LibraryTest(args));
-
+               
                File sources = new File("test/");
                if (sources.isDirectory()) {
                        for (File file : sources.listFiles()) {
@@ -71,7 +70,8 @@ public class Test extends TestLauncher {
                                        continue;
                                }
 
-                               addSeries(new ConversionTest(uri, expectedDir, resultDir, args));
+                               addSeries(new ConversionTest(file.getName(), uri, expectedDir,
+                                               resultDir, args));
                        }
                }
        }
@@ -107,32 +107,23 @@ public class Test extends TestLauncher {
                        }
                        localCache.mkdirs();
 
-                       FileOutputStream out = null;
-                       try {
-                               out = new FileOutputStream(new File(tmpConfig,
-                                               "config.properties"));
-                               Properties props = new Properties();
-                               props.setProperty("CACHE_DIR", localCache.getAbsolutePath());
-                               props.store(out, null);
-                       } finally {
-                               if (out != null) {
-                                       out.close();
-                               }
-                       }
-
                        ConfigBundle config = new ConfigBundle();
                        Bundles.setDirectory(tmpConfig.getAbsolutePath());
+                       config.setString(Config.CACHE_DIR, localCache.getAbsolutePath());
+                       config.setInteger(Config.CACHE_MAX_TIME_STABLE, -1);
+                       config.setInteger(Config.CACHE_MAX_TIME_CHANGING, -1);
                        config.updateFile(tmpConfig.getPath());
-
                        System.setProperty("CONFIG_DIR", tmpConfig.getAbsolutePath());
 
+                       Instance.init(true);
+                       Instance.getCache().setOffline(offline);
+
                        TestLauncher tests = new Test(args);
                        tests.setDetails(verbose);
 
                        result = tests.launch();
 
                        IOUtils.deltree(tmpConfig);
-                       IOUtils.deltree(localCache);
                } finally {
                        // Test temp files
                        tempFiles.close();