--- old/test/jaxp/javax/xml/jaxp/unittest/transform/OutputPropertiesTest.java 2019-07-02 20:52:05.396722909 +0000 +++ new/test/jaxp/javax/xml/jaxp/unittest/transform/OutputPropertiesTest.java 2019-07-02 20:52:05.032714208 +0000 @@ -24,21 +24,79 @@ package transform; import java.io.StringReader; +import java.io.StringWriter; import java.util.Properties; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; import javax.xml.transform.Templates; +import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.testng.Assert; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; /* * @test - * @bug 8219705 + * @bug 8219705 8223291 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest * @run testng transform.OutputPropertiesTest * @summary Verifies the output properties are set correctly */ public class OutputPropertiesTest { + /* + DataProvider: for testing indentation + Data: xml, expected result + */ + @DataProvider(name = "Indentation") + public Object[][] getData() { + String mix = "\n" + + " abc\n" + + " mix\n" + + " xyz\n" + + " "; + return new Object[][]{ + {"abcxyz", "abcdataxyz"}, + {"abcxyz", "abc & xyz"}, + {"", "data"}, + {"abcmixxyz", mix} + }; + } + + + /** + * bug 8223291 + * Verifies that no extra indentation is added for CDATA. + * @param xml the xml content to be tested + * @param expected the expected result + * @throws Exception + */ + @Test(dataProvider = "Indentation") + public void testIndentation(String xml, String expected) throws Exception + { + StreamSource source = new StreamSource(new StringReader("" + xml + "")); + StreamResult result = new StreamResult(new StringWriter()); + + Transformer tform = TransformerFactory.newInstance().newTransformer(); + tform.setOutputProperty(OutputKeys.INDENT, "yes"); + tform.transform(source, result); + + String xml1 = result.getWriter().toString(); + + Document document = DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .parse(new InputSource(new StringReader(xml1))); + + String resultData = document.getElementsByTagName("bar") + .item(0) + .getTextContent(); + + Assert.assertEquals(resultData, expected); + } + @Test public void testOutputProperties() throws Exception { String xslData = "" @@ -63,11 +121,12 @@ for (int i = 0; i < prNames.length; i++) { String value = properties.getProperty(prNames[i]); - String msg = "The value of the property '" + prNames[i] + "' should be '" + String msg = "The value of the property '" + prNames[i] + "' should be '" + prValues[i] + "' when the method is '" + prValues[0] + "'. \n"; Assert.assertEquals(value, prValues[i], msg); System.out.println( prNames[i] + ": actual: " + value + ", expected: " + prValues[i]); } } + }