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.

EventProcessingTestCase.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.events;
  19. import java.io.FileInputStream;
  20. import java.io.IOException;
  21. import java.io.InputStream;
  22. import javax.xml.transform.Result;
  23. import javax.xml.transform.Source;
  24. import javax.xml.transform.Transformer;
  25. import javax.xml.transform.TransformerException;
  26. import javax.xml.transform.TransformerFactory;
  27. import javax.xml.transform.sax.SAXResult;
  28. import javax.xml.transform.stream.StreamSource;
  29. import org.junit.Test;
  30. import org.xml.sax.SAXException;
  31. import org.apache.commons.io.output.NullOutputStream;
  32. import org.apache.xmlgraphics.util.MimeConstants;
  33. import org.apache.fop.ResourceEventProducer;
  34. import org.apache.fop.apps.FOPException;
  35. import org.apache.fop.apps.FOUserAgent;
  36. import org.apache.fop.apps.Fop;
  37. import org.apache.fop.apps.FopFactory;
  38. import org.apache.fop.area.AreaEventProducer;
  39. import org.apache.fop.fo.FOValidationEventProducer;
  40. import org.apache.fop.fo.flow.table.TableEventProducer;
  41. import org.apache.fop.layoutmgr.BlockLevelEventProducer;
  42. import org.apache.fop.layoutmgr.inline.InlineLevelEventProducer;
  43. /**
  44. * Tests that the event notification system runs smoothly.
  45. */
  46. public class EventProcessingTestCase {
  47. private final FopFactory fopFactory = FopFactory.newInstance();
  48. private final TransformerFactory tFactory = TransformerFactory.newInstance();
  49. private static final String BASE_DIR = "test/events/";
  50. public void doTest(InputStream inStream, String fopConf, String expectedEventID)
  51. throws FOPException, TransformerException, IOException, SAXException {
  52. EventChecker eventChecker = new EventChecker(expectedEventID);
  53. if (fopConf != null) {
  54. fopFactory.setUserConfig(fopConf);
  55. }
  56. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  57. userAgent.getEventBroadcaster().addEventListener(eventChecker);
  58. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, new NullOutputStream());
  59. Transformer transformer = tFactory.newTransformer();
  60. Source src = new StreamSource(inStream);
  61. Result res = new SAXResult(fop.getDefaultHandler());
  62. transformer.transform(src, res);
  63. eventChecker.end();
  64. }
  65. public void doTest(String filename, String expectedEventID) throws
  66. FOPException, TransformerException, IOException, SAXException {
  67. doTest(filename, null, expectedEventID);
  68. }
  69. public void doTest(String filename, String fopConf, String expectedEventID) throws
  70. FOPException, TransformerException, IOException, SAXException {
  71. doTest(new FileInputStream(BASE_DIR + filename), fopConf, expectedEventID);
  72. }
  73. @Test
  74. public void testArea() throws TransformerException, IOException, SAXException {
  75. doTest("area.fo",
  76. AreaEventProducer.class.getName() + ".unresolvedIDReferenceOnPage");
  77. }
  78. @Test
  79. public void testResource() throws FOPException, TransformerException, IOException,
  80. SAXException {
  81. doTest("resource.fo",
  82. ResourceEventProducer.class.getName() + ".imageNotFound");
  83. }
  84. @Test
  85. public void testValidation() throws FOPException, TransformerException, IOException,
  86. SAXException {
  87. doTest("validation.fo",
  88. FOValidationEventProducer.class.getName() + ".invalidPropertyValue");
  89. }
  90. @Test
  91. public void testTable() throws FOPException, TransformerException, IOException, SAXException {
  92. doTest("table.fo",
  93. TableEventProducer.class.getName() + ".noTablePaddingWithCollapsingBorderModel");
  94. }
  95. @Test
  96. public void testBlockLevel() throws FOPException, TransformerException, IOException,
  97. SAXException {
  98. doTest("block-level.fo",
  99. BlockLevelEventProducer.class.getName() + ".overconstrainedAdjustEndIndent");
  100. }
  101. @Test
  102. public void testInlineLevel() throws FOPException, TransformerException, IOException,
  103. SAXException {
  104. doTest("inline-level.fo",
  105. InlineLevelEventProducer.class.getName() + ".lineOverflows");
  106. }
  107. }