--- old/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest.java 2014-12-31 11:40:14.140046451 -0800 +++ new/test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest.java 2014-12-31 11:40:14.062046329 -0800 @@ -24,7 +24,7 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.FilePermission; import java.io.IOException; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; @@ -39,10 +39,12 @@ import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamSource; -import static jaxp.library.JAXPTestUtilities.failUnexpected; +import jaxp.library.JAXPBaseTest; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import org.w3c.dom.Document; import org.xml.sax.InputSource; @@ -51,138 +53,174 @@ /** * Basic test cases for Transformer API */ -public class TransformerTest { +public class TransformerTest extends JAXPBaseTest { /** * XSLT file serves every test method. */ private final static String TEST_XSL = XML_DIR + "cities.xsl"; - /** - * This tests if newTransformer(StreamSource) method returns Transformer - */ - @Test - public void transformer01() { - try { - TransformerFactory tfactory = TransformerFactory.newInstance(); - StreamSource streamSource = new StreamSource( - new File(TEST_XSL)); - Transformer transformer = tfactory.newTransformer(streamSource); - assertNotNull(transformer); - } catch (TransformerConfigurationException ex){ - failUnexpected(ex); - } - } /** - * This tests if newTransformer(SAXSource) method returns Transformer + * Save system property for restoring. */ - @Test - public void transformer02() { - try { - TransformerFactory tfactory = TransformerFactory.newInstance(); - InputSource is = new InputSource( - new FileInputStream(TEST_XSL)); - SAXSource saxSource = new SAXSource(is); - Transformer transformer = tfactory.newTransformer(saxSource); - assertNotNull(transformer); - } catch (TransformerConfigurationException | FileNotFoundException ex){ - failUnexpected(ex); - } + @BeforeGroups (groups = {"readLocalFiles"}) + public void setFilePermissions() { + setPermissions(new FilePermission(TEST_XSL, "read")); } - + /** - * This tests if newTransformer(DOMSource) method returns Transformer + * Restore the system property. */ - @Test - public void transformer03() { - try { - TransformerFactory tfactory = TransformerFactory.newInstance(); - - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document document = db.parse(new File(TEST_XSL)); - DOMSource domSource = new DOMSource(document); - - Transformer transformer = tfactory.newTransformer(domSource); - assertNotNull(transformer); - } catch (TransformerConfigurationException | IOException - | ParserConfigurationException | SAXException ex){ - failUnexpected(ex); - } + @AfterGroups (groups = {"readLocalFiles"}) + public void restoreFilePermissions() { + setPermissions(); } /** - * This tests set/get ErrorListener methods of Transformer + * This tests if newTransformer(StreamSource) method returns Transformer. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. */ - @Test - public void transformer04() { - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document document = db.parse(new File(TEST_XSL)); - DOMSource domSource = new DOMSource(document); - - Transformer transformer = TransformerFactory.newInstance() - .newTransformer(domSource); - transformer.setErrorListener(new MyErrorListener()); - assertNotNull(transformer.getErrorListener()); - assertTrue(transformer.getErrorListener() instanceof MyErrorListener); - } catch (IOException | IllegalArgumentException | ParserConfigurationException - | TransformerConfigurationException | SAXException ex){ - failUnexpected(ex); - } + @Test (groups = {"readLocalFiles"}) + public void transformer01() throws TransformerConfigurationException { + TransformerFactory tfactory = TransformerFactory.newInstance(); + StreamSource streamSource = new StreamSource( + new File(TEST_XSL)); + Transformer transformer = tfactory.newTransformer(streamSource); + assertNotNull(transformer); } /** - * This tests getOutputProperties() method of Transformer + * This tests if newTransformer(SAXSource) method returns Transformer. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. */ - @Test - public void transformer05() { - try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document document = db.parse(new File(TEST_XSL)); - DOMSource domSource = new DOMSource(document); - - Transformer transformer = TransformerFactory.newInstance(). - newTransformer(domSource); - Properties prop = transformer.getOutputProperties(); - - assertEquals(prop.getProperty("indent"), "yes"); - assertEquals(prop.getProperty("method"), "xml"); - assertEquals(prop.getProperty("encoding"), "UTF-8"); - assertEquals(prop.getProperty("standalone"), "no"); - assertEquals(prop.getProperty("version"), "1.0"); - assertEquals(prop.getProperty("omit-xml-declaration"), "no"); - } catch (ParserConfigurationException | SAXException | IOException - | TransformerConfigurationException ex){ - failUnexpected(ex); + @Test (groups = {"readLocalFiles"}) + public void transformer02() throws IOException, TransformerConfigurationException { + try (FileInputStream fis = new FileInputStream(TEST_XSL)) { + TransformerFactory tfactory = TransformerFactory.newInstance(); + SAXSource saxSource = new SAXSource(new InputSource(fis)); + Transformer transformer = tfactory.newTransformer(saxSource); + assertNotNull(transformer); } } /** - * This tests getOutputProperty() method of Transformer - */ - @Test - public void transformer06() { - try { - TransformerFactory tfactory = TransformerFactory.newInstance(); + * This tests if newTransformer(DOMSource) method returns Transformer. + * + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + */ + @Test (groups = {"readLocalFiles"}) + public void transformer03() throws ParserConfigurationException, SAXException, + IOException, TransformerConfigurationException { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = tfactory.newTransformer(domSource); + assertNotNull(transformer); + } + + /** + * This tests set/get ErrorListener methods of Transformer. + * + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + */ + @Test (groups = {"readLocalFiles"}) + public void transformer04() throws ParserConfigurationException, + SAXException, IOException, TransformerConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(domSource); + transformer.setErrorListener(new MyErrorListener()); + assertNotNull(transformer.getErrorListener()); + assertTrue(transformer.getErrorListener() instanceof MyErrorListener); + } + + /** + * This tests getOutputProperties() method of Transformer. + * + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + */ + @Test (groups = {"readLocalFiles"}) + public void transformer05() throws ParserConfigurationException, + SAXException, IOException, TransformerConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); + + Transformer transformer = TransformerFactory.newInstance(). + newTransformer(domSource); + Properties prop = transformer.getOutputProperties(); + + assertEquals(prop.getProperty("indent"), "yes"); + assertEquals(prop.getProperty("method"), "xml"); + assertEquals(prop.getProperty("encoding"), "UTF-8"); + assertEquals(prop.getProperty("standalone"), "no"); + assertEquals(prop.getProperty("version"), "1.0"); + assertEquals(prop.getProperty("omit-xml-declaration"), "no"); + } + + /** + * This tests getOutputProperty() method of Transformer. + * + * @throws SAXException If any parse errors occur. + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws TransformerConfigurationException If for some reason the + * TransformerHandler can not be created. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. + */ + @Test (groups = {"readLocalFiles"}) + public void transformer06() throws ParserConfigurationException, + SAXException, IOException, TransformerConfigurationException { + TransformerFactory tfactory = TransformerFactory.newInstance(); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(new File(TEST_XSL)); + DOMSource domSource = new DOMSource(document); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - DocumentBuilder db = dbf.newDocumentBuilder(); - Document document = db.parse(new File(TEST_XSL)); - DOMSource domSource = new DOMSource(document); - - Transformer transformer = tfactory.newTransformer(domSource); - assertEquals(transformer.getOutputProperty("method"), "xml"); - } catch (ParserConfigurationException | SAXException | IOException - | TransformerConfigurationException | IllegalArgumentException ex){ - failUnexpected(ex); - } + Transformer transformer = tfactory.newTransformer(domSource); + assertEquals(transformer.getOutputProperty("method"), "xml"); } }