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