1 /* |
1 /* |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
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. |
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.xpath.ptests; |
24 package javax.xml.xpath.ptests; |
25 |
25 |
26 import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL; |
26 import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL; |
27 import javax.xml.xpath.XPathFactory; |
27 import javax.xml.xpath.XPathFactory; |
28 import javax.xml.xpath.XPathFactoryConfigurationException; |
28 import javax.xml.xpath.XPathFactoryConfigurationException; |
29 import static jaxp.library.JAXPTestUtilities.failUnexpected; |
29 import jaxp.library.JAXPBaseTest; |
30 import static org.testng.AssertJUnit.assertNotNull; |
30 import static org.testng.AssertJUnit.assertNotNull; |
31 import org.testng.annotations.Test; |
31 import org.testng.annotations.Test; |
32 |
32 |
33 /** |
33 /** |
34 * Class containing the test cases for XPathFactory API. |
34 * Class containing the test cases for XPathFactory API. |
35 */ |
35 */ |
36 public class XPathFactoryTest { |
36 public class XPathFactoryTest extends JAXPBaseTest { |
37 /** |
37 /** |
38 * Valid URL for creating a XPath factory. |
38 * Valid URL for creating a XPath factory. |
39 */ |
39 */ |
40 private static final String VALID_URL = "http://java.sun.com/jaxp/xpath/dom"; |
40 private static final String VALID_URL = "http://java.sun.com/jaxp/xpath/dom"; |
41 |
41 |
52 assertNotNull(XPathFactory.newInstance()); |
52 assertNotNull(XPathFactory.newInstance()); |
53 } |
53 } |
54 |
54 |
55 /** |
55 /** |
56 * XPathFactory.newInstance(String uri) throws NPE if uri is null. |
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. |
57 */ |
60 */ |
58 @Test(expectedExceptions = NullPointerException.class) |
61 @Test(expectedExceptions = NullPointerException.class) |
59 private void testCheckXPathFactory02() { |
62 public void testCheckXPathFactory02() throws XPathFactoryConfigurationException { |
60 try { |
63 XPathFactory.newInstance(null); |
61 XPathFactory.newInstance(null); |
|
62 } catch (XPathFactoryConfigurationException ex) { |
|
63 failUnexpected(ex); |
|
64 } |
|
65 } |
64 } |
66 |
65 |
67 /** |
66 /** |
68 * XPathFactory.newInstance(String uri) throws XPFCE if uri is just a blank |
67 * XPathFactory.newInstance(String uri) throws XPFCE if uri is just a blank |
69 * string. |
68 * string. |
70 * |
69 * |
71 * @throws XPathFactoryConfigurationException |
70 * @throws XPathFactoryConfigurationException If the specified object model |
|
71 * is unavailable, or if there is a configuration error. |
72 */ |
72 */ |
73 @Test(expectedExceptions = XPathFactoryConfigurationException.class) |
73 @Test(expectedExceptions = XPathFactoryConfigurationException.class) |
74 public void testCheckXPathFactory03() throws XPathFactoryConfigurationException { |
74 public void testCheckXPathFactory03() throws XPathFactoryConfigurationException { |
75 XPathFactory.newInstance(" "); |
75 XPathFactory.newInstance(" "); |
76 } |
76 } |
77 |
77 |
78 /** |
78 /** |
79 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
79 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
80 * url - "http://java.sun.com/jaxp/xpath/dom". |
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. |
81 */ |
84 */ |
82 @Test |
85 @Test |
83 public void testCheckXPathFactory04() { |
86 public void testCheckXPathFactory04() throws XPathFactoryConfigurationException { |
84 try { |
87 assertNotNull(XPathFactory.newInstance(VALID_URL)); |
85 assertNotNull(XPathFactory.newInstance(VALID_URL)); |
|
86 } catch (XPathFactoryConfigurationException ex) { |
|
87 failUnexpected(ex); |
|
88 } |
|
89 } |
88 } |
90 |
89 |
91 /** |
90 /** |
92 * Test for constructor - XPathFactory.newInstance(String uri) with invalid |
91 * Test for constructor - XPathFactory.newInstance(String uri) with invalid |
93 * url - "http://java.sun.com/jaxp/xpath/dom1". |
92 * url - "http://java.sun.com/jaxp/xpath/dom1". |
94 * |
93 * |
95 * @throws XPathFactoryConfigurationException |
94 * @throws XPathFactoryConfigurationException If the specified object model |
|
95 * is unavailable, or if there is a configuration error. |
96 */ |
96 */ |
97 @Test(expectedExceptions = XPathFactoryConfigurationException.class) |
97 @Test(expectedExceptions = XPathFactoryConfigurationException.class) |
98 public void testCheckXPathFactory05() throws XPathFactoryConfigurationException { |
98 public void testCheckXPathFactory05() throws XPathFactoryConfigurationException { |
99 XPathFactory.newInstance(INVALID_URL); |
99 XPathFactory.newInstance(INVALID_URL); |
100 } |
100 } |
110 |
110 |
111 /** |
111 /** |
112 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
112 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
113 * url - "http://java.sun.com/jaxp/xpath/dom" and creating XPath with |
113 * url - "http://java.sun.com/jaxp/xpath/dom" and creating XPath with |
114 * newXPath(). |
114 * newXPath(). |
|
115 * |
|
116 * @throws XPathFactoryConfigurationException If the specified object model |
|
117 * is unavailable, or if there is a configuration error. |
115 */ |
118 */ |
116 @Test |
119 @Test |
117 public void testCheckXPathFactory07() { |
120 public void testCheckXPathFactory07() throws XPathFactoryConfigurationException { |
118 try { |
121 assertNotNull(XPathFactory.newInstance(VALID_URL).newXPath()); |
119 assertNotNull(XPathFactory.newInstance(VALID_URL).newXPath()); |
|
120 } catch (XPathFactoryConfigurationException ex) { |
|
121 failUnexpected(ex); |
|
122 } |
|
123 } |
122 } |
124 |
123 |
125 /** |
124 /** |
126 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
125 * Test for constructor - XPathFactory.newInstance(String uri) with valid |
127 * uri - DOM_OBJECT_MODEL.toString(). |
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. |
128 */ |
130 */ |
129 @Test |
131 @Test |
130 public void testCheckXPathFactory08() { |
132 public void testCheckXPathFactory08() throws XPathFactoryConfigurationException { |
131 try { |
133 assertNotNull(XPathFactory.newInstance(DOM_OBJECT_MODEL)); |
132 assertNotNull(XPathFactory.newInstance(DOM_OBJECT_MODEL)); |
|
133 } catch (XPathFactoryConfigurationException ex) { |
|
134 failUnexpected(ex); |
|
135 } |
|
136 } |
134 } |
137 } |
135 } |