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
18package validation.jdk8037819;
19
20import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;
21import com.sun.org.apache.xerces.internal.xs.ItemPSVI;
22import org.testng.annotations.AfterClass;
23import org.testng.annotations.BeforeClass;
24import org.testng.annotations.Test;
25import validation.BaseTest;
26
27public class IgnoreXSITypeTest_A_A extends BaseTest {
28
29    protected String getXMLDocument() {
30        return "xsitype_A_A.xml";
31    }
32
33    protected String getSchemaFile() {
34        return "base.xsd";
35    }
36
37    public IgnoreXSITypeTest_A_A(String name) {
38        super(name);
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        checkResult();
131    }
132
133    private void checkFalseResult() {
134        checkResult();
135    }
136
137    private void checkResult() {
138        assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
139        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
140                .getValidationAttempted());
141        assertElementName("A", fRootNode.getElementDeclaration().getName());
142        assertTypeName("Y", fRootNode.getTypeDefinition().getName());
143        assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
144
145        PSVIElementNSImpl child = super.getChild(1);
146        assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
147        assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
148                .getValidationAttempted());
149        assertElementName("A", child.getElementDeclaration().getName());
150        assertTypeName("Y", child.getTypeDefinition().getName());
151        assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
152    }
153}
154