1 /* 2 * Copyright (c) 2003, 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.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 /** 67 * XPathFactory.newInstance(String uri) throws XPFCE if uri is just a blank 68 * string. 69 * 70 * @throws XPathFactoryConfigurationException If the specified object model 71 * is unavailable, or if there is a configuration error. 72 */ 73 @Test(expectedExceptions = XPathFactoryConfigurationException.class) 74 public void testCheckXPathFactory03() throws XPathFactoryConfigurationException { 75 XPathFactory.newInstance(" "); 76 } 77 78 /** 79 * Test for constructor - XPathFactory.newInstance(String uri) with valid 80 * url - "http://java.sun.com/jaxp/xpath/dom". 81 * 82 * @throws XPathFactoryConfigurationException If the specified object model 83 * is unavailable, or if there is a configuration error. 84 */ 85 @Test 86 public void testCheckXPathFactory04() throws XPathFactoryConfigurationException { 87 assertNotNull(XPathFactory.newInstance(VALID_URL)); 88 } 89 90 /** 91 * Test for constructor - XPathFactory.newInstance(String uri) with invalid 92 * url - "http://java.sun.com/jaxp/xpath/dom1". 93 * 94 * @throws XPathFactoryConfigurationException If the specified object model 95 * is unavailable, or if there is a configuration error. 96 */ 97 @Test(expectedExceptions = XPathFactoryConfigurationException.class) 98 public void testCheckXPathFactory05() throws XPathFactoryConfigurationException { 99 XPathFactory.newInstance(INVALID_URL); 100 } 101 102 /** 103 * Test for constructor - XPathFactory.newInstance() and creating XPath with 104 * newXPath(). 105 */ 106 @Test 107 public void testCheckXPathFactory06() { 108 assertNotNull(XPathFactory.newInstance().newXPath()); 109 } 110 111 /** 112 * Test for constructor - XPathFactory.newInstance(String uri) with valid 113 * url - "http://java.sun.com/jaxp/xpath/dom" and creating XPath with 114 * newXPath(). 115 * 116 * @throws XPathFactoryConfigurationException If the specified object model 117 * is unavailable, or if there is a configuration error. 118 */ 119 @Test 120 public void testCheckXPathFactory07() throws XPathFactoryConfigurationException { 121 assertNotNull(XPathFactory.newInstance(VALID_URL).newXPath()); 122 } 123 124 /** 125 * Test for constructor - XPathFactory.newInstance(String uri) with valid 126 * uri - DOM_OBJECT_MODEL.toString(). 127 * 128 * @throws XPathFactoryConfigurationException If the specified object model 129 * is unavailable, or if there is a configuration error. 130 */ 131 @Test 132 public void testCheckXPathFactory08() throws XPathFactoryConfigurationException { 133 assertNotNull(XPathFactory.newInstance(DOM_OBJECT_MODEL)); 134 } 135 }