1 /* 2 * Copyright (c) 1999, 2016, 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 javax.xml.parsers.ptests; 25 26 import static jaxp.library.JAXPTestUtilities.setSystemProperty; 27 import static jaxp.library.JAXPTestUtilities.clearSystemProperty; 28 29 import javax.xml.parsers.DocumentBuilderFactory; 30 import javax.xml.parsers.FactoryConfigurationError; 31 import javax.xml.parsers.SAXParserFactory; 32 33 import org.testng.annotations.AfterTest; 34 import org.testng.annotations.BeforeTest; 35 import org.testng.annotations.Listeners; 36 import org.testng.annotations.Test; 37 38 /** 39 * Class containing the test cases for SAXParserFactory/DocumentBuilderFactory 40 * newInstance methods. 41 */ 42 /* 43 * @test 44 * @library /javax/xml/jaxp/libs 45 * @run testng/othervm -DrunSecMngr=true javax.xml.parsers.ptests.FactoryConfErrorTest 46 * @run testng/othervm javax.xml.parsers.ptests.FactoryConfErrorTest 47 */ 48 @Listeners({jaxp.library.BasePolicy.class}) 49 public class FactoryConfErrorTest { 50 51 /** 52 * Set properties DocumentBuilderFactory and SAXParserFactory to invalid 53 * value before any test run. 54 */ 55 @BeforeTest 56 public void setup() { 57 setSystemProperty("javax.xml.parsers.DocumentBuilderFactory", "xx"); 58 setSystemProperty("javax.xml.parsers.SAXParserFactory", "xx"); 59 } 60 61 /** 62 * Restore properties DocumentBuilderFactory and SAXParserFactory to default 63 * value after all tests run. 64 */ 65 @AfterTest 66 public void cleanup() { 67 clearSystemProperty("javax.xml.parsers.DocumentBuilderFactory"); 68 clearSystemProperty("javax.xml.parsers.SAXParserFactory"); 69 } 70 71 /** 72 * To test exception thrown if javax.xml.parsers.SAXParserFactory property 73 * is invalid. 74 */ 75 @Test(expectedExceptions = FactoryConfigurationError.class) 76 public void testNewInstance01() { 77 SAXParserFactory.newInstance(); 78 } 79 80 /** 81 * To test exception thrown if javax.xml.parsers.DocumentBuilderFactory is 82 * invalid. 83 */ 84 @Test(expectedExceptions = FactoryConfigurationError.class) 85 public void testNewInstance02() { 86 DocumentBuilderFactory.newInstance(); 87 } 88 } 89 90