r600 - in trunk/jrst/src/test/java/org/nuiton/jrst: . bugs
Author: tchemit Date: 2011-06-09 16:25:13 +0200 (Thu, 09 Jun 2011) New Revision: 600 Url: http://nuiton.org/repositories/revision/jrst/600 Log: fix tests while using java.io.tmpdir + NEVER delete a file generated file in a test Modified: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/InfiniteLoopTest.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TitlesTest.java Modified: trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/JRSTCompareDocutils.java 2011-06-09 14:25:13 UTC (rev 600) @@ -1,28 +1,11 @@ package org.nuiton.jrst; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringReader; -import java.io.StringWriter; -import java.net.URL; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.io.FileFilter; - -import javax.xml.transform.TransformerException; - import junit.framework.Assert; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.DifferenceListener; - import org.custommonkey.xmlunit.IgnoreTextAndAttributeValuesDifferenceListener; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -32,10 +15,24 @@ import org.nuiton.i18n.init.ClassPathI18nInitializer; import org.nuiton.util.FileUtil; +import javax.xml.transform.TransformerException; +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URL; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; + public class JRSTCompareDocutils { /** to use log facility, just put in your code: log.info(\"...\"); */ @@ -47,6 +44,12 @@ /** Commande utilisee pour transformer le rst en html */ private static String rst2html = "rst2html"; + public static void prepareTmpDir() throws IOException { + + File testFile = new File(System.getProperty("java.io.tmpdir")); + + FileUtil.createDirectoryIfNecessary(testFile); + } public static void main(String[] args) throws Exception { Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/DirectiveTest.java 2011-06-09 14:25:13 UTC (rev 600) @@ -25,13 +25,16 @@ package org.nuiton.jrst.bugs; -import java.io.File; - import org.apache.commons.io.FileUtils; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; +import org.nuiton.jrst.JRSTCompareDocutils; +import java.io.File; +import java.io.IOException; + /** * Test concernant les directives. * @@ -43,6 +46,11 @@ */ public class DirectiveTest { + @BeforeClass + public static void beforeClass () throws IOException { + JRSTCompareDocutils.prepareTmpDir(); + } + /** * Test que les options des directives images sont correctement * parsées. @@ -53,7 +61,7 @@ public void testImageDirectiveOption() throws Exception { File in = new File("src/test/resources/bugs/testImages21.rst"); File out = File.createTempFile("jrst-testImages", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -75,7 +83,7 @@ public void testContentDirective() throws Exception { File in = new File("src/test/resources/bugs/testContent877.rst"); File out = File.createTempFile("jrst-testContent", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/InfiniteLoopTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/InfiniteLoopTest.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/InfiniteLoopTest.java 2011-06-09 14:25:13 UTC (rev 600) @@ -27,10 +27,13 @@ import org.dom4j.Document; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; +import org.nuiton.jrst.JRSTCompareDocutils; import org.nuiton.jrst.JRSTReader; import org.nuiton.jrst.JRSTReaderTest; +import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; @@ -46,6 +49,11 @@ */ public class InfiniteLoopTest { + @BeforeClass + public static void beforeClass () throws IOException { + JRSTCompareDocutils.prepareTmpDir(); + } + /** * Test de parser un fichier et déclare le test en echec si il dure * plus de 5s. (bug #697). @@ -55,15 +63,14 @@ @Test(timeout = 5000) public void testInfiniteLoop() throws Exception { URL url = JRSTReaderTest.class.getResource("/bugs/infiniteLoop.rst"); - Document doc = null; Reader in = new InputStreamReader(url.openStream()); try { JRSTReader jrst = new JRSTReader(); - doc = jrst.read(in); + Document doc = jrst.read(in); + Assert.assertNotNull(doc); } finally { in.close(); } - Assert.assertNotNull(doc); } } Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TableTest.java 2011-06-09 14:25:13 UTC (rev 600) @@ -25,14 +25,16 @@ package org.nuiton.jrst.bugs; -import java.io.File; - import junit.framework.Assert; - import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; +import org.nuiton.jrst.JRSTCompareDocutils; +import java.io.File; +import java.io.IOException; + /** * Test concernant les tables en général. * @@ -44,6 +46,11 @@ */ public class TableTest { + @BeforeClass + public static void beforeClass () throws IOException { + JRSTCompareDocutils.prepareTmpDir(); + } + /** * Test que la présence d'un caractères | ne fait pas planter * la generation des tables. @@ -54,7 +61,7 @@ public void testTableSpecialChar() throws Exception { File in = new File("src/test/resources/bugs/testTable1290.rst"); File out = File.createTempFile("jrst-tables", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -71,7 +78,7 @@ public void testTableIndentation() throws Exception { File in = new File("src/test/resources/bugs/testTable1375.rst"); File out = File.createTempFile("jrst-tables", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TextTest.java 2011-06-09 14:25:13 UTC (rev 600) @@ -25,17 +25,19 @@ package org.nuiton.jrst.bugs; -import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import junit.framework.Assert; - import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import org.nuiton.jrst.JRST; +import org.nuiton.jrst.JRSTCompareDocutils; +import java.io.File; +import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Test sur les elements de type text (liens, styles...) * @@ -47,6 +49,11 @@ */ public class TextTest { + @BeforeClass + public static void beforeClass () throws IOException { + JRSTCompareDocutils.prepareTmpDir(); + } + /** * Test que les liens avec parametres sont correctement parsés. * @@ -56,7 +63,7 @@ public void testLinksParameters() throws Exception { File in = new File("src/test/resources/bugs/testLinks.rst"); File out = File.createTempFile("jrst-testLinks", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -75,7 +82,7 @@ public void testLinksSpecialCharacters() throws Exception { File in = new File("src/test/resources/bugs/testLinks1380.rst"); File out = File.createTempFile("jrst-testLinks", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -93,7 +100,7 @@ public void testTabCharacter() throws Exception { File in = new File("src/test/resources/bugs/testTab1378.rst"); File out = File.createTempFile("jrst-testTab1378", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -111,7 +118,7 @@ public void testOptionLists() throws Exception { File in = new File("src/test/resources/bugs/testOptionsList644.rst"); File out = File.createTempFile("jrst-testOptionList644", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); @@ -135,7 +142,7 @@ public void testLinkEscape() throws Exception { File in = new File("src/test/resources/bugs/testLinks.rst"); File out = File.createTempFile("jrst-testLinks", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out); Modified: trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TitlesTest.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TitlesTest.java 2011-06-09 08:55:20 UTC (rev 599) +++ trunk/jrst/src/test/java/org/nuiton/jrst/bugs/TitlesTest.java 2011-06-09 14:25:13 UTC (rev 600) @@ -25,14 +25,16 @@ package org.nuiton.jrst.bugs; -import java.io.File; - import junit.framework.Assert; - import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.jrst.JRST; +import org.nuiton.jrst.JRSTCompareDocutils; +import java.io.File; +import java.io.IOException; + /** * Test concernant les titres en général. * @@ -44,6 +46,11 @@ */ public class TitlesTest { + @BeforeClass + public static void beforeClass () throws IOException { + JRSTCompareDocutils.prepareTmpDir(); + } + /** * Test que la génération fonctionne meme s'il n'y a pas de titre * de niveau 2. @@ -53,7 +60,7 @@ public void testNoSubtitle() throws Exception { File in = new File("src/test/resources/bugs/testNoSubtitle.rst"); File out = File.createTempFile("jrst-RstToHtml2", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); } @@ -67,7 +74,7 @@ public void testNoContentBetweenTitles() throws Exception { File in = new File("src/test/resources/bugs/testNoContentSubtitles.rst"); File out = File.createTempFile("jrst-testNoContentSubtitles", ".html"); - out.deleteOnExit(); +// out.deleteOnExit(); JRST.generate(JRST.TYPE_HTML, in, out, JRST.Overwrite.ALLTIME); String content = FileUtils.readFileToString(out);
participants (1)
-
tchemit@users.nuiton.org