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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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;
  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.TransformerFactory;
  24. import javax.xml.transform.sax.SAXResult;
  25. import javax.xml.transform.stream.StreamSource;
  26. import org.apache.commons.io.output.ByteArrayOutputStream;
  27. import org.apache.fop.apps.FOUserAgent;
  28. import org.apache.fop.apps.Fop;
  29. import org.apache.fop.apps.FopFactory;
  30. import org.apache.fop.apps.MimeConstants;
  31. import org.apache.fop.cli.InputHandler;
  32. /**
  33. * Basic runtime test for the old Fop class. It is used to verify that
  34. * nothing obvious is broken after compiling.
  35. */
  36. public class BasicDriverTestCase extends AbstractFOPTestCase {
  37. private FopFactory fopFactory = FopFactory.newInstance();
  38. /**
  39. * @see junit.framework.TestCase#TestCase(String)
  40. */
  41. public BasicDriverTestCase(String name) {
  42. super(name);
  43. }
  44. /**
  45. * Tests Fop with JAXP and OutputStream generating PDF.
  46. * @throws Exception if anything fails
  47. */
  48. public void testFO2PDFWithJAXP() throws Exception {
  49. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  50. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  51. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  52. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout);
  53. TransformerFactory factory = TransformerFactory.newInstance();
  54. Transformer transformer = factory.newTransformer(); //Identity transf.
  55. Source src = new StreamSource(foFile);
  56. Result res = new SAXResult(fop.getDefaultHandler());
  57. transformer.transform(src, res);
  58. assertTrue("Generated PDF has zero length", baout.size() > 0);
  59. }
  60. /**
  61. * Tests Fop with JAXP and OutputStream generating PostScript.
  62. * @throws Exception if anything fails
  63. */
  64. public void testFO2PSWithJAXP() throws Exception {
  65. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  66. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  67. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  68. Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout);
  69. TransformerFactory factory = TransformerFactory.newInstance();
  70. Transformer transformer = factory.newTransformer(); //Identity transf.
  71. Source src = new StreamSource(foFile);
  72. Result res = new SAXResult(fop.getDefaultHandler());
  73. transformer.transform(src, res);
  74. assertTrue("Generated PostScript has zero length", baout.size() > 0);
  75. }
  76. /**
  77. * Tests Fop with JAXP and OutputStream generating RTF.
  78. * @throws Exception if anything fails
  79. */
  80. public void testFO2RTFWithJAXP() throws Exception {
  81. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  82. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  83. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  84. Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);
  85. TransformerFactory factory = TransformerFactory.newInstance();
  86. Transformer transformer = factory.newTransformer(); //Identity transf.
  87. Source src = new StreamSource(foFile);
  88. Result res = new SAXResult(fop.getDefaultHandler());
  89. transformer.transform(src, res);
  90. assertTrue("Generated RTF has zero length", baout.size() > 0);
  91. }
  92. /**
  93. * Tests Fop with XsltInputHandler and OutputStream.
  94. * @throws Exception if anything fails
  95. */
  96. public void testFO2PDFWithXSLTInputHandler() throws Exception {
  97. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  98. File xmlFile = new File(getBaseDir(), "test/xml/1.xml");
  99. File xsltFile = new File(getBaseDir(), "test/xsl/doc.xsl");
  100. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  101. InputHandler handler = new InputHandler(xmlFile, xsltFile, null);
  102. handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout);
  103. assertTrue("Generated PDF has zero length", baout.size() > 0);
  104. }
  105. }