Path: blob/master/test/jdk/javax/xml/jaxp/testng/validation/jdk8037819/UnparsedEntityCheckingTest.java
41159 views
/*1* Licensed to the Apache Software Foundation (ASF) under one or more2* contributor license agreements. See the NOTICE file distributed with3* this work for additional information regarding copyright ownership.4* The ASF licenses this file to You under the Apache License, Version 2.05* (the "License"); you may not use this file except in compliance with6* the License. You may obtain a copy of the License at7*8* http://www.apache.org/licenses/LICENSE-2.09*10* Unless required by applicable law or agreed to in writing, software11* distributed under the License is distributed on an "AS IS" BASIS,12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13* See the License for the specific language governing permissions and14* limitations under the License.15*/16package validation.jdk8037819;1718import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;19import com.sun.org.apache.xerces.internal.xs.ItemPSVI;20import org.testng.annotations.AfterClass;21import org.testng.annotations.BeforeClass;22import org.testng.annotations.Test;23import validation.BaseTest;2425public class UnparsedEntityCheckingTest extends BaseTest {26public static final String UNDECLARED_ENTITY = "UndeclaredEntity";2728protected String getXMLDocument() {29return "unparsedEntity.xml";30}3132protected String getSchemaFile() {33return "base.xsd";34}3536protected String[] getRelevantErrorIDs() {37return new String[] { UNDECLARED_ENTITY };38}3940public UnparsedEntityCheckingTest(String name) {41super(name);42}4344@BeforeClass45protected void setUp() throws Exception {46super.setUp();47}4849@AfterClass50protected void tearDown() throws Exception {51super.tearDown();52}5354@Test55public void testDefaultValid() {56try {57reset();58validateDocument();59} catch (Exception e) {60fail("Validation failed: " + e.getMessage());61}6263checkDefault();64}6566@Test67public void testSetFalseValid() {68try {69reset();70fValidator.setFeature(UNPARSED_ENTITY_CHECKING, false);71validateDocument();72} catch (Exception e) {73fail("Validation failed: " + e.getMessage());74}7576checkDefault();77}7879@Test80public void testSetTrueValid() {81try {82reset();83fValidator.setFeature(UNPARSED_ENTITY_CHECKING, true);84validateDocument();85} catch (Exception e) {86fail("Validation failed: " + e.getMessage());87}8889checkDefault();90}9192@Test93public void testDefaultInvalid() {94try {95reset();96((PSVIElementNSImpl) fRootNode).setAttributeNS(null,97"unparsedEntityAttr", "invalid");98validateDocument();99} catch (Exception e) {100fail("Validation failed: " + e.getMessage());101}102103checkInvalid();104}105106@Test107public void testSetFalseInvalid() {108try {109reset();110((PSVIElementNSImpl) fRootNode).setAttributeNS(null,111"unparsedEntityAttr", "invalid");112fValidator.setFeature(UNPARSED_ENTITY_CHECKING, false);113validateDocument();114} catch (Exception e) {115fail("Validation failed: " + e.getMessage());116}117118checkDefault();119}120121@Test122public void testSetTrueInvalid() {123try {124reset();125((PSVIElementNSImpl) fRootNode).setAttributeNS(null,126"unparsedEntityAttr", "invalid");127fValidator.setFeature(UNPARSED_ENTITY_CHECKING, true);128validateDocument();129} catch (Exception e) {130fail("Validation failed: " + e.getMessage());131}132133checkInvalid();134}135136private void checkDefault() {137assertNoError(UNDECLARED_ENTITY);138assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());139assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode140.getValidationAttempted());141assertElementName("A", fRootNode.getElementDeclaration().getName());142assertTypeName("X", fRootNode.getTypeDefinition().getName());143}144145private void checkInvalid() {146assertError(UNDECLARED_ENTITY);147assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());148assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode149.getValidationAttempted());150assertElementName("A", fRootNode.getElementDeclaration().getName());151assertTypeName("X", fRootNode.getTypeDefinition().getName());152}153}154155156