8352cb0d0d7a2a8a0f98685fd269a8b043d49468
[utils] / support / test / org / wamblee / xml / XslTransformerTest.java
1 /*
2  * Copyright 2005 the original author or authors.
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
17 package org.wamblee.xml;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.File;
21
22 import javax.xml.parsers.DocumentBuilder;
23 import javax.xml.parsers.DocumentBuilderFactory;
24 import javax.xml.transform.Result;
25 import javax.xml.transform.Source;
26 import javax.xml.transform.stream.StreamResult;
27 import javax.xml.transform.stream.StreamSource;
28
29 import junit.framework.TestCase;
30
31 import org.w3c.dom.Document;
32 import org.wamblee.io.FileSystemUtils;
33 import org.wamblee.io.InputResource;
34 import org.wamblee.io.TestResource;
35
36 /**
37  * Tests the XSL transformer.
38  */
39 public class XslTransformerTest extends TestCase {
40     
41     private static final String REPORT_XML = "report.xml";
42     private static final String REPORT_TO_HTML_XSLT = "reportToHtml.xsl";
43
44     /**
45      * Transforms a file while using the default resolver, 
46      * where the included file can be found. 
47      * Verifies the transformation is done correctly.
48      *
49      */
50     public void testTransformUsingDefaultResolver() throws Exception {
51         XslTransformer transformer = new XslTransformer();
52         
53         InputResource xmlResource = new TestResource(XslTransformerTest.class, REPORT_XML);
54         Source xslt = new StreamSource(new File( FileSystemUtils.getTestInputDir(XslTransformerTest.class), REPORT_TO_HTML_XSLT));
55         
56         byte[] documentData = FileSystemUtils.read(xmlResource.getInputStream()).getBytes();
57         DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 
58         Document document = builder.parse(xmlResource.getInputStream());
59         Source documentSource = new StreamSource(xmlResource.getInputStream());
60         
61         Document output1 = transformer.transform(documentData, xslt); 
62         Document output2 = transformer.transform(document, xslt);
63         ByteArrayOutputStream os = new ByteArrayOutputStream(); 
64         Result output = new StreamResult(os);
65         transformer.transform(documentSource, output, xslt);
66         transformer.textTransform(documentData, xslt);
67     }
68     
69     /**
70      * Transforms a file using the default resolver where the
71      * included file cannot be found. 
72      * Verifies that a TransformerException is thrown. 
73      *
74      */
75     public void testTransformUsingDefaultResolverFails() { 
76         fail(); 
77     }
78     
79     /**
80      * Transforms a file using an invalid Xslt. 
81      * Verifies that a TransformerException is thrown. 
82      *
83      */
84     public void testTransformInvalidXslt() { 
85         fail(); 
86     }
87     
88     /**
89      * Transforms a file using a non-well formed xslt. 
90      * Verifies that a TransformerException is thrown. 
91      *
92      */
93     public void testTransformNonWellformedXslt() { 
94         fail();
95     }
96    
97     /**
98      * Transforms a file using a class path resolver. 
99      *
100      */
101     public void testTransformUsingClassPathResolver() { 
102         fail();    
103     }
104
105     /**
106      * Transforms a file to text output. 
107      * Verifies the file is transformed correctly. 
108      *
109      */
110     public void testTransformToTextOutput() { 
111         fail();
112     }
113 }