aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMehdi Houshmand <mehdi@apache.org>2012-06-11 14:35:57 +0000
committerMehdi Houshmand <mehdi@apache.org>2012-06-11 14:35:57 +0000
commit24664f14599a17792b0704ae352702407cb5c0e0 (patch)
tree59683751374bde46ab68937c4bca3f600203d1a0 /test
parent991d69ab0cb29b8efe1fa3efc72ef16a1065e450 (diff)
downloadxmlgraphics-fop-24664f14599a17792b0704ae352702407cb5c0e0.tar.gz
xmlgraphics-fop-24664f14599a17792b0704ae352702407cb5c0e0.zip
Removed AFP resource handling mechanism in favour of a unified resource resolver
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_URI_Unification@1348871 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/java/org/apache/fop/URIResolutionTestCase.java4
-rw-r--r--test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java10
-rw-r--r--test/java/org/apache/fop/apps/AFPRendererConfBuilder.java56
-rw-r--r--test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java4
-rw-r--r--test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java212
-rw-r--r--test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java4
-rw-r--r--test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java4
-rw-r--r--test/java/org/apache/fop/pdf/PDFFactoryTestCase.java8
-rw-r--r--test/java/org/apache/fop/render/afp/AFPRendererConfigParserTestCase.java69
-rw-r--r--test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java227
10 files changed, 505 insertions, 93 deletions
diff --git a/test/java/org/apache/fop/URIResolutionTestCase.java b/test/java/org/apache/fop/URIResolutionTestCase.java
index a63c1c5b6..f1dd89725 100644
--- a/test/java/org/apache/fop/URIResolutionTestCase.java
+++ b/test/java/org/apache/fop/URIResolutionTestCase.java
@@ -52,9 +52,9 @@ import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.FopFactoryBuilder;
import org.apache.fop.apps.MimeConstants;
-import org.apache.fop.apps.io.DefaultResourceResolver;
import org.apache.fop.apps.io.Resource;
import org.apache.fop.apps.io.ResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.render.xml.XMLRenderer;
import static org.apache.fop.FOPTestUtils.getBaseDir;
@@ -177,7 +177,7 @@ public class URIResolutionTestCase {
}
private static final class CustomURIResolver implements ResourceResolver {
- private final DefaultResourceResolver defaultImpl = new DefaultResourceResolver();
+ private final ResourceResolver defaultImpl = ResourceResolverFactory.createDefaultResourceResolver();
public Resource getResource(URI uri) throws IOException {
if (uri.getScheme().equals("funky") && uri.getSchemeSpecificPart().equals("myimage123")) {
diff --git a/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
index c9ea9a5f4..27a3a41d0 100644
--- a/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
+++ b/test/java/org/apache/fop/afp/AFPResourceManagerTestCase.java
@@ -19,9 +19,6 @@
package org.apache.fop.afp;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -30,6 +27,11 @@ import org.junit.Test;
import org.apache.xmlgraphics.util.MimeConstants;
+import org.apache.fop.apps.io.ResourceResolverFactory;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
/**
* Test case for {@link AFPResourceManager}.
*/
@@ -39,7 +41,7 @@ public class AFPResourceManagerTestCase {
@Before
public void setUp() throws IOException {
- sut = new AFPResourceManager();
+ sut = new AFPResourceManager(ResourceResolverFactory.createDefaultWrapper());
AFPPaintingState paintingState = new AFPPaintingState();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
DataStream stream = sut.createDataStream(paintingState, outStream);
diff --git a/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java b/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
index 40932f7fd..4ce9cb2a0 100644
--- a/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
+++ b/test/java/org/apache/fop/apps/AFPRendererConfBuilder.java
@@ -20,6 +20,7 @@
package org.apache.fop.apps;
+import java.net.URI;
import java.util.Map;
import org.w3c.dom.Element;
@@ -33,11 +34,17 @@ import static org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions.MODE
import static org.apache.fop.render.afp.AFPRendererConfig.Options.DEFAULT_RESOURCE_LEVELS;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_DITHERING_QUALITY;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_FS45;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_JPEG;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_MAPPING_OPTION;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_MODE;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_NATIVE;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.IMAGES_WRAP_PSEG;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.JPEG_ALLOW_JPEG_EMBEDDING;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.JPEG_BITMAP_ENCODING_QUALITY;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.RENDERER_RESOLUTION;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.LINE_WIDTH_CORRECTION;
-import static org.apache.fop.render.afp.AFPRendererConfig.Options.RESOURCE_GROUP_FILE;
+import static org.apache.fop.render.afp.AFPRendererConfig.Options.RESOURCE_GROUP_URI;
import static org.apache.fop.render.afp.AFPRendererConfig.Options.SHADING;
/**
@@ -82,12 +89,12 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
return this;
}
- public AFPRendererConfBuilder setResourceGroupFile(String value) {
- createTextElement(RESOURCE_GROUP_FILE, value);
+ public AFPRendererConfBuilder setResourceGroupUri(String uri) {
+ createTextElement(RESOURCE_GROUP_URI, uri);
return this;
}
- public AFPRendererConfBuilder setResourceResourceLevels(Map<String, String> levels) {
+ public AFPRendererConfBuilder setDefaultResourceLevels(Map<String, String> levels) {
Element e = createElement(DEFAULT_RESOURCE_LEVELS.getName());
for (String key : levels.keySet()) {
e.setAttribute(key, levels.get(key));
@@ -99,6 +106,8 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
private final Element el;
+ private Element jpeg;
+
private ImagesBuilder(AFPRendererConfig.ImagesModeOptions mode) {
el = createElement(IMAGES.getName());
setAttribute(IMAGES_MODE, mode.getName());
@@ -108,29 +117,58 @@ public final class AFPRendererConfBuilder extends RendererConfBuilder {
return setAttribute(name, value);
}
+ public ImagesBuilder setAllowJpegEmbedding(boolean value) {
+ getJpeg().setAttribute(JPEG_ALLOW_JPEG_EMBEDDING.getName(), String.valueOf(value));
+ return this;
+ }
+
+ public ImagesBuilder setBitmapEncodingQuality(float value) {
+ getJpeg().setAttribute(JPEG_BITMAP_ENCODING_QUALITY.getName(), String.valueOf(value));
+ return this;
+ }
+
public ImagesBuilder setDitheringQuality(String value) {
return setAttribute(IMAGES_DITHERING_QUALITY, value);
}
public ImagesBuilder setDitheringQuality(float value) {
- return setAttribute(IMAGES_DITHERING_QUALITY, String.valueOf(value));
+ return setAttribute(IMAGES_DITHERING_QUALITY, value);
+ }
+
+ public ImagesBuilder setFs45(boolean value) {
+ return setAttribute(IMAGES_FS45, value);
+ }
+
+ public ImagesBuilder setMappingOption(String value) {
+ return setAttribute(IMAGES_MAPPING_OPTION, value);
+ }
+
+ public ImagesBuilder setWrapPseg(boolean value) {
+ return setAttribute(IMAGES_WRAP_PSEG, value);
}
public ImagesBuilder setNativeImageSupport(boolean value) {
- return setAttribute(IMAGES_NATIVE, String.valueOf(value));
+ return setAttribute(IMAGES_NATIVE, value);
}
public AFPRendererConfBuilder endImages() {
return AFPRendererConfBuilder.this.endImages();
}
- private ImagesBuilder setAttribute(Options options, String value) {
+ private ImagesBuilder setAttribute(Options options, Object value) {
return setAttribute(options.getName(), value);
}
- private ImagesBuilder setAttribute(String name, String value) {
- el.setAttribute(name, value);
+ private ImagesBuilder setAttribute(String name, Object value) {
+ el.setAttribute(name, String.valueOf(value));
return this;
}
+
+ private Element getJpeg() {
+ if (jpeg == null) {
+ jpeg = createElement(IMAGES_JPEG.getName(), el);
+ }
+ return jpeg;
+ }
}
}
diff --git a/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java b/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java
index edb20fad6..f56373218 100644
--- a/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java
+++ b/test/java/org/apache/fop/apps/FopFactoryBuilderTestCase.java
@@ -27,7 +27,7 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
-import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.area.AreaTreeHandler;
import org.apache.fop.area.Block;
import org.apache.fop.fo.FONode;
@@ -67,7 +67,7 @@ public class FopFactoryBuilderTestCase {
@Test(expected = IllegalArgumentException.class)
public void testNullParamsInConstructor() throws URISyntaxException {
- new FopFactoryBuilder(null, new DefaultResourceResolver());
+ new FopFactoryBuilder(null, ResourceResolverFactory.createDefaultResourceResolver());
}
@Test
diff --git a/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java b/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java
new file mode 100644
index 000000000..223f74045
--- /dev/null
+++ b/test/java/org/apache/fop/apps/io/ResourceResolverFactoryTestCase.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.apps.io;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+public class ResourceResolverFactoryTestCase {
+
+ private static final byte[] DATA = new byte[]{(byte) 0, (byte) 1, (byte) 2};
+
+ private void writeDataTo(File f) throws IOException {
+ writeDataTo(new FileOutputStream(f));
+ }
+
+ private void writeDataTo(OutputStream os) throws IOException {
+ os.write(DATA);
+ os.close();
+ }
+
+ private void checkStream(InputStream inputStream) throws IOException {
+ byte[] actual = new byte[DATA.length];
+ for (int i = 0; i < DATA.length; i++) {
+ actual[i] = (byte) inputStream.read();
+ }
+ assertEquals(-1, inputStream.read());
+ assertArrayEquals(DATA, actual);
+ }
+
+ @Test
+ public void testDefaultResourceResolverGetResource() throws Exception {
+ ResourceResolver sut = ResourceResolverFactory.createDefaultResourceResolver();
+ File inputFile = File.createTempFile("prefix", "suffix");
+ InputStream is = null;
+ try {
+ writeDataTo(inputFile);
+ is = sut.getResource(inputFile.toURI());
+ checkStream(is);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ inputFile.delete();
+ }
+ }
+
+ @Test
+ public void testDefaultResourceResolverGetOutput() throws Exception {
+ ResourceResolver sut = ResourceResolverFactory.createDefaultResourceResolver();
+ File outputFile = File.createTempFile("prefix", "suffix");
+ writeDataTo(sut.getOutputStream(outputFile.toURI()));
+ InputStream is = new FileInputStream(outputFile);
+ try {
+ checkStream(is);
+ } finally {
+ is.close();
+ }
+ }
+
+ private static class TestCreateTempAwareResourceResolverHelper implements ResourceResolver {
+
+ final TempResourceResolver tempResourceResolver = mock(TempResourceResolver.class);
+
+ final ResourceResolver defaultResourceResolver = mock(ResourceResolver.class);
+
+ final ResourceResolver sut = ResourceResolverFactory.createTempAwareResourceResolver(
+ tempResourceResolver, defaultResourceResolver);
+
+ public Resource getResource(URI uri) throws IOException {
+ return sut.getResource(uri);
+ }
+ public OutputStream getOutputStream(URI uri) throws IOException {
+ return sut.getOutputStream(uri);
+ }
+ }
+
+ @Test
+ public void testCreateTempAwareResourceResolverForTmpResource() throws Exception {
+ URI uri = URI.create("tmp:///id");
+ TestCreateTempAwareResourceResolverHelper helper = new TestCreateTempAwareResourceResolverHelper();
+ helper.getResource(uri);
+ verify(helper.tempResourceResolver, times(1)).getResource(uri.getPath());
+ verify(helper.defaultResourceResolver, never()).getResource(uri);
+ }
+
+ @Test
+ public void testCreateTempAwareResourceResolverForRegularResource() throws Exception {
+ URI uri = URI.create("file:///path/to/file");
+ TestCreateTempAwareResourceResolverHelper helper = new TestCreateTempAwareResourceResolverHelper();
+ helper.getResource(uri);
+ verify(helper.tempResourceResolver, never()).getResource(uri.getPath());
+ verify(helper.defaultResourceResolver, times(1)).getResource(uri);
+ }
+
+ @Test
+ public void testCreateTempAwareResourceResolverForTmpOuput() throws Exception {
+ URI uri = URI.create("tmp:///id");
+ TestCreateTempAwareResourceResolverHelper helper = new TestCreateTempAwareResourceResolverHelper();
+ helper.getOutputStream(uri);
+ verify(helper.tempResourceResolver, times(1)).getOutputStream(uri.getPath());
+ verify(helper.defaultResourceResolver, never()).getOutputStream(uri);
+ }
+
+ @Test
+ public void testCreateTempAwareResourceResolverForRegularOutput() throws Exception {
+ URI uri = URI.create("file:///path/to/file");
+ TestCreateTempAwareResourceResolverHelper helper = new TestCreateTempAwareResourceResolverHelper();
+ helper.getOutputStream(uri);
+ verify(helper.tempResourceResolver, never()).getOutputStream(uri.getPath());
+ verify(helper.defaultResourceResolver, times(1)).getOutputStream(uri);
+ }
+
+ @Test
+ public void testCreateSchemaAwareResourceResolverForDefaultResource() throws Exception {
+ URI uri = URI.create("file:///path/to/file");
+ TestCreateSchemaAwareResourceResolverBuilderHelper helper
+ = new TestCreateSchemaAwareResourceResolverBuilderHelper();
+ helper.getResource(uri);
+ verify(helper.registedResourceResolver, never()).getResource(uri);
+ verify(helper.defaultResourceResolver, times(1)).getResource(uri);
+ }
+
+ @Test
+ public void testCreateSchemaAwareResourceResolverForRegisteredResource() throws Exception {
+ URI uri = URI.create(TestCreateSchemaAwareResourceResolverBuilderHelper.SCHEMA + ":///path");
+ TestCreateSchemaAwareResourceResolverBuilderHelper helper
+ = new TestCreateSchemaAwareResourceResolverBuilderHelper();
+ helper.getResource(uri);
+ verify(helper.registedResourceResolver, times(1)).getResource(uri);
+ verify(helper.defaultResourceResolver, never()).getResource(uri);
+ }
+
+ @Test
+ public void testCreateSchemaAwareResourceResolverForDefaultOutput() throws Exception {
+ URI uri = URI.create("file:///path/to/file");
+ TestCreateSchemaAwareResourceResolverBuilderHelper helper
+ = new TestCreateSchemaAwareResourceResolverBuilderHelper();
+ helper.getOutputStream(uri);
+ verify(helper.registedResourceResolver, never()).getOutputStream(uri);
+ verify(helper.defaultResourceResolver, times(1)).getOutputStream(uri);
+ }
+
+ @Test
+ public void testCreateSchemaAwareResourceResolverForRegisteredOutput() throws Exception {
+ URI uri = URI.create(TestCreateSchemaAwareResourceResolverBuilderHelper.SCHEMA + ":///path");
+ TestCreateSchemaAwareResourceResolverBuilderHelper helper
+ = new TestCreateSchemaAwareResourceResolverBuilderHelper();
+ helper.getOutputStream(uri);
+ verify(helper.registedResourceResolver, times(1)).getOutputStream(uri);
+ verify(helper.defaultResourceResolver, never()).getOutputStream(uri);
+ }
+
+ private static class TestCreateSchemaAwareResourceResolverBuilderHelper implements ResourceResolver {
+
+ private static final String SCHEMA = "protocol";
+
+ final ResourceResolver registedResourceResolver = mock(ResourceResolver.class);
+
+ final ResourceResolver defaultResourceResolver = mock(ResourceResolver.class);
+
+ final ResourceResolver sut;
+
+ TestCreateSchemaAwareResourceResolverBuilderHelper() {
+ ResourceResolverFactory.SchemaAwareResourceResolverBuilder builder
+ = ResourceResolverFactory.createSchemaAwareResourceResolverBuilder(
+ defaultResourceResolver);
+ builder.registerResourceResolverForSchema(SCHEMA, registedResourceResolver);
+ sut = builder.build();
+
+ }
+
+ public Resource getResource(URI uri) throws IOException {
+ return sut.getResource(uri);
+ }
+ public OutputStream getOutputStream(URI uri) throws IOException {
+ return sut.getOutputStream(uri);
+ }
+ }
+
+}
+
diff --git a/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java b/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java
index 4a261c87e..761333183 100644
--- a/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java
+++ b/test/java/org/apache/fop/fonts/DejaVuLGCSerifTestCase.java
@@ -24,7 +24,7 @@ import java.io.File;
import org.junit.Before;
import org.junit.Test;
-import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.apps.io.URIResolverWrapper;
import static org.junit.Assert.assertEquals;
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertEquals;
public class DejaVuLGCSerifTestCase {
private URIResolverWrapper resolver = new URIResolverWrapper(new File(".").toURI(),
- new DefaultResourceResolver());
+ ResourceResolverFactory.createDefaultResourceResolver());
private CustomFont font;
/**
diff --git a/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java b/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
index 1c4e92aec..edd65f108 100644
--- a/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
+++ b/test/java/org/apache/fop/fonts/truetype/TTFFontLoaderTestCase.java
@@ -25,7 +25,7 @@ import java.net.URI;
import org.junit.Test;
-import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.apps.io.URIResolverWrapper;
import org.apache.fop.fonts.EncodingMode;
@@ -42,7 +42,7 @@ public class TTFFontLoaderTestCase {
boolean useComplexScriptFeatures = false;
File file = new File("test/resources/fonts/ttf/DejaVuLGCSerif.ttf");
URI absoluteFilePath = file.toURI();
- URIResolverWrapper resolver = DefaultResourceResolver.createDefaultWrapper();
+ URIResolverWrapper resolver = ResourceResolverFactory.createDefaultWrapper();
String fontName = "Deja Vu";
boolean embedded = false;
boolean useKerning = true;
diff --git a/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java b/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
index e108266b5..80cbddd2d 100644
--- a/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
+++ b/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java
@@ -19,15 +19,15 @@
package org.apache.fop.pdf;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
-import org.apache.fop.apps.io.DefaultResourceResolver;
+import org.apache.fop.apps.io.ResourceResolverFactory;
import org.apache.fop.apps.io.URIResolverWrapper;
import org.apache.fop.fonts.CIDSubset;
import org.apache.fop.fonts.MultiByteFont;
+import static org.junit.Assert.assertEquals;
+
/**
* Test case for {@link PDFFactory}.
*/
@@ -56,7 +56,7 @@ public class PDFFactoryTestCase {
}
PDFDocument doc = new PDFDocument("Test");
PDFFactory pdfFactory = new PDFFactory(doc);
- MockedFont font = new MockedFont(DefaultResourceResolver.createDefaultWrapper());
+ MockedFont font = new MockedFont(ResourceResolverFactory.createDefaultWrapper());
PDFFont pdfDejaVu = pdfFactory.makeFont("DejaVu", "DejaVu", "TTF", font, font);
assertEquals("/EAAAAA+DejaVu", pdfDejaVu.getBaseFont().toString());
diff --git a/test/java/org/apache/fop/render/afp/AFPRendererConfigParserTestCase.java b/test/java/org/apache/fop/render/afp/AFPRendererConfigParserTestCase.java
index 233e636ca..799045872 100644
--- a/test/java/org/apache/fop/render/afp/AFPRendererConfigParserTestCase.java
+++ b/test/java/org/apache/fop/render/afp/AFPRendererConfigParserTestCase.java
@@ -38,7 +38,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public class AFPRendererConfigParserTestCase
-extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererConfig> {
+ extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererConfig> {
public AFPRendererConfigParserTestCase() {
super(new AFPRendererConfigParser(), AFPRendererConfBuilder.class);
@@ -63,21 +63,22 @@ extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererCo
@Test
public void testLineWidthCorrection() throws Exception {
parseConfig(createRenderer());
- assertEquals(AFPConstants.LINE_WIDTH_CORRECTION, conf.getLineWidthCorrection().floatValue(), 0.0001f);
+ assertEquals(AFPConstants.LINE_WIDTH_CORRECTION,
+ conf.getLineWidthCorrection().floatValue(), 0.0001f);
parseConfig(createRenderer().setLineWidthCorrection(1f));
assertEquals(Float.valueOf(1f), conf.getLineWidthCorrection());
}
@Test
- public void testResourceGroupFile() throws Exception {
+ public void testResourceGroupUri() throws Exception {
parseConfig(createRenderer());
- assertEquals(null, conf.getDefaultResourceGroupFilePath());
+ assertEquals(null, conf.getDefaultResourceGroupUri());
// TODO yuck!
File file = File.createTempFile("AFPRendererConfigParserTestCase", "");
try {
file.delete();
- parseConfig(createRenderer().setResourceGroupFile(file.getAbsolutePath()));
- assertEquals(file.getAbsolutePath(), conf.getDefaultResourceGroupFilePath());
+ parseConfig(createRenderer().setResourceGroupUri(file.toURI().toASCIIString()));
+ assertEquals(file.toURI(), conf.getDefaultResourceGroupUri());
} finally {
file.delete();
}
@@ -89,7 +90,7 @@ extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererCo
assertNull(conf.getResourceLevelDefaults());
Map<String, String> levels = new HashMap<String, String>();
levels.put("goca", "page");
- parseConfig(createRenderer().setResourceResourceLevels(levels));
+ parseConfig(createRenderer().setDefaultResourceLevels(levels));
assertNotNull(conf.getResourceLevelDefaults());
}
@@ -99,23 +100,22 @@ extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererCo
assertEquals(false, conf.isColorImages());
assertEquals(Integer.valueOf(8), conf.getBitsPerPixel());
ImagesModeOptions mode = MODE_GRAYSCALE;
- parseConfig(createRenderer()
- .startImages(mode)
- .setModeAttribute(mode.getModeAttribute(), String.valueOf(1))
- .endImages());
+ parseConfig(createRenderer().startImages(mode)
+ .setModeAttribute(mode.getModeAttribute(), String.valueOf(1))
+ .endImages());
assertEquals(false, conf.isColorImages());
assertEquals(Integer.valueOf(1), conf.getBitsPerPixel());
mode = MODE_COLOR;
parseConfig(createRenderer()
- .startImages(mode)
- .setModeAttribute(mode.getModeAttribute(), String.valueOf(false))
- .endImages());
+ .startImages(mode)
+ .setModeAttribute(mode.getModeAttribute(),
+ String.valueOf(false))
+ .endImages());
assertEquals(true, conf.isColorImages());
assertEquals(false, conf.isCmykImagesSupported());
- parseConfig(createRenderer()
- .startImages(mode)
- .setModeAttribute(mode.getModeAttribute(), String.valueOf(true))
- .endImages());
+ parseConfig(createRenderer().startImages(mode)
+ .setModeAttribute(mode.getModeAttribute(), String.valueOf(true))
+ .endImages());
assertEquals(true, conf.isColorImages());
assertEquals(true, conf.isCmykImagesSupported());
}
@@ -152,6 +152,39 @@ extends AbstractRendererConfigParserTester<AFPRendererConfBuilder, AFPRendererCo
assertEquals(0.25f, conf.getDitheringQuality(), 0.001f);
}
+ @Test
+ public void testAllowJpegEmbedding() throws Exception {
+ parseConfig();
+ assertEquals(false, conf.allowJpegEmbedding());
+
+ parseConfig(createRenderer().startImages().setAllowJpegEmbedding(true).endImages());
+ assertEquals(true, conf.allowJpegEmbedding());
+ }
+
+ @Test
+ public void testBitmapEncodingQuality() throws Exception {
+ parseConfig();
+ assertEquals(1.0f, conf.getBitmapEncodingQuality(), 0.001f);
+ parseConfig(createRenderer().startImages().setBitmapEncodingQuality(0.5f).endImages());
+ assertEquals(0.5f, conf.getBitmapEncodingQuality(), 0.001f);
+ }
+
+ @Test
+ public void testFS45() throws Exception {
+ parseConfig();
+ assertEquals(false, conf.isFs45());
+ parseConfig(createRenderer().startImages().setFs45(true).endImages());
+ assertEquals(true, conf.isFs45());
+ }
+
+ @Test
+ public void tesPseg() throws Exception {
+ parseConfig();
+ assertEquals(false, conf.isWrapPseg());
+ parseConfig(createRenderer().startImages().setWrapPseg(true).endImages());
+ assertEquals(true, conf.isWrapPseg());
+ }
+
@Test(expected = IllegalArgumentException.class)
public void testForNameException() throws Exception {
ImagesModeOptions.forName("_");
diff --git a/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
index 67f40b6e5..115b3149a 100644
--- a/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
+++ b/test/java/org/apache/fop/render/afp/AFPRendererConfiguratorTestCase.java
@@ -15,72 +15,199 @@
* limitations under the License.
*/
-/* $Id$ */
-
package org.apache.fop.render.afp;
-import java.io.File;
-import java.io.IOException;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
import org.junit.Test;
-import org.xml.sax.SAXException;
+import org.mockito.ArgumentCaptor;
-import org.apache.fop.afp.AFPPaintingState;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.apps.FopFactory;
+import org.apache.fop.afp.AFPResourceLevel;
+import org.apache.fop.afp.AFPResourceLevel.ResourceType;
+import org.apache.fop.afp.AFPResourceLevelDefaults;
+import org.apache.fop.apps.AFPRendererConfBuilder;
+import org.apache.fop.apps.AbstractRendererConfiguratorTest;
+import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.afp.AFPRendererConfig.AFPRendererConfigParser;
-import org.apache.fop.render.intermediate.IFContext;
+import org.apache.fop.render.afp.AFPRendererConfig.ImagesModeOptions;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.mockito.Mockito.verify;
-/**
- * Test case for {@link AFPRendererConfigurator}.
- */
-public class AFPRendererConfiguratorTestCase {
- private FOUserAgent userAgent;
-
- private AFPRendererConfigurator sut;
-
- /**
- * Assigns an FOUserAgen with a config file at <code>uri</code>
- *
- * @param uri the URI of the config file
- */
- private void setConfigFile(String uri) {
- String confTestsDir = "test/resources/conf/afp/";
- try {
- userAgent = FopFactory.newInstance(new File(confTestsDir + uri)).newFOUserAgent();
- sut = new AFPRendererConfigurator(userAgent, new AFPRendererConfigParser());
- } catch (IOException ioe) {
- fail("IOException: " + ioe);
- } catch (SAXException se) {
- fail("SAXException: " + se);
+public class AFPRendererConfiguratorTestCase extends
+ AbstractRendererConfiguratorTest<AFPRendererConfigurator, AFPRendererConfBuilder> {
+
+ public AFPRendererConfiguratorTestCase() {
+ super(MimeConstants.MIME_AFP, AFPRendererConfBuilder.class, AFPDocumentHandler.class);
+ }
+
+ @Override
+ public void setUpDocumentHandler() {
+ }
+
+ @Override
+ protected AFPRendererConfigurator createConfigurator() {
+ return new AFPRendererConfigurator(userAgent, new AFPRendererConfigParser());
+ }
+
+ private AFPDocumentHandler getDocHandler() {
+ return (AFPDocumentHandler) docHandler;
+ }
+
+ @Test
+ public void testColorImages() throws Exception {
+ parseConfig(createBuilder().startImages(ImagesModeOptions.MODE_COLOR)
+ .endImages());
+ verify(getDocHandler()).setColorImages(true);
+
+ parseConfig(createBuilder().startImages(ImagesModeOptions.MODE_GRAYSCALE)
+ .endImages());
+ verify(getDocHandler()).setColorImages(false);
+ }
+
+ @Test
+ public void testCMYKImagesSupport() throws Exception {
+ parseConfig(createBuilder().startImages(ImagesModeOptions.MODE_COLOR)
+ .setModeAttribute("cmyk", "true")
+ .endImages());
+ verify(getDocHandler()).setCMYKImagesSupported(true);
+
+ parseConfig(createBuilder().startImages(ImagesModeOptions.MODE_COLOR)
+ .setModeAttribute("cmyk", "false")
+ .endImages());
+ verify(getDocHandler()).setCMYKImagesSupported(false);
+ }
+
+ @Test
+ public void testBitsPerPixel() throws Exception {
+ for (int bpp = 0; bpp < 40; bpp += 8) {
+ parseConfig(createBuilder().startImages()
+ .setModeAttribute("bits-per-pixel", String.valueOf(bpp))
+ .endImages());
+ verify(getDocHandler()).setBitsPerPixel(bpp);
+ }
+ }
+
+ @Test
+ public void testDitheringQuality() throws Exception {
+ float ditheringQuality = 100f;
+ parseConfig(createBuilder().startImages()
+ .setDitheringQuality(ditheringQuality)
+ .endImages());
+ verify(getDocHandler()).setDitheringQuality(ditheringQuality);
+
+ ditheringQuality = 1000f;
+ parseConfig(createBuilder().startImages()
+ .setDitheringQuality(ditheringQuality)
+ .endImages());
+ verify(getDocHandler()).setDitheringQuality(ditheringQuality);
+ }
+
+ @Test
+ public void testNativeImagesSupported() throws Exception {
+ parseConfig(createBuilder().startImages()
+ .setNativeImageSupport(true)
+ .endImages());
+ verify(getDocHandler()).setNativeImagesSupported(true);
+
+ parseConfig(createBuilder().startImages()
+ .setNativeImageSupport(false)
+ .endImages());
+ verify(getDocHandler()).setNativeImagesSupported(false);
+ }
+
+ @Test
+ public void testShadingMode() throws Exception {
+ for (AFPShadingMode mode : AFPShadingMode.values()) {
+ parseConfig(createBuilder().setShading(mode));
+ verify(getDocHandler()).setShadingMode(mode);
}
}
- /**
- * Test several config files relating to JPEG images in AFP.
- *
- * @throws FOPException if an error is thrown
- */
@Test
- public void testJpegImageConfig() throws FOPException {
- testJpegSettings("no_image_config.xconf", 1.0f, false);
- testJpegSettings("can_embed_jpeg.xconf", 1.0f, true);
- testJpegSettings("bitmap_encode_quality.xconf", 0.5f, false);
+ public void testRendererResolution() throws Exception {
+ for (int resolution = 0; resolution < 1000; resolution += 100) {
+ parseConfig(createBuilder().setRenderingResolution(resolution));
+ verify(getDocHandler()).setResolution(resolution);
+ }
+ }
+
+ @Test
+ public void testLineWidthCorrection() throws Exception {
+ for (float resolution = 0; resolution < 50; resolution += 5) {
+ parseConfig(createBuilder().setLineWidthCorrection(resolution));
+ verify(getDocHandler()).setLineWidthCorrection(resolution);
+ }
+ }
+
+ @Test
+ public void testResourceGroupURI() throws Exception {
+ URI uri = URI.create("test://URI/just/used/for/testing");
+ parseConfig(createBuilder().setResourceGroupUri(uri.toASCIIString()));
+ verify(getDocHandler()).setDefaultResourceGroupUri(uri);
+ }
+
+ @Test
+ public void testResourceLevelDefaults() throws Exception {
+ testResourceLevelDefault(ResourceType.DOCUMENT);
+ }
+
+ private void testResourceLevelDefault(ResourceType resType) throws Exception {
+ Map<String, String> resourceLevels = new HashMap<String, String>();
+ resourceLevels.put("goca", resType.getName());
+ parseConfig(createBuilder().setDefaultResourceLevels(resourceLevels));
+ ArgumentCaptor<AFPResourceLevelDefaults> argument = ArgumentCaptor.forClass(AFPResourceLevelDefaults.class);
+ verify(getDocHandler()).setResourceLevelDefaults(argument.capture());
+ AFPResourceLevel expectedLevel = new AFPResourceLevel(resType);
+ assertEquals(expectedLevel, argument.getValue().getDefaultResourceLevel((byte) 3));
+ }
+
+ @Test
+ public void testExternalResourceDefault() throws Exception {
+ testResourceLevelDefault(ResourceType.EXTERNAL);
}
- private void testJpegSettings(String uri, float bitmapEncodingQual, boolean canEmbed)
- throws FOPException {
- AFPDocumentHandler docHandler = new AFPDocumentHandler(new IFContext(userAgent));
+ @Test
+ public void testInlineResourceDefault() throws Exception {
+ testResourceLevelDefault(ResourceType.INLINE);
+ }
+
+ @Test
+ public void testPageResourceDefault() throws Exception {
+ testResourceLevelDefault(ResourceType.PAGE);
+ }
+
+ @Test
+ public void testPageGroupResourceDefault() throws Exception {
+ testResourceLevelDefault(ResourceType.PAGE_GROUP);
+ }
- setConfigFile(uri);
- sut.configure(docHandler);
+ @Test
+ public void testPrintFileResourceDefault() throws Exception {
+ testResourceLevelDefault(ResourceType.PRINT_FILE);
+ }
+
+ @Test
+ public void testBitmapEncodeQuality() throws Exception {
+ parseConfig(createBuilder().startImages()
+ .setBitmapEncodingQuality(0.5f)
+ .endImages());
+ verify(getDocHandler()).setBitmapEncodingQuality(0.5f);
+ }
+
+ @Test
+ public void testCanEmbedJpeg() throws Exception {
+ parseConfig(createBuilder().startImages()
+ .setAllowJpegEmbedding(true)
+ .endImages());
+ verify(getDocHandler()).canEmbedJpeg(true);
- AFPPaintingState paintingState = docHandler.getPaintingState();
- assertEquals(bitmapEncodingQual, paintingState.getBitmapEncodingQuality(), 0.01f);
- assertEquals(canEmbed, paintingState.canEmbedJpeg());
+ parseConfig(createBuilder().startImages()
+ .setAllowJpegEmbedding(false)
+ .endImages());
+ verify(getDocHandler()).canEmbedJpeg(false);
}
+
}