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

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 static org.junit.Assert.assertTrue;
  20. import java.io.File;
  21. import javax.xml.transform.Result;
  22. import javax.xml.transform.Source;
  23. import javax.xml.transform.Transformer;
  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.ByteArrayOutputStream;
  28. import org.apache.fop.apps.FOUserAgent;
  29. import org.apache.fop.apps.Fop;
  30. import org.apache.fop.apps.FopFactory;
  31. import org.apache.fop.apps.MimeConstants;
  32. import org.apache.fop.cli.InputHandler;
  33. import org.junit.Test;
  34. /**
  35. * Basic runtime test for the old Fop class. It is used to verify that
  36. * nothing obvious is broken after compiling.
  37. */
  38. public class BasicDriverTestCase extends AbstractFOPTest {
  39. private FopFactory fopFactory = FopFactory.newInstance();
  40. /**
  41. * Tests Fop with JAXP and OutputStream generating PDF.
  42. * @throws Exception if anything fails
  43. */
  44. @Test
  45. public void testFO2PDFWithJAXP() throws Exception {
  46. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  47. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  48. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  49. Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout);
  50. TransformerFactory factory = TransformerFactory.newInstance();
  51. Transformer transformer = factory.newTransformer(); //Identity transf.
  52. Source src = new StreamSource(foFile);
  53. Result res = new SAXResult(fop.getDefaultHandler());
  54. transformer.transform(src, res);
  55. assertTrue("Generated PDF has zero length", baout.size() > 0);
  56. }
  57. /**
  58. * Tests Fop with JAXP and OutputStream generating PostScript.
  59. * @throws Exception if anything fails
  60. */
  61. @Test
  62. public void testFO2PSWithJAXP() throws Exception {
  63. FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
  64. File foFile = new File(getBaseDir(), "test/xml/bugtests/block.fo");
  65. ByteArrayOutputStream baout = new ByteArrayOutputStream();
  66. Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout);
  67. TransformerFactory factory = TransformerFactory.newInstance();
  68. Transformer transformer = factory.newTransformer(); //Identity transf.
  69. Source src = new StreamSource(foFile);
  70. Result res = new SAXResult(fop.getDefaultHandler());
  71. transformer.transform(src, res);
  72. assertTrue("Generated PostScript has zero length", baout.size() > 0);
  73. }
  74. /**
  75. * Tests Fop with JAXP and OutputStream generating RTF.
  76. * @throws Exception if anything fails
  77. */
  78. @Test
  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. @Test
  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. }