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