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.xml.sax.SAXException; |
|
21 import org.testng.annotations.AfterClass; |
|
22 import org.testng.annotations.BeforeClass; |
|
23 import org.testng.annotations.Test; |
|
24 |
|
25 // duplicate IDs |
|
26 // reference to non-existent ID |
|
27 |
|
28 public class IdIdrefCheckingTest extends BaseTest { |
|
29 public static final String DUPLICATE_ID = "cvc-id.2"; |
|
30 |
|
31 public static final String NO_ID_BINDING = "cvc-id.1"; |
|
32 |
|
33 protected String getXMLDocument() { |
|
34 return "idIdref.xml"; |
|
35 } |
|
36 |
|
37 protected String getSchemaFile() { |
|
38 return "base.xsd"; |
|
39 } |
|
40 |
|
41 protected String[] getRelevantErrorIDs() { |
|
42 return new String[] { DUPLICATE_ID, NO_ID_BINDING }; |
|
43 } |
|
44 |
|
45 public IdIdrefCheckingTest(String name) { |
|
46 super(name); |
|
47 } |
|
48 |
|
49 @BeforeClass |
|
50 protected void setUp() throws Exception { |
|
51 super.setUp(); |
|
52 } |
|
53 |
|
54 @AfterClass |
|
55 protected void tearDown() throws Exception { |
|
56 super.tearDown(); |
|
57 } |
|
58 |
|
59 @Test |
|
60 public void testDefault() { |
|
61 try { |
|
62 reset(); |
|
63 validateDocument(); |
|
64 } catch (Exception e) { |
|
65 fail("Validation failed: " + e.getMessage()); |
|
66 } |
|
67 |
|
68 checkDefault(); |
|
69 } |
|
70 |
|
71 @Test |
|
72 public void testSetFalse() { |
|
73 try { |
|
74 reset(); |
|
75 fValidator.setFeature(ID_IDREF_CHECKING, false); |
|
76 validateDocument(); |
|
77 } catch (Exception e) { |
|
78 fail("Validation failed: " + e.getMessage()); |
|
79 } |
|
80 |
|
81 checkValidResult(); |
|
82 } |
|
83 |
|
84 @Test |
|
85 public void testSetTrue() { |
|
86 try { |
|
87 reset(); |
|
88 fValidator.setFeature(ID_IDREF_CHECKING, true); |
|
89 validateDocument(); |
|
90 } catch (Exception e) { |
|
91 fail("Validation failed: " + e.getMessage()); |
|
92 } |
|
93 |
|
94 checkDefault(); |
|
95 } |
|
96 |
|
97 private void checkDefault() { |
|
98 assertError(DUPLICATE_ID); |
|
99 assertError(NO_ID_BINDING); |
|
100 |
|
101 assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity()); |
|
102 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode |
|
103 .getValidationAttempted()); |
|
104 assertElementName("A", fRootNode.getElementDeclaration().getName()); |
|
105 assertTypeName("X", fRootNode.getTypeDefinition().getName()); |
|
106 |
|
107 PSVIElementNSImpl child = super.getChild(1); |
|
108 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
109 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
110 .getValidationAttempted()); |
|
111 assertElementName("A", child.getElementDeclaration().getName()); |
|
112 assertTypeName("idType", child.getTypeDefinition().getName()); |
|
113 |
|
114 child = super.getChild(2); |
|
115 assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity()); |
|
116 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
117 .getValidationAttempted()); |
|
118 assertElementName("A", child.getElementDeclaration().getName()); |
|
119 assertTypeName("idType", child.getTypeDefinition().getName()); |
|
120 |
|
121 child = super.getChild(3); |
|
122 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
123 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
124 .getValidationAttempted()); |
|
125 assertElementName("A", child.getElementDeclaration().getName()); |
|
126 assertTypeName("idrefType", child.getTypeDefinition().getName()); |
|
127 } |
|
128 |
|
129 private void checkValidResult() { |
|
130 assertNoError(DUPLICATE_ID); |
|
131 assertNoError(NO_ID_BINDING); |
|
132 |
|
133 assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity()); |
|
134 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode |
|
135 .getValidationAttempted()); |
|
136 assertElementName("A", fRootNode.getElementDeclaration().getName()); |
|
137 assertTypeName("X", fRootNode.getTypeDefinition().getName()); |
|
138 |
|
139 PSVIElementNSImpl child = super.getChild(1); |
|
140 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
141 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
142 .getValidationAttempted()); |
|
143 assertElementName("A", child.getElementDeclaration().getName()); |
|
144 assertTypeName("idType", child.getTypeDefinition().getName()); |
|
145 |
|
146 child = super.getChild(2); |
|
147 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
148 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
149 .getValidationAttempted()); |
|
150 assertElementName("A", child.getElementDeclaration().getName()); |
|
151 assertTypeName("idType", child.getTypeDefinition().getName()); |
|
152 |
|
153 child = super.getChild(3); |
|
154 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); |
|
155 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child |
|
156 .getValidationAttempted()); |
|
157 assertElementName("A", child.getElementDeclaration().getName()); |
|
158 assertTypeName("idrefType", child.getTypeDefinition().getName()); |
|
159 } |
|
160 } |
|