aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/fotreetest
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2011-10-04 10:09:01 +0000
committerVincent Hennebert <vhennebert@apache.org>2011-10-04 10:09:01 +0000
commit91c66d97428aa57c844ec58e1deb07a8ab745574 (patch)
treed6062f718053ad636c8f587d5d5f199e9d158252 /test/java/org/apache/fop/fotreetest
parent7d33c81a0a079336dd1ffcac97e4ee1dfba16c36 (diff)
downloadxmlgraphics-fop-91c66d97428aa57c844ec58e1deb07a8ab745574.tar.gz
xmlgraphics-fop-91c66d97428aa57c844ec58e1deb07a8ab745574.zip
Bugzilla #51928: Upgraded all tests to JUnit 4
Patch by Mehdi Houshmand, applied with minor cosmetics and error fixes git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1178747 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/java/org/apache/fop/fotreetest')
-rw-r--r--test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java121
-rw-r--r--test/java/org/apache/fop/fotreetest/FOTreeTester.java152
-rw-r--r--test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java7
3 files changed, 117 insertions, 163 deletions
diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
index 76faa21c9..6e6f62b92 100644
--- a/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
+++ b/test/java/org/apache/fop/fotreetest/FOTreeTestSuite.java
@@ -19,129 +19,20 @@
package org.apache.fop.fotreetest;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.AndFileFilter;
-import org.apache.commons.io.filefilter.IOFileFilter;
-import org.apache.commons.io.filefilter.NameFileFilter;
-import org.apache.commons.io.filefilter.PrefixFileFilter;
-import org.apache.commons.io.filefilter.SuffixFileFilter;
-import org.apache.commons.io.filefilter.TrueFileFilter;
-
-import org.apache.fop.DebugHelper;
import org.apache.fop.fo.flow.table.CollapsedConditionalBorderTestCase;
import org.apache.fop.fo.flow.table.IllegalRowSpanTestCase;
import org.apache.fop.fo.flow.table.RowGroupBuilderTestCase;
import org.apache.fop.fo.flow.table.TableColumnColumnNumberTestCase;
import org.apache.fop.fo.flow.table.TooManyColumnsTestCase;
-import org.apache.fop.layoutengine.LayoutEngineTestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
/**
* JUnit test suit for running layout engine test under JUnit control.
*/
+@RunWith(Suite.class)
+@Suite.SuiteClasses({ TooManyColumnsTestCase.class, IllegalRowSpanTestCase.class,
+ RowGroupBuilderTestCase.class, TableColumnColumnNumberTestCase.class,
+ CollapsedConditionalBorderTestCase.class, FOTreeTester.class })
public final class FOTreeTestSuite {
-
- static {
- DebugHelper.registerStandardElementListObservers();
- }
-
- private FOTreeTestSuite() {
- //don't instantiate!
- }
-
- /**
- * @return the test suite with all the tests (one for each XML file)
- * @throws IOException in case of an I/O problem
- */
- public static Test suite() throws IOException {
- TestSuite suite = new TestSuite();
- addXMLTestCases(suite);
- addUnitTestCases(suite);
- return suite;
- }
-
- private static void addXMLTestCases(TestSuite suite) throws IOException {
- File mainDir = new File("test/fotree");
-
- final FOTreeTester tester = new FOTreeTester();
-
- IOFileFilter filter;
- String single = System.getProperty("fop.fotree.single");
- String startsWith = System.getProperty("fop.fotree.starts-with");
- if (single != null) {
- filter = new NameFileFilter(single);
- } else if (startsWith != null) {
- filter = new PrefixFileFilter(startsWith);
- filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
- } else {
- filter = new SuffixFileFilter(".fo");
- filter = LayoutEngineTestSuite.decorateWithDisabledList(filter);
- }
- Collection files = FileUtils.listFiles(new File(mainDir, "testcases"),
- filter, TrueFileFilter.INSTANCE);
- String privateTests = System.getProperty("fop.fotree.private");
- if ("true".equalsIgnoreCase(privateTests)) {
- Collection privateFiles = FileUtils.listFiles(
- new File(mainDir, "private-testcases"),
- filter, TrueFileFilter.INSTANCE);
- files.addAll(privateFiles);
- }
- Iterator i = files.iterator();
- while (i.hasNext()) {
- File f = (File)i.next();
- addTestCase(suite, tester, f);
- }
- }
-
- private static void addTestCase(TestSuite suite,
- final FOTreeTester tester, final File f) {
- suite.addTest(new FOTreeTestCase(f.getName()) {
- public void runTest() throws Exception {
- try {
- prepare(tester, f);
- testMain();
- } catch (Exception e) {
- org.apache.commons.logging.LogFactory.getLog(this.getClass()).info(
- "Error on " + f.getName());
- throw e;
- }
- }
- });
- }
-
- private static void addUnitTestCases(TestSuite suite) {
- suite.addTestSuite(TooManyColumnsTestCase.class);
- suite.addTestSuite(IllegalRowSpanTestCase.class);
- suite.addTestSuite(RowGroupBuilderTestCase.class);
- suite.addTestSuite(TableColumnColumnNumberTestCase.class);
- suite.addTestSuite(CollapsedConditionalBorderTestCase.class);
- }
-
- private static class FOTreeTestCase extends TestCase {
-
- private FOTreeTester tester;
- private File testFile;
-
- public FOTreeTestCase(String name) {
- super(name);
- }
-
- public void prepare(FOTreeTester tester, File testFile) {
- //super(testFile.getName());
- this.tester = tester;
- this.testFile = testFile;
- }
-
- public void testMain() throws Exception {
- tester.runTest(testFile);
- }
- }
}
diff --git a/test/java/org/apache/fop/fotreetest/FOTreeTester.java b/test/java/org/apache/fop/fotreetest/FOTreeTester.java
index ba9fde4f9..80bf44034 100644
--- a/test/java/org/apache/fop/fotreetest/FOTreeTester.java
+++ b/test/java/org/apache/fop/fotreetest/FOTreeTester.java
@@ -20,88 +20,154 @@
package org.apache.fop.fotreetest;
import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLFilterImpl;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.AndFileFilter;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.PrefixFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+
+import org.apache.fop.DebugHelper;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryConfigurator;
import org.apache.fop.fotreetest.ext.TestElementMapping;
+import org.apache.fop.layoutengine.LayoutEngineTestUtils;
import org.apache.fop.util.ConsoleEventListenerForTests;
/**
* Test driver class for FO tree tests.
*/
+@RunWith(Parameterized.class)
public class FOTreeTester {
+ @BeforeClass
+ public static void registerElementListObservers() {
+ DebugHelper.registerStandardElementListObservers();
+ }
+
+ @Parameters
+ public static Collection<File[]> testXMLTestCases() throws Exception {
+ File mainDir = new File("test/fotree");
+
+ IOFileFilter filter;
+ String single = System.getProperty("fop.fotree.single");
+ String startsWith = System.getProperty("fop.fotree.starts-with");
+ if (single != null) {
+ filter = new NameFileFilter(single);
+ } else if (startsWith != null) {
+ filter = new PrefixFileFilter(startsWith);
+ filter = new AndFileFilter(filter, new SuffixFileFilter(".fo"));
+ } else {
+ filter = new SuffixFileFilter(".fo");
+ filter = LayoutEngineTestUtils.decorateWithDisabledList(filter);
+ }
+ Collection<File> files = FileUtils.listFiles(new File(mainDir, "testcases"), filter,
+ TrueFileFilter.INSTANCE);
+ String privateTests = System.getProperty("fop.fotree.private");
+ if ("true".equalsIgnoreCase(privateTests)) {
+ Collection privateFiles = FileUtils.listFiles(new File(mainDir, "private-testcases"),
+ filter, TrueFileFilter.INSTANCE);
+ files.addAll(privateFiles);
+ }
+ // Unfortunately JUnit forces us to return a collection of arrays.
+ Collection<File[]> parameters = new ArrayList<File[]>();
+ for (File f : files) {
+ parameters.add(new File[] { f });
+ }
+ return parameters;
+ }
+
private FopFactory fopFactory = FopFactory.newInstance();
+ private final File testFile;
+
/**
* Main constructor
+ *
+ * @param testFile the FO file to test
*/
- public FOTreeTester() {
+ public FOTreeTester(File testFile) {
fopFactory.addElementMapping(new TestElementMapping());
+ this.testFile = testFile;
}
/**
* Runs a test.
- * @param testFile the test file.
* @throws Exception if a test or FOP itself fails
*/
- public void runTest(File testFile) throws Exception {
- ResultCollector collector = ResultCollector.getInstance();
- collector.reset();
-
- SAXParserFactory spf = SAXParserFactory.newInstance();
- spf.setNamespaceAware(true);
- spf.setValidating(false);
- SAXParser parser = spf.newSAXParser();
- XMLReader reader = parser.getXMLReader();
-
- //Resetting values modified by processing instructions
- fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(
- FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE);
- fopFactory.setSourceResolution(FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION);
-
- FOUserAgent ua = fopFactory.newFOUserAgent();
- ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString());
- ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
- ua.getEventBroadcaster().addEventListener(
- new ConsoleEventListenerForTests(testFile.getName()));
-
- //Used to set values in the user agent through processing instructions
- reader = new PIListener(reader, ua);
-
- Fop fop = fopFactory.newFop(ua);
-
- reader.setContentHandler(fop.getDefaultHandler());
- reader.setDTDHandler(fop.getDefaultHandler());
- reader.setErrorHandler(fop.getDefaultHandler());
- reader.setEntityResolver(fop.getDefaultHandler());
+ @Test
+ public void runTest() throws Exception {
try {
- reader.parse(testFile.toURI().toURL().toExternalForm());
- } catch (Exception e) {
- collector.notifyError(e.getLocalizedMessage());
- throw e;
- }
+ ResultCollector collector = ResultCollector.getInstance();
+ collector.reset();
+
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ spf.setValidating(false);
+ SAXParser parser = spf.newSAXParser();
+ XMLReader reader = parser.getXMLReader();
+
+ // Resetting values modified by processing instructions
+ fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(
+ FopFactoryConfigurator.DEFAULT_BREAK_INDENT_INHERITANCE);
+ fopFactory.setSourceResolution(FopFactoryConfigurator.DEFAULT_SOURCE_RESOLUTION);
+
+ FOUserAgent ua = fopFactory.newFOUserAgent();
+ ua.setBaseURL(testFile.getParentFile().toURI().toURL().toString());
+ ua.setFOEventHandlerOverride(new DummyFOEventHandler(ua));
+ ua.getEventBroadcaster().addEventListener(
+ new ConsoleEventListenerForTests(testFile.getName()));
+
+ // Used to set values in the user agent through processing instructions
+ reader = new PIListener(reader, ua);
+
+ Fop fop = fopFactory.newFop(ua);
+
+ reader.setContentHandler(fop.getDefaultHandler());
+ reader.setDTDHandler(fop.getDefaultHandler());
+ reader.setErrorHandler(fop.getDefaultHandler());
+ reader.setEntityResolver(fop.getDefaultHandler());
+ try {
+ reader.parse(testFile.toURI().toURL().toExternalForm());
+ } catch (Exception e) {
+ collector.notifyError(e.getLocalizedMessage());
+ throw e;
+ }
- List results = collector.getResults();
- if (results.size() > 0) {
- for (int i = 0; i < results.size(); i++) {
- System.out.println((String)results.get(i));
+ List results = collector.getResults();
+ if (results.size() > 0) {
+ for (int i = 0; i < results.size(); i++) {
+ System.out.println((String) results.get(i));
+ }
+ throw new IllegalStateException((String) results.get(0));
}
- throw new IllegalStateException((String)results.get(0));
+ } catch (Exception e) {
+ org.apache.commons.logging.LogFactory.getLog(this.getClass()).info(
+ "Error on " + testFile.getName());
+ throw e;
}
}
- private class PIListener extends XMLFilterImpl {
+ private static class PIListener extends XMLFilterImpl {
private FOUserAgent userAgent;
diff --git a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java
index 5513a89ab..0906c266d 100644
--- a/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java
+++ b/test/java/org/apache/fop/fotreetest/FOTreeUnitTester.java
@@ -24,15 +24,12 @@ import java.io.File;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import junit.framework.TestCase;
-
-import org.xml.sax.XMLReader;
-
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.fo.FOEventHandler;
import org.apache.fop.util.ConsoleEventListenerForTests;
+import org.xml.sax.XMLReader;
/**
@@ -40,7 +37,7 @@ import org.apache.fop.util.ConsoleEventListenerForTests;
* to parse an FO file and register a proper {@link FOEventHandler}. That handler will be
* the entry point to test classes from the FObj hierarchy.
*/
-public abstract class FOTreeUnitTester extends TestCase {
+public abstract class FOTreeUnitTester {
private XMLReader foReader;