/* * Copyright 2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.wamblee.xml; import java.io.ByteArrayOutputStream; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import junit.framework.TestCase; import org.w3c.dom.Document; import org.wamblee.io.FileSystemUtils; import org.wamblee.io.InputResource; import org.wamblee.io.TestResource; /** * Tests the XSL transformer. */ public class XslTransformerTest extends TestCase { private static final String REPORT_XML = "report.xml"; private static final String REPORT_TO_HTML_XSLT = "reportToHtml.xsl"; /** * Transforms a file while using the default resolver, * where the included file can be found. * Verifies the transformation is done correctly. * */ public void testTransformUsingDefaultResolver() throws Exception { XslTransformer transformer = new XslTransformer(); InputResource xmlResource = new TestResource(XslTransformerTest.class, REPORT_XML); Source xslt = new StreamSource(new File( FileSystemUtils.getTestInputDir(XslTransformerTest.class), REPORT_TO_HTML_XSLT)); byte[] documentData = FileSystemUtils.read(xmlResource.getInputStream()).getBytes(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(xmlResource.getInputStream()); Source documentSource = new StreamSource(xmlResource.getInputStream()); Document output1 = transformer.transform(documentData, xslt); Document output2 = transformer.transform(document, xslt); ByteArrayOutputStream os = new ByteArrayOutputStream(); Result output = new StreamResult(os); transformer.transform(documentSource, output, xslt); transformer.textTransform(documentData, xslt); } /** * Transforms a file using the default resolver where the * included file cannot be found. * Verifies that a TransformerException is thrown. * */ public void testTransformUsingDefaultResolverFails() { fail(); } /** * Transforms a file using an invalid Xslt. * Verifies that a TransformerException is thrown. * */ public void testTransformInvalidXslt() { fail(); } /** * Transforms a file using a non-well formed xslt. * Verifies that a TransformerException is thrown. * */ public void testTransformNonWellformedXslt() { fail(); } /** * Transforms a file using a class path resolver. * */ public void testTransformUsingClassPathResolver() { fail(); } /** * Transforms a file to text output. * Verifies the file is transformed correctly. * */ public void testTransformToTextOutput() { fail(); } }