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 */
17package validation.jdk8037819;
18
19import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;
20import com.sun.org.apache.xerces.internal.xs.ItemPSVI;
21import org.testng.annotations.AfterClass;
22import org.testng.annotations.BeforeClass;
23import org.testng.annotations.Test;
24import validation.BaseTest;
25
26public class IgnoreXSITypeTest_C_AC extends BaseTest {
27
28    protected String getXMLDocument() {
29        return "xsitype_C_AC.xml";
30    }
31
32    protected String getSchemaFile() {
33        return "base.xsd";
34    }
35
36    public IgnoreXSITypeTest_C_AC(String name) {
37        super(name);
38    }
39
40
41    @BeforeClass
42    protected void setUp() throws Exception {
43        super.setUp();
44    }
45
46    @AfterClass
47    protected void tearDown() throws Exception {
48        super.tearDown();
49    }
50
51    @Test
52    public void testDefaultDocument() {
53        try {
54            reset();
55            validateDocument();
56        } catch (Exception e) {
57            fail("Validation failed: " + e.getMessage());
58        }
59
60        // default value of the feature is false
61        checkFalseResult();
62    }
63
64    @Test
65    public void testDefaultFragment() {
66        try {
67            reset();
68            validateFragment();
69        } catch (Exception e) {
70            fail("Validation failed: " + e.getMessage());
71        }
72
73        // default value of the feature is false
74        checkFalseResult();
75    }
76
77    @Test
78    public void testSetFalseDocument() {
79        try {
80            reset();
81            fValidator.setFeature(IGNORE_XSI_TYPE, false);
82            validateDocument();
83        } catch (Exception e) {
84            fail("Validation failed: " + e.getMessage());
85        }
86
87        checkFalseResult();
88    }
89
90    @Test
91    public void testSetFalseFragment() {
92        try {
93            reset();
94            fValidator.setFeature(IGNORE_XSI_TYPE, false);
95            validateFragment();
96        } catch (Exception e) {
97            fail("Validation failed: " + e.getMessage());
98        }
99
100        checkFalseResult();
101    }
102
103    @Test
104    public void testSetTrueDocument() {
105        try {
106            reset();
107            fValidator.setFeature(IGNORE_XSI_TYPE, true);
108            validateDocument();
109        } catch (Exception e) {
110            fail("Validation failed: " + e.getMessage());
111        }
112
113        checkTrueResult();
114    }
115
116    @Test
117    public void testSetTrueFragment() {
118        try {
119            reset();
120            fValidator.setFeature(IGNORE_XSI_TYPE, true);
121            validateFragment();
122        } catch (Exception e) {
123            fail("Validation failed: " + e.getMessage());
124        }
125
126        checkTrueResult();
127    }
128
129    private void checkTrueResult() {
130        assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
131        assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode
132                .getValidationAttempted());
133        assertElementNull(fRootNode.getElementDeclaration());
134        assertAnyType(fRootNode.getTypeDefinition());
135
136        PSVIElementNSImpl child = super.getChild(1);
137        assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
138        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
139                .getValidationAttempted());
140        assertElementName("A", child.getElementDeclaration().getName());
141        assertTypeName("Y", child.getTypeDefinition().getName());
142        assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
143
144        child = super.getChild(2);
145        assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, child.getValidity());
146        assertValidationAttempted(ItemPSVI.VALIDATION_NONE, child
147                .getValidationAttempted());
148        assertElementNull(child.getElementDeclaration());
149        assertAnyType(child.getTypeDefinition());
150    }
151
152    private void checkFalseResult() {
153        assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
154        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
155                .getValidationAttempted());
156        assertElementNull(fRootNode.getElementDeclaration());
157        assertTypeName("Y", fRootNode.getTypeDefinition().getName());
158        assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
159
160        PSVIElementNSImpl child = super.getChild(1);
161        assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
162        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
163                .getValidationAttempted());
164        assertElementName("A", child.getElementDeclaration().getName());
165        assertTypeName("Y", child.getTypeDefinition().getName());
166        assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
167
168        child = super.getChild(2);
169        assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
170        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
171                .getValidationAttempted());
172        assertElementNull(child.getElementDeclaration());
173        assertTypeName("Y", child.getTypeDefinition().getName());
174        assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
175    }
176}
177