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 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.IOException;
  20. import java.io.InputStream;
  21. import java.net.URI;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.xml.sax.SAXException;
  25. import static org.junit.Assert.assertEquals;
  26. import static org.junit.Assert.assertFalse;
  27. import static org.junit.Assert.assertTrue;
  28. /**
  29. * Test case for {@link FopConfParser}.
  30. */
  31. public class FopConfParserTestCase {
  32. private final URI baseURI = URI.create("test/config/fop_factory_tests/");
  33. private FopConfBuilder builder;
  34. @Before
  35. public void setUp() {
  36. builder = new FopConfBuilder();
  37. }
  38. public static FopFactory getFopFactory(InputStream fopConfStream, URI baseURI) {
  39. FopConfParser confParser;
  40. try {
  41. confParser = new FopConfParser(fopConfStream, baseURI);
  42. return confParser.getFopFactoryBuilder().build();
  43. } catch (SAXException e) {
  44. throw new RuntimeException(e);
  45. } catch (IOException e) {
  46. throw new RuntimeException(e);
  47. }
  48. }
  49. private FopFactory buildFactory() {
  50. FopConfParser confParser;
  51. try {
  52. confParser = new FopConfParser(builder.build(), baseURI);
  53. return confParser.getFopFactoryBuilder().build();
  54. } catch (SAXException e) {
  55. throw new RuntimeException(e);
  56. } catch (IOException e) {
  57. throw new RuntimeException(e);
  58. }
  59. }
  60. @Test
  61. public void testDefaults() {
  62. FopFactory config = buildFactory();
  63. FopFactoryBuilderTestCase.testDefaults(config, baseURI);
  64. }
  65. @Test
  66. public void testStrictUserConfigValidation() {
  67. builder.setStrictValidation(false);
  68. assertFalse(buildFactory().validateUserConfigStrictly());
  69. }
  70. @Test
  71. public void testAccessibility() {
  72. builder.setAccessibility(false);
  73. assertFalse(buildFactory().isAccessibilityEnabled());
  74. }
  75. @Test
  76. public void testSourceResolution() {
  77. float srcRes = 123.456f;
  78. builder.setSourceResolution(srcRes);
  79. assertEquals(srcRes, buildFactory().getSourceResolution(), 0.0001f);
  80. }
  81. @Test
  82. public void testTargetResolution() {
  83. float targetRes = 123.456f;
  84. builder.setTargetResolution(targetRes);
  85. assertEquals(targetRes, buildFactory().getTargetResolution(), 0.0001f);
  86. }
  87. @Test
  88. public void testBreakIndentInheritance() {
  89. builder.setBreakIndentInheritance(true);
  90. assertTrue(buildFactory().isBreakIndentInheritanceOnReferenceAreaBoundary());
  91. }
  92. @Test
  93. public void testDefaultPageSettings() {
  94. float height = 12.345f;
  95. float width = 67.89f;
  96. builder.setDefaultPageSettings(height, width);
  97. FopFactory factory = buildFactory();
  98. assertEquals("12.345", factory.getPageHeight());
  99. assertEquals("67.89", factory.getPageWidth());
  100. }
  101. @Test
  102. public void testPreferRenderer() {
  103. builder.setPreferRenderer(true);
  104. assertTrue(buildFactory().getRendererFactory().isRendererPreferred());
  105. }
  106. }