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_A_C extends BaseTest { |
|
25 |
|
26 protected String getXMLDocument() { |
|
27 return "xsitype_A_C.xml"; |
|
28 } |
|
29 |
|
30 protected String getSchemaFile() { |
|
31 return "base.xsd"; |
|
32 } |
|
33 |
|
34 public IgnoreXSITypeTest_A_C(String name) { |
|
35 super(name); |
|
36 } |
|
37 |
|
38 |
|
39 @BeforeClass |
|
40 protected void setUp() throws Exception { |
|
41 super.setUp(); |
|
42 } |
|
43 |
|
44 @AfterClass |
|
45 protected void tearDown() throws Exception { |
|
46 super.tearDown(); |
|
47 } |
|
48 |
|
49 @Test |
|
50 public void testDefaultDocument() { |
|
51 try { |
|
52 reset(); |
|
53 validateDocument(); |
|
54 } catch (Exception e) { |
|
55 fail("Validation failed: " + e.getMessage()); |
|
56 } |
|
57 |
|
58 // default value of the feature is false |
|
59 checkFalseResult(); |
|
60 } |
|
61 |
|
62 @Test |
|
63 public void testDefaultFragment() { |
|
64 try { |
|
65 reset(); |
|
66 validateFragment(); |
|
67 } catch (Exception e) { |
|
68 fail("Validation failed: " + e.getMessage()); |
|
69 } |
|
70 |
|
71 // default value of the feature is false |
|
72 checkFalseResult(); |
|
73 } |
|
74 |
|
75 @Test |
|
76 public void testSetFalseDocument() { |
|
77 try { |
|
78 reset(); |
|
79 fValidator.setFeature(IGNORE_XSI_TYPE, false); |
|
80 validateDocument(); |
|
81 } catch (Exception e) { |
|
82 fail("Validation failed: " + e.getMessage()); |
|
83 } |
|
84 |
|
85 checkFalseResult(); |
|
86 } |
|
87 |
|
88 @Test |
|
89 public void testSetFalseFragment() { |
|
90 try { |
|
91 reset(); |
|
92 fValidator.setFeature(IGNORE_XSI_TYPE, false); |
|
93 validateFragment(); |
|
94 } catch (Exception e) { |
|
95 fail("Validation failed: " + e.getMessage()); |
|
96 } |
|
97 |
|
98 checkFalseResult(); |
|
99 } |
|
100 |
|
101 @Test |
|
102 public void testSetTrueDocument() { |
|
103 try { |
|
104 reset(); |
|
105 fValidator.setFeature(IGNORE_XSI_TYPE, true); |
|
106 validateDocument(); |
|
107 } catch (Exception e) { |
|
108 fail("Validation failed: " + e.getMessage()); |
|
109 } |
|
110 |
|
111 checkTrueResult(); |
|
112 } |
|
113 |
|
114 @Test |
|
115 public void testSetTrueFragment() { |
|
116 try { |
|
117 reset(); |
|
118 fValidator.setFeature(IGNORE_XSI_TYPE, true); |
|
119 validateFragment(); |
|
120 } catch (Exception e) { |
|
121 fail("Validation failed: " + e.getMessage()); |
|
122 } |
|
123 |
|
124 checkTrueResult(); |
|
125 } |
|
126 |
|
127 private void checkTrueResult() { |
|
128 checkResult(); |
|
129 } |
|
130 |
|
131 private void checkFalseResult() { |
|
132 checkResult(); |
|
133 } |
|
134 |
|
135 private void checkResult() { |
|
136 assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity()); |
|
137 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode |
|
138 .getValidationAttempted()); |
|
139 assertElementName("A", fRootNode.getElementDeclaration().getName()); |
|
140 assertTypeName("Y", fRootNode.getTypeDefinition().getName()); |
|
141 assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace()); |
|
142 |
|
143 PSVIElementNSImpl child = super.getChild(1); |
|
144 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
145 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
146 .getValidationAttempted()); |
|
147 assertElementNull(child.getElementDeclaration()); |
|
148 assertTypeName("Y", child.getTypeDefinition().getName()); |
|
149 assertTypeNamespaceNull(child.getTypeDefinition().getNamespace()); |
|
150 } |
|
151 } |
|