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 package javax.xml.transform.ptests; 24 25 import java.io.*; 26 import java.io.FileOutputStream; 27 import javax.xml.parsers.*; 28 import javax.xml.transform.*; 29 import javax.xml.transform.dom.*; 30 import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; 31 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 32 import javax.xml.transform.stream.*; 33 import jaxp.library.JAXPFileBaseTest; 34 import static jaxp.library.JAXPTestUtilities.USER_DIR; 35 import static jaxp.library.JAXPTestUtilities.compareWithGold; 36 import static org.testng.Assert.assertTrue; 37 import org.testng.annotations.Test; 38 import org.w3c.dom.*; 39 40 /** 41 * Class containing the test cases for TransformerFactory API's 42 * getAssociatedStyleSheet method. 43 */ 44 public class TransformerFactoryTest extends JAXPFileBaseTest { 45 /** 46 * This test case checks for the getAssociatedStylesheet method 47 * of TransformerFactory. 48 * The style sheet returned is then copied to an tfactory01.out 49 * It will then be verified to see if it matches the golden files. 50 * 51 * @throws Exception If any errors occur. 52 */ 53 @Test 54 public void tfactory01() throws Exception { 55 String outputFile = USER_DIR + "tfactory01.out"; 56 String goldFile = GOLDEN_DIR + "tfactory01GF.out"; 57 String xmlFile = XML_DIR + "TransformerFactoryTest.xml"; 58 String xmlURI = "file:///" + XML_DIR; 59 60 try (FileInputStream fis = new FileInputStream(xmlFile); 61 FileOutputStream fos = new FileOutputStream(outputFile);) { 62 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 63 64 DocumentBuilder db = dbf.newDocumentBuilder(); | 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 package javax.xml.transform.ptests; 24 25 import java.io.*; 26 27 import javax.xml.parsers.*; 28 import javax.xml.transform.*; 29 import javax.xml.transform.dom.*; 30 31 import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR; 32 import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR; 33 34 import javax.xml.transform.stream.*; 35 36 import jaxp.library.JAXPFileBaseTest; 37 import static jaxp.library.JAXPTestUtilities.USER_DIR; 38 import static jaxp.library.JAXPTestUtilities.compareWithGold; 39 import static org.testng.Assert.assertNotNull; 40 import static org.testng.Assert.assertTrue; 41 42 import org.testng.annotations.DataProvider; 43 import org.testng.annotations.Test; 44 import org.w3c.dom.*; 45 46 /** 47 * Class containing the test cases for TransformerFactory API's 48 * getAssociatedStyleSheet method and TransformerFactory.newInstance(factoryClassName , classLoader). 49 */ 50 public class TransformerFactoryTest extends JAXPFileBaseTest { 51 private static final String TRANSFORMER_FACTORY_CLASSNAME = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"; 52 53 @DataProvider(name = "parameters") 54 public Object[][] getValidateParameters() { 55 return new Object[][] { { TRANSFORMER_FACTORY_CLASSNAME, null }, { TRANSFORMER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } }; 56 } 57 58 /* 59 * test for TransformerFactory.newInstance(java.lang.String 60 * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName 61 * points to correct implementation of 62 * javax.xml.transform.TransformerFactory , should return newInstance of 63 * TransformerFactory 64 */ 65 @Test(dataProvider = "parameters") 66 public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws TransformerConfigurationException { 67 TransformerFactory tf = TransformerFactory.newInstance(factoryClassName, classLoader); 68 Transformer transformer = tf.newTransformer(); 69 assertNotNull(transformer); 70 } 71 72 @DataProvider(name = "invalid-parameters") 73 public Object[][] getInvalidateParameters() { 74 return new Object[][] { { null, null }, { null, this.getClass().getClassLoader() } }; 75 } 76 77 /* 78 * test for TransformerFactory.newInstance(java.lang.String 79 * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is 80 * null , should throw TransformerFactoryConfigurationError 81 */ 82 @Test(expectedExceptions = TransformerFactoryConfigurationError.class, dataProvider = "invalid-parameters") 83 public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) { 84 TransformerFactory.newInstance(factoryClassName, classLoader); 85 } 86 87 /** 88 * This test case checks for the getAssociatedStylesheet method 89 * of TransformerFactory. 90 * The style sheet returned is then copied to an tfactory01.out 91 * It will then be verified to see if it matches the golden files. 92 * 93 * @throws Exception If any errors occur. 94 */ 95 @Test 96 public void tfactory01() throws Exception { 97 String outputFile = USER_DIR + "tfactory01.out"; 98 String goldFile = GOLDEN_DIR + "tfactory01GF.out"; 99 String xmlFile = XML_DIR + "TransformerFactoryTest.xml"; 100 String xmlURI = "file:///" + XML_DIR; 101 102 try (FileInputStream fis = new FileInputStream(xmlFile); 103 FileOutputStream fos = new FileOutputStream(outputFile);) { 104 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 105 106 DocumentBuilder db = dbf.newDocumentBuilder(); |