1 /*
2 * Copyright (c) 1999, 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 org.testng.Assert.assertNotNull;
29 import static org.testng.Assert.assertNull;
30 import static org.testng.Assert.assertSame;
31
32 import java.io.File;
33 import java.io.IOException;
34
35 import javax.xml.parsers.DocumentBuilderFactory;
36 import javax.xml.parsers.ParserConfigurationException;
37 import javax.xml.transform.Result;
38 import javax.xml.transform.Source;
39 import javax.xml.transform.dom.DOMResult;
40 import javax.xml.transform.dom.DOMSource;
41 import javax.xml.transform.sax.SAXResult;
42 import javax.xml.transform.sax.SAXSource;
43 import javax.xml.transform.stream.StreamSource;
44 import javax.xml.validation.Schema;
45 import javax.xml.validation.SchemaFactory;
46 import javax.xml.validation.Validator;
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.xml.sax.ErrorHandler;
55 import org.xml.sax.InputSource;
56 import org.xml.sax.SAXException;
57 import org.xml.sax.SAXNotRecognizedException;
58 import org.xml.sax.SAXNotSupportedException;
59 import org.xml.sax.helpers.DefaultHandler;
60
61 /*
62 * @summary Class containing the test cases for Validator API
63 */
64 public class ValidatorTest extends JAXPFileBaseTest {
65
66 @BeforeClass
67 public void setup() throws SAXException, IOException, ParserConfigurationException {
68 schema = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI).newSchema(new File(XML_DIR + "test.xsd"));
69
70 assertNotNull(schema);
71
72 xmlFileUri = filenameToURL(XML_DIR + "test.xml");
73
74 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
75 dbf.setNamespaceAware(true);
76 xmlDoc = dbf.newDocumentBuilder().parse(xmlFileUri);
77 }
78
79 @Test
80 public void testValidateStreamSource() throws SAXException, IOException {
81 Validator validator = getValidator();
82 validator.setErrorHandler(new MyErrorHandler());
83 validator.validate(getStreamSource());
84 }
|
1 /*
2 * Copyright (c) 1999, 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 org.testng.Assert.assertNotNull;
29 import static org.testng.Assert.assertNull;
30 import static org.testng.Assert.assertSame;
31
32 import java.io.File;
33 import java.io.IOException;
34
35 import javax.xml.parsers.DocumentBuilderFactory;
36 import javax.xml.parsers.ParserConfigurationException;
37 import javax.xml.transform.Result;
38 import javax.xml.transform.Source;
39 import javax.xml.transform.dom.DOMResult;
40 import javax.xml.transform.dom.DOMSource;
41 import javax.xml.transform.sax.SAXResult;
42 import javax.xml.transform.sax.SAXSource;
43 import javax.xml.transform.stream.StreamSource;
44 import javax.xml.validation.Schema;
45 import javax.xml.validation.SchemaFactory;
46 import javax.xml.validation.Validator;
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.xml.sax.ErrorHandler;
54 import org.xml.sax.InputSource;
55 import org.xml.sax.SAXException;
56 import org.xml.sax.SAXNotRecognizedException;
57 import org.xml.sax.SAXNotSupportedException;
58 import org.xml.sax.helpers.DefaultHandler;
59
60 /*
61 * @summary Class containing the test cases for Validator API
62 */
63 @Listeners({jaxp.library.FilePolicy.class})
64 public class ValidatorTest {
65
66 @BeforeClass
67 public void setup() throws SAXException, IOException, ParserConfigurationException {
68 schema = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI).newSchema(new File(XML_DIR + "test.xsd"));
69
70 assertNotNull(schema);
71
72 xmlFileUri = filenameToURL(XML_DIR + "test.xml");
73
74 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
75 dbf.setNamespaceAware(true);
76 xmlDoc = dbf.newDocumentBuilder().parse(xmlFileUri);
77 }
78
79 @Test
80 public void testValidateStreamSource() throws SAXException, IOException {
81 Validator validator = getValidator();
82 validator.setErrorHandler(new MyErrorHandler());
83 validator.validate(getStreamSource());
84 }
|