1 /*
2 * Copyright (c) 2002, 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 */
28 import static jaxp.library.JAXPTestUtilities.filenameToURL;
29 import static org.testng.Assert.assertEquals;
30 import static test.astro.AstroConstants.ASTROCAT;
31 import static test.astro.AstroConstants.JAXP_SCHEMA_LANGUAGE;
32 import static test.astro.AstroConstants.JAXP_SCHEMA_SOURCE;
33
34 import java.net.MalformedURLException;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37
38 import javax.xml.namespace.NamespaceContext;
39 import javax.xml.namespace.QName;
40 import javax.xml.parsers.DocumentBuilder;
41 import javax.xml.parsers.DocumentBuilderFactory;
42 import javax.xml.xpath.XPath;
43 import javax.xml.xpath.XPathExpression;
44 import javax.xml.xpath.XPathExpressionException;
45 import javax.xml.xpath.XPathFactory;
46 import javax.xml.xpath.XPathVariableResolver;
47
48 import jaxp.library.JAXPFileBaseTest;
49
50 import org.testng.annotations.BeforeClass;
51 import org.testng.annotations.DataProvider;
52 import org.testng.annotations.Test;
53 import org.w3c.dom.Document;
54 import org.w3c.dom.NodeList;
55 import org.xml.sax.InputSource;
56
57 /*
58 * @summary test XPath API
59 */
60 @Test(singleThreaded = true)
61 public class XPathAPITest extends JAXPFileBaseTest {
62 private static final String STARDB_STAR_3_CONSTELLATION = "//astro:stardb/astro:star[3]/astro:constellation";
63 private static final String STARDB_STAR = "//astro:stardb/astro:star";
64 private Document doc;
65 private XPathFactory xpf;
66 private NamespaceContext nsContext;
67
68 @BeforeClass
69 public void setup() throws Exception {
70 DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
71 df.setNamespaceAware(true);
72 df.setValidating(true);
73 df.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
74 df.setAttribute(JAXP_SCHEMA_SOURCE, "catalog.xsd");
75 DocumentBuilder bldr = df.newDocumentBuilder();
76 doc = bldr.parse(ASTROCAT);
77
78 xpf = XPathFactory.newInstance(DOM_OBJECT_MODEL);
79
80 nsContext = new MyNamespaceContext();
81 }
|
1 /*
2 * Copyright (c) 2002, 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 */
28 import static jaxp.library.JAXPTestUtilities.filenameToURL;
29 import static org.testng.Assert.assertEquals;
30 import static test.astro.AstroConstants.ASTROCAT;
31 import static test.astro.AstroConstants.JAXP_SCHEMA_LANGUAGE;
32 import static test.astro.AstroConstants.JAXP_SCHEMA_SOURCE;
33
34 import java.net.MalformedURLException;
35 import java.util.ArrayList;
36 import java.util.Iterator;
37
38 import javax.xml.namespace.NamespaceContext;
39 import javax.xml.namespace.QName;
40 import javax.xml.parsers.DocumentBuilder;
41 import javax.xml.parsers.DocumentBuilderFactory;
42 import javax.xml.xpath.XPath;
43 import javax.xml.xpath.XPathExpression;
44 import javax.xml.xpath.XPathExpressionException;
45 import javax.xml.xpath.XPathFactory;
46 import javax.xml.xpath.XPathVariableResolver;
47
48 import org.testng.annotations.BeforeClass;
49 import org.testng.annotations.DataProvider;
50 import org.testng.annotations.Listeners;
51 import org.testng.annotations.Test;
52 import org.w3c.dom.Document;
53 import org.w3c.dom.NodeList;
54 import org.xml.sax.InputSource;
55
56 /*
57 * @summary test XPath API
58 */
59 @Test(singleThreaded = true)
60 @Listeners({jaxp.library.FilePolicy.class})
61 public class XPathAPITest {
62 private static final String STARDB_STAR_3_CONSTELLATION = "//astro:stardb/astro:star[3]/astro:constellation";
63 private static final String STARDB_STAR = "//astro:stardb/astro:star";
64 private Document doc;
65 private XPathFactory xpf;
66 private NamespaceContext nsContext;
67
68 @BeforeClass
69 public void setup() throws Exception {
70 DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
71 df.setNamespaceAware(true);
72 df.setValidating(true);
73 df.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
74 df.setAttribute(JAXP_SCHEMA_SOURCE, "catalog.xsd");
75 DocumentBuilder bldr = df.newDocumentBuilder();
76 doc = bldr.parse(ASTROCAT);
77
78 xpf = XPathFactory.newInstance(DOM_OBJECT_MODEL);
79
80 nsContext = new MyNamespaceContext();
81 }
|