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_A extends BaseTest { 27 28 protected String getXMLDocument() { 29 return "xsitype_C_A.xml"; 30 } 31 32 protected String getSchemaFile() { 33 return "base.xsd"; 34 } 35 36 public IgnoreXSITypeTest_C_A(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 checkChild(); 137 } 138 139 private void checkFalseResult() { 140 assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity()); 141 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode 142 .getValidationAttempted()); 143 assertElementNull(fRootNode.getElementDeclaration()); 144 assertTypeName("Y", fRootNode.getTypeDefinition().getName()); 145 assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace()); 146 147 checkChild(); 148 } 149 150 private void checkChild() { 151 PSVIElementNSImpl child = super.getChild(1); 152 assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity()); 153 assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child 154 .getValidationAttempted()); 155 assertElementName("A", child.getElementDeclaration().getName()); 156 assertTypeName("Y", child.getTypeDefinition().getName()); 157 assertTypeNamespaceNull(child.getTypeDefinition().getNamespace()); 158 } 159} 160