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

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