1 /*
2 * Copyright (c) 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 package xpath;
24
25 import java.io.File;
26
27 import javax.xml.xpath.XPath;
28 import javax.xml.xpath.XPathNodes;
29 import javax.xml.xpath.XPathEvaluationResult;
30 import javax.xml.xpath.XPathExpressionException;
31
32 import static org.testng.Assert.assertEquals;
33 import static org.testng.Assert.assertTrue;
34
35 import org.testng.annotations.Test;
36 import org.w3c.dom.Document;
37 import org.w3c.dom.Node;
38
39 /*
40 * @bug 8054196
41 * @summary Test for the project XPath: support any type. This test covers the new
42 * evaluateExpression methods of XPath, as well as XPathNodes and XPathEvaluationResult.
43 */
44 public class XPathAnyTypeTest extends XPathTestBase {
45 /*
46 Test for resolveFunction(QName functionName,int arity); evaluate throws
47 NPE if functionName is null.
48 */
49
50 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
51 public void testCheckXPathFunctionResolver02(XPath xpath) throws XPathExpressionException {
52 xpath.setXPathFunctionResolver((functionName, arity) -> null);
53 assertEquals(xpath.evaluate(null, "5"), "2");
54 }
55 /*
56 Check that NPE is thrown when expression is null.
57 */
58
59 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
60 public void test01(XPath xpath) throws XPathExpressionException {
61 double result = xpath.evaluateExpression(null, (Object) null, Double.class);
62 }
63
|
1 /*
2 * Copyright (c) 2016, 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 package xpath;
24
25 import java.io.File;
26
27 import javax.xml.xpath.XPath;
28 import javax.xml.xpath.XPathNodes;
29 import javax.xml.xpath.XPathEvaluationResult;
30 import javax.xml.xpath.XPathExpressionException;
31
32 import static org.testng.Assert.assertEquals;
33 import static org.testng.Assert.assertTrue;
34
35 import org.testng.annotations.Listeners;
36 import org.testng.annotations.Test;
37 import org.w3c.dom.Document;
38 import org.w3c.dom.Node;
39
40 /*
41 * @bug 8054196
42 * @summary Test for the project XPath: support any type. This test covers the new
43 * evaluateExpression methods of XPath, as well as XPathNodes and XPathEvaluationResult.
44 */
45 @Listeners({jaxp.library.BasePolicy.class})
46 public class XPathAnyTypeTest extends XPathTestBase {
47 /*
48 Test for resolveFunction(QName functionName,int arity); evaluate throws
49 NPE if functionName is null.
50 */
51
52 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
53 public void testCheckXPathFunctionResolver02(XPath xpath) throws XPathExpressionException {
54 xpath.setXPathFunctionResolver((functionName, arity) -> null);
55 assertEquals(xpath.evaluate(null, "5"), "2");
56 }
57 /*
58 Check that NPE is thrown when expression is null.
59 */
60
61 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
62 public void test01(XPath xpath) throws XPathExpressionException {
63 double result = xpath.evaluateExpression(null, (Object) null, Double.class);
64 }
65
|