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.

BasicDriverTestCase.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 1999-2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop;
  18. import java.io.File;
  19. import javax.xml.transform.Result;
  20. import javax.xml.transform.Source;
  21. import javax.xml.transform.Transformer;
  22. import javax.xml.transform.TransformerFactory;
  23. import javax.xml.transform.sax.SAXResult;
  24. import javax.xml.transform.stream.StreamSource;
  25. import org.apache.commons.io.output.ByteArrayOutputStream;
  26. import org.apache.fop.apps.FOUserAgent;
  27. import org.apache.fop.apps.Fop;
  28. import org.apache.fop.apps.FopFactory;
  29. import org.apache.fop.apps.MimeConstants;
  30. import org.apache.fop.cli.InputHandler;
  31. /**
  32. * Basic runtime test for the old Fop class. It is used to verify that
  33. * nothing obvious is broken after compiling.
  34. */
  35. public class BasicDriverTestCase extends AbstractFOPTestCase {
  36. private FopFactory fopFactory = FopFactory.newInstance();
  37. /**
  38. * @see junit.framework.TestCase#TestCase(String)
  39. */
  40. public BasicDriverTestCase(String name) {
  41. super(name);
  42. }
  43. /**
  44. * Tests Fop with JAXP and OutputStream generating PDF.
  45. * @throws Exception if anything fails
  46. */
  47. public void testFO2PDFWithJAXP() throws Exception {
  48. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  49. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  50. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  51. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout);
  52. TransformerFactory factory = TransformerFactory.newInstance();
  53. Transformer transformer = factory.newTransformer(); //Identity transf.
  54. Source src = new StreamSource(foFile);
  55. Result res = new SAXResult(fop.getDefaultHandler());
  56. transformer.transform(src, res);
  57. assertTrue("Generated PDF has zero length", baout.size() > 0);
  58. }
  59. /**
  60. * Tests Fop with JAXP and OutputStream generating PostScript.
  61. * @throws Exception if anything fails
  62. */
  63. public void testFO2PSWithJAXP() throws Exception {
  64. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  65. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  66. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  67. Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout);
  68. TransformerFactory factory = TransformerFactory.newInstance();
  69. Transformer transformer = factory.newTransformer(); //Identity transf.
  70. Source src = new StreamSource(foFile);
  71. Result res = new SAXResult(fop.getDefaultHandler());
  72. transformer.transform(src, res);
  73. assertTrue("Generated PostScript has zero length", baout.size() > 0);
  74. }
  75. /**
  76. * Tests Fop with JAXP and OutputStream generating RTF.
  77. * @throws Exception if anything fails
  78. */
  79. public void testFO2RTFWithJAXP() throws Exception {
  80. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  81. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  82. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  83. Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);
  84. TransformerFactory factory = TransformerFactory.newInstance();
  85. Transformer transformer = factory.newTransformer(); //Identity transf.
  86. Source src = new StreamSource(foFile);
  87. Result res = new SAXResult(fop.getDefaultHandler());
  88. transformer.transform(src, res);
  89. assertTrue("Generated RTF has zero length", baout.size() > 0);
  90. }
  91. /**
  92. * Tests Fop with XsltInputHandler and OutputStream.
  93. * @throws Exception if anything fails
  94. */
  95. public void testFO2PDFWithXSLTInputHandler() throws Exception {
  96. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  97. File xmlFile = new File(getBaseDir(), "test/xml/1.xml");
  98. File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
  99. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  100. InputHandler handler = new InputHandler(xmlFile, xsltFile, null);
  101. handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout);
  102. assertTrue("Generated PDF has zero length", baout.size() > 0);
  103. }
  104. }