< prev index next >

test/javax/xml/jaxp/functional/javax/xml/transform/ptests/TransformerTest.java

Print this page

        

*** 22,32 **** */ package javax.xml.transform.ptests; import java.io.File; import java.io.FileInputStream; ! import java.io.FileNotFoundException; import java.io.IOException; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; --- 22,32 ---- */ package javax.xml.transform.ptests; import java.io.File; import java.io.FileInputStream; ! import java.io.FilePermission; import java.io.IOException; import java.util.Properties; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException;
*** 37,125 **** import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; 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 static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * Basic test cases for Transformer API */ ! public class TransformerTest { /** * 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 ! */ ! @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); } } /** ! * This tests if newTransformer(DOMSource) method returns Transformer ! */ ! @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); - } } /** ! * This tests set/get ErrorListener methods of Transformer ! */ ! @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); --- 37,157 ---- import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamSource; ! 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; import org.xml.sax.SAXException; /** * Basic test cases for Transformer API */ ! public class TransformerTest extends JAXPBaseTest { /** * XSLT file serves every test method. */ private final static String TEST_XSL = XML_DIR + "cities.xsl"; + + /** + * Save system property for restoring. + */ + @BeforeGroups (groups = {"readLocalFiles"}) + public void setFilePermissions() { + setPermissions(new FilePermission(TEST_XSL, "read")); + } + /** ! * Restore the system property. */ ! @AfterGroups (groups = {"readLocalFiles"}) ! public void restoreFilePermissions() { ! setPermissions(); ! } ! ! /** ! * This tests if newTransformer(StreamSource) method returns Transformer. ! * @throws TransformerConfigurationException If for some reason the ! * TransformerHandler can not be created. ! */ ! @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 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 (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 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);
*** 127,148 **** 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); - } } /** ! * This tests getOutputProperties() method of Transformer ! */ ! @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); --- 159,185 ---- 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);
*** 155,190 **** 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); - } } /** ! * This tests getOutputProperty() method of Transformer ! */ ! @Test ! public void transformer06() { ! 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); assertEquals(transformer.getOutputProperty("method"), "xml"); - } catch (ParserConfigurationException | SAXException | IOException - | TransformerConfigurationException | IllegalArgumentException ex){ - failUnexpected(ex); - } } } /** * Simple ErrorListener print out all exception. --- 192,228 ---- 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); Transformer transformer = tfactory.newTransformer(domSource); assertEquals(transformer.getOutputProperty("method"), "xml"); } } /** * Simple ErrorListener print out all exception.
< prev index next >