From 06befaee4e5f7fc07017ed739f01df5a88f09635 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 18 Sep 2019 22:33:47 +0200 Subject: [PATCH] tests: allow testing live URLs --- .../nikiroo/fanfix/test/ConversionTest.java | 46 ++++++++++++++----- src/be/nikiroo/fanfix/test/Test.java | 29 ++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/be/nikiroo/fanfix/test/ConversionTest.java b/src/be/nikiroo/fanfix/test/ConversionTest.java index 371c05a..035a848 100644 --- a/src/be/nikiroo/fanfix/test/ConversionTest.java +++ b/src/be/nikiroo/fanfix/test/ConversionTest.java @@ -23,10 +23,11 @@ class ConversionTest extends TestLauncher { private String resultDir; private List realTypes; private Map> skipCompare; + private Map> 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>(); + skipCompareCross = new HashMap>(); + skipCompare.put("epb.ncx", Arrays.asList(" ", " ")); 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(" ")); + skipCompareCross.put("index.html", + Arrays.asList("
")); + 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> skipCompare = errMess.startsWith("Cross") ? this.skipCompareCross + : this.skipCompare; + FilenameFilter filter = null; if (limitTiFiles != null) { filter = new FilenameFilter() { diff --git a/src/be/nikiroo/fanfix/test/Test.java b/src/be/nikiroo/fanfix/test/Test.java index 7aac0ce..35fdec1 100644 --- a/src/be/nikiroo/fanfix/test/Test.java +++ b/src/be/nikiroo/fanfix/test/Test.java @@ -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(); -- 2.27.0