jaxp/test/javax/xml/jaxp/functional/javax/xml/parsers/ptests/FactoryConfErrorTest.java
changeset 28445 5a87f52ca380
parent 27983 f5f19fe0e83b
child 40223 64662417aa2d
equal deleted inserted replaced
28344:722378bc599e 28445:5a87f52ca380
     1 /*
     1 /*
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    24 package javax.xml.parsers.ptests;
    24 package javax.xml.parsers.ptests;
    25 
    25 
    26 import javax.xml.parsers.DocumentBuilderFactory;
    26 import javax.xml.parsers.DocumentBuilderFactory;
    27 import javax.xml.parsers.FactoryConfigurationError;
    27 import javax.xml.parsers.FactoryConfigurationError;
    28 import javax.xml.parsers.SAXParserFactory;
    28 import javax.xml.parsers.SAXParserFactory;
       
    29 import jaxp.library.JAXPBaseTest;
    29 
    30 
    30 import org.testng.annotations.AfterTest;
    31 import org.testng.annotations.AfterTest;
    31 import org.testng.annotations.BeforeTest;
    32 import org.testng.annotations.BeforeTest;
    32 import org.testng.annotations.Test;
    33 import org.testng.annotations.Test;
    33 
    34 
    34 /**
    35 /**
    35  * Class containing the test cases for SAXParserFactory/DocumentBuilderFactory
    36  * Class containing the test cases for SAXParserFactory/DocumentBuilderFactory
    36  * newInstance methods.
    37  * newInstance methods.
    37  */
    38  */
    38 public class FactoryConfErrorTest {
    39 public class FactoryConfErrorTest extends JAXPBaseTest {
    39 
    40 
    40     /**
    41     /**
    41      * Set properties DocumentBuilderFactory and SAXParserFactory to invalid
    42      * Set properties DocumentBuilderFactory and SAXParserFactory to invalid
    42      * value before any test run.
    43      * value before any test run.
    43      */
    44      */
    44     @BeforeTest
    45     @BeforeTest
    45     public void setup() {
    46     public void setup() {
    46         System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "xx");
    47         setSystemProperty("javax.xml.parsers.DocumentBuilderFactory", "xx");
    47         System.setProperty("javax.xml.parsers.SAXParserFactory", "xx");
    48         setSystemProperty("javax.xml.parsers.SAXParserFactory", "xx");
    48     }
    49     }
    49 
    50 
    50     /**
    51     /**
    51      * Restore properties DocumentBuilderFactory and SAXParserFactory to default
    52      * Restore properties DocumentBuilderFactory and SAXParserFactory to default
    52      * value after all tests run.
    53      * value after all tests run.
    53      */
    54      */
    54     @AfterTest
    55     @AfterTest
    55     public void cleanup() {
    56     public void cleanup() {
    56         System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
    57         setSystemProperty("javax.xml.parsers.DocumentBuilderFactory", null);
    57         System.clearProperty("javax.xml.parsers.SAXParserFactory");
    58         setSystemProperty("javax.xml.parsers.SAXParserFactory", null);
    58     }
    59     }
    59 
    60 
    60     /**
    61     /**
    61      * To test exception thrown if javax.xml.parsers.SAXParserFactory property
    62      * To test exception thrown if javax.xml.parsers.SAXParserFactory property
    62      * is invalid.
    63      * is invalid.
    65     public void testNewInstance01() {
    66     public void testNewInstance01() {
    66         SAXParserFactory.newInstance();
    67         SAXParserFactory.newInstance();
    67     }
    68     }
    68 
    69 
    69     /**
    70     /**
    70      * To test exeception thrown if javax.xml.parsers.DocumentBuilderFactory is
    71      * To test exception thrown if javax.xml.parsers.DocumentBuilderFactory is
    71      * invalid.
    72      * invalid.
    72      */
    73      */
    73     @Test(expectedExceptions = FactoryConfigurationError.class)
    74     @Test(expectedExceptions = FactoryConfigurationError.class)
    74     public void testNewInstance02() {
    75     public void testNewInstance02() {
    75         DocumentBuilderFactory.newInstance();
    76         DocumentBuilderFactory.newInstance();