(no commit message)
[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         XmlUtils.assertEquals("output", output1, output2);
64         ByteArrayOutputStream os = new ByteArrayOutputStream(); 
65         Result output = new StreamResult(os);
66         transformer.transform(documentSource, output, xslt);
67         transformer.textTransform(documentData, xslt);
68     }
69     
70     /**
71      * Transforms a file using the default resolver where the
72      * included file cannot be found. 
73      * Verifies that a TransformerException is thrown. 
74      *
75      */
76     public void testTransformUsingDefaultResolverFails() { 
77         fail(); 
78     }
79     
80     /**
81      * Transforms a file using an invalid Xslt. 
82      * Verifies that a TransformerException is thrown. 
83      *
84      */
85     public void testTransformInvalidXslt() { 
86         fail(); 
87     }
88     
89     /**
90      * Transforms a file using a non-well formed xslt. 
91      * Verifies that a TransformerException is thrown. 
92      *
93      */
94     public void testTransformNonWellformedXslt() { 
95         fail();
96     }
97    
98     /**
99      * Transforms a file using a class path resolver. 
100      *
101      */
102     public void testTransformUsingClassPathResolver() { 
103         fail();    
104     }
105
106     /**
107      * Transforms a file to text output. 
108      * Verifies the file is transformed correctly. 
109      *
110      */
111     public void testTransformToTextOutput() { 
112         fail();
113     }
114 }