author | joehw |
Wed, 28 Jan 2015 22:49:58 -0800 | |
changeset 28697 | fae50549d70d |
child 40223 | 64662417aa2d |
permissions | -rw-r--r-- |
28697
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
1 |
/* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
4 |
* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
8 |
* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
13 |
* accompanied this code). |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
14 |
* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
18 |
* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
21 |
* questions. |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
22 |
*/ |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
23 |
package javax.xml.validation.ptests; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
24 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
25 |
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
26 |
import static javax.xml.validation.ptests.ValidationTestConst.XML_DIR; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
27 |
import static jaxp.library.JAXPTestUtilities.filenameToURL; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
28 |
import static org.testng.Assert.assertEquals; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
29 |
import static org.testng.Assert.assertFalse; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
30 |
import static org.testng.Assert.assertTrue; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
31 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
32 |
import java.io.File; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
33 |
import java.io.IOException; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
34 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
35 |
import javax.xml.parsers.ParserConfigurationException; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
36 |
import javax.xml.parsers.SAXParserFactory; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
37 |
import javax.xml.validation.Schema; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
38 |
import javax.xml.validation.SchemaFactory; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
39 |
import javax.xml.validation.TypeInfoProvider; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
40 |
import javax.xml.validation.ValidatorHandler; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
41 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
42 |
import jaxp.library.JAXPFileBaseTest; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
43 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
44 |
import org.testng.annotations.Test; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
45 |
import org.xml.sax.Attributes; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
46 |
import org.xml.sax.InputSource; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
47 |
import org.xml.sax.SAXException; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
48 |
import org.xml.sax.XMLReader; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
49 |
import org.xml.sax.helpers.DefaultHandler; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
50 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
51 |
/* |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
52 |
* @summary test ValidatorHandler.getTypeInfoProvider() |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
53 |
*/ |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
54 |
public class TypeInfoProviderTest extends JAXPFileBaseTest { |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
55 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
56 |
private ValidatorHandler validatorHandler; |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
57 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
58 |
@Test |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
59 |
public void test() throws SAXException, ParserConfigurationException, IOException { |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
60 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
61 |
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
62 |
Schema schema = sf.newSchema(new File(XML_DIR + "shiporder11.xsd")); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
63 |
validatorHandler = schema.newValidatorHandler(); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
64 |
MyDefaultHandler myDefaultHandler = new MyDefaultHandler(); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
65 |
validatorHandler.setContentHandler(myDefaultHandler); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
66 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
67 |
InputSource is = new InputSource(filenameToURL(XML_DIR + "shiporder11.xml")); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
68 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
69 |
SAXParserFactory parserFactory = SAXParserFactory.newInstance(); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
70 |
parserFactory.setNamespaceAware(true); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
71 |
XMLReader xmlReader = parserFactory.newSAXParser().getXMLReader(); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
72 |
xmlReader.setContentHandler(validatorHandler); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
73 |
xmlReader.parse(is); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
74 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
75 |
} |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
76 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
77 |
private class MyDefaultHandler extends DefaultHandler { |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
78 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
79 |
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
80 |
TypeInfoProvider typeInfoProvider = validatorHandler.getTypeInfoProvider(); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
81 |
int index = atts.getIndex("orderid"); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
82 |
if (index != -1) { |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
83 |
System.out.println(" Index " + index); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
84 |
System.out.println(" ElementType " + typeInfoProvider.getElementTypeInfo().getTypeName()); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
85 |
assertEquals(typeInfoProvider.getAttributeTypeInfo(index).getTypeName(), "string"); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
86 |
assertTrue(typeInfoProvider.isSpecified(index)); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
87 |
assertFalse(typeInfoProvider.isIdAttribute(index)); |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
88 |
} |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
89 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
90 |
} |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
91 |
|
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
92 |
} |
fae50549d70d
8051547: Convert JAXP function tests: javax.xml.validation.* to jtreg (testng) tests
joehw
parents:
diff
changeset
|
93 |
} |