< prev index next >

test/javax/xml/jaxp/functional/javax/xml/xpath/ptests/XPathFactoryTest.java

Print this page




   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.xpath.ptests;
  25 
  26 import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;


  27 import javax.xml.xpath.XPathFactory;
  28 import javax.xml.xpath.XPathFactoryConfigurationException;

  29 import jaxp.library.JAXPBaseTest;
  30 import static org.testng.AssertJUnit.assertNotNull;


  31 import org.testng.annotations.Test;
  32 
  33 /**
  34  * Class containing the test cases for XPathFactory API.
  35  */
  36 public class XPathFactoryTest extends JAXPBaseTest {
  37     /**
  38      * Valid URL for creating a XPath factory.
  39      */
  40     private static final String VALID_URL = "http://java.sun.com/jaxp/xpath/dom";
  41 
  42     /**
  43      * Invalid URL not able to create a XPath factory.
  44      */
  45     private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
  46 
























































  47     /**
  48      * Test for constructor - XPathFactory.newInstance().
  49      */
  50     @Test
  51     public void testCheckXPathFactory01() {
  52         assertNotNull(XPathFactory.newInstance());
  53     }
  54 
  55     /**
  56      * XPathFactory.newInstance(String uri) throws NPE if uri is null.
  57      *
  58      * @throws XPathFactoryConfigurationException If the specified object model
  59     *          is unavailable, or if there is a configuration error.
  60      */
  61     @Test(expectedExceptions = NullPointerException.class)
  62     public void testCheckXPathFactory02() throws XPathFactoryConfigurationException {
  63         XPathFactory.newInstance(null);
  64     }
  65 
  66     /**




   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.xpath.ptests;
  25 
  26 import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;
  27 
  28 import javax.xml.xpath.XPath;
  29 import javax.xml.xpath.XPathFactory;
  30 import javax.xml.xpath.XPathFactoryConfigurationException;
  31 
  32 import jaxp.library.JAXPBaseTest;
  33 import static org.testng.Assert.assertNotNull;
  34 
  35 import org.testng.annotations.DataProvider;
  36 import org.testng.annotations.Test;
  37 
  38 /**
  39  * Class containing the test cases for XPathFactory API.
  40  */
  41 public class XPathFactoryTest extends JAXPBaseTest {
  42     /**
  43      * Valid URL for creating a XPath factory.
  44      */
  45     private static final String VALID_URL = "http://java.sun.com/jaxp/xpath/dom";
  46 
  47     /**
  48      * Invalid URL not able to create a XPath factory.
  49      */
  50     private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
  51     
  52     private static final String URI = "http://java.sun.com/jaxp/xpath/dom";
  53     private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
  54 
  55     @DataProvider(name = "parameters")
  56     public Object[][] getValidateParameters() {
  57         return new Object[][] { { URI, XPATH_FACTORY_CLASSNAME, null }, { URI, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
  58     }
  59 
  60     /*
  61      * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
  62      * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
  63      * points to correct implementation of javax.xml.xpath.XPathFactory , should
  64      * return newInstance of XPathFactory
  65      */
  66     @Test(dataProvider = "parameters")
  67     public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
  68         XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
  69         XPath xpath = xpf.newXPath();
  70         assertNotNull(xpath);
  71     }
  72 
  73     @DataProvider(name = "invalid-parameters")
  74     public Object[][] getInvalidateParameters() {
  75         return new Object[][] { { URI, null, null }, { URI, null, this.getClass().getClassLoader() } };
  76     }
  77 
  78     /*
  79      * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
  80      * factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
  81      * null , should throw XPathFactoryConfigurationException
  82      */
  83     @Test(expectedExceptions = XPathFactoryConfigurationException.class, dataProvider = "invalid-parameters")
  84     public void testNewInstanceWithNullFactoryClassName(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
  85         XPathFactory.newInstance(uri, factoryClassName, classLoader);
  86     }
  87 
  88     /*
  89      * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
  90      * factoryClassName, java.lang.ClassLoader classLoader) uri is null , should
  91      * throw NPE
  92      */
  93     @Test(expectedExceptions = NullPointerException.class)
  94     public void testNewInstanceWithNullUri() throws XPathFactoryConfigurationException {
  95         XPathFactory.newInstance(null, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
  96     }
  97 
  98     /*
  99      * test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
 100      * factoryClassName, java.lang.ClassLoader classLoader) uri is empty, should
 101      * throw IllegalArgumentException
 102      */
 103     @Test(expectedExceptions = IllegalArgumentException.class)
 104     public void testNewInstanceWithEmptyUri() throws XPathFactoryConfigurationException {
 105         XPathFactory.newInstance("", XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
 106     }
 107 
 108     /**
 109      * Test for constructor - XPathFactory.newInstance().
 110      */
 111     @Test
 112     public void testCheckXPathFactory01() {
 113         assertNotNull(XPathFactory.newInstance());
 114     }
 115 
 116     /**
 117      * XPathFactory.newInstance(String uri) throws NPE if uri is null.
 118      *
 119      * @throws XPathFactoryConfigurationException If the specified object model
 120     *          is unavailable, or if there is a configuration error.
 121      */
 122     @Test(expectedExceptions = NullPointerException.class)
 123     public void testCheckXPathFactory02() throws XPathFactoryConfigurationException {
 124         XPathFactory.newInstance(null);
 125     }
 126 
 127     /**


< prev index next >