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
24 package xpath;
25
26 import java.io.File;
27
28 import javax.xml.xpath.XPath;
29 import javax.xml.xpath.XPathExpression;
30 import javax.xml.xpath.XPathExpressionException;
31 import javax.xml.xpath.XPathNodes;
32 import javax.xml.xpath.XPathEvaluationResult;
33
34 import static org.testng.Assert.assertEquals;
35 import static org.testng.Assert.assertTrue;
36
37 import org.testng.annotations.Test;
38 import org.w3c.dom.Document;
39 import org.w3c.dom.Node;
40
41 /*
42 * @bug 8054196
43 * @summary Test for the project XPath: support any type. This test covers the new
44 * evaluateExpression methods of XPathExpression.
45 */
46 public class XPathExpAnyTypeTest extends XPathTestBase {
47
48 /*
49 * Check that NPE is thrown when the class type is null.
50 */
51 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
52 public void test02(XPath xpath) throws XPathExpressionException {
53 XPathExpression exp = xpath.compile("1+1");
54 double result = exp.evaluateExpression((Object)null, null);
55 }
56
57 /*
58 * Parameter item can be null when the expression does not depends on the
59 * context.
60 */
61 @Test(dataProvider = "xpath")
62 public void test03(XPath xpath) throws XPathExpressionException {
63 XPathExpression exp = xpath.compile("1+1");
64 int result = exp.evaluateExpression((Object)null, Integer.class);
65 assertTrue(result == 2);
|
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
24 package xpath;
25
26 import java.io.File;
27
28 import javax.xml.xpath.XPath;
29 import javax.xml.xpath.XPathExpression;
30 import javax.xml.xpath.XPathExpressionException;
31 import javax.xml.xpath.XPathNodes;
32 import javax.xml.xpath.XPathEvaluationResult;
33
34 import static org.testng.Assert.assertEquals;
35 import static org.testng.Assert.assertTrue;
36
37 import org.testng.annotations.Listeners;
38 import org.testng.annotations.Test;
39 import org.w3c.dom.Document;
40 import org.w3c.dom.Node;
41
42 /*
43 * @bug 8054196
44 * @summary Test for the project XPath: support any type. This test covers the new
45 * evaluateExpression methods of XPathExpression.
46 */
47 @Listeners({jaxp.library.BasePolicy.class})
48 public class XPathExpAnyTypeTest extends XPathTestBase {
49
50 /*
51 * Check that NPE is thrown when the class type is null.
52 */
53 @Test(dataProvider = "xpath", expectedExceptions = NullPointerException.class)
54 public void test02(XPath xpath) throws XPathExpressionException {
55 XPathExpression exp = xpath.compile("1+1");
56 double result = exp.evaluateExpression((Object)null, null);
57 }
58
59 /*
60 * Parameter item can be null when the expression does not depends on the
61 * context.
62 */
63 @Test(dataProvider = "xpath")
64 public void test03(XPath xpath) throws XPathExpressionException {
65 XPathExpression exp = xpath.compile("1+1");
66 int result = exp.evaluateExpression((Object)null, Integer.class);
67 assertTrue(result == 2);
|