--- /dev/null 2014-09-08 10:45:56.830930409 -0700 +++ new/test/javax/xml/jaxp/functional/org/apache/qetest/trax/URIResolverTest.java 2014-12-31 11:40:31.932074108 -0800 @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + */ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.qetest.trax; + +import java.io.IOException; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import jaxp.library.JAXPFileBaseTest; +import static jaxp.library.JAXPTestUtilities.compareWithGold; +import static jaxp.library.JAXPTestUtilities.filenameToURL; +import static org.apache.qetest.trax.TraxConst.GOLDEN_DIR; +import static org.apache.qetest.trax.TraxConst.XML_DIR; +import static jaxp.library.JAXPTestUtilities.getNextFile; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import org.testng.annotations.Test; + +/** + * Verify that URIResolvers are called properly. + */ +public class URIResolverTest extends JAXPFileBaseTest { + /** + * Build a style-sheet/do a transform with lots of URIs to resolve. + * Verify that the URIResolver is called properly. + * + * @throws TransformerConfigurationException Thrown in case of {@linkplain + * java.util.ServiceConfigurationError service configuration error} or if + * the implementation is not available or cannot be instantiated. + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read. + */ + @Test + public void testCase1() throws TransformerException, IOException { + setPermissions(new RuntimePermission("accessClassInPackage.com.sun.org.apache.xml.internal.utils"), + new RuntimePermission("accessClassInPackage.com.sun.org.apache.xpath.internal.objects")); + String xslFile = XML_DIR + "URIResolverTest.xsl"; + String xmlFile = XML_DIR + "URIResolverTest.xml"; + String goldFile = GOLDEN_DIR + "URIResolverTest.out"; + + // Validate various URI's to be resolved during stylesheet + // build with the loggingURIResolver + String[] expXslUris = { + "{" + filenameToURL(xslFile) + "}" + "impincl/SystemIdImport.xsl", + "{" + filenameToURL(xslFile) + "}" + "impincl/SystemIdInclude.xsl" + }; + CheckingURIResolver chkURIResolver = new CheckingURIResolver(expXslUris); + TransformerFactory factory = TransformerFactory.newInstance(); + // Set the URIResolver and validate it + factory.setURIResolver(chkURIResolver); + Templates templates = factory.newTemplates(new StreamSource(xslFile)); + Transformer transformer = templates.newTransformer(); + assertEquals(factory.getURIResolver(), chkURIResolver); + + // Validate various URI's to be resolved during transform + // time with the loggingURIResolver + String[] expectedXmlUris = { + "{" + filenameToURL(xslFile) + "}" + "../impincl/SystemIdImport.xsl", + "{" + filenameToURL(xslFile) + "}" + "impincl/SystemIdImport.xsl", + "{" + filenameToURL(xslFile) + "}" + "systemid/impincl/SystemIdImport.xsl", + }; + CheckingURIResolver transfomerResolver = new CheckingURIResolver(expectedXmlUris); + transformer.setURIResolver(transfomerResolver); + String outputFile = getNextFile(this.getClass()); + transformer.transform(new StreamSource(filenameToURL(xmlFile)), + new StreamResult(outputFile)); + assertTrue(compareWithGold(goldFile, outputFile)); + } +}