1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package transform;
  25 
  26 import java.io.StringReader;
  27 import java.util.Properties;
  28 import javax.xml.transform.Templates;
  29 import javax.xml.transform.TransformerFactory;
  30 import javax.xml.transform.stream.StreamSource;
  31 import org.testng.Assert;
  32 import org.testng.annotations.Test;
  33 
  34 /*
  35  * @test
  36  * @bug 8219705
  37  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  38  * @run testng transform.OutputPropertiesTest
  39  * @summary Verifies the output properties are set correctly
  40  */
  41 public class OutputPropertiesTest {
  42     @Test
  43     public void testOutputProperties() throws Exception {
  44         String xslData = "<?xml version='1.0'?>"
  45                 + "<xsl:stylesheet"
  46                 + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
  47                 + " version='1.0'"
  48                 + ">\n"
  49                 + "   <xsl:output method='html'/>\n"
  50                 + "   <xsl:template match='/'>\n"
  51                 + "     Hello World! \n"
  52                 + "   </xsl:template>\n"
  53                 + "</xsl:stylesheet>";
  54 
  55         System.out.println(xslData);
  56 
  57         Templates templates = TransformerFactory.newInstance()
  58                     .newTemplates(new StreamSource(new StringReader(xslData)));
  59 
  60         Properties properties = templates.getOutputProperties();
  61         String[] prNames = new String[]{"method", "version", "indent", "media-type"};
  62         String[] prValues = new String[]{"html", "4.0", "yes", "text/xhtml"};
  63 
  64         for (int i = 0; i < prNames.length; i++) {
  65             String value = properties.getProperty(prNames[i]);
  66             String msg = "The value of the property '" + prNames[i] + "' should be '"
  67                     + prValues[i] + "' when the method is '" + prValues[0] + "'. \n";
  68             Assert.assertEquals(value, prValues[i], msg);
  69             System.out.println(
  70                     prNames[i] + ": actual: " + value + ", expected: " + prValues[i]);
  71         }
  72     }
  73 }