From 26754b99a67cc3b7ece7b08983218766a69d0be1 Mon Sep 17 00:00:00 2001 From: Daniel Persson Date: Mon, 8 Jan 2018 22:04:22 +0100 Subject: [PATCH] test: clean API constructor test and CLI tests + deprecate other tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on @kalaspuffar’s work on #828 - use the locale object as the `Messages` lookup key to work around test failing when the messages created with the US default locale were retrieved when looking up the English locale - add test dependency to `com.googlecode.json-simple:json-simple` for easy JSON parsing - minor cleanup of `AbstractEpubCheckTest` - cleanup `api_Test` to `ApiConstructosTest` - consolidate CLI tests from `CLITest` and `command_line_Test` to a new `CommandLineTest` test class - rename class `com.adobe.epubcheck.test.common` to `CommonTestRunner` - add dreprecation annotation to the following test classes, pending refactoring: - CommonTestRunner - JsonCompare - Epub20CheckTest - Epub20CheckExpandedTest - Epub30CheckTest - Epub30CheckExpandedTest - LocalizationTest - NavCheckerTest - OCFCheckerTest - OCFFilenameCheckerTest - OCFMockPackage - MetadataSetTest - OPFCheckerTest - OPFCheckerTestChecks - OPSCheckerTest - OverlayCheckerTest - StressTest - MessageDictionary_LocalizationTest - OutputDifferenceListener - OverriddenMessageDictionaryTest - TestRunListener - UtilMessage_LocalizationTest - css_Test - debug - dtBook_Test - encryption_Test - message_coverage - opf_Test - package_Test - script_Test - single_file_Test - toc_Test - xhtml_Test - ExtraReportTest - OPFPeekerTest - PathUtilTest - ValidationReport - PrefixParsingTest - PropertyTest - VocabTest --- pom.xml | 6 + .../com/adobe/epubcheck/util/Messages.java | 9 +- .../epubcheck/api/AbstractEpubCheckTest.java | 18 +- .../ApiConstructorsTest.java} | 49 +- .../api/Epub20CheckExpandedTest.java | 1 + .../adobe/epubcheck/api/Epub20CheckTest.java | 1 + .../api/Epub30CheckExpandedTest.java | 1 + .../adobe/epubcheck/api/Epub30CheckTest.java | 1 + .../adobe/epubcheck/api/LocalizationTest.java | 1 + .../java/com/adobe/epubcheck/cli/CLITest.java | 400 --------- .../adobe/epubcheck/nav/NavCheckerTest.java | 1 + .../adobe/epubcheck/ocf/OCFCheckerTest.java | 1 + .../epubcheck/ocf/OCFFilenameCheckerTest.java | 1 + .../adobe/epubcheck/ocf/OCFMockPackage.java | 1 + .../adobe/epubcheck/opf/MetadataSetTest.java | 1 + .../adobe/epubcheck/opf/OPFCheckerTest.java | 1 + .../epubcheck/opf/OPFCheckerTestChecks.java | 1 + .../adobe/epubcheck/ops/OPSCheckerTest.java | 1 + .../epubcheck/overlay/OverlayCheckerTest.java | 1 + .../adobe/epubcheck/stress/StressTest.java | 1 + .../{common.java => CommonTestRunner.java} | 15 +- .../{jsonCompare.java => JsonCompare.java} | 3 +- .../MessageDictionary_LocalizationTest.java | 1 + .../epubcheck/test/NoExitSecurityManager.java | 2 +- .../test/OutputDifferenceListener.java | 1 + .../test/OverriddenMessageDictionaryTest.java | 4 +- .../adobe/epubcheck/test/TestRunListener.java | 1 + .../test/UtilMessage_LocalizationTest.java | 1 + .../epubcheck/test/command_line_Test.java | 422 ---------- .../com/adobe/epubcheck/test/css_Test.java | 10 +- .../java/com/adobe/epubcheck/test/debug.java | 1 + .../com/adobe/epubcheck/test/dtBook_Test.java | 8 +- .../adobe/epubcheck/test/encryption_Test.java | 12 +- .../epubcheck/test/message_coverage.java | 1 + .../com/adobe/epubcheck/test/opf_Test.java | 7 +- .../adobe/epubcheck/test/package_Test.java | 49 +- .../com/adobe/epubcheck/test/script_Test.java | 8 +- .../epubcheck/test/single_file_Test.java | 3 +- .../com/adobe/epubcheck/test/toc_Test.java | 6 +- .../com/adobe/epubcheck/test/xhtml_Test.java | 5 +- .../epubcheck/tools/CommandLineTest.java | 792 ++++++++++++++++++ .../adobe/epubcheck/util/ExtraReportTest.java | 1 + .../adobe/epubcheck/util/OPFPeekerTest.java | 1 + .../adobe/epubcheck/util/PathUtilTest.java | 2 + .../epubcheck/util/ValidationReport.java | 1 + .../epubcheck/vocab/PrefixParsingTest.java | 1 + .../adobe/epubcheck/vocab/PropertyTest.java | 1 + .../com/adobe/epubcheck/vocab/VocabTest.java | 1 + .../epubcheck/api/InputStream_Expected.txt | 1 + .../epubcheck/api/PrintWriter_Expected.txt | 1 + .../test/api/InputStream_Expected.txt | 2 - .../test/api/PrintWriter_Expected.txt | 2 - .../20-severity-tester/META-INF/container.xml | 6 + .../20-severity-tester/OPS/content_001.xhtml | 11 + .../tools/20-severity-tester/OPS/package.opf | 14 + .../tools/20-severity-tester/OPS/toc.ncx | 18 + .../tools/20-severity-tester/mimetype | 1 + .../20-warning-tester/META-INF/container.xml | 6 + .../20-warning-tester/OPS/content_001.xhtml | 11 + .../20-warning-tester/OPS/content_002.xhtml | 11 + .../tools/20-warning-tester/OPS/package.opf | 15 + .../tools/20-warning-tester/OPS/toc.ncx | 18 + .../tools/20-warning-tester/mimetype | 1 + .../META-INF/container.xml | 6 + .../30-mimetype-invalid/OPS/content_001.xhtml | 11 + .../tools/30-mimetype-invalid/OPS/nav.xhtml | 19 + .../tools/30-mimetype-invalid/OPS/package.opf | 16 + .../tools/30-mimetype-invalid/mimetype | 1 + .../30-valid-test/META-INF/container.xml | 6 + .../tools/30-valid-test/OPS/content_001.xhtml | 11 + .../tools/30-valid-test/OPS/nav.xhtml | 19 + .../tools/30-valid-test/OPS/package.opf | 16 + .../epubcheck/tools/30-valid-test/mimetype | 1 + .../adobe/epubcheck/tools/nav-no-toc.xhtml | 31 + .../epubcheck/tools/severity_override.txt | 4 + .../tools/severity_override_bad_id.txt | 3 + .../tools/severity_override_bad_message.txt | 2 + .../tools/severity_override_bad_severity.txt | 3 + .../severity_override_bad_suggestion.txt | 2 + .../com/adobe/epubcheck/tools/valid.epub | Bin 0 -> 1770 bytes .../com/adobe/epubcheck/tools/wrong_extension | Bin 0 -> 1770 bytes .../epubcheck/tools/wrong_extension.ePub | Bin 0 -> 1770 bytes .../adobe/epubcheck/tools/wrong_extension.zip | Bin 0 -> 1770 bytes .../minimal-epub/30/minimal-epub-30.epub | Bin 0 -> 1770 bytes 84 files changed, 1207 insertions(+), 919 deletions(-) rename src/test/java/com/adobe/epubcheck/{test/api_Test.java => api/ApiConstructorsTest.java} (68%) delete mode 100644 src/test/java/com/adobe/epubcheck/cli/CLITest.java rename src/test/java/com/adobe/epubcheck/test/{common.java => CommonTestRunner.java} (94%) rename src/test/java/com/adobe/epubcheck/test/{jsonCompare.java => JsonCompare.java} (99%) delete mode 100644 src/test/java/com/adobe/epubcheck/test/command_line_Test.java create mode 100644 src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java create mode 100644 src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt create mode 100644 src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt delete mode 100644 src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt delete mode 100644 src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx create mode 100644 src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/META-INF/container.xml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/content_001.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/nav.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/package.opf create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/mimetype create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf create mode 100644 src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype create mode 100644 src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml create mode 100644 src/test/resources/com/adobe/epubcheck/tools/severity_override.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt create mode 100644 src/test/resources/com/adobe/epubcheck/tools/valid.epub create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub create mode 100644 src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip create mode 100644 src/test/resources/minimal-epub/30/minimal-epub-30.epub diff --git a/pom.xml b/pom.xml index df80ffc26..c61ce384e 100644 --- a/pom.xml +++ b/pom.xml @@ -221,6 +221,12 @@ jackson-mapper-asl 1.9.12 + + com.googlecode.json-simple + json-simple + 1.1.1 + test + xmlunit xmlunit diff --git a/src/main/java/com/adobe/epubcheck/util/Messages.java b/src/main/java/com/adobe/epubcheck/util/Messages.java index f1b72dc42..687c6140a 100644 --- a/src/main/java/com/adobe/epubcheck/util/Messages.java +++ b/src/main/java/com/adobe/epubcheck/util/Messages.java @@ -43,7 +43,7 @@ public class Messages { private static final String BUNDLE_NAME = "com.adobe.epubcheck.util.messages"; - private static final Table messageTable = HashBasedTable.create(); + private static final Table messageTable = HashBasedTable.create(); private ResourceBundle bundle; private Locale locale; @@ -86,9 +86,8 @@ public static Messages getInstance(Locale locale, Class cls) locale = (locale == null) ? Locale.getDefault() : locale; String bundleKey = (cls==null)? BUNDLE_NAME : getBundleName(cls); - String localeKey = locale.getLanguage(); - if (messageTable.contains(bundleKey, localeKey)) { - instance = messageTable.get(bundleKey, localeKey); + if (messageTable.contains(bundleKey, locale)) { + instance = messageTable.get(bundleKey, locale); } else { @@ -97,7 +96,7 @@ public static Messages getInstance(Locale locale, Class cls) if (instance == null) { instance = new Messages(locale, bundleKey); - messageTable.put(bundleKey, localeKey, instance); + messageTable.put(bundleKey, locale, instance); } } } diff --git a/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java b/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java index efebfd24e..2dc5c1097 100644 --- a/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java @@ -39,6 +39,7 @@ import java.util.LinkedList; import java.util.List; +import com.adobe.epubcheck.api.*; import com.adobe.epubcheck.util.*; import org.junit.Before; @@ -47,14 +48,12 @@ public abstract class AbstractEpubCheckTest { - private String basepath; - List expectedWarnings = new LinkedList(); - List expectedErrors = new LinkedList(); - List expectedFatals = new LinkedList(); - List expectedInfos = new LinkedList(); - List expectedUsages = new LinkedList(); - + protected List expectedWarnings = new LinkedList(); + protected List expectedErrors = new LinkedList(); + protected List expectedFatals = new LinkedList(); + protected List expectedInfos = new LinkedList(); + protected List expectedUsages = new LinkedList(); protected AbstractEpubCheckTest(String basepath) { @@ -86,11 +85,6 @@ public void testValidateDocument(String fileName, String resultFile) testValidateDocument(fileName, resultFile, null, false, false); } - public void testValidateDocument(String fileName, String resultFile, boolean usage, boolean verbose) - { - testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, usage, verbose); - } - public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile, boolean usage, boolean verbose) { diff --git a/src/test/java/com/adobe/epubcheck/test/api_Test.java b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java similarity index 68% rename from src/test/java/com/adobe/epubcheck/test/api_Test.java rename to src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java index 9f27e173a..427ef51a4 100644 --- a/src/test/java/com/adobe/epubcheck/test/api_Test.java +++ b/src/test/java/com/adobe/epubcheck/api/ApiConstructorsTest.java @@ -1,4 +1,4 @@ -package com.adobe.epubcheck.test; +package com.adobe.epubcheck.api; import java.io.File; import java.io.FileInputStream; @@ -15,12 +15,13 @@ import com.adobe.epubcheck.api.EpubCheck; import com.adobe.epubcheck.api.Report; +import com.adobe.epubcheck.test.CommonTestRunner; import com.adobe.epubcheck.util.WriterReportImpl; /** * Test the various constructors for the EpubCheck Object. */ -public class api_Test +public class ApiConstructorsTest { private Locale defaultLocale; @@ -38,44 +39,63 @@ public void after() throws Exception Locale.setDefault(defaultLocale); } + + /** + * Checking if the standard API constructor can take an epub and validate it. + * + * @throws Exception + */ @Test - public void EpubCheck1_Test() throws Exception + public void StandardConstructorTest() throws Exception { File epub = getTestEpub(); EpubCheck check = new EpubCheck(epub); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have no errors.", 0, check.doValidate()); } + /** + * Checking if we can apply a PrintWriter to the constructor and get the expected output written + * to the supplied PrintWriter. + * + * @throws Exception + */ @Test - public void EpubCheck_PrintWriter_Test() throws Exception + public void PrintWriterConstructorTest() throws Exception { try { File epub = getTestEpub(); - URL expectedUrl = common.class.getResource("api"); + URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); + File actualResults = new File(outputPath + "/PrintWriter_Actual.txt"); File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt"); FileOutputStream outputStream = new FileOutputStream(actualResults); PrintWriter out = new PrintWriter(outputStream); EpubCheck check = new EpubCheck(epub, out); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have no errors.", 0, check.doValidate()); out.flush(); outputStream.close(); out.close(); Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists()); Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists()); - common.compareText(expectedResults, actualResults); + CommonTestRunner.compareText(expectedResults, actualResults); } catch (URISyntaxException e) { throw new IllegalStateException("Cannot find test file", e); } } + /** + * Checking if we can stream a epub to the constructor and use a Report object to + * summarize the output. + * + * @throws Exception + */ @Test - public void EpubCheck_InputStream_Test() throws Exception + public void InputStreamConstructorTest() throws Exception { try { File epub = getTestEpub(); - URL expectedUrl = common.class.getResource("api"); + URL expectedUrl = this.getClass().getResource(""); String outputPath = new File(expectedUrl.toURI()).getAbsolutePath(); File actualResults = new File(outputPath + "/InputStream_Actual.txt"); File expectedResults = new File(outputPath + "/InputStream_Expected.txt"); @@ -85,23 +105,24 @@ public void EpubCheck_InputStream_Test() throws Exception FileInputStream epubStream = new FileInputStream(epub); Report report = new WriterReportImpl(out, "Testing 123"); EpubCheck check = new EpubCheck(epubStream, report, epub.getPath()); - Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate()); + Assert.assertEquals("The file should have generated errors.", 0, check.doValidate()); out.flush(); outputStream.close(); out.close(); epubStream.close(); + Assert.assertEquals("Errors reported", 0, report.getErrorCount()); Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists()); Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists()); - common.compareText(expectedResults, actualResults); + CommonTestRunner.compareText(expectedResults, actualResults); } catch (URISyntaxException e) { throw new IllegalStateException("Cannot find test file", e); } } - private File getTestEpub() + private File getTestEpub() throws Exception { try { - URL inputUrl = common.class.getResource("../../../../30/epub/invalid/font_no_fallback.epub"); + URL inputUrl = this.getClass().getResource("../../../../minimal-epub/30/minimal-epub-30.epub"); String inputPath = new File(inputUrl.toURI()).getAbsolutePath(); File epub = new File(inputPath); Assert.assertTrue("Couldn't find resource: " + inputPath, epub.exists()); diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java index a6c11733e..063fe6e7e 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java @@ -28,6 +28,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub20CheckExpandedTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java index 9ff14f1c7..0622ef6e8 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java @@ -30,6 +30,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub20CheckTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java index c14299ab1..9635c3933 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckExpandedTest.java @@ -29,6 +29,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub30CheckExpandedTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java index 4deae518c..aff1936ba 100644 --- a/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java +++ b/src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java @@ -28,6 +28,7 @@ import com.adobe.epubcheck.messages.MessageId; +@Deprecated public class Epub30CheckTest extends AbstractEpubCheckTest { diff --git a/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java b/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java index d86c0c4ad..4ae26970b 100644 --- a/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/api/LocalizationTest.java @@ -16,6 +16,7 @@ import com.adobe.epubcheck.messages.Message; import com.adobe.epubcheck.util.FeatureEnum; +@Deprecated public class LocalizationTest { diff --git a/src/test/java/com/adobe/epubcheck/cli/CLITest.java b/src/test/java/com/adobe/epubcheck/cli/CLITest.java deleted file mode 100644 index 1c6c8d52f..000000000 --- a/src/test/java/com/adobe/epubcheck/cli/CLITest.java +++ /dev/null @@ -1,400 +0,0 @@ -package com.adobe.epubcheck.cli; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintStream; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Locale; - -import org.junit.Test; - -import com.adobe.epubcheck.tool.EpubChecker; - -public class CLITest -{ - private static String epubPath = "/30/epub/"; - private static String expPath = "/30/expanded/"; - private static String singlePath = "/30/single/"; - - private static String epubApiPath = "/com/adobe/epubcheck/test/package/"; - - @Test - public void testNPE() - { - assertEquals(1, run(null)); - } - - //@Test // STA - test passes in UI but fails in Maven - public void testValidEPUB() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub"})); - } - - @Test - public void testValidEPUBArchive() - { - assertEquals(0, run(new String[]{expPath + "valid/lorem-basic-ncx/", "-mode", "exp", "-save"})); - - // since issue #255 we need the absolute path to check the saved outfile - File baseDirParent = new File(getAbsoluteBasedir(expPath + "valid/lorem-basic-ncx/")).getParentFile(); - File out = new File(baseDirParent + File.separator + "lorem-basic-ncx.epub"); - - assertTrue(out.exists()); - if (out.exists()) - { - out.delete(); - } - } - - @Test - public void testInvalidEPUB() - { - assertEquals(1, run(new String[]{epubPath + "invalid/lorem-xht-sch-1.epub"})); - } - - @Test - public void testValidExp() - { - assertEquals(0, run(new String[]{expPath + "valid/lorem-basic/", "-mode", "exp"})); - } - - @Test - public void testInvalidExp() - { - assertEquals(1, run(new String[]{expPath + "invalid/lorem-xhtml-rng-1/", "-mode", "exp"})); - } - - @Test - public void testValidSingle() - { - assertEquals(0, run(new String[]{singlePath + "nav/valid/nav001.xhtml", "-mode", "nav"})); - } - - @Test - public void testInvalidSingle() - { - assertEquals(1, run(new String[]{singlePath + "nav/invalid/noTocNav.xhtml", "-mode", "nav"})); - } - - @Test - public void testExtension1() - { - assertEquals(0, run(new String[]{epubPath + "invalid/extension-1.ePub"})); - } - - @Test - public void testExtension2() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension.zip", "--profile", "default"})); - } - - @Test - public void testExtension3() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension_v3.zip", "--profile", "default"})); - } - - @Test - public void testExtension4() - { - assertEquals(0, run(new String[]{epubApiPath + "wrong_extension_v3", "--profile", "default"})); - } - - @Test - public void testOutputXMLCreation() - { - File xmlOut1 = new File("outfile.xml"); - if(xmlOut1.exists()) xmlOut1.delete(); - - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-out", "outfile.xml"})); - - assertTrue(xmlOut1.exists()); - if(xmlOut1.exists()) xmlOut1.delete(); - } - - @Test - public void testOutputXMLCreation_ModeExpanded() - { - File xmlOut2 = new File("outfile2.xml"); - if(xmlOut2.exists()) - { - xmlOut2.delete(); - } - - assertEquals(1, run(new String[]{expPath + "invalid/lorem-xhtml-rng-1/", "-mode", "exp", "-out", "outfile2.xml"})); - - assertTrue(xmlOut2.exists()); - if(xmlOut2.exists()) - { - xmlOut2.delete(); - } - } - - @Test - public void testQuietRun() - { - PrintStream outOrig = System.out; - CountingOutStream outCount = new CountingOutStream(); - System.setOut(new PrintStream(outCount)); - String epubFilePath = getAbsoluteBasedir(epubPath + "valid/lorem.epub"); - EpubChecker epubChecker = new EpubChecker(); - int result = epubChecker.run(new String[]{ epubFilePath, "--quiet", "--failonwarnings" }); - System.setOut(outOrig); - assertEquals(0, result); - // System.err.println("Output [" + outCount.getValue() + "]"); - assertEquals("Output [" + outCount.getValue() + "]", 0, outCount.getCounts()); - } - - @Test - public void testQuietRunWithOutput() - { - final String xmlOutFileName = "outfile4.xml"; - final File xmlOut = new File(xmlOutFileName); - if(xmlOut.exists()) xmlOut.delete(); - - PrintStream outOrig = System.out; - CountingOutStream outCount = new CountingOutStream(); - System.setOut(new PrintStream(outCount)); - String epubFilePath = getAbsoluteBasedir(epubPath + "valid/lorem.epub"); - EpubChecker epubChecker = new EpubChecker(); - int result = epubChecker.run(new String[]{ epubFilePath, "--quiet", "--out", xmlOutFileName}); - System.setOut(outOrig); - assertEquals(0, result); - // System.err.println("Output [" + outCount.getValue() + "]"); - assertEquals("Output [" + outCount.getValue() + "]", 0, outCount.getCounts()); - - assertTrue(xmlOut.exists()); - if(xmlOut.exists()) - { - xmlOut.delete(); - } - } - - @Test - public void testHelpRun1() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--help"})); - } - - @Test - public void testHelpRun2() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-h"})); - } - - @Test - public void testHelpRun3() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-?"})); - } - - @Test - public void testVersionRun1() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "--version"})); - } - - @Test - public void testVersionRun2() - { - assertEquals(0, run(new String[]{epubPath + "valid/lorem.epub", "-version"})); - } - - @Test - public void testInvalidOption() - { - /* Make sure an unrecognized option generates an error. */ - assertEquals(1, run(new String[]{epubPath + "valid/lorem.epub", "--invalidoption"})); - } - - - @Test - public void testLocalizationWithValidLocaleAndLocalization() - { - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "fr-FR" - }); - System.setOut(outOrig); - assertTrue("Valid Locale should use correct language.", stream.getValue().indexOf("faites") >= 0); - } - - @Test - public void testLocalizationWithValidLocaleAndNoLocalization() - { - Locale temp = Locale.getDefault(); - Locale.setDefault(Locale.FRANCE); - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "ar-eg" - }); - System.setOut(outOrig); - assertTrue("Valid Locale without translation should fallback to JVM default.", stream.getValue().indexOf("faites en utilisant") >= 0); - Locale.setDefault(temp); - } - - @Test - public void testLocalizationWithSkippedLocale() - { - assertEquals("Skipped argument to --lang should fail.", 1, run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "--bad" - })); - } - - @Test - public void testLocalizationWithUnknownLocale() - { - // Rather than attempt to validate locales or match them with available - // translations, it seems preferrable to follow the pattern that the JDK - // has set and allow it to naturally fall back to the default (JVM) default. - Locale previousLocale = Locale.getDefault(); - try { - Locale.setDefault(Locale.FRANCE); - PrintStream outOrig = System.out; - CountingOutStream stream = new CountingOutStream(); - System.setOut(new PrintStream(stream)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale", "foobar" - }); - System.setOut(outOrig); - assertTrue("Invalid Locale should use JVM default.", stream.getValue().indexOf("faites en utilisant") >= 0); - } finally { - Locale.setDefault(previousLocale); - } - - } - - @Test - public void testLocalizationWithNoLocale() - { - assertEquals("--locale with no language tag is clearly an error, fail with message.", - 1, run(new String[]{ - getAbsoluteBasedir(epubPath + "valid/lorem.epub"), - "--locale" - })); - } - - - @Test - public void testVersionMessageComesFirst() - { - PrintStream outOrig = System.out; - PrintStream errOrig = System.err; - CountingOutStream out = new CountingOutStream(); - System.setOut(new PrintStream(out)); - System.setErr(new PrintStream(out)); - EpubChecker epubChecker = new EpubChecker(); - epubChecker.run( - new String[] { getAbsoluteBasedir(expPath + "invalid/mimetype-file-incorrect-value"), "-mode", "exp", "--locale", "en" }); - System.setOut(outOrig); - System.setErr(errOrig); - int versionMessageIndex = out.getValue().indexOf("Validating using"); - int mimetypeErrorMessageIndex = out.getValue().indexOf("mimetype"); - assertTrue("Version message should be in the output.", - versionMessageIndex >= 0); - assertTrue("PKG-007 should be in the output.", - mimetypeErrorMessageIndex >= 0); - assertTrue("Version message should be printed before PKG-007", - versionMessageIndex < mimetypeErrorMessageIndex); - } - - - private int run(String[] args, boolean verbose) - { - PrintStream outOrig = System.out; - PrintStream errOrig = System.err; - if (!verbose) - { - System.setOut(new NullPrintStream()); - System.setErr(new NullPrintStream()); - } - - if (args != null) - { - args[0] = getAbsoluteBasedir(args[0]); - } - else - { - return 1; - } - EpubChecker checker = new EpubChecker(); - int result = checker.run(args); - System.setOut(outOrig); - System.setErr(errOrig); - return result; - } - - public int run(String[] args) - { - return run(args, false); - } - - private String getAbsoluteBasedir(String base) - { - try { - URL fileURL = this.getClass().getResource(base); - if(fileURL != null) { - String filePath = new File(fileURL.toURI()).getAbsolutePath(); - return filePath; - } else { - return base; - } - } catch (URISyntaxException e) { - throw new IllegalStateException("Cannot find test file", e); - } - } - - class CountingOutStream extends OutputStream - { - int counts; - StringBuilder sb = new StringBuilder(); - - public int getCounts() - { - return counts; - } - - public String getValue() - { - return sb.toString(); - } - - @Override - public void write(int b) - { - sb.append((char)b); - counts++; - } - } - - class NullPrintStream extends PrintStream - { - public NullPrintStream() - { - super(new OutputStream() - { - @Override - public void write(int b) throws IOException - { - } - }); - } - } -} - diff --git a/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java b/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java index 509f2e785..08fb95f8b 100644 --- a/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/nav/NavCheckerTest.java @@ -45,6 +45,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class NavCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java index 176305b6c..254e3e141 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFCheckerTest.java @@ -42,6 +42,7 @@ includes the relinquishment of all rights to enforce (by lawsuit import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OCFCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java b/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java index 8d05008d6..5550fed53 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFFilenameCheckerTest.java @@ -32,6 +32,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OCFFilenameCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java b/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java index 15274b7b2..04abccf91 100644 --- a/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java +++ b/src/test/java/com/adobe/epubcheck/ocf/OCFMockPackage.java @@ -13,6 +13,7 @@ import com.adobe.epubcheck.api.Report; +@Deprecated public class OCFMockPackage extends OCFPackage { HashSet dirEntries, mockEntries; diff --git a/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java b/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java index 1fcef9eb5..c1b3a0cd4 100644 --- a/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java +++ b/src/test/java/com/adobe/epubcheck/opf/MetadataSetTest.java @@ -9,6 +9,7 @@ import com.adobe.epubcheck.opf.MetadataSet.Builder; import com.adobe.epubcheck.vocab.Property; +@Deprecated public class MetadataSetTest { diff --git a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java index 6f18dc673..6dffede54 100644 --- a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTest.java @@ -46,6 +46,7 @@ import com.adobe.epubcheck.util.outWriter; import com.google.common.collect.Lists; +@Deprecated public class OPFCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java index 2c36cea59..dfb985d0b 100644 --- a/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java +++ b/src/test/java/com/adobe/epubcheck/opf/OPFCheckerTestChecks.java @@ -24,6 +24,7 @@ includes the relinquishment of all rights to enforce (by lawsuit package com.adobe.epubcheck.opf; +@Deprecated public class OPFCheckerTestChecks { diff --git a/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java b/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java index 5a2798e85..a8c7aaad5 100644 --- a/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/ops/OPSCheckerTest.java @@ -49,6 +49,7 @@ import com.adobe.epubcheck.util.ValidationReport.ItemReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OPSCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java b/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java index f561f8016..b001da03f 100644 --- a/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java +++ b/src/test/java/com/adobe/epubcheck/overlay/OverlayCheckerTest.java @@ -45,6 +45,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class OverlayCheckerTest { diff --git a/src/test/java/com/adobe/epubcheck/stress/StressTest.java b/src/test/java/com/adobe/epubcheck/stress/StressTest.java index 006af4fd6..76a7b0ef5 100644 --- a/src/test/java/com/adobe/epubcheck/stress/StressTest.java +++ b/src/test/java/com/adobe/epubcheck/stress/StressTest.java @@ -26,6 +26,7 @@ import com.adobe.epubcheck.util.ValidationReport; import com.google.common.io.Files; +@Deprecated public class StressTest { diff --git a/src/test/java/com/adobe/epubcheck/test/common.java b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java similarity index 94% rename from src/test/java/com/adobe/epubcheck/test/common.java rename to src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java index a85b23499..8533f8072 100644 --- a/src/test/java/com/adobe/epubcheck/test/common.java +++ b/src/test/java/com/adobe/epubcheck/test/CommonTestRunner.java @@ -20,7 +20,8 @@ import java.util.List; import java.util.Locale; -public class common +@Deprecated +public class CommonTestRunner { private static final Messages messages = Messages.getInstance(); @@ -46,7 +47,7 @@ public static void runExpTest(String componentName, String testName, int expecte case XMP : extension = "xmp"; break; } int extraArgsLength = extraArgs != null ? extraArgs.length : 0; - URL inputUrl = common.class.getResource(componentName + "/" + testName); + URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + testName); Assert.assertNotNull("Input folder is missing.", inputUrl); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/../" + testName + (useNullOutputPath ? "check." : "_actual_results.") + extension; @@ -71,7 +72,7 @@ public static void runExpTest(String componentName, String testName, int expecte runCustomTest(componentName, testName, expectedReturnCode, args.toArray(new String[args.size()])); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results." + extension); + URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results." + extension); Assert.assertNotNull("Expected file is missing.", expectedUrl); File expectedOutput = new File(decodeURLtoString(expectedUrl)); Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); @@ -107,7 +108,7 @@ public static void runEpubTest(String componentName, String testName, int expect case XMP : extension = "xmp"; break; } int extraArgsLength = extraArgs != null ? extraArgs.length : 0; - URL inputUrl = common.class.getResource(componentName + "/" + testName); + URL inputUrl = CommonTestRunner.class.getResource(componentName + "/" + testName); Assert.assertNotNull("Input folder is missing.", inputUrl); String inputPath = decodeURLtoString(inputUrl); // In case of epub input, the input is a file not a directory @@ -137,7 +138,7 @@ public static void runEpubTest(String componentName, String testName, int expect runCustomTest(componentName, testName, expectedReturnCode, args.toArray(new String[args.size()])); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results." + extension); + URL expectedUrl = CommonTestRunner.class.getResource(componentName + "/" + testName + "_expected_results." + extension); Assert.assertNotNull("Expected file is missing.", expectedUrl); File expectedOutput = new File(decodeURLtoString(expectedUrl)); Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); @@ -152,7 +153,7 @@ public static void runEpubTest(String componentName, String testName, int expect public static void runCustomTest(String componentName, String testName, int expectedReturnCode, String... args) { - runCustomTest(componentName, testName, expectedReturnCode, false, args); + runCustomTest(componentName, testName, expectedReturnCode, true, args); } public static void runCustomTest(String componentName, String testName, int expectedReturnCode, boolean quiet, String... args) @@ -223,7 +224,7 @@ public static void compareJson(File expectedOutput, File actualOutput) ignoreFields.add("/checker/path"); try { - jsonCompare.compareJsonFiles(expectedOutput, actualOutput, ignoreFields); + JsonCompare.compareJsonFiles(expectedOutput, actualOutput, ignoreFields); } catch (Exception ex) { diff --git a/src/test/java/com/adobe/epubcheck/test/jsonCompare.java b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java similarity index 99% rename from src/test/java/com/adobe/epubcheck/test/jsonCompare.java rename to src/test/java/com/adobe/epubcheck/test/JsonCompare.java index 1d48ebdd7..add6b5d64 100644 --- a/src/test/java/com/adobe/epubcheck/test/jsonCompare.java +++ b/src/test/java/com/adobe/epubcheck/test/JsonCompare.java @@ -14,7 +14,8 @@ import junit.framework.Assert; -public class jsonCompare +@Deprecated +public class JsonCompare { public static void compareJsonFiles(File expected, File actual, ArrayList ignoreFields) throws IOException { diff --git a/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java b/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java index 7d8eeb5d4..7c4a73f6f 100644 --- a/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/test/MessageDictionary_LocalizationTest.java @@ -6,6 +6,7 @@ import org.junit.Assert; import org.junit.Test; +@Deprecated public class MessageDictionary_LocalizationTest { @Test diff --git a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java index ad62922fd..09eb9e216 100644 --- a/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java +++ b/src/test/java/com/adobe/epubcheck/test/NoExitSecurityManager.java @@ -14,7 +14,7 @@ public class NoExitSecurityManager extends SecurityManager { - protected static class ExitException extends SecurityException + public static class ExitException extends SecurityException { public final int status; diff --git a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java index 4f4152a9b..5a4fd674c 100644 --- a/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java +++ b/src/test/java/com/adobe/epubcheck/test/OutputDifferenceListener.java @@ -18,6 +18,7 @@ * Time: 11:02 AM * To change this template use File | Settings | File Templates. */ +@Deprecated public class OutputDifferenceListener implements DifferenceListener { private int skippedComparisons = 0; diff --git a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java index 88a0c3e20..68b4aa764 100644 --- a/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java +++ b/src/test/java/com/adobe/epubcheck/test/OverriddenMessageDictionaryTest.java @@ -8,9 +8,11 @@ import com.adobe.epubcheck.util.DefaultReportImpl; import java.io.File; import java.net.URL; + import org.junit.Assert; import org.junit.Test; +@Deprecated public class OverriddenMessageDictionaryTest { @@ -18,7 +20,7 @@ public class OverriddenMessageDictionaryTest public void ensureOverridenMessages() { String testName = "severity_overrideOk.txt"; - URL inputUrl = common.class.getResource("command_line"); + URL inputUrl = OverriddenMessageDictionaryTest.class.getResource("command_line"); String inputPath = inputUrl.getPath(); String overrideFile = inputPath + "/" + testName; diff --git a/src/test/java/com/adobe/epubcheck/test/TestRunListener.java b/src/test/java/com/adobe/epubcheck/test/TestRunListener.java index a65d50301..c671a9b9d 100644 --- a/src/test/java/com/adobe/epubcheck/test/TestRunListener.java +++ b/src/test/java/com/adobe/epubcheck/test/TestRunListener.java @@ -14,6 +14,7 @@ import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.util.outWriter; +@Deprecated public class TestRunListener extends RunListener { @Override diff --git a/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java b/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java index 44b1fafd0..93f661fc9 100644 --- a/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java +++ b/src/test/java/com/adobe/epubcheck/test/UtilMessage_LocalizationTest.java @@ -6,6 +6,7 @@ import org.junit.Before; import org.junit.Test; +@Deprecated public class UtilMessage_LocalizationTest { private static final String NO_ERRORS_OR_WARNINGS = "no_errors__or_warnings"; diff --git a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java b/src/test/java/com/adobe/epubcheck/test/command_line_Test.java deleted file mode 100644 index 2597a1e89..000000000 --- a/src/test/java/com/adobe/epubcheck/test/command_line_Test.java +++ /dev/null @@ -1,422 +0,0 @@ -package com.adobe.epubcheck.test; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintStream; -import java.net.URL; -import java.util.Locale; - -import junit.framework.Assert; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.adobe.epubcheck.api.EpubCheck; -import com.adobe.epubcheck.test.common.TestOutputType; -import com.adobe.epubcheck.tool.Checker; -import com.adobe.epubcheck.util.CheckUtil; -import com.adobe.epubcheck.util.HandlerUtil; -import com.adobe.epubcheck.util.Messages; -import com.adobe.epubcheck.util.PathUtil; -import com.adobe.epubcheck.util.ResourceUtil; - -public class command_line_Test -{ - private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); - private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - - private SecurityManager originalManager; - private PrintStream originalOut; - private PrintStream originalErr; - private Locale defaultLocale; - private final Messages messages = Messages.getInstance(Locale.ENGLISH); - - @Before - public void setUp() throws Exception - { - defaultLocale = Locale.getDefault(); - Locale.setDefault(Locale.ENGLISH); - this.originalManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); - originalOut = System.out; - originalErr = System.err; - System.setOut(new PrintStream(outContent)); - System.setErr(new PrintStream(errContent)); - } - - @After - public void tearDown() throws Exception - { - System.setSecurityManager(this.originalManager); - System.setOut(originalOut); - System.setErr(originalErr); - Locale.setDefault(defaultLocale); - } - - @Test - public void static_class_Test() - { - //This will create an instance of classes that have nothing but static methods for the sake of code coverage. - Checker checker = new Checker(); - Assert.assertTrue("Checker string isn't as expected", checker.toString().startsWith("com.adobe.epubcheck.tool.Checker")); - - HandlerUtil handlerUtil = new HandlerUtil(); - Assert.assertTrue("HandlerUtil string isn't as expected", handlerUtil.toString().startsWith("com.adobe.epubcheck.util.HandlerUtil")); - - PathUtil pathUtil = new PathUtil(); - Assert.assertTrue("PathUtil string isn't as expected", pathUtil.toString().startsWith("com.adobe.epubcheck.util.PathUtil")); - - CheckUtil checkUtil = new CheckUtil(); - Assert.assertTrue("CheckUtil string isn't as expected", checkUtil.toString().startsWith("com.adobe.epubcheck.util.CheckUtil")); - - ResourceUtil resourceUtil = new ResourceUtil(); - Assert.assertTrue("ResourceUtil string isn't as expected", resourceUtil.toString().startsWith("com.adobe.epubcheck.util.ResourceUtil")); - } - - @Test - public void empty_Test() - { - common.runCustomTest("command_line", "empty", 1); - Assert.assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); - } - - @Test - public void help_Test() - { - common.runCustomTest("command_line", "help", 1, true, "-?"); - Assert.assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); - String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); - String actual = outContent.toString(); - actual = actual.replaceAll("[\\s]+", " "); - Assert.assertTrue("Help output isn't as expected", actual.contains(expected)); - } - - @Test - public void conflicting_output_Test() - { - common.runCustomTest("command_line", "conflicting_output", 1, "-o", "foo.xml", "-j", "bar.json"); - Assert.assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); - } - - @Test - public void SeveritiesUsage_Test() - { - runSeverityTest("severity", "command_line", "severity_usage", 1, "-u"); - } - - @Test - public void SeveritiesWarning_Test() - { - runSeverityTest("severity", "command_line", "severity_warning", 1, "-w"); - } - - @Test - public void SeveritiesError_Test() - { - runSeverityTest("severity", "command_line", "severity_error", 1, "-e"); - } - - @Test - public void SeveritiesFatal_Test() - { - runSeverityTest("severity", "command_line", "severity_fatal", 0, "-f"); - } - - @Test - public void SeveritiesOverrideOk_Test() - { - String testName = "severity_overrideOk"; - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideMissingFile_Test() - { - String testName = "severity_overrideMissingFile"; - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadId_Test() - { - String testName = "severity_overrideBadId"; - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadSeverity_Test() - { - String testName = "severity_overrideBadSeverity"; - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - @Test - public void SeveritiesOverrideBadMessage_Test() - { - String testName = "severity_overrideBadMessage"; - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String configFile = inputPath + "/" + testName + ".txt"; - runSeverityTest("severity", "command_line", testName, 1, "-c", configFile, "-u"); - } - - - @Test - @Ignore // too cumbersome to maintain - public void SeveritiesList_Test() - { - //public static void runCustomTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) - URL inputUrl = common.class.getResource("command_line"); - String inputPath = inputUrl.getPath(); - String outputPath = inputPath + "/listSeverities" + "_actual_results.txt"; - String expectedUrl = inputPath + "/listSeverities" + "_expected_results.txt"; - common.runCustomTest("command_line", "listSeverities", 0, "--listChecks", outputPath); - - File actualOutput = new File(outputPath); - Assert.assertTrue("Output file is missing.", actualOutput.exists()); - File expectedOutput = new File(expectedUrl); - Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); - - try - { - common.compareText(expectedOutput, actualOutput); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Test - public void passonwarnings_Test() - { - runExtraCommandLineArgTest("passonwarnings", 0, new String[0]); - } - - @Test - public void jsonfile_Test() - { - common.runExpTest("command_line", "jsonfile", 0, TestOutputType.JSON, false, true, new String[0]); - } - - @Test - public void xmlfile_Test() - { - common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XML, false, true, new String[0]); - } - - @Test - public void xmpfile_Test() - { - common.runExpTest("command_line", "xmlfile", 0, TestOutputType.XMP, false, true, new String[0]); - } - - @Test - public void failonwarnings_Test() - { - String[] extraArgs = {"--failonwarnings"}; - runExtraCommandLineArgTest("failonwarnings", 1, extraArgs); - } - - - public static void runExtraCommandLineArgTest(String testName, int expectedReturnCode, String[] extraArgs) - { - common.runExpTest("command_line", testName, expectedReturnCode, TestOutputType.JSON, false, false, extraArgs); - } - - public static void runSeverityTest(String epubName, String componentName, String testName, int expectedReturnCode, String... args) - { - File actualOutput; - PrintStream ps = null; - PrintStream origErr = System.err; - PrintStream origOut = System.out; - try - { - String[] theArgs = new String[3 + args.length]; - URL inputUrl = common.class.getResource(componentName + "/" + epubName); - Assert.assertNotNull("Input folder is missing.", inputUrl); - String inputPath = inputUrl.getPath(); - String outputPath = inputPath + "/../" + testName + "_actual_results.txt"; - - theArgs[0] = inputPath; - theArgs[1] = "-mode"; - theArgs[2] = "exp"; - System.arraycopy(args, 0, theArgs, 3, args.length); - - actualOutput = new File(outputPath); - ps = new PrintStream(actualOutput); - System.setErr(ps); - System.setOut(ps); - common.runCustomTest(componentName, testName, expectedReturnCode, theArgs); - System.setErr(origErr); - System.setOut(origOut); - ps.flush(); - ps.close(); - ps = null; - - Assert.assertTrue("Output file is missing.", actualOutput.exists()); - URL expectedUrl = common.class.getResource(componentName + "/" + testName + "_expected_results.txt"); - Assert.assertNotNull("Expected file is missing.", expectedUrl); - File expectedOutput = new File(expectedUrl.getPath()); - Assert.assertTrue("Expected file is missing.", expectedOutput.exists()); - try - { - differ d = new differ(expectedOutput, actualOutput, 3); - Assert.assertTrue("expected file does not match actual file", d.areTheSame()); - } - catch (Exception ex) - { - System.err.println(ex.getMessage()); - } - File tempFile = new File(testName + ".epub"); - - Assert.assertFalse("Temp file left over after test: " + tempFile.getPath(), tempFile.exists()); - } - catch (FileNotFoundException ex) - { - System.err.println("File not found: " + testName + "_actual_results.txt"); - } - finally - { - if (ps != null) - { - System.setErr(origErr); - System.setOut(origOut); - } - } - } - - private static class differ - { - File expected; - File actual; - int skip; - - public differ(File expected, File actual, int skip) - { - this.expected = expected; - this.actual = actual; - this.skip = skip; - } - - public boolean areTheSame() - { - BufferedReader aR = null; - BufferedReader eR = null; - try - { - int lineNumber = 0; - aR = new BufferedReader(new FileReader(actual)); - eR = new BufferedReader(new FileReader(expected)); - - String a; - String e = null; - - while (((a = aR.readLine()) != null) && - ((e = eR.readLine()) != null)) - { - if (++lineNumber > skip) - { - if (a != null && e != null) - { - int x1 = a.indexOf(": "); - int y1 = e.indexOf(": "); - Assert.assertEquals("lines do not match(" + lineNumber + ")", y1 >= 0 ? e.substring(0, y1) : "", x1 >= 0 ? a.substring(0, x1) : ""); - - int x2 = a.lastIndexOf("):"); - int y2 = e.lastIndexOf("):"); - if (x2 != -1 && y2 != -1) - { - Assert.assertEquals(a.length() - x2, e.length() - y2); - } - - if (y1 > 0) - { - String x = a.substring(0, x1); - String y = e.substring(0, y1); - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + x + "' expected: '" + y + "'", 0, y.compareTo(x)); - } - else - { - Assert.assertEquals(e, a); - } - if (y2 > 0) - { - String x = a.substring(x2); - String y = e.substring(y2); - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + x + "' expected: '" + y + "'", 0, y.compareTo(x)); - } - else if (!a.contains("com.adobe.epubcheck")) - { - Assert.assertEquals("lines do not match(" + lineNumber + "): actual:'" + a + "' expected: '" + e + "'", e, a); - } - } - } - } - if (a != null && a.startsWith("Completed command_line test")) - { - a = null; - } - if (e != null && e.startsWith("Completed command_line test")) - { - e = null; - } - Assert.assertTrue("files are not the same length", ((a == null || a.length() == 0) && (e == null || e.length() == 0))); - } - catch (FileNotFoundException ex) - { - Assert.assertTrue("actual file not found", actual.exists()); - Assert.assertTrue("expected file not found", expected.exists()); - } - catch (IOException io) - { - io.printStackTrace(); - } - finally - { - if (aR != null) - { - try - { - aR.close(); - } - catch (IOException e1) - { - e1.printStackTrace(); - } - } - if (eR != null) - { - try - { - eR.close(); - } - catch (IOException e2) - { - e2.printStackTrace(); - } - } - } - return true; - } - } - -} diff --git a/src/test/java/com/adobe/epubcheck/test/css_Test.java b/src/test/java/com/adobe/epubcheck/test/css_Test.java index 1fa73dacd..2329ea852 100644 --- a/src/test/java/com/adobe/epubcheck/test/css_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/css_Test.java @@ -1,11 +1,11 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.adobe.epubcheck.test.common.TestOutputType; - +@Deprecated public class css_Test { private SecurityManager originalManager; @@ -145,16 +145,16 @@ public void font_encryption_idpf_xmp_Test() throws Exception private void runCSSJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.JSON); } private void runCSSXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.XML); } private void runCSSXmpTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("css", testName, expectedReturnCode, TestOutputType.XMP); + CommonTestRunner.runExpTest("css", testName, expectedReturnCode, TestOutputType.XMP); } } diff --git a/src/test/java/com/adobe/epubcheck/test/debug.java b/src/test/java/com/adobe/epubcheck/test/debug.java index 5084996b1..77f13b92d 100644 --- a/src/test/java/com/adobe/epubcheck/test/debug.java +++ b/src/test/java/com/adobe/epubcheck/test/debug.java @@ -10,6 +10,7 @@ * Time: 5:15 PM * To change this template use File | Settings | File Templates. */ +@Deprecated public class debug { private final Messages messages = Messages.getInstance(); diff --git a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java index 0c7ff6fcd..15c66f680 100644 --- a/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/dtBook_Test.java @@ -1,10 +1,10 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; - +@Deprecated public class dtBook_Test { private SecurityManager originalManager; @@ -37,12 +37,12 @@ public void Basic_XML_Test() throws Exception private void runDTBookJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.JSON); } private void runDTBookXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("DTBook", testName, expectedReturnCode, TestOutputType.XML); } } diff --git a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java index ed36dbc8b..b141f66a1 100644 --- a/src/test/java/com/adobe/epubcheck/test/encryption_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/encryption_Test.java @@ -1,9 +1,9 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; - +@Deprecated public class encryption_Test { private SecurityManager originalManager; @@ -20,25 +20,25 @@ public void tearDown() throws Exception { @Test public void epub30_font_obfuscation_encryption_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, + CommonTestRunner.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, TestOutputType.XML, false, new String[] {"-w"}); } @Test public void epub30_font_obfuscation_encryption_xmp_Test() throws Exception { - common.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, + CommonTestRunner.runEpubTest("encryption", "epub30_font_obfuscation.epub", 0, TestOutputType.XMP, false, new String[] {"-w"}); } @Test public void epub20_minimal_encryption_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub20_minimal_encryption.epub", 1, + CommonTestRunner.runEpubTest("encryption", "epub20_minimal_encryption.epub", 1, TestOutputType.XML, false, new String[] {"-w"}); } @Test public void epub20_encryption_binary_content_xml_Test() throws Exception { - common.runEpubTest("encryption", "epub20_encryption_binary_content.epub", 1, + CommonTestRunner.runEpubTest("encryption", "epub20_encryption_binary_content.epub", 1, TestOutputType.XML, false, new String[] {"-w"}); } } diff --git a/src/test/java/com/adobe/epubcheck/test/message_coverage.java b/src/test/java/com/adobe/epubcheck/test/message_coverage.java index 006ed68b1..89a039112 100644 --- a/src/test/java/com/adobe/epubcheck/test/message_coverage.java +++ b/src/test/java/com/adobe/epubcheck/test/message_coverage.java @@ -18,6 +18,7 @@ /** * Test the coverage of reported message ids by all the tests. This test should run after all the others have completed. */ +@Deprecated public class message_coverage { @Test diff --git a/src/test/java/com/adobe/epubcheck/test/opf_Test.java b/src/test/java/com/adobe/epubcheck/test/opf_Test.java index 1431dc97d..94add5f23 100644 --- a/src/test/java/com/adobe/epubcheck/test/opf_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/opf_Test.java @@ -1,9 +1,10 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; +@Deprecated public class opf_Test { private SecurityManager originalManager; @@ -207,11 +208,11 @@ public void Missing_unique_id_Test() private void runOpfJsonTest(String testName, int expectedReturnCode) { - common.runExpTest("opf", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("opf", testName, expectedReturnCode, TestOutputType.JSON); } private void runOpfXmlTest(String testName, int expectedReturnCode) { - common.runExpTest("opf", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("opf", testName, expectedReturnCode, TestOutputType.XML); } } diff --git a/src/test/java/com/adobe/epubcheck/test/package_Test.java b/src/test/java/com/adobe/epubcheck/test/package_Test.java index 0d5e4e7a0..e09c44915 100644 --- a/src/test/java/com/adobe/epubcheck/test/package_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/package_Test.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Locale; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -18,12 +19,12 @@ import com.adobe.epubcheck.opf.OPFChecker; import com.adobe.epubcheck.opf.ValidationContext.ValidationContextBuilder; import com.adobe.epubcheck.reporting.CheckingReport; -import com.adobe.epubcheck.test.common.TestOutputType; import com.adobe.epubcheck.util.EPUBVersion; import com.adobe.epubcheck.util.ValidationReport; import junit.framework.Assert; +@Deprecated public class package_Test { private SecurityManager originalManager; @@ -150,7 +151,7 @@ public void empty_dir_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/empty_dir_actual_results.json"; String expectedOutputPath = inputPath + "/empty_dir_expected_results.json"; @@ -158,12 +159,12 @@ public void empty_dir_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "empty_dir", 1, args); + CommonTestRunner.runCustomTest("package", "empty_dir", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test @@ -171,7 +172,7 @@ public void corrupt_file_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/corrupt_file_actual_results.json"; String expectedOutputPath = inputPath + "/corrupt_file_expected_results.json"; @@ -179,19 +180,19 @@ public void corrupt_file_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "corrupt_file", 1, args); + CommonTestRunner.runCustomTest("package", "corrupt_file", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void blank_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); inputPath += "/blank.epub"; ValidationReport report = new ValidationReport(inputPath); @@ -214,7 +215,7 @@ public void wrong_type_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_type_actual_results.json"; String expectedOutputPath = inputPath + "/wrong_type_expected_results.json"; @@ -222,12 +223,12 @@ public void wrong_type_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "wrong_type", 1, args); + CommonTestRunner.runCustomTest("package", "wrong_type", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } // @Test There are different results when running through IntelliJ and running @@ -237,7 +238,7 @@ public void empty_archive_Test() throws Exception { String[] args = new String[3]; - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/empty_archive_actual_results.json"; String expectedOutputPath = inputPath + "/empty_archive_expected_results.json"; @@ -245,19 +246,19 @@ public void empty_archive_Test() args[0] = inputPath; args[1] = "-j"; args[2] = outputPath; - common.runCustomTest("package", "empty_archive", 1, args); + CommonTestRunner.runCustomTest("package", "empty_archive", 1, args); File actualOutput = new File(outputPath); Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void wrong_extension_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_extension_actual_results.json"; String expectedOutputPath = inputPath + "/wrong_extension_expected_results.json"; @@ -273,14 +274,14 @@ public void wrong_extension_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void wrong_extension_version3_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/wrong_extension_v3_actual_results.json"; System.out.println(outputPath); @@ -297,14 +298,14 @@ public void wrong_extension_version3_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void missing_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/missing_file_actual_results.json"; String expectedOutputPath = inputPath + "/missing_file_expected_results.json"; @@ -320,14 +321,14 @@ public void missing_file_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } @Test public void missing_opf_epub_file_Test() throws Exception { - URL inputUrl = common.class.getResource("package"); + URL inputUrl = CommonTestRunner.class.getResource("package"); String inputPath = decodeURLtoString(inputUrl); String outputPath = inputPath + "/missing_opf_epub_file_actual_results.json"; String expectedOutputPath = inputPath + "/missing_opf_epub_file_expected_results.json"; @@ -344,19 +345,19 @@ public void missing_opf_epub_file_Test() Assert.assertTrue("Output file is missing.", actualOutput.exists()); File expectedOutput = new File(expectedOutputPath); Assert.assertTrue("Expected output file is missing.", expectedOutput.exists()); - common.compareJson(expectedOutput, actualOutput); + CommonTestRunner.compareJson(expectedOutput, actualOutput); } private void runPackageJsonTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("package", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("package", testName, expectedReturnCode, TestOutputType.JSON); } private void runPackageXmlTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("package", testName, expectedReturnCode, TestOutputType.XML); + CommonTestRunner.runExpTest("package", testName, expectedReturnCode, TestOutputType.XML); } private static String decodeURLtoString(URL url) { diff --git a/src/test/java/com/adobe/epubcheck/test/script_Test.java b/src/test/java/com/adobe/epubcheck/test/script_Test.java index 548ad0166..9928c8b13 100644 --- a/src/test/java/com/adobe/epubcheck/test/script_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/script_Test.java @@ -1,9 +1,9 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; - +@Deprecated public class script_Test { private SecurityManager originalManager; @@ -60,11 +60,11 @@ public void epub2_script_Test() throws Exception @Test public void epub2_script_xmp_Test() throws Exception { - common.runExpTest("scripts", "epub2", 1, TestOutputType.XMP); + CommonTestRunner.runExpTest("scripts", "epub2", 1, TestOutputType.XMP); } private void runScriptTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("scripts", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("scripts", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java index a8ea559d1..23b365559 100644 --- a/src/test/java/com/adobe/epubcheck/test/single_file_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/single_file_Test.java @@ -13,6 +13,7 @@ /** * Test the processing of single files that are not ePubs */ +@Deprecated public class single_file_Test { private SecurityManager originalManager; @@ -40,7 +41,7 @@ public void remote_Test() throws Exception PrintStream originalErr = System.err; System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - common.runCustomTest("command_line", "remote", 1, true, "-mode", "nav", "-v", "3.0", "http://localhost:8080/noexist.nav"); + CommonTestRunner.runCustomTest("command_line", "remote", 1, true, "-mode", "nav", "-v", "3.0", "http://localhost:8080/noexist.nav"); //The exception string is different on iOS than it is on Windows. //This is why we are examining the command line rather than comparing json files. diff --git a/src/test/java/com/adobe/epubcheck/test/toc_Test.java b/src/test/java/com/adobe/epubcheck/test/toc_Test.java index 67342e892..49c9c05b3 100644 --- a/src/test/java/com/adobe/epubcheck/test/toc_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/toc_Test.java @@ -1,10 +1,10 @@ package com.adobe.epubcheck.test; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; - +@Deprecated public class toc_Test { private SecurityManager originalManager; @@ -42,7 +42,7 @@ public void invalid_ncx_Test() throws Exception private void runTocTest(String testName, int expectedReturnCode) throws Exception { - common.runExpTest("toc", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("toc", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java index a732f610a..500576d8d 100644 --- a/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java +++ b/src/test/java/com/adobe/epubcheck/test/xhtml_Test.java @@ -2,10 +2,11 @@ import org.junit.*; -import com.adobe.epubcheck.test.common.TestOutputType; +import com.adobe.epubcheck.test.CommonTestRunner.TestOutputType; import java.util.Locale; +@Deprecated public class xhtml_Test { private SecurityManager originalManager; @@ -131,6 +132,6 @@ public void singleline_test() private void runXhtmlTest(String testName, int expectedReturnCode) { - common.runExpTest("xhtml", testName, expectedReturnCode, TestOutputType.JSON); + CommonTestRunner.runExpTest("xhtml", testName, expectedReturnCode, TestOutputType.JSON); } } diff --git a/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java new file mode 100644 index 000000000..3f9337894 --- /dev/null +++ b/src/test/java/com/adobe/epubcheck/tools/CommandLineTest.java @@ -0,0 +1,792 @@ +package com.adobe.epubcheck.tools; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.URL; +import java.util.Locale; +import java.util.regex.Pattern; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.json.simple.JSONValue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.adobe.epubcheck.api.EpubCheck; +import com.adobe.epubcheck.test.NoExitSecurityManager; +import com.adobe.epubcheck.tool.Checker; +import com.adobe.epubcheck.util.Messages; + +public class CommandLineTest { + + private final Pattern usagePattern = Pattern.compile("^([\\s\\S]*\\n)?USAGE\\([\\s\\S]*$"); + private final Pattern warningPattern = Pattern.compile("^([\\s\\S]*\\n)?WARNING\\([\\s\\S]*$"); + private final Pattern errorPattern = Pattern.compile("^([\\s\\S]*\\n)?ERROR\\([\\s\\S]*$"); + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); + + private SecurityManager originalManager; + private PrintStream originalOut; + private PrintStream originalErr; + private final Messages messages = Messages.getInstance(Locale.ENGLISH); + private Locale defaultLocale; + + @Before + public void setUp() + { + defaultLocale = Locale.getDefault(); + Locale.setDefault(Locale.ENGLISH); + this.originalManager = System.getSecurityManager(); + System.setSecurityManager(new NoExitSecurityManager()); + originalOut = System.out; + originalErr = System.err; + System.setOut(new PrintStream(outContent)); + System.setErr(new PrintStream(errContent)); + } + + @After + public void tearDown() + { + Locale.setDefault(defaultLocale); + System.setSecurityManager(this.originalManager); + System.setOut(originalOut); + System.setErr(originalErr); + } + + /** + * Checks if for any reason the input arguments are null the return code is + * set appropriately. + */ + @Test + public void nullPointerExceptionTest() + { + runCommandLineTest(1, (String[]) null); + } + + /** + * Testing the save function, using a directory with a correct epub structure it will + * produce a correct packaged epub. + */ + @Test + public void archivingValidEPUBDirectoryTest() + { + URL inputUrl = CommandLineTest.class.getResource("30-valid-test"); + File inputFile = new File(inputUrl.getPath()); + File out = new File(inputFile.getParent() + File.separator + "30-valid-test.epub"); + if (out.exists()) + { + out.delete(); + } + + runCommandLineTest(0, "--mode", "exp", inputUrl.getPath(), "--save"); + + runCommandLineTest(0, out.getAbsolutePath()); + + if (out.exists()) + { + out.delete(); + } + } + + /** + * Check if we can validate a single navigation file. + */ + @Test + public void singleNavigationFileTest() + { + URL inputUrl = CommandLineTest.class.getResource("30-valid-test/OPS/nav.xhtml"); + runCommandLineTest(0, "-mode", "nav", inputUrl.getPath()); + } + + /** + * Validate that testing a single navigation file without table of contents will + * yield an error code. + */ + @Test + public void singleNavigationWithoutTableOfContentsTest() + { + URL inputUrl = CommandLineTest.class.getResource("nav-no-toc.xhtml"); + runCommandLineTest(1, "-mode", "nav", inputUrl.getPath()); + } + + /** + * This test runs the program without any arguments, expected is a message about that + * arguments are required. + */ + @Test + public void noArgumentsTest() + { + runCommandLineTest(1); + assertEquals("Command output not as expected", messages.get("argument_needed"), errContent.toString().trim()); + } + + /** + * Verify that an epub with a strange casing will generate a warning. + */ + @Test + public void extensionTest1() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension.ePub"); + runCommandLineTest(0, inputUrl.getPath()); + assertTrue( + "Warning PKG-016 should be present when file has an incorrect extension", + errContent.toString().contains("WARNING(PKG-016)") + ); + } + + /** + * Verify that a zipfile will inform the user that this is an uncommon extension. + */ + @Test + public void extensionTest2() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension.zip"); + runCommandLineTest(0, inputUrl.getPath(), "--profile", "default"); + assertTrue( + "Info PKG-024 should be present when file has an uncommon extension", + errContent.toString().contains("INFO(PKG-024)") + ); + } + + /** + * Verify that an epub without extension works without any exceptions. + */ + @Test + public void extensionTest3() + { + URL inputUrl = CommandLineTest.class.getResource("wrong_extension"); + runCommandLineTest(0, inputUrl.getPath(), "--profile", "default"); + } + + /** + * Validate that the -out parameter will generate a well formed xml output. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void outputXMLReportTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "-out", tmpFile.getAbsolutePath()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Validate that the -out parameter will generate a well formed xml output for + * unpacked epubs. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void outputXMLModeExpandedReportTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("30-valid-test"); + runCommandLineTest(0, inputUrl.getPath(), "-mode", "exp", "-out", tmpFile.getAbsolutePath()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Verify that no extra output is present when quiet mode is enabled. + */ + @Test + public void quietTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + runCommandLineTest(1, inputUrl.getPath(), "-mode", "exp", "--quiet", "--failonwarnings"); + + assertEquals("Output should not be present", 0, outContent.size()); + } + + + /** + * Testing that no output is present when the flag quiet is set and that we get a correct xml + * output report with the output flag. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void quietRunWithOutputTest() throws Exception + { + File tmpFile = File.createTempFile("test", ".xml"); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "--quiet", "-out", tmpFile.getAbsolutePath()); + + assertEquals("Output should not be present", 0, outContent.size()); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Testing that invalid options will return an invalid return code. We also need + * to inform the user which option was invalid. + */ + @Test + public void invalidOptionTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--invalidoption"); + + assertTrue( + "Should contain the invalid option", + errContent.toString().contains("--invalidoption") + ); + } + + /** + * When a translation is missing in that language it should fallback to the JVM default + * localization language. + */ + @Test + public void missingTranslationShouldFallbackTest() + { + Locale temp = Locale.getDefault(); + Locale.setDefault(Locale.FRANCE); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + + try + { + Checker.main(new String[] {inputUrl.getPath(), "--locale", "ar-eg"}); + } + catch (NoExitSecurityManager.ExitException e) + { + assertEquals("Return code should be zero", 0, e.status); + } + + assertTrue( + "Valid Locale without translation should fallback to JVM default.", + outContent.toString().contains("faites en utilisant") + ); + Locale.setDefault(temp); + } + + /** + * When a translation is missing in that language it should fallback to the JVM default + * localization language. + */ + @Test + public void localeShouldTranslateTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(0, inputUrl.getPath(), "--locale", "fr-FR"); + + assertTrue( + "Valid Locale without translation should fallback to JVM default.", + outContent.toString().contains("faites en utilisant") + ); + } + + /** + * When the user has forgot to specify the value for the locale parameter it should be + * clear that it is missing from the command line. + */ + @Test + public void skippedLocaleShouldFailTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--locale", "--bad"); + + assertTrue( + "User should be informed about skipped locale", + errContent.toString().contains("--bad") + ); + } + + /** + * When the user uses an incorrect locale the translation should fallback on the + * JVM default language. + */ + @Test + public void incorrectLocaleShouldFailTest() + { + Locale.setDefault(Locale.FRANCE); + + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + + try + { + Checker.main(new String[] {inputUrl.getPath(), "--locale", "foobar"}); + } + catch (NoExitSecurityManager.ExitException e) + { + assertEquals("Return code should be zero", 0, e.status); + } + + assertTrue( + "Invalid Locale should use JVM default.", + outContent.toString().contains("faites en utilisant") + ); + } + + /** + * When the locale parameter value is missing the missing_locale message should + * be present in error output. + */ + @Test + public void missingLocaleShouldFailTest() + { + URL inputUrl = CommandLineTest.class.getResource("valid.epub"); + runCommandLineTest(1, inputUrl.getPath(), "--locale"); + + assertEquals( + "Missing locale message should be present", + messages.get("missing_locale"), + errContent.toString().trim() + ); + } + + + /** + * Running with the question mark argument, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest1() + { + runCommandLineTest( 1, "-?"); + assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Running with the single dash help argument, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest2() + { + runCommandLineTest( 1, "-help"); + assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Running with the double dash help argument, expected that we create some output where output contains + * the version number. + */ + @Test + public void helpMessageTest3() + { + runCommandLineTest( 1, "--help"); + assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("help_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Testing that the version command could be opened using double dash syntax. + */ + @Test + public void versionDisplayTest1() + { + runCommandLineTest(1, "--version"); + assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Testing that the version command could be opened using single dash syntax. + */ + @Test + public void versionDisplayTest2() + { + runCommandLineTest(1, "-version"); + assertEquals("Command output not as expected", messages.get("no_file_specified"), errContent.toString().trim()); + String expected = String.format(messages.get("epubcheck_version_text").replaceAll("[\\s]+", " "), EpubCheck.version()); + String actual = outContent.toString(); + actual = actual.replaceAll("[\\s]+", " "); + assertTrue("Help output isn't as expected", actual.contains(expected)); + } + + /** + * Tests that the version message is displayed on the first line + */ + @Test + public void versionInfoComesFirst() + { + OutputStream out = new ByteArrayOutputStream(); + System.setOut(new PrintStream(out)); + System.setErr(new PrintStream(out)); + URL inputUrl = CommandLineTest.class.getResource("30-mimetype-invalid"); + runCommandLineTest(1, inputUrl.getPath(), "-mode", "exp"); + int versionMessageIndex = out.toString().indexOf("Validating using"); + int mimetypeErrorMessageIndex = out.toString().indexOf("mimetype"); + assertTrue("Version message should be in the output.", versionMessageIndex >= 0); + assertTrue("PKG-007 should be in the output.", mimetypeErrorMessageIndex >= 0); + assertTrue("Version message should be printed before PKG-007", versionMessageIndex < mimetypeErrorMessageIndex); + } + + + /** + * This test checks if multiple output formats are chosen, expected is an error message instructing + * user to choose either output formats but not both. + */ + @Test + public void conflictingOutputTest() + { + runCommandLineTest(1, "-o", "foo.xml", "-j", "bar.json"); + assertEquals("Command output not as expected", messages.get("output_type_conflict"), errContent.toString().trim()); + } + + /** + * Checks if the usage messages are shown when the usage flag is set. + */ + @Test + public void severitiesUsageTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + runCommandLineTest(1, "-u", "--mode", "exp", inputUrl.getPath()); + + assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); + assertTrue("Usage should be present", usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks if the warning messages are shown when the warning flag is set, + * but no usage messages. + */ + @Test + public void severitiesWarningTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + runCommandLineTest(1, "-w", "--mode", "exp", inputUrl.getPath()); + + assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + assertTrue("Warnings should be present", warningPattern.matcher(errContent.toString()).matches()); + assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks if the error messages are shown when the error flag is set, but no usage or + * warning messages. + */ + @Test + public void severitiesErrorTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + runCommandLineTest(1, "-e", "--mode", "exp", inputUrl.getPath()); + + assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * Checks that no error, warning or usage messages are shown when fatal flag is set. + */ + @Test + public void severitiesFatalTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + runCommandLineTest(0, "-f", "--mode", "exp", inputUrl.getPath()); + + assertTrue("Errors should not be present", !errorPattern.matcher(errContent.toString()).matches()); + assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + } + + /** + * This test checks that we can override some error severity, messages and/or + * suppress them all together. + */ + @Test + public void severitiesOverrideTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + runCommandLineTest( + 1, "-c", configUrl.getPath(), "-u", "--mode", "exp", + inputUrl.getPath() + ); + + assertTrue("Errors should be present", errorPattern.matcher(errContent.toString()).matches()); + assertTrue("Warnings should not be present", !warningPattern.matcher(errContent.toString()).matches()); + assertTrue("Usage should not be present", !usagePattern.matcher(outContent.toString()).matches()); + + assertTrue( + "Overridden message should be present", + errContent.toString().contains("This is an overridden message")); + } + + + /** + * Ensures that the right error code is present when the override configuration file + * is missing. + */ + @Test + public void severitiesOverrideMissingFileTest() + { + URL configUrl = CommandLineTest.class.getResource("."); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + + runCommandLineTest( + 1, "-c", configUrl.getPath() + "/severity_override.missing_file", + "-u", "--mode", "exp", inputUrl.getPath() + ); + + assertTrue( + "Error CHK-001 should be present when file is missing", + errContent.toString().contains("ERROR(CHK-001)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity id that is not valid. + */ + @Test + public void severitiesOverrideBadIdTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_id.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + runCommandLineTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() + ); + + assertTrue( + "Error CHK-002 should be present when file contains a bad id", + errContent.toString().contains("ERROR(CHK-002)") + ); + } + + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity value that is not valid. + */ + @Test + public void severitiesOverrideBadSeverityTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_severity.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + runCommandLineTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() + ); + + assertTrue( + "Error CHK-003 should be present when file contains a bad severity", + errContent.toString().contains("ERROR(CHK-003)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity message that is not valid. (Incorrect number of parameters) + */ + @Test + public void severitiesOverrideBadMessageTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_message.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + runCommandLineTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() + ); + + assertTrue( + "Error CHK-004 should be present when file contains a bad message", + errContent.toString().contains("ERROR(CHK-004)") + ); + } + + /** + * Ensures that the right error code is present when the override configuration + * contains a severity suggestion that is not valid. (Incorrect number of parameters) + */ + @Test + public void severitiesOverrideBadSuggestionTest() + { + URL configUrl = CommandLineTest.class.getResource("severity_override_bad_suggestion.txt"); + URL inputUrl = CommandLineTest.class.getResource("20-severity-tester"); + + runCommandLineTest( + 1, "-c", configUrl.getPath(), "-u", + "--mode", "exp", inputUrl.getPath() + ); + + assertTrue( + "Error CHK-005 should be present when file contains a bad message", + errContent.toString().contains("ERROR(CHK-005)") + ); + } + + /** + * This test contains warnings but should not fail. We expect the return code to be 0 + */ + @Test + public void passOnWarningsTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + runCommandLineTest( + 0, "-u", "--mode", "exp", inputUrl.getPath() + ); + } + + + /** + * This test contains warnings and the flag --failonwarnings will force warnings to + * fail. We expect the return code to be 1. + */ + @Test + public void failOnWarningsTest() + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + runCommandLineTest( + 1, "-u", "--mode", "exp", + "--failonwarnings", inputUrl.getPath() + ); + } + + /** + * Create an json file output and validate that it parses as a correct json document. + * + * @throws Exception Throws an exception if the temp file can't be created. + */ + @Test + public void jsonFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".json"); + runCommandLineTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-j", tmpFile.getAbsolutePath() + ); + + Object document = JSONValue.parse(new FileReader(tmpFile)); + assertNotNull("Incorrect json", document); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + + /** + * Create xml file output and validate that it parses as a correct XML document. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void xmlFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".xml"); + runCommandLineTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-o", tmpFile.getAbsolutePath() + ); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + /** + * Create xmp file output and validate that it parses as a correct XML document. + * + * @throws Exception Any parsing errors will be thrown as an exception. + */ + @Test + public void xmpFileTest() throws Exception + { + URL inputUrl = CommandLineTest.class.getResource("20-warning-tester"); + + File tmpFile = File.createTempFile("test", ".xmp"); + runCommandLineTest( + 0, "--mode", "exp", inputUrl.getPath(), + "-x", tmpFile.getAbsolutePath() + ); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + db.parse(tmpFile); + + if(tmpFile.exists()) + { + tmpFile.delete(); + } + } + + public static void runCommandLineTest(int expectedReturnCode, String... args) + { + int result = Integer.MAX_VALUE; + try + { + Checker.main(args); + } + catch (NoExitSecurityManager.ExitException e) + { + result = e.status; + } + + assertEquals("Return code", expectedReturnCode, result); + } + +} \ No newline at end of file diff --git a/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java b/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java index 394e1536a..653110e5f 100644 --- a/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java +++ b/src/test/java/com/adobe/epubcheck/util/ExtraReportTest.java @@ -1,5 +1,6 @@ package com.adobe.epubcheck.util; +@Deprecated public interface ExtraReportTest { public void test(ValidationReport testReport); } diff --git a/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java b/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java index 7e9e056cf..889235ada 100644 --- a/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java +++ b/src/test/java/com/adobe/epubcheck/util/OPFPeekerTest.java @@ -39,6 +39,7 @@ import com.adobe.epubcheck.opf.OPFPeeker; import com.google.common.collect.Sets; +@Deprecated public class OPFPeekerTest { diff --git a/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java b/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java index d9bd6b868..b8eef903f 100644 --- a/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java +++ b/src/test/java/com/adobe/epubcheck/util/PathUtilTest.java @@ -6,6 +6,8 @@ import org.junit.Test; + +@Deprecated public class PathUtilTest { diff --git a/src/test/java/com/adobe/epubcheck/util/ValidationReport.java b/src/test/java/com/adobe/epubcheck/util/ValidationReport.java index 56f6397ec..132c3f3e5 100644 --- a/src/test/java/com/adobe/epubcheck/util/ValidationReport.java +++ b/src/test/java/com/adobe/epubcheck/util/ValidationReport.java @@ -31,6 +31,7 @@ import com.adobe.epubcheck.messages.MessageId; import com.adobe.epubcheck.messages.Severity; +@Deprecated public class ValidationReport extends MasterReport { String info = ""; diff --git a/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java b/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java index 6f0f6bbc7..6ea9a5425 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/PrefixParsingTest.java @@ -37,6 +37,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +@Deprecated public class PrefixParsingTest { diff --git a/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java b/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java index 55dbf5c07..60ccde510 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/PropertyTest.java @@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableSet; +@Deprecated public class PropertyTest { diff --git a/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java b/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java index 47982f257..f9041be81 100644 --- a/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java +++ b/src/test/java/com/adobe/epubcheck/vocab/VocabTest.java @@ -48,6 +48,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +@Deprecated public class VocabTest { diff --git a/src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt b/src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt new file mode 100644 index 000000000..61748ad01 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/api/InputStream_Expected.txt @@ -0,0 +1 @@ +WARNING: : Testing 123 diff --git a/src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt b/src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt new file mode 100644 index 000000000..0a460c0cf --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/api/PrintWriter_Expected.txt @@ -0,0 +1 @@ +WARNING: : diff --git a/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt b/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt deleted file mode 100644 index 6233215c9..000000000 --- a/src/test/resources/com/adobe/epubcheck/test/api/InputStream_Expected.txt +++ /dev/null @@ -1,2 +0,0 @@ -WARNING: : Testing 123 -ERROR: EPUB/lorem.opf(13,63): Spine item with non-standard media-type 'font/opentype' has no fallback. diff --git a/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt b/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt deleted file mode 100644 index a4ac9b6de..000000000 --- a/src/test/resources/com/adobe/epubcheck/test/api/PrintWriter_Expected.txt +++ /dev/null @@ -1,2 +0,0 @@ -WARNING: : -ERROR: EPUB/lorem.opf(13,63): Spine item with non-standard media-type 'font/opentype' has no fallback. diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf new file mode 100644 index 000000000..f6e69b17a --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/package.opf @@ -0,0 +1,14 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-severity-tester/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml new file mode 100644 index 000000000..a42aa4e84 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/content_002.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf new file mode 100644 index 000000000..737953278 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/package.opf @@ -0,0 +1,15 @@ + + + + Minimal EPUB 2.0 + en + NOID + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx new file mode 100644 index 000000000..618e220d9 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/OPS/toc.ncx @@ -0,0 +1,18 @@ + + + + + + + Minimal EPUB 2.0 + + + + + Loomings + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/20-warning-tester/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/content_001.xhtml new file mode 100644 index 000000000..2f8492a6f --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/nav.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/nav.xhtml new file mode 100644 index 000000000..fb044b8c6 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/nav.xhtml @@ -0,0 +1,19 @@ + + + + + Minimal Nav + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/package.opf new file mode 100644 index 000000000..0d1eec6e9 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/OPS/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/mimetype b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/mimetype new file mode 100644 index 000000000..8f3a928e7 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-mimetype-invalid/mimetype @@ -0,0 +1 @@ +application/something+else \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml new file mode 100644 index 000000000..cd9945b48 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml new file mode 100644 index 000000000..2f8492a6f --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/content_001.xhtml @@ -0,0 +1,11 @@ + + + + + Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml new file mode 100644 index 000000000..fb044b8c6 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/nav.xhtml @@ -0,0 +1,19 @@ + + + + + Minimal Nav + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf new file mode 100644 index 000000000..0d1eec6e9 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/OPS/package.opf @@ -0,0 +1,16 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-06-14T00:00:01Z + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype new file mode 100644 index 000000000..57ef03f24 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/30-valid-test/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file diff --git a/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml b/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml new file mode 100644 index 000000000..e398567d2 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/nav-no-toc.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + diff --git a/src/test/resources/com/adobe/epubcheck/tools/severity_override.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override.txt new file mode 100644 index 000000000..debc01bfe --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/severity_override.txt @@ -0,0 +1,4 @@ +ID Severity Message Suggestion +RSC-008 ERROR This is an overridden message This is an overridden suggestion. +OPF-003 ERROR +HTM-010 SUPPRESSED diff --git a/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt new file mode 100644 index 000000000..5eb7404d6 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_id.txt @@ -0,0 +1,3 @@ +ID Severity +BogusID ERROR + diff --git a/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt new file mode 100644 index 000000000..d00b71cd7 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_message.txt @@ -0,0 +1,2 @@ +ID Severity Message Suggestion +RSC-008 ERROR This is an overridden message with too many parameters: %1$s %2$s %3$s %4$s %5$s %6$s diff --git a/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt new file mode 100644 index 000000000..b46282201 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_severity.txt @@ -0,0 +1,3 @@ +ID Severity +CSS-012 BogusSeverity + diff --git a/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt new file mode 100644 index 000000000..949130513 --- /dev/null +++ b/src/test/resources/com/adobe/epubcheck/tools/severity_override_bad_suggestion.txt @@ -0,0 +1,2 @@ +ID Severity Message Suggestion +RSC-008 WARNING This is an overridden message. This is an overridden suggestion with too many parameters: %1$s %2$s %3$s %4$s %5$s %6$s diff --git a/src/test/resources/com/adobe/epubcheck/tools/valid.epub b/src/test/resources/com/adobe/epubcheck/tools/valid.epub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.ePub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip b/src/test/resources/com/adobe/epubcheck/tools/wrong_extension.zip new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001 diff --git a/src/test/resources/minimal-epub/30/minimal-epub-30.epub b/src/test/resources/minimal-epub/30/minimal-epub-30.epub new file mode 100644 index 0000000000000000000000000000000000000000..d67360689fefefd5eea181e3908cf007ed455cde GIT binary patch literal 1770 zcmWIWW@h1H0D&EG8Q%Gct93+xY!K!E;@r&K)RM}A)Wm{j+Dw$+)#^+?U;4fZmnF6GCy zrwT;}$ePM^|LIC$Oy;?lC?}q|(A(#zcx<271^NDef}vG$f%_Rj0f6w{|Kn_`iHr;k z6POqn_@Mz%keHmEn4YSaUy#-t2H1g`O<(6F7&$n}>y72y2w=)v5I(4Je_>8=bPnsxl1wU_e>TdGk{K#_E*mBb@ zQT}}S@+N1IPYqT9#~ifvLKb!(epzd8|EznL%*Ur+U)nkKFXoVI=DuGp_j`l(!7Gf_ z)=#E|pO9d_+IlLjbC=(y)#Xb+eLQK$ZFyQ#Jteh$V)8KtH>zH z&6zsU*Z;5qPuuys>p6B_-cryImRI)R@v-&<8Hos)%s zpZtBxQ0M#HRBKtb$FWC0n>_Z}earkl<&yV}(A)KVNBId!l=h!0!_uB(+NaZ~W&tYuSCDH<8m~IqvfdM@EU(Zhidb zwTd|BmMBvZVTb0h)7FoDmh0>ew-zYwQYc)K@OJiL7wfIb7k3_UUa#G^uP-a)Ls=JR zgtFsCvlqTcv)>0;*PPyDGk5m%<06YiI8+@4>^VCk8CfF#q`BTTpUd_B@PD5D-bXa8 zT30YnKfi)$llrXwZ=cfD6`s9(X}-+2mI*c7%&IkK-Uf!35is0Dq2UI~pQ(8z@dgHl zknjubKkaweK*Z(x+weP8{&Nm630bal(G(Ku(7VOzJ^jwLX@7!pJbr(_!RM4zDsN@H zIPrD&#Sgv70q4FgS((L@VSjhQo1N+jk#My!hiS^7rVCi@f0{CdTfmdgHmTw?oi9C?@4_{9NOe$sUWA z{js^vvG$pUVt|%8%P;D5Y7WS J&Wshr0|2uWew+XR literal 0 HcmV?d00001