KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > BasicDriverTestCase


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
18 /* $Id: BasicDriverTestCase.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop;
21
22 import java.io.File JavaDoc;
23
24 import javax.xml.transform.Result JavaDoc;
25 import javax.xml.transform.Source JavaDoc;
26 import javax.xml.transform.Transformer JavaDoc;
27 import javax.xml.transform.TransformerFactory JavaDoc;
28 import javax.xml.transform.sax.SAXResult JavaDoc;
29 import javax.xml.transform.stream.StreamSource JavaDoc;
30
31 import org.apache.commons.io.output.ByteArrayOutputStream;
32 import org.apache.fop.apps.FOUserAgent;
33 import org.apache.fop.apps.Fop;
34 import org.apache.fop.apps.FopFactory;
35 import org.apache.fop.apps.MimeConstants;
36 import org.apache.fop.cli.InputHandler;
37
38 /**
39  * Basic runtime test for the old Fop class. It is used to verify that
40  * nothing obvious is broken after compiling.
41  */

42 public class BasicDriverTestCase extends AbstractFOPTestCase {
43
44     private FopFactory fopFactory = FopFactory.newInstance();
45
46     /**
47      * @see junit.framework.TestCase#TestCase(String)
48      */

49     public BasicDriverTestCase(String JavaDoc name) {
50         super(name);
51     }
52
53     /**
54      * Tests Fop with JAXP and OutputStream generating PDF.
55      * @throws Exception if anything fails
56      */

57     public void testFO2PDFWithJAXP() throws Exception JavaDoc {
58         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
59         File JavaDoc foFile = new File JavaDoc(getBaseDir(), "test/xml/bugtests/block.fo");
60         ByteArrayOutputStream baout = new ByteArrayOutputStream();
61         Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout);
62         
63         TransformerFactory JavaDoc factory = TransformerFactory.newInstance();
64         Transformer JavaDoc transformer = factory.newTransformer(); //Identity transf.
65
Source JavaDoc src = new StreamSource JavaDoc(foFile);
66         Result JavaDoc res = new SAXResult JavaDoc(fop.getDefaultHandler());
67         transformer.transform(src, res);
68         
69         assertTrue("Generated PDF has zero length", baout.size() > 0);
70     }
71
72     /**
73      * Tests Fop with JAXP and OutputStream generating PostScript.
74      * @throws Exception if anything fails
75      */

76     public void testFO2PSWithJAXP() throws Exception JavaDoc {
77         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
78         File JavaDoc foFile = new File JavaDoc(getBaseDir(), "test/xml/bugtests/block.fo");
79         ByteArrayOutputStream baout = new ByteArrayOutputStream();
80         Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout);
81         
82         TransformerFactory JavaDoc factory = TransformerFactory.newInstance();
83         Transformer JavaDoc transformer = factory.newTransformer(); //Identity transf.
84
Source JavaDoc src = new StreamSource JavaDoc(foFile);
85         Result JavaDoc res = new SAXResult JavaDoc(fop.getDefaultHandler());
86         transformer.transform(src, res);
87         
88         assertTrue("Generated PostScript has zero length", baout.size() > 0);
89     }
90
91     /**
92      * Tests Fop with JAXP and OutputStream generating RTF.
93      * @throws Exception if anything fails
94      */

95     public void testFO2RTFWithJAXP() throws Exception JavaDoc {
96         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
97         File JavaDoc foFile = new File JavaDoc(getBaseDir(), "test/xml/bugtests/block.fo");
98         ByteArrayOutputStream baout = new ByteArrayOutputStream();
99         Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout);
100         
101         TransformerFactory JavaDoc factory = TransformerFactory.newInstance();
102         Transformer JavaDoc transformer = factory.newTransformer(); //Identity transf.
103
Source JavaDoc src = new StreamSource JavaDoc(foFile);
104         Result JavaDoc res = new SAXResult JavaDoc(fop.getDefaultHandler());
105         transformer.transform(src, res);
106         
107         assertTrue("Generated RTF has zero length", baout.size() > 0);
108     }
109
110     /**
111      * Tests Fop with XsltInputHandler and OutputStream.
112      * @throws Exception if anything fails
113      */

114     public void testFO2PDFWithXSLTInputHandler() throws Exception JavaDoc {
115         FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
116         File JavaDoc xmlFile = new File JavaDoc(getBaseDir(), "test/xml/1.xml");
117         File JavaDoc xsltFile = new File JavaDoc(getBaseDir(), "test/xsl/doc.xsl");
118         ByteArrayOutputStream baout = new ByteArrayOutputStream();
119         
120         InputHandler handler = new InputHandler(xmlFile, xsltFile, null);
121         handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout);
122         
123         assertTrue("Generated PDF has zero length", baout.size() > 0);
124     }
125
126 }
127
Popular Tags