2 * Copyright 2005-2010 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.xml;
18 import junit.framework.TestCase;
20 import org.w3c.dom.ls.LSInput;
21 import org.w3c.dom.ls.LSResourceResolver;
22 import org.wamblee.io.ClassPathResource;
23 import org.wamblee.io.FileSystemUtils;
25 import java.io.IOException;
27 import javax.xml.transform.Source;
28 import javax.xml.transform.TransformerException;
29 import javax.xml.transform.URIResolver;
30 import javax.xml.transform.stream.StreamSource;
33 * Tests for {@link org.wamblee.xml.ClasspathUriResolver}.
35 * @author Erik Brakkee
37 public class ClasspathUriResolverTest extends TestCase {
38 private static final String EXISTING_RESOURCE = "org/wamblee/xml/reportToHtml.xsl";
39 private static final String NON_EXISTING_RESOURCE = "org/wamblee/xml/reportToHtml-nonexisting.xsl";
40 private ClasspathUriResolver resolver;
45 * @see junit.framework.TestCase#setUp()
48 protected void setUp() throws Exception {
49 resolver = new ClasspathUriResolver();
53 * Resolves an existing file. Verifies the file is resolved correctly.
55 * @throws TransformerException
58 public void testResolveExistingFileURIResolver()
59 throws TransformerException, IOException {
60 Source source = resolver
61 .resolve(EXISTING_RESOURCE, "");
62 assertTrue(source instanceof StreamSource);
64 String resolved = FileSystemUtils.read(((StreamSource) source)
67 ClassPathResource resource = new ClassPathResource(
69 String expected = FileSystemUtils.read(resource.getInputStream());
70 assertEquals(expected, resolved);
74 * Resolves a non-existing file. Verifies that a TransformerException is
78 public void testResolveNonExistingFileURIResolver() {
81 .resolve(NON_EXISTING_RESOURCE, "");
82 } catch (TransformerException e) {
90 * Resolves an existing file. Verifies the file is resolved correctly.
92 * @throws TransformerException
95 public void testResolveExistingFileLSResourceResolver()
96 throws TransformerException, IOException {
97 LSInput source = resolver.resolveResource(null, null, "kees",
98 EXISTING_RESOURCE, null);
99 assertNotNull(source);
101 assertEquals("kees", source.getPublicId());
102 assertEquals(EXISTING_RESOURCE, source.getSystemId());
104 String resolved = FileSystemUtils.read(source.getByteStream());
106 ClassPathResource resource = new ClassPathResource(
108 String expected = FileSystemUtils.read(resource.getInputStream());
109 assertEquals(expected, resolved);
113 * Resolves a non-existing file. Verifies that a TransformerException is
117 public void testResolveNonExistingFileLSResourceResolver() {
118 LSInput input = resolver.resolveResource(null, null, "kees",
119 NON_EXISTING_RESOURCE, null);