jdk/test/javax/xml/jaxp/testng/validation/8037819/IgnoreXSITypeTest_C_A.java
changeset 27129 98b357b2e8a6
parent 27128 d1480cb49283
parent 27116 64a78dd93766
child 27130 41df50e7303d
equal deleted inserted replaced
27128:d1480cb49283 27129:98b357b2e8a6
     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.testng.annotations.AfterClass;
       
    21 import org.testng.annotations.BeforeClass;
       
    22 import org.testng.annotations.Test;
       
    23 
       
    24 public class IgnoreXSITypeTest_C_A extends BaseTest {
       
    25 
       
    26     protected String getXMLDocument() {
       
    27         return "xsitype_C_A.xml";
       
    28     }
       
    29 
       
    30     protected String getSchemaFile() {
       
    31         return "base.xsd";
       
    32     }
       
    33 
       
    34     public IgnoreXSITypeTest_C_A(String name) {
       
    35         super(name);
       
    36     }
       
    37 
       
    38 
       
    39     @BeforeClass
       
    40     protected void setUp() throws Exception {
       
    41         super.setUp();
       
    42     }
       
    43 
       
    44     @AfterClass
       
    45     protected void tearDown() throws Exception {
       
    46         super.tearDown();
       
    47     }
       
    48 
       
    49     @Test
       
    50     public void testDefaultDocument() {
       
    51         try {
       
    52             reset();
       
    53             validateDocument();
       
    54         } catch (Exception e) {
       
    55             fail("Validation failed: " + e.getMessage());
       
    56         }
       
    57 
       
    58         // default value of the feature is false
       
    59         checkFalseResult();
       
    60     }
       
    61 
       
    62     @Test
       
    63     public void testDefaultFragment() {
       
    64         try {
       
    65             reset();
       
    66             validateFragment();
       
    67         } catch (Exception e) {
       
    68             fail("Validation failed: " + e.getMessage());
       
    69         }
       
    70 
       
    71         // default value of the feature is false
       
    72         checkFalseResult();
       
    73     }
       
    74 
       
    75     @Test
       
    76     public void testSetFalseDocument() {
       
    77         try {
       
    78             reset();
       
    79             fValidator.setFeature(IGNORE_XSI_TYPE, false);
       
    80             validateDocument();
       
    81         } catch (Exception e) {
       
    82             fail("Validation failed: " + e.getMessage());
       
    83         }
       
    84 
       
    85         checkFalseResult();
       
    86     }
       
    87 
       
    88     @Test
       
    89     public void testSetFalseFragment() {
       
    90         try {
       
    91             reset();
       
    92             fValidator.setFeature(IGNORE_XSI_TYPE, false);
       
    93             validateFragment();
       
    94         } catch (Exception e) {
       
    95             fail("Validation failed: " + e.getMessage());
       
    96         }
       
    97 
       
    98         checkFalseResult();
       
    99     }
       
   100 
       
   101     @Test
       
   102     public void testSetTrueDocument() {
       
   103         try {
       
   104             reset();
       
   105             fValidator.setFeature(IGNORE_XSI_TYPE, true);
       
   106             validateDocument();
       
   107         } catch (Exception e) {
       
   108             fail("Validation failed: " + e.getMessage());
       
   109         }
       
   110 
       
   111         checkTrueResult();
       
   112     }
       
   113 
       
   114     @Test
       
   115     public void testSetTrueFragment() {
       
   116         try {
       
   117             reset();
       
   118             fValidator.setFeature(IGNORE_XSI_TYPE, true);
       
   119             validateFragment();
       
   120         } catch (Exception e) {
       
   121             fail("Validation failed: " + e.getMessage());
       
   122         }
       
   123 
       
   124         checkTrueResult();
       
   125     }
       
   126 
       
   127     private void checkTrueResult() {
       
   128         assertValidity(ItemPSVI.VALIDITY_NOTKNOWN, fRootNode.getValidity());
       
   129         assertValidationAttempted(ItemPSVI.VALIDATION_PARTIAL, fRootNode
       
   130                 .getValidationAttempted());
       
   131         assertElementNull(fRootNode.getElementDeclaration());
       
   132         assertAnyType(fRootNode.getTypeDefinition());
       
   133 
       
   134         checkChild();
       
   135     }
       
   136 
       
   137     private void checkFalseResult() {
       
   138         assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
       
   139         assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
       
   140                 .getValidationAttempted());
       
   141         assertElementNull(fRootNode.getElementDeclaration());
       
   142         assertTypeName("Y", fRootNode.getTypeDefinition().getName());
       
   143         assertTypeNamespaceNull(fRootNode.getTypeDefinition().getNamespace());
       
   144 
       
   145         checkChild();
       
   146     }
       
   147 
       
   148     private void checkChild() {
       
   149         PSVIElementNSImpl child = super.getChild(1);
       
   150         assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());
       
   151         assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child
       
   152                 .getValidationAttempted());
       
   153         assertElementName("A", child.getElementDeclaration().getName());
       
   154         assertTypeName("Y", child.getTypeDefinition().getName());
       
   155         assertTypeNamespaceNull(child.getTypeDefinition().getNamespace());
       
   156     }
       
   157 }