jdk/test/javax/xml/jaxp/testng/validation/8037819/UnparsedEntityCheckingTest.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 UnparsedEntityCheckingTest extends BaseTest {
       
    25     public static final String UNDECLARED_ENTITY = "UndeclaredEntity";
       
    26 
       
    27     protected String getXMLDocument() {
       
    28         return "unparsedEntity.xml";
       
    29     }
       
    30 
       
    31     protected String getSchemaFile() {
       
    32         return "base.xsd";
       
    33     }
       
    34 
       
    35     protected String[] getRelevantErrorIDs() {
       
    36         return new String[] { UNDECLARED_ENTITY };
       
    37     }
       
    38 
       
    39     public UnparsedEntityCheckingTest(String name) {
       
    40         super(name);
       
    41     }
       
    42 
       
    43     @BeforeClass
       
    44     protected void setUp() throws Exception {
       
    45         super.setUp();
       
    46     }
       
    47 
       
    48     @AfterClass
       
    49     protected void tearDown() throws Exception {
       
    50         super.tearDown();
       
    51     }
       
    52 
       
    53     @Test
       
    54     public void testDefaultValid() {
       
    55         try {
       
    56             reset();
       
    57             validateDocument();
       
    58         } catch (Exception e) {
       
    59             fail("Validation failed: " + e.getMessage());
       
    60         }
       
    61 
       
    62         checkDefault();
       
    63     }
       
    64 
       
    65     @Test
       
    66     public void testSetFalseValid() {
       
    67         try {
       
    68             reset();
       
    69             fValidator.setFeature(UNPARSED_ENTITY_CHECKING, false);
       
    70             validateDocument();
       
    71         } catch (Exception e) {
       
    72             fail("Validation failed: " + e.getMessage());
       
    73         }
       
    74 
       
    75         checkDefault();
       
    76     }
       
    77 
       
    78     @Test
       
    79     public void testSetTrueValid() {
       
    80         try {
       
    81             reset();
       
    82             fValidator.setFeature(UNPARSED_ENTITY_CHECKING, true);
       
    83             validateDocument();
       
    84         } catch (Exception e) {
       
    85             fail("Validation failed: " + e.getMessage());
       
    86         }
       
    87 
       
    88         checkDefault();
       
    89     }
       
    90 
       
    91     @Test
       
    92     public void testDefaultInvalid() {
       
    93         try {
       
    94             reset();
       
    95             ((PSVIElementNSImpl) fRootNode).setAttributeNS(null,
       
    96                     "unparsedEntityAttr", "invalid");
       
    97             validateDocument();
       
    98         } catch (Exception e) {
       
    99             fail("Validation failed: " + e.getMessage());
       
   100         }
       
   101 
       
   102         checkInvalid();
       
   103     }
       
   104 
       
   105     @Test
       
   106     public void testSetFalseInvalid() {
       
   107         try {
       
   108             reset();
       
   109             ((PSVIElementNSImpl) fRootNode).setAttributeNS(null,
       
   110                     "unparsedEntityAttr", "invalid");
       
   111             fValidator.setFeature(UNPARSED_ENTITY_CHECKING, false);
       
   112             validateDocument();
       
   113         } catch (Exception e) {
       
   114             fail("Validation failed: " + e.getMessage());
       
   115         }
       
   116 
       
   117         checkDefault();
       
   118     }
       
   119 
       
   120     @Test
       
   121     public void testSetTrueInvalid() {
       
   122         try {
       
   123             reset();
       
   124             ((PSVIElementNSImpl) fRootNode).setAttributeNS(null,
       
   125                     "unparsedEntityAttr", "invalid");
       
   126             fValidator.setFeature(UNPARSED_ENTITY_CHECKING, true);
       
   127             validateDocument();
       
   128         } catch (Exception e) {
       
   129             fail("Validation failed: " + e.getMessage());
       
   130         }
       
   131 
       
   132         checkInvalid();
       
   133     }
       
   134 
       
   135     private void checkDefault() {
       
   136         assertNoError(UNDECLARED_ENTITY);
       
   137         assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());
       
   138         assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
       
   139                 .getValidationAttempted());
       
   140         assertElementName("A", fRootNode.getElementDeclaration().getName());
       
   141         assertTypeName("X", fRootNode.getTypeDefinition().getName());
       
   142     }
       
   143 
       
   144     private void checkInvalid() {
       
   145         assertError(UNDECLARED_ENTITY);
       
   146         assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());
       
   147         assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode
       
   148                 .getValidationAttempted());
       
   149         assertElementName("A", fRootNode.getElementDeclaration().getName());
       
   150         assertTypeName("X", fRootNode.getTypeDefinition().getName());
       
   151     }
       
   152 }