aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java')
-rw-r--r--test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java76
1 files changed, 24 insertions, 52 deletions
diff --git a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java b/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
index 465e1405c..c246488e1 100644
--- a/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
+++ b/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
@@ -27,17 +27,11 @@ import java.io.OutputStream;
import java.net.MalformedURLException;
import javax.xml.transform.ErrorListener;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
import org.custommonkey.xmlunit.XMLTestCase;
import org.w3c.dom.Document;
@@ -45,11 +39,13 @@ import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.io.output.NullOutputStream;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
+import org.apache.fop.events.model.EventSeverity;
+import org.apache.fop.layoutengine.TestEnvironment;
import org.apache.fop.util.ConsoleEventListenerForTests;
/**
@@ -57,12 +53,11 @@ import org.apache.fop.util.ConsoleEventListenerForTests;
*/
public abstract class AbstractIntermediateTestCase extends XMLTestCase {
- /** the FOP factory */
- protected static FopFactory fopFactory = FopFactory.newInstance();
+ /** the test environment */
+ protected static TestEnvironment env = new TestEnvironment();
- /** the JAXP transformer factory */
- protected static SAXTransformerFactory tFactory
- = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
+ /** the FOP factory */
+ protected FopFactory fopFactory;
/** the main base directory for tests */
protected File mainDir = new File("test/layoutengine");
@@ -71,18 +66,20 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/** the output directory for any files generated by the tests */
protected File outputDir;
- private static Templates stylesheet = null;
-
/** the test file */
protected File testFile;
+ /** the test document as DOM */
+ protected Document testDoc;
/** the intermediate format document as DOM */
protected Document intermediate;
/**
* Constructor for the test suite that is used for each test file.
* @param testFile the test file to run
+ * @throws IOException if an I/O error occurs while loading the test case
*/
- public AbstractIntermediateTestCase(File testFile) {
+ public AbstractIntermediateTestCase(File testFile)
+ throws IOException {
super(testFile.getName());
this.testFile = testFile;
}
@@ -91,10 +88,11 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
protected void setUp() throws Exception {
super.setUp();
setupOutputDirectory();
- intermediate = buildIntermediateDocument(
- new StreamSource(testFile), getStylesheet());
+ this.testDoc = env.loadTestCase(testFile);
+ this.fopFactory = env.getFopFactory(testDoc);
+ intermediate = buildIntermediateDocument(env.getTestcase2FOStylesheet());
if (outputDir != null) {
- saveDOM(intermediate, new File(outputDir,
+ env.saveDOM(intermediate, new File(outputDir,
getName() + ".1" + getIntermediateFileExtension()));
}
validate(intermediate);
@@ -102,7 +100,10 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/** {@inheritDoc} */
protected void tearDown() throws Exception {
- this.intermediate = null; //Release memory
+ //Release memory
+ this.intermediate = null;
+ this.fopFactory = null;
+ this.testDoc = null;
super.tearDown();
}
@@ -132,40 +133,11 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
/**
* Builds an intermediate format document from a source file.
- * @param source the source file
* @param templates the (optional) stylesheet
* @return the intermediate format document as a DOM
* @throws Exception if an error occurs while processing the document
*/
- protected abstract Document buildIntermediateDocument(
- Source source, Templates templates) throws Exception;
-
- /**
- * Returns the stylesheet that transforms layout engine test cases into normal FO files.
- * @return the stylesheet
- * @throws TransformerConfigurationException if the stylesheet cannot be instantiated
- */
- protected Templates getStylesheet() throws TransformerConfigurationException {
- if (stylesheet == null) {
- File xsltFile = new File(mainDir, "testcase2fo.xsl");
- stylesheet = tFactory.newTemplates(new StreamSource(xsltFile));
- }
- return stylesheet;
- }
-
- /**
- * Saves a DOM to a file.
- * @param doc the DOM Document
- * @param tgtFile the target file
- * @throws Exception if an error occurs while serializing the DOM
- */
- protected void saveDOM(Document doc, File tgtFile) throws Exception {
- Transformer transformer = tFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- Source src = new DOMSource(doc);
- Result res = new StreamResult(tgtFile);
- transformer.transform(src, res);
- }
+ protected abstract Document buildIntermediateDocument(Templates templates) throws Exception;
/**
* Creates a new FOP user agent.
@@ -176,7 +148,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
try {
userAgent.setBaseURL(testDir.toURI().toURL().toExternalForm());
userAgent.getEventBroadcaster().addEventListener(
- new ConsoleEventListenerForTests(testFile.getName()));
+ new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.FATAL));
} catch (MalformedURLException e) {
//ignore, won't happen
}
@@ -204,7 +176,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
Document doc = parseAndRenderToIntermediateFormat(src);
if (outputDir != null) {
File tgtFile = new File(outputDir, getName() + ".2" + getIntermediateFileExtension());
- saveDOM(doc, tgtFile);
+ env.saveDOM(doc, tgtFile);
}
assertXMLEqual(intermediate, doc);
@@ -230,7 +202,7 @@ public abstract class AbstractIntermediateTestCase extends XMLTestCase {
out = new FileOutputStream(tgtFile);
out = new BufferedOutputStream(out);
} else {
- out = new ByteArrayOutputStream();
+ out = new NullOutputStream();
}
try {
Source src = new DOMSource(intermediate);