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.

FopFactoryBuilderTestCase.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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.net.URI;
  20. import java.net.URISyntaxException;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import org.junit.Before;
  24. import org.junit.Test;
  25. import static org.junit.Assert.assertEquals;
  26. import static org.junit.Assert.assertFalse;
  27. import static org.junit.Assert.assertNull;
  28. import static org.junit.Assert.assertTrue;
  29. import static org.junit.Assert.fail;
  30. import org.apache.fop.apps.io.ResourceResolverFactory;
  31. import org.apache.fop.area.AreaTreeHandler;
  32. import org.apache.fop.area.Block;
  33. import org.apache.fop.fo.FONode;
  34. import org.apache.fop.fo.extensions.ExternalDocument;
  35. import org.apache.fop.fo.pagination.Flow;
  36. import org.apache.fop.fo.pagination.PageSequence;
  37. import org.apache.fop.fo.pagination.SideRegion;
  38. import org.apache.fop.fo.pagination.StaticContent;
  39. import org.apache.fop.fo.pagination.Title;
  40. import org.apache.fop.layoutmgr.ExternalDocumentLayoutManager;
  41. import org.apache.fop.layoutmgr.FlowLayoutManager;
  42. import org.apache.fop.layoutmgr.LayoutManager;
  43. import org.apache.fop.layoutmgr.LayoutManagerMaker;
  44. import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
  45. import org.apache.fop.layoutmgr.StaticContentLayoutManager;
  46. import org.apache.fop.layoutmgr.inline.ContentLayoutManager;
  47. /**
  48. * Test case for {@link FopFactoryBuilder}.
  49. */
  50. public class FopFactoryBuilderTestCase {
  51. private FopFactoryBuilder defaultBuilder;
  52. private static final String POST_SET_ERROR_MSG = "Should not be able to set any properties"
  53. + " once the builder has built a FopFactory.";
  54. @Before
  55. public void setUp() {
  56. defaultBuilder = new FopFactoryBuilder(URI.create("."));
  57. }
  58. @Test(expected = IllegalArgumentException.class)
  59. public void testNullParamsInConstructor() throws URISyntaxException {
  60. new FopFactoryBuilder(null, ResourceResolverFactory.createDefaultResourceResolver());
  61. }
  62. @Test
  63. public void testDefaultImplementation() {
  64. testDefaults(defaultBuilder.build(), URI.create("."));
  65. }
  66. private FopFactory buildFopFactory() {
  67. return defaultBuilder.build();
  68. }
  69. public static void testDefaults(FopFactory factory, URI baseURI) {
  70. assertFalse(factory.isAccessibilityEnabled());
  71. assertNull(factory.getLayoutManagerMakerOverride());
  72. assertEquals(FopFactoryConfig.DEFAULT_STRICT_FO_VALIDATION, factory.validateStrictly());
  73. assertEquals(FopFactoryConfig.DEFAULT_STRICT_USERCONFIG_VALIDATION,
  74. factory.validateUserConfigStrictly());
  75. assertEquals(FopFactoryConfig.DEFAULT_BREAK_INDENT_INHERITANCE,
  76. factory.isBreakIndentInheritanceOnReferenceAreaBoundary());
  77. assertEquals(FopFactoryConfig.DEFAULT_SOURCE_RESOLUTION, factory.getSourceResolution(),
  78. 0.001f);
  79. assertEquals(FopFactoryConfig.DEFAULT_TARGET_RESOLUTION, factory.getTargetResolution(),
  80. 0.001f);
  81. assertEquals(FopFactoryConfig.DEFAULT_PAGE_HEIGHT, factory.getPageHeight());
  82. assertEquals(FopFactoryConfig.DEFAULT_PAGE_WIDTH, factory.getPageWidth());
  83. assertFalse(factory.getRendererFactory().isRendererPreferred());
  84. }
  85. @Test
  86. public void testSetGetAccessibility() {
  87. runSetterTest(new Runnable() {
  88. public void run() {
  89. defaultBuilder.setAccessibility(true);
  90. assertTrue(buildFopFactory().isAccessibilityEnabled());
  91. }
  92. });
  93. }
  94. @Test
  95. public void testsetGetLMM() {
  96. runSetterTest(new Runnable() {
  97. public void run() {
  98. LayoutManagerMaker testLmm = new LayoutManagerMaker() {
  99. public StaticContentLayoutManager makeStaticContentLayoutManager(
  100. PageSequenceLayoutManager pslm, StaticContent sc, Block block) {
  101. return null;
  102. }
  103. public StaticContentLayoutManager makeStaticContentLayoutManager(
  104. PageSequenceLayoutManager pslm, StaticContent sc, SideRegion reg) {
  105. return null;
  106. }
  107. public PageSequenceLayoutManager makePageSequenceLayoutManager(AreaTreeHandler ath,
  108. PageSequence ps) {
  109. return null;
  110. }
  111. public void makeLayoutManagers(FONode node, List lms) {
  112. }
  113. public LayoutManager makeLayoutManager(FONode node) {
  114. return null;
  115. }
  116. public FlowLayoutManager makeFlowLayoutManager(PageSequenceLayoutManager pslm,
  117. Flow flow) {
  118. return null;
  119. }
  120. public ExternalDocumentLayoutManager makeExternalDocumentLayoutManager(
  121. AreaTreeHandler ath, ExternalDocument ed) {
  122. return null;
  123. }
  124. public ContentLayoutManager makeContentLayoutManager(PageSequenceLayoutManager pslm,
  125. Title title) {
  126. return null;
  127. }
  128. };
  129. defaultBuilder.setLayoutManagerMakerOverride(testLmm);
  130. assertEquals(testLmm, buildFopFactory().getLayoutManagerMakerOverride());
  131. }
  132. });
  133. }
  134. @Test
  135. public void testSetGetBaseURI() {
  136. runSetterTest(new Runnable() {
  137. public void run() {
  138. URI nonDefaultURI = URI.create("./test/");
  139. defaultBuilder.setBaseURI(nonDefaultURI);
  140. assertEquals(nonDefaultURI, defaultBuilder.buildConfiguration().getBaseURI());
  141. }
  142. });
  143. }
  144. @Test
  145. public void testGetSetValidateFO() {
  146. runSetterTest(new Runnable() {
  147. public void run() {
  148. defaultBuilder.setStrictFOValidation(false);
  149. assertFalse(buildFopFactory().validateStrictly());
  150. }
  151. });
  152. }
  153. @Test
  154. public void testGetSetValidateUserConfig() {
  155. runSetterTest(new Runnable() {
  156. public void run() {
  157. defaultBuilder.setStrictUserConfigValidation(false);
  158. assertFalse(buildFopFactory().validateUserConfigStrictly());
  159. }
  160. });
  161. }
  162. @Test
  163. public void testGetSetBreakInheritance() {
  164. runSetterTest(new Runnable() {
  165. public void run() {
  166. defaultBuilder.setBreakIndentInheritanceOnReferenceAreaBoundary(true);
  167. assertTrue(buildFopFactory().isBreakIndentInheritanceOnReferenceAreaBoundary());
  168. }
  169. });
  170. }
  171. @Test
  172. public void testGetSetSourceRes() {
  173. runSetterTest(new Runnable() {
  174. public void run() {
  175. float testRes = 10f;
  176. defaultBuilder.setSourceResolution(testRes);
  177. assertEquals(testRes, buildFopFactory().getSourceResolution(), 0.0001);
  178. }
  179. });
  180. }
  181. @Test
  182. public void testGetSetTargetRes() {
  183. runSetterTest(new Runnable() {
  184. public void run() {
  185. float testRes = 10f;
  186. defaultBuilder.setTargetResolution(testRes);
  187. assertEquals(testRes, buildFopFactory().getTargetResolution(), 0.0001f);
  188. }
  189. });
  190. }
  191. @Test
  192. public void testGetSetPageHeight() {
  193. runSetterTest(new Runnable() {
  194. public void run() {
  195. String testString = "Purely for testing";
  196. defaultBuilder.setPageHeight(testString);
  197. assertEquals(testString, buildFopFactory().getPageHeight());
  198. }
  199. });
  200. }
  201. @Test
  202. public void testGetSetPageWidth() {
  203. runSetterTest(new Runnable() {
  204. public void run() {
  205. String testString = "Purely for testing";
  206. defaultBuilder.setPageWidth(testString);
  207. assertEquals(testString, buildFopFactory().getPageWidth());
  208. }
  209. });
  210. }
  211. @Test
  212. public void testGetSetIsNamespaceIgnored() {
  213. runSetterTest(new Runnable() {
  214. public void run() {
  215. String testString = "Purely for testing";
  216. defaultBuilder.ignoreNamespace(testString);
  217. assertTrue(buildFopFactory().isNamespaceIgnored(testString));
  218. }
  219. });
  220. }
  221. @Test
  222. public void testGetSetListNamespaceIgnored() {
  223. runSetterTest(new Runnable() {
  224. public void run() {
  225. List<String> strings = new ArrayList<String>();
  226. strings.add("1");
  227. strings.add("2");
  228. strings.add("3");
  229. defaultBuilder.ignoreNamespaces(strings);
  230. FopFactory factory = buildFopFactory();
  231. assertTrue(factory.isNamespaceIgnored("1"));
  232. assertTrue(factory.isNamespaceIgnored("2"));
  233. assertTrue(factory.isNamespaceIgnored("3"));
  234. }
  235. });
  236. }
  237. @Test
  238. public void testGetSetPreferRenderer() {
  239. runSetterTest(new Runnable() {
  240. public void run() {
  241. defaultBuilder.setPreferRenderer(true);
  242. assertTrue(buildFopFactory().getRendererFactory().isRendererPreferred());
  243. }
  244. });
  245. }
  246. private void runSetterTest(Runnable setterTest) {
  247. setterTest.run();
  248. try {
  249. setterTest.run();
  250. fail(POST_SET_ERROR_MSG);
  251. } catch (IllegalStateException e) {
  252. // Expected
  253. }
  254. }
  255. }