Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

FontManagerConfiguratorTestCase.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.fonts;
  19. import java.io.File;
  20. import java.io.FileNotFoundException;
  21. import java.io.IOException;
  22. import java.net.URI;
  23. import org.junit.Before;
  24. import org.junit.Test;
  25. import org.xml.sax.SAXException;
  26. import org.apache.fop.apps.FOPException;
  27. import org.apache.fop.apps.FopConfBuilder;
  28. import org.apache.fop.apps.FopConfParser;
  29. import org.apache.fop.apps.FopFactory;
  30. import static org.apache.fop.apps.FopConfParserTestCase.getFopFactory;
  31. import static org.junit.Assert.assertEquals;
  32. /**
  33. * A test case for {@link FontManagerConfigurator}.
  34. */
  35. public class FontManagerConfiguratorTestCase {
  36. private FopConfBuilder builder;
  37. public final URI baseURI = new File("test/config/").getAbsoluteFile().toURI();
  38. @Before
  39. public void setUp() {
  40. builder = new FopConfBuilder();
  41. }
  42. private FontManager setBaseAndGetManager(String fontBase) {
  43. builder.setFontBaseURI(fontBase);
  44. return getManager();
  45. }
  46. private FontManager getManager() {
  47. FopFactory factory = getFopFactory(builder.build(), baseURI);
  48. return factory.getFontManager();
  49. }
  50. @Test(expected = FOPException.class)
  51. public void invalidURI() throws SAXException, IOException {
  52. builder.setFontBaseURI("$$%%**~{}][");
  53. FopConfParser confParser = new FopConfParser(builder.build(), baseURI);
  54. confParser.getFopFactoryBuilder().build();
  55. }
  56. @Test
  57. public void relativeFontBaseURITest() {
  58. String actualBase = "../../resources/fonts/ttf/";
  59. FontManager fontManager = setBaseAndGetManager(actualBase);
  60. URI expectedURI = baseURI.resolve(actualBase);
  61. assertEquals(expectedURI, fontManager.getResourceResolver().getBaseURI());
  62. }
  63. @Test
  64. public void currentRelativeFontBaseTest() {
  65. String actualBase = ".";
  66. FontManager fontManager = setBaseAndGetManager(actualBase);
  67. assertEquals(baseURI, fontManager.getResourceResolver().getBaseURI());
  68. }
  69. /**
  70. * This test is an interesting one; it's basically testing that if a base URI pointing to a
  71. * directory that doesn't exist is used, an error is not thrown. The URI resolver should handle
  72. * any {@link FileNotFoundException}s, not the configuration. We're NOT testing whether a font
  73. * can be resolved here, just that the URI resolver accepts it as its base URI.
  74. */
  75. @Test
  76. public void fontBaseDoesntExist() {
  77. // TODO: Sort this out
  78. String actualBase = "non-existing-dir/";
  79. FontManager fontManager = setBaseAndGetManager(actualBase);
  80. assertEquals(baseURI.resolve("non-existing-dir/"),
  81. fontManager.getResourceResolver().getBaseURI());
  82. }
  83. /**
  84. * Tests that when no <font-base> is given, it falls back to the URI used in <base>.
  85. */
  86. @Test
  87. public void noFontBaseURITest() {
  88. String actualBase = "../../resources/images/";
  89. builder.setBaseURI(actualBase);
  90. FontManager fontManager = getManager();
  91. assertEquals(baseURI.resolve(actualBase),
  92. fontManager.getResourceResolver().getBaseURI());
  93. }
  94. @Test
  95. public void absoluteBaseURI() {
  96. String absoluteBase = "test:///absolute/";
  97. FontManager fontManager = setBaseAndGetManager(absoluteBase);
  98. assertEquals(URI.create(absoluteBase), fontManager.getResourceResolver().getBaseURI());
  99. }
  100. }