--- /dev/null 2014-09-08 10:45:56.830930409 -0700 +++ new/test/javax/xml/jaxp/functional/org/apache/qetest/trax/TemplateAPITest.java 2015-01-09 15:41:39.896121957 -0800 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015, 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.FilePermission; +import java.util.Properties; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamSource; +import jaxp.library.JAXPBaseTest; +import static org.apache.qetest.trax.TraxConst.XML_DIR; +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +/** + * Basic API coverage test for the Templates class of TRAX. + */ +public class TemplateAPITest extends JAXPBaseTest{ + /** + * TRAX Templates: cover newTransformer(),getOutputProperties() APIs and + * basic functionality. + * @throws javax.xml.transform.TransformerConfigurationException + */ + @Test + public void test() throws TransformerConfigurationException { + setPermissions(new FilePermission(XML_DIR + "-", "read")); + final String xslFile = XML_DIR + "TransformerAPIParam.xsl"; + final String outputFormatXSL = XML_DIR + "TransformerAPIOutputFormat.xsl"; + + TransformerFactory factory = TransformerFactory.newInstance(); + Templates templates1 = factory.newTemplates(new StreamSource(xslFile)); + + // Cover APIs newTransformer(), getOutputProperties() + Transformer transformer = templates1.newTransformer(); + assertNotNull(transformer); + Properties outputFormat = templates1.getOutputProperties(); + assertNotNull(outputFormat); + + // Check that the local stylesheet.getProperty has default set, cf. + // getOutputProperties javadoc + assertEquals(outputFormat.getProperty(OutputKeys.METHOD), "xml"); + assertNull(outputFormat.get(OutputKeys.METHOD)); + assertEquals(outputFormat.getProperty(OutputKeys.INDENT), "no"); + assertNull(outputFormat.get(OutputKeys.INDENT)); + + Templates templates2 + = factory.newTemplates(new StreamSource(outputFormatXSL)); + Properties outputFormat2 = templates2.getOutputProperties(); + assertNotNull(outputFormat2); + + // Known outputFormat property name/value from outputFormatXSL. + final String OUTPUT_FORMAT_NAME = OutputKeys.CDATA_SECTION_ELEMENTS; + final String OUTPUT_FORMAT_VALUE = "cdataHere "; + + // Test known properties + outputFormat2.getProperty(OUTPUT_FORMAT_NAME); + assertEquals(outputFormat2.getProperty(OUTPUT_FORMAT_NAME), OUTPUT_FORMAT_VALUE); + assertEquals(outputFormat2.getProperty("omit-xml-declaration"), "yes"); + } +}