author | joehw |
Mon, 13 Oct 2014 14:11:20 -0700 | |
changeset 27037 | 5a6ef51923c4 |
permissions | -rw-r--r-- |
27037
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
1 |
/* |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
2 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
3 |
* contributor license agreements. See the NOTICE file distributed with |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
4 |
* this work for additional information regarding copyright ownership. |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
5 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
6 |
* (the "License"); you may not use this file except in compliance with |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
7 |
* the License. You may obtain a copy of the License at |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
8 |
* |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
10 |
* |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
11 |
* Unless required by applicable law or agreed to in writing, software |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
14 |
* See the License for the specific language governing permissions and |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
15 |
* limitations under the License. |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
16 |
*/ |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
17 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
18 |
package validation.jdk8036951; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
19 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
20 |
import java.io.File; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
21 |
import java.io.FileNotFoundException; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
22 |
import java.net.URL; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
23 |
import javax.xml.XMLConstants; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
24 |
import javax.xml.transform.Source; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
25 |
import javax.xml.transform.stream.StreamSource; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
26 |
import javax.xml.validation.Schema; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
27 |
import javax.xml.validation.SchemaFactory; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
28 |
import javax.xml.validation.Validator; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
29 |
import org.testng.annotations.AfterClass; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
30 |
import org.testng.annotations.BeforeClass; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
31 |
import org.testng.annotations.Test; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
32 |
import org.xml.sax.SAXException; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
33 |
import org.xml.sax.SAXNotRecognizedException; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
34 |
import org.xml.sax.SAXNotSupportedException; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
35 |
import validation.BaseTest; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
36 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
37 |
/** |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
38 |
* @author Peter McCracken, IBM |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
39 |
* @version $Id$ |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
40 |
*/ |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
41 |
public class FeaturePropagationTest extends BaseTest { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
42 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
43 |
public final String FEATURE_STRING_DEFAULT_FALSE = "http://apache.org/xml/features/honour-all-schemaLocations"; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
44 |
public final String FEATURE_STRING_DEFAULT_TRUE = "http://apache.org/xml/features/validation/schema-full-checking"; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
45 |
public final String SECURITY_MANAGER = "http://apache.org/xml/properties/security-manager"; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
46 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
47 |
public FeaturePropagationTest(String name) { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
48 |
super(name); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
49 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
50 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
51 |
@BeforeClass |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
52 |
protected void setUp() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
53 |
super.setUp(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
54 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
55 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
56 |
@AfterClass |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
57 |
protected void tearDown() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
58 |
super.tearDown(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
59 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
60 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
61 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
62 |
public void testPropertyReset() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
63 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
64 |
Schema schema = makeSchema(factory, null); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
65 |
Validator validator = schema.newValidator(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
66 |
Object beforeReset = validator.getProperty(SECURITY_MANAGER); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
67 |
validator.setProperty(SECURITY_MANAGER, null); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
68 |
Object changed = validator.getProperty(SECURITY_MANAGER); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
69 |
//for JDK, this is changed since by default the security manager is set |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
70 |
assertTrue("Property value should have changed after calling setProperty().", beforeReset != changed); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
71 |
validator.reset(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
72 |
Object afterReset = validator.getProperty(SECURITY_MANAGER); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
73 |
assertTrue("Property value should be the same after calling reset()", beforeReset == afterReset); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
74 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
75 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
76 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
77 |
public void testFeatureReset() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
78 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
79 |
Schema schema = makeSchema(factory, null); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
80 |
Validator validator = schema.newValidator(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
81 |
validator.setFeature(FEATURE_STRING_DEFAULT_TRUE, false); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
82 |
validator.setFeature(FEATURE_STRING_DEFAULT_FALSE, true); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
83 |
validator.reset(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
84 |
boolean value = validator.getFeature(FEATURE_STRING_DEFAULT_TRUE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
85 |
assertTrue("After reset, value of feature on Validator should be true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
86 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_FALSE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
87 |
assertFalse("After reset, value of feature on Validator should be false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
88 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
89 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
90 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
91 |
public void testSecureProcessingFeaturePropagationAndReset() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
92 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
93 |
boolean value; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
94 |
value = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
95 |
//default is true for JDK |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
96 |
//assertFalse("Default value of feature on SchemaFactory should have been false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
97 |
assertTrue("Default value of feature on SchemaFactory should have been false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
98 |
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
99 |
Schema schema = makeSchema(factory, null); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
100 |
Validator validator = schema.newValidator(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
101 |
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
102 |
assertTrue("Value of feature on Validator should have been true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
103 |
validator.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
104 |
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
105 |
assertFalse("Value of feature on Validator should have been false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
106 |
validator.reset(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
107 |
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
108 |
assertTrue("After reset, value of feature on Validator should be true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
109 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
110 |
/* |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
111 |
* Using four basically identical tests to try out the different |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
112 |
* instance classes of Schema. They shouldn't differ, because the relevant |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
113 |
* code is in a common base class. |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
114 |
*/ |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
115 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
116 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
117 |
public void testFeaturePropagationNull() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
118 |
checkFeaturesOnValidator(null); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
119 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
120 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
121 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
122 |
public void testFeaturePropagationEmpty() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
123 |
checkFeaturesOnValidator(new Source[] {}); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
124 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
125 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
126 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
127 |
public void testFeaturePropagationSingle() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
128 |
checkFeaturesOnValidator(new Source[] {makeSource("base.xsd")}); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
129 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
130 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
131 |
@Test |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
132 |
public void testFeaturePropagationMultiple() throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
133 |
checkFeaturesOnValidator(new Source[] {makeSource("base.xsd"), makeSource("idc.xsd")}); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
134 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
135 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
136 |
private void checkFeaturesOnValidator(Source[] sources) throws Exception { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
137 |
try { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
138 |
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
139 |
Schema schema = makeSchema(factory, sources); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
140 |
Validator validator = schema.newValidator(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
141 |
boolean value; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
142 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_TRUE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
143 |
assertTrue("Default value of feature on Validator should have been true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
144 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_FALSE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
145 |
assertFalse("Default value of feature on Validator should have been false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
146 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
147 |
// checking that the value propagates to the validator |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
148 |
factory.setFeature(FEATURE_STRING_DEFAULT_TRUE, false); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
149 |
factory.setFeature(FEATURE_STRING_DEFAULT_FALSE, true); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
150 |
schema = makeSchema(factory, sources); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
151 |
validator = schema.newValidator(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
152 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_TRUE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
153 |
assertFalse("Value of feature on Validator should have been false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
154 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_FALSE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
155 |
assertTrue("Value of feature on Validator should have been true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
156 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
157 |
// checking that the validator contains a copy of the features, not a reference |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
158 |
factory.setFeature(FEATURE_STRING_DEFAULT_TRUE, true); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
159 |
factory.setFeature(FEATURE_STRING_DEFAULT_FALSE, false); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
160 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_TRUE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
161 |
assertFalse("Value of feature on Validator should have stayed false.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
162 |
value = validator.getFeature(FEATURE_STRING_DEFAULT_FALSE); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
163 |
assertTrue("Value of feature on Validator should have stayed true.", value); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
164 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
165 |
catch (SAXNotRecognizedException e) { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
166 |
fail(e.getMessage()); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
167 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
168 |
catch (SAXNotSupportedException e) { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
169 |
fail(e.getMessage()); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
170 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
171 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
172 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
173 |
private Schema makeSchema(SchemaFactory factory, Source[] sources) throws SAXException { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
174 |
if (sources == null) { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
175 |
return factory.newSchema(); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
176 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
177 |
else { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
178 |
return factory.newSchema(sources); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
179 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
180 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
181 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
182 |
private Source makeSource(String xsd) throws FileNotFoundException { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
183 |
return new StreamSource(fSchemaURL.toExternalForm()); |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
184 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
185 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
186 |
@Override |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
187 |
protected String getSchemaFile() { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
188 |
return "base.xsd"; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
189 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
190 |
|
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
191 |
@Override |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
192 |
protected String getXMLDocument() { |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
193 |
//not needed |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
194 |
return null; |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
195 |
} |
5a6ef51923c4
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents:
diff
changeset
|
196 |
} |