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