[FOray-commit] SF.net SVN: foray:[12763] trunk/foray/foray-app/src/test/java/org/foray/ app
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-12-02 19:53:27
|
Revision: 12763
http://sourceforge.net/p/foray/code/12763
Author: victormote
Date: 2022-12-02 19:53:24 +0000 (Fri, 02 Dec 2022)
Log Message:
-----------
Improvements to test helpers.
Modified Paths:
--------------
trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java
trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestInvalidXml.java
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/AreaTreeCreator.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -41,9 +41,11 @@
import org.foray.pioneer.PioneerLayoutStrategy;
import org.axsl.area.AreaTreeException;
+import org.axsl.fotree.FoTreeException;
import org.axsl.linebreak.LineBreakerFactory;
-import java.io.IOException;
+import org.junit.Assert;
+
import java.util.Iterator;
/**
@@ -62,16 +64,15 @@
/**
* Constructor.
- * @throws IOException For errors obtaining the build properties.
- * @throws ForayException For errors initializing the FOray-specific
- * objects.
*/
- private AreaTreeCreator() throws IOException, ForayException {
- final AreaTreeFactory4a areaTreeFactory = ForaySpecific.makeAreaTreeFactory();
- this.areaTreeFactory = areaTreeFactory;
- final LineBreakerFactory lbFactory = ForaySpecific.makeLineBreakerFactory();
- final PioneerFactory layoutFactory = ForaySpecific.makeLayoutFactory(lbFactory);
- this.layoutFactory = layoutFactory;
+ private AreaTreeCreator() {
+ try {
+ this.areaTreeFactory = ForaySpecific.makeAreaTreeFactory();
+ final LineBreakerFactory lbFactory = ForaySpecific.makeLineBreakerFactory();
+ this.layoutFactory = ForaySpecific.makeLayoutFactory(lbFactory);
+ } catch (final ForayException e) {
+ Assert.fail(e.getMessage());
+ }
}
/**
@@ -79,13 +80,9 @@
* @return The singleton instance.
* @throws ForayException For errors creating the singleton instance.
*/
- public static AreaTreeCreator getInstance() throws ForayException {
+ public static AreaTreeCreator getInstance() {
if (AreaTreeCreator.theInstance == null) {
- try {
- AreaTreeCreator.theInstance = new AreaTreeCreator();
- } catch (final IOException e) {
- throw new ForayException(e);
- }
+ AreaTreeCreator.theInstance = new AreaTreeCreator();
}
return AreaTreeCreator.theInstance;
}
@@ -95,11 +92,16 @@
* @param file The file to be converted.
* @param lbFactory The line-breaker factory.
* @return The parsed FO Tree instance.
- * @throws ForayException For errors building the FO Tree.
+ * @throws FoTreeException For errors building the FO Tree.
*/
- public AreaTree4a buildAreaTree(final String file, final LineBreakerFactory lbFactory) throws ForayException {
+ public AreaTree4a buildAreaTree(final String file, final LineBreakerFactory lbFactory) {
final FoDocumentReader foReader = FoDocumentReader.getInstance();
- final FoTree4a foTree = foReader.buildFoTree(file);
+ FoTree4a foTree = null;
+ try {
+ foTree = foReader.buildFoTree(file);
+ } catch (final FoTreeException e) {
+ Assert.fail(e.getMessage());
+ }
final Root4a root = foTree.getRootFo();
final AreaTree4a areaTree = this.areaTreeFactory.makeAreaTree(foTree);
final PioneerLayoutStrategy layout = this.layoutFactory.makeLayout();
@@ -106,14 +108,14 @@
final Iterator<PageSequence4a> iterator = root.getPageSequenceIterator();
while (iterator.hasNext()) {
final PageSequence4a pageSequence = iterator.next();
+ final PageCollection4a collection = areaTree.makePageCollection(pageSequence);
+ if (collection == null) {
+ Assert.fail("No PageCollection created.");
+ }
try {
- final PageCollection4a collection = areaTree.makePageCollection(pageSequence);
- if (collection == null) {
- throw new ForayException("Error creating page collection.");
- }
layout.formatPageSequence(collection);
} catch (final AreaTreeException e) {
- throw new ForayException(e);
+ Assert.fail(e.getMessage());
}
}
return areaTree;
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/area/TestVertical.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -37,7 +37,9 @@
import org.foray.area.TextArea;
import org.foray.core.ForayException;
+import org.axsl.area.AreaTreeException;
import org.axsl.font.FontUse;
+import org.axsl.fotree.FoTreeException;
import org.junit.Assert;
import org.junit.Ignore;
@@ -54,7 +56,7 @@
*/
@Test
@Ignore
- public void testVertical001() throws ForayException {
+ public void testVertical001() throws FoTreeException, AreaTreeException {
final AreaTreeCreator creator = AreaTreeCreator.getInstance();
final AreaTree4a areaTree = creator.buildAreaTree("fo/vertical-001.fo", getLineBreakerFactory());
final NormalFlowRa4a firstNormalFlowArea = this.getFirstNormalFlowArea(
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/FoDocumentReader.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -45,6 +45,7 @@
import org.xml.sax.InputSource;
+import org.junit.Assert;
import org.mockito.Mockito;
import java.io.File;
@@ -52,11 +53,11 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
+import java.net.MalformedURLException;
import java.net.URL;
/**
- * Singleton Helper class for tests that parses an input file and returns an
- * FoTree instance for testing.
+ * Singleton Helper class for tests that parses an input file and returns an {@link FoTree4a} instance for testing.
*/
public final class FoDocumentReader {
@@ -75,21 +76,37 @@
* @throws ForayException For errors initializing the FOray-specific
* objects.
*/
- private FoDocumentReader() throws IOException, ForayException {
+ private FoDocumentReader() {
final String orthographyConfigPath = "../foray-orthography/src/test/resources/orthography-config.xml";
- final URL orthographyFile = new URL("file", null, orthographyConfigPath);
+ URL orthographyFile = null;
+ try {
+ orthographyFile = new URL("file", null, orthographyConfigPath);
+ } catch (final MalformedURLException e) {
+ Assert.fail(e.getMessage());
+ }
final SessionConfig sessionConfig = Mockito.mock(SessionConfig.class);
Mockito.when(sessionConfig.optionOrthographyConfiguration()).thenReturn(orthographyFile);
- this.testDirectory = Environment.getTestDirectory();
+ FontServer fontServer = null;
+ GraphicServer graphicServer = null;
+ FoOrthographyServer hyphenServer = null;
+ try {
+ fontServer = ForaySpecific.makeFontServer(sessionConfig);
+ graphicServer = ForaySpecific.makeGraphicServer();
+ hyphenServer = ForaySpecific.makeHyphenationServer(sessionConfig);
+ } catch (final ForayException e) {
+ Assert.fail(e.getMessage());
+ }
- final FontServer fontServer = ForaySpecific.makeFontServer(sessionConfig);
- final GraphicServer graphicServer = ForaySpecific.makeGraphicServer();
- final FoOrthographyServer hyphenServer = ForaySpecific.makeHyphenationServer(sessionConfig);
final URL[] graphicSearchPath = new URL[1];
- final URL testDirUrl = this.testDirectory.toURI().toURL();
- graphicSearchPath[0] = UrlFactory.createURL(testDirUrl, "fo/");
+ try {
+ this.testDirectory = Environment.getTestDirectory();
+ final URL testDirUrl = this.testDirectory.toURI().toURL();
+ graphicSearchPath[0] = UrlFactory.createURL(testDirUrl, "fo/");
+ } catch (final IOException e) {
+ Assert.fail(e.getMessage());
+ }
final boolean cachingGraphics = false;
this.treeServer = new FoTreeServer4a(fontServer, hyphenServer, graphicServer, graphicSearchPath,
@@ -99,15 +116,10 @@
/**
* Returns the singleton instance.
* @return The singleton instance.
- * @throws ForayException For errors creating the singleton instance.
*/
- public static FoDocumentReader getInstance() throws ForayException {
+ public static FoDocumentReader getInstance() {
if (FoDocumentReader.theInstance == null) {
- try {
- FoDocumentReader.theInstance = new FoDocumentReader();
- } catch (final IOException e) {
- throw new ForayException(e);
- }
+ FoDocumentReader.theInstance = new FoDocumentReader();
}
return FoDocumentReader.theInstance;
}
@@ -118,18 +130,28 @@
* @return The parsed FO Tree instance.
* @throws ForayException For errors building the FO Tree.
*/
- public FoTree4a buildFoTree(final String file) throws ForayException {
- final FoTree4a foTree;
+ public FoTree4a buildFoTree(final String file) throws FoTreeException {
+ File testDirectory = null;
try {
- final Reader reader = new FileReader(file);
- final InputSource inputSource = new InputSource(reader);
- final FoTreeParser4a parser = this.treeServer.makeFoTreeParser();
- parser.parseFoTree(inputSource);
- foTree = parser.getFoTree();
- } catch (FileNotFoundException | FoTreeException e) {
- throw new ForayException(e);
+ testDirectory = Environment.getTestDirectory();
+ } catch (final IOException e) {
+ Assert.fail("Failure retrieving test directory from Environment.");
}
+ final File inputFile = new File(testDirectory, file);
+ Reader reader = null;
+ try {
+ reader = new FileReader(inputFile);
+ } catch (final FileNotFoundException e) {
+ Assert.fail("File not found: " + inputFile.getAbsolutePath());
+ }
+ final InputSource inputSource = new InputSource(reader);
+
+
+ final FoTreeParser4a parser = this.treeServer.makeFoTreeParser();
+ parser.parseFoTree(inputSource);
+ final FoTree4a foTree = parser.getFoTree();
+
final FontServer fontServer = this.treeServer.getFontServer();
final FontConsumer fontConsumer = fontServer.makeFontConsumer(null);
foTree.setFontConsumer(fontConsumer);
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestFont.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -35,6 +35,7 @@
import org.foray.fotree.fo.obj.Flow4a;
import org.axsl.font.Font;
+import org.axsl.fotree.FoTreeException;
import org.junit.Assert;
import org.junit.Ignore;
@@ -53,10 +54,9 @@
*/
@Test
@Ignore
- public void testFontFamily001() throws ForayException {
+ public void testFontFamily001() throws FoTreeException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
- final FoTree4a foTree = reader.buildFoTree(
- "fo/font-family-001.fo");
+ final FoTree4a foTree = reader.buildFoTree("fo/font-family-001.fo");
final Flow4a flow = this.getFlow(foTree);
FoObj node = flow.formattingObjectChildAt(0);
@@ -80,11 +80,11 @@
/**
* Test of fo/font-size-001.fo.
- * @throws ForayException For errors creating the FO Tree.
+ * @throws FoTreeException For errors creating the FO Tree.
*/
@Test
@Ignore
- public void testFontSize001() throws ForayException {
+ public void testFontSize001() throws FoTreeException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
final FoTree4a foTree = reader.buildFoTree("fo/font-size-001.fo");
final Flow4a flow = this.getFlow(foTree);
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestGraphic.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -28,7 +28,6 @@
package org.foray.app.fo;
-import org.foray.core.ForayException;
import org.foray.fotree.FoObj;
import org.foray.fotree.FoTree4a;
import org.foray.fotree.fo.obj.Block4a;
@@ -36,6 +35,8 @@
import org.foray.fotree.fo.obj.InstreamForeignObject4a;
import org.foray.fotree.svg.obj.InstreamSvgElement;
+import org.axsl.fotree.FoTreeException;
+
import org.junit.Assert;
/**
@@ -46,12 +47,11 @@
/**
* Test of fo/graphic-001.fo.
* This file contains an fo:instream-foreign-object with a simple SVG in it.
- * @throws ForayException For errors creating the FO Tree.
+ * @throws FoTreeException For errors creating the FO Tree.
*/
- public void testGraphic001() throws ForayException {
+ public void testGraphic001() throws FoTreeException {
final FoDocumentReader reader = FoDocumentReader.getInstance();
- final FoTree4a foTree = reader.buildFoTree(
- "fo/graphic-001.fo");
+ final FoTree4a foTree = reader.buildFoTree("fo/graphic-001.fo");
final Flow4a flow = this.getFlow(foTree);
/* The second child should be a block ... */
Modified: trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestInvalidXml.java
===================================================================
--- trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestInvalidXml.java 2022-12-02 16:46:01 UTC (rev 12762)
+++ trunk/foray/foray-app/src/test/java/org/foray/app/fo/TestInvalidXml.java 2022-12-02 19:53:24 UTC (rev 12763)
@@ -28,25 +28,27 @@
package org.foray.app.fo;
-import org.foray.core.ForayException;
+import org.axsl.fotree.FoTreeException;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
/**
* Tests for parsing invalid XML in FO input.
*/
-public class TestInvalidXml extends TestCase {
+public class TestInvalidXml {
/**
* Test of fo/invalid-xml-001.fo.
- * @throws ForayException For errors creating the FO Tree.
*/
- public void testXml001() throws ForayException {
+ @Test
+ public void testXml001() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-xml-001.fo");
- fail("Expected ForayException indicating invalid XML content.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating invalid XML content.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
@@ -53,14 +55,14 @@
/**
* Test of fo/invalid-xml-002.fo.
- * @throws ForayException For errors creating the FO Tree.
*/
- public void testXml002() throws ForayException {
+ @Test
+ public void testXml002() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-xml-002.fo");
- fail("Expected ForayException indicating invalid XML content.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating invalid XML content.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
@@ -67,14 +69,14 @@
/**
* Test of fo/invalid-xml-003.fo.
- * @throws ForayException For errors creating the FO Tree.
*/
- public void testXml003() throws ForayException {
+ @Test
+ public void testXml003() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-xml-003.fo");
- fail("Expected ForayException indicating invalid XML content.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating invalid XML content.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
@@ -81,31 +83,30 @@
/**
* Test of fo/invalid-ns-001.fo, which contains an unregistered namespace.
- * @throws ForayException For errors creating the FO Tree.
*/
- public void testNamespace001() throws ForayException {
+ @Ignore
+ @Test
+ public void testNamespace001() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-ns-001.fo");
- fail("Expected ForayException indicating an unregistered "
- + "namespace.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating an unregistered namespace.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
/**
- * Test of fo/invalid-ns-002.fo, which contains an unregistered namespace
- * inside some foreign xml.
- * @throws ForayException For errors creating the FO Tree.
+ * Test of fo/invalid-ns-002.fo, which contains an unregistered namespace inside some foreign xml.
*/
- public void testNamespace002() throws ForayException {
+ @Ignore
+ @Test
+ public void testNamespace002() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-ns-002.fo");
- fail("Expected ForayException indicating an unregistered "
- + "namespace.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating an unregistered namespace.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
@@ -112,15 +113,14 @@
/**
* Test of fo/invalid-fo-001.fo, which has no root element.
- * @throws ForayException For errors creating the FO Tree.
*/
- public void testFo001() throws ForayException {
+ @Test
+ public void testFo001() {
final FoDocumentReader reader = FoDocumentReader.getInstance();
try {
reader.buildFoTree("fo/invalid-fo-001.fo");
- fail("Expected ForayException indicating that the root element "
- + "is missing.");
- } catch (final ForayException e) {
+ Assert.fail("Expected ForayException indicating that the root element is missing.");
+ } catch (final FoTreeException e) {
/* Do nothing. This is the expected case. */
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|