1 /* |
|
2 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 * contributor license agreements. See the NOTICE file distributed with |
|
4 * this work for additional information regarding copyright ownership. |
|
5 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 * (the "License"); you may not use this file except in compliance with |
|
7 * the License. You may obtain a copy of the License at |
|
8 * |
|
9 * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 * |
|
11 * Unless required by applicable law or agreed to in writing, software |
|
12 * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 * See the License for the specific language governing permissions and |
|
15 * limitations under the License. |
|
16 */ |
|
17 |
|
18 import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl; |
|
19 import com.sun.org.apache.xerces.internal.xs.ItemPSVI; |
|
20 import org.testng.annotations.AfterClass; |
|
21 import org.testng.annotations.BeforeClass; |
|
22 import org.testng.annotations.Test; |
|
23 |
|
24 public class IgnoreXSITypeTest_C_CA extends BaseTest { |
|
25 |
|
26 protected String getXMLDocument() { |
|
27 return "xsitype_C_CA.xml"; |
|
28 } |
|
29 |
|
30 protected String getSchemaFile() { |
|
31 return "base.xsd"; |
|
32 } |
|
33 |
|
34 public IgnoreXSITypeTest_C_CA(String name) { |
|
35 super(name); |
|
36 } |
|
37 |
|
38 @BeforeClass |
|
39 protected void setUp() throws Exception { |
|
40 super.setUp(); |
|
41 } |
|
42 |
|
43 @AfterClass |
|
44 protected void tearDown() throws Exception { |
|
45 super.tearDown(); |
|
46 } |
|
47 |
|
48 @Test |
|
49 public void testDefaultDocument() { |
|
50 try { |
|
51 reset(); |
|
52 validateDocument(); |
|
53 } catch (Exception e) { |
|
54 fail("Validation failed: " + e.getMessage()); |
|
55 } |
|
56 |
|
57 // default value of the feature is false |
|
58 checkFalseResult(); |
|
59 } |
|
60 |
|
61 @Test |
|
62 public void testDefaultFragment() { |
|
63 try { |
|
64 reset(); |
|
65 validateFragment(); |
|
66 } catch (Exception e) { |
|
67 fail("Validation failed: " + e.getMessage()); |
|
68 } |
|
69 |
|
70 // default value of the feature is false |
|
71 checkFalseResult(); |
|
72 } |
|
73 |
|
74 @Test |
|
75 public void testSetFalseDocument() { |
|
76 try { |
|
77 reset(); |
|
78 fValidator.setFeature(IGNORE_XSI_TYPE, false); |
|
79 validateDocument(); |
|
80 } catch (Exception e) { |
|
81 fail("Validation failed: " + e.getMessage()); |
|
82 } |
|
83 |
|
84 checkFalseResult(); |
|
85 } |
|
86 |
|
87 @Test |
|
88 public void testSetFalseFragment() { |
|
89 try { |
|
90 reset(); |
|
91 fValidator.setFeature(IGNORE_XSI_TYPE, false); |
|
92 validateFragment(); |
|
93 } catch (Exception e) { |
|
94 fail("Validation failed: " + e.getMessage()); |
|
95 } |
|
96 |
|
97 checkFalseResult(); |
|
98 } |
|
99 |
|
100 @Test |
|
101 public void testSetTrueDocument() { |
|
102 try { |
|
103 reset(); |
|
104 fValidator.setFeature(IGNORE_XSI_TYPE, true); |
|
105 validateDocument(); |
|
106 } catch (Exception e) { |
|
107 fail("Validation failed: " + e.getMessage()); |
|
108 } |
|
109 |
|
110 checkTrueResult(); |
|
111 } |
|
112 |
|
113 @Test |
|
114 public void testSetTrueFragment() { |
|
115 try { |
|
116 reset(); |
|
117 fValidator.setFeature(IGNORE_XSI_TYPE, true); |
|
118 validateFragment(); |
|
119 } catch (Exception e) { |
|
120 fail("Validation failed: " + e.getMessage()); |
|
121 } |
|
122 |
|
123 checkTrueResult(); |
|
124 } |
|
125 |
|
126 private void checkTrueResult() { |
|
127 assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity()); |
|
128 assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode |
|
129 .getValidationAttempted()); |
|
130 assertElementNull(fRootNode.getElementDeclaration()); |
|
131 assertAnyType(fRootNode.getTypeDefinition()); |
|
132 |
|
133 PSVIElementNSImpl child = super.getChild(1); |
|
134 assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, child.getValidity()); |
|
135 assertValidationAttempted(ItemPSVI.VALIDATION_NONE, child |
|
136 .getValidationAttempted()); |
|
137 assertElementNull(child.getElementDeclaration()); |
|
138 assertAnyType(child.getTypeDefinition()); |
|
139 |
|
140 child = super.getChild(2); |
|
141 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
142 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
143 .getValidationAttempted()); |
|
144 assertElementName("A", child.getElementDeclaration().getName()); |
|
145 assertTypeName("Y", child.getTypeDefinition().getName()); |
|
146 assertTypeNamespaceNull(child.getTypeDefinition().getNamespace()); |
|
147 } |
|
148 |
|
149 private void checkFalseResult() { |
|
150 assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity()); |
|
151 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode |
|
152 .getValidationAttempted()); |
|
153 assertElementNull(fRootNode.getElementDeclaration()); |
|
154 assertTypeName("Y", fRootNode.getTypeDefinition().getName()); |
|
155 assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace()); |
|
156 |
|
157 PSVIElementNSImpl child = super.getChild(1); |
|
158 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
159 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
160 .getValidationAttempted()); |
|
161 assertElementNull(child.getElementDeclaration()); |
|
162 assertTypeName("Y", child.getTypeDefinition().getName()); |
|
163 assertTypeNamespaceNull(child.getTypeDefinition().getNamespace()); |
|
164 |
|
165 child = super.getChild(2); |
|
166 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
167 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
168 .getValidationAttempted()); |
|
169 assertElementName("A", child.getElementDeclaration().getName()); |
|
170 assertTypeName("Y", child.getTypeDefinition().getName()); |
|
171 assertTypeNamespaceNull(child.getTypeDefinition().getNamespace()); |
|
172 } |
|
173 } |
|