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.3KB

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