Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

BasicDriverTestCase.java 4.4KB

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