You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FopConfParserTestCase.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.apps;
  19. import java.io.File;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import java.net.URI;
  23. import org.junit.Before;
  24. import org.junit.Test;
  25. import org.xml.sax.SAXException;
  26. import static org.junit.Assert.assertEquals;
  27. import static org.junit.Assert.assertFalse;
  28. import static org.junit.Assert.assertTrue;
  29. /**
  30. * Test case for {@link FopConfParser}.
  31. */
  32. public class FopConfParserTestCase {
  33. private final URI baseURI = URI.create("test/config/fop_factory_tests/");
  34. private FopConfBuilder builder;
  35. @Before
  36. public void setUp() {
  37. builder = new FopConfBuilder();
  38. }
  39. public static FopFactory getFopFactory(InputStream fopConfStream, URI baseURI) {
  40. FopConfParser confParser;
  41. try {
  42. confParser = new FopConfParser(fopConfStream, baseURI);
  43. return confParser.getFopFactoryBuilder().build();
  44. } catch (SAXException e) {
  45. throw new RuntimeException(e);
  46. } catch (IOException e) {
  47. throw new RuntimeException(e);
  48. }
  49. }
  50. private FopFactory buildFactory() {
  51. FopConfParser confParser;
  52. try {
  53. confParser = new FopConfParser(builder.build(), baseURI);
  54. return confParser.getFopFactoryBuilder().build();
  55. } catch (SAXException e) {
  56. throw new RuntimeException(e);
  57. } catch (IOException e) {
  58. throw new RuntimeException(e);
  59. }
  60. }
  61. @Test
  62. public void testDefaults() {
  63. FopFactory config = buildFactory();
  64. FopFactoryBuilderTestCase.testDefaults(config, baseURI);
  65. }
  66. @Test
  67. public void testStrictFOValidation() {
  68. builder.setStrictValidation(false);
  69. assertFalse(buildFactory().validateStrictly());
  70. }
  71. @Test
  72. public void testStrictUserValidation() {
  73. builder.setStrictConfiguration(false);
  74. assertFalse(buildFactory().validateUserConfigStrictly());
  75. }
  76. @Test
  77. public void testAccessibility() {
  78. builder.setAccessibility(false, true);
  79. assertFalse(buildFactory().isAccessibilityEnabled());
  80. }
  81. @Test
  82. public void testAccessibilityKeepEmptyTags() {
  83. builder.setAccessibility(true, false);
  84. assertFalse(buildFactory().isKeepEmptyTags());
  85. }
  86. @Test
  87. public void testSourceResolution() {
  88. float srcRes = 123.456f;
  89. builder.setSourceResolution(srcRes);
  90. assertEquals(srcRes, buildFactory().getSourceResolution(), 0.0001f);
  91. }
  92. @Test
  93. public void testTargetResolution() {
  94. float targetRes = 123.456f;
  95. builder.setTargetResolution(targetRes);
  96. assertEquals(targetRes, buildFactory().getTargetResolution(), 0.0001f);
  97. }
  98. @Test
  99. public void testBreakIndentInheritance() {
  100. builder.setBreakIndentInheritance(true);
  101. assertTrue(buildFactory().isBreakIndentInheritanceOnReferenceAreaBoundary());
  102. }
  103. @Test
  104. public void testDefaultPageSettings() {
  105. float height = 12.345f;
  106. float width = 67.89f;
  107. builder.setDefaultPageSettings(height, width);
  108. FopFactory factory = buildFactory();
  109. assertEquals("12.345", factory.getPageHeight());
  110. assertEquals("67.89", factory.getPageWidth());
  111. }
  112. @Test
  113. public void testPreferRenderer() {
  114. builder.setPreferRenderer(true);
  115. assertTrue(buildFactory().getRendererFactory().isRendererPreferred());
  116. }
  117. @Test
  118. public void testRelativeURINoBaseNoFont() throws Exception {
  119. checkRelativeURIs("test/config/relative-uri/no-base_no-font.xconf",
  120. "", "");
  121. }
  122. @Test
  123. public void testRelativeURINoBaseFont() throws Exception {
  124. checkRelativeURIs("test/config/relative-uri/no-base_font.xconf",
  125. "", "test/config/relative-uri/fonts/");
  126. }
  127. @Test
  128. public void testRelativeURIBaseNoFont() throws Exception {
  129. checkRelativeURIs("test/config/relative-uri/base_no-font.xconf",
  130. "test/config/relative-uri/relative/", "test/config/relative-uri/relative/");
  131. }
  132. @Test
  133. public void testRelativeURIBaseFont() throws Exception {
  134. checkRelativeURIs("test/config/relative-uri/base_font.xconf",
  135. "test/config/relative-uri/relative/", "test/config/relative-uri/fonts/");
  136. }
  137. private void checkRelativeURIs(String conf, String expectedBase, String expectedFontBase)
  138. throws SAXException, IOException {
  139. File configFile = new File(conf);
  140. URI currentDir = new File(".").getCanonicalFile().toURI();
  141. FopConfParser parser = new FopConfParser(configFile, currentDir);
  142. FopFactoryBuilder fopFactoryBuilder = parser.getFopFactoryBuilder();
  143. assertEquals("base URI", currentDir.resolve(expectedBase),
  144. fopFactoryBuilder.getBaseURI());
  145. assertEquals("font base", currentDir.resolve(expectedFontBase),
  146. fopFactoryBuilder.getFontManager().getResourceResolver().getBaseURI());
  147. }
  148. }