Path: blob/master/test/jdk/javax/xml/jaxp/testng/validation/jdk8037819/IdIdrefCheckingTest.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.xml.sax.SAXException;21import org.testng.annotations.AfterClass;22import org.testng.annotations.BeforeClass;23import org.testng.annotations.Test;24import validation.BaseTest;2526// duplicate IDs27// reference to non-existent ID2829public class IdIdrefCheckingTest extends BaseTest {30public static final String DUPLICATE_ID = "cvc-id.2";3132public static final String NO_ID_BINDING = "cvc-id.1";3334protected String getXMLDocument() {35return "idIdref.xml";36}3738protected String getSchemaFile() {39return "base.xsd";40}4142protected String[] getRelevantErrorIDs() {43return new String[] { DUPLICATE_ID, NO_ID_BINDING };44}4546public IdIdrefCheckingTest(String name) {47super(name);48}4950@BeforeClass51protected void setUp() throws Exception {52super.setUp();53}5455@AfterClass56protected void tearDown() throws Exception {57super.tearDown();58}5960@Test61public void testDefault() {62try {63reset();64validateDocument();65} catch (Exception e) {66fail("Validation failed: " + e.getMessage());67}6869checkDefault();70}7172@Test73public void testSetFalse() {74try {75reset();76fValidator.setFeature(ID_IDREF_CHECKING, false);77validateDocument();78} catch (Exception e) {79fail("Validation failed: " + e.getMessage());80}8182checkValidResult();83}8485@Test86public void testSetTrue() {87try {88reset();89fValidator.setFeature(ID_IDREF_CHECKING, true);90validateDocument();91} catch (Exception e) {92fail("Validation failed: " + e.getMessage());93}9495checkDefault();96}9798private void checkDefault() {99assertError(DUPLICATE_ID);100assertError(NO_ID_BINDING);101102assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());103assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode104.getValidationAttempted());105assertElementName("A", fRootNode.getElementDeclaration().getName());106assertTypeName("X", fRootNode.getTypeDefinition().getName());107108PSVIElementNSImpl child = super.getChild(1);109assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());110assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child111.getValidationAttempted());112assertElementName("A", child.getElementDeclaration().getName());113assertTypeName("idType", child.getTypeDefinition().getName());114115child = super.getChild(2);116assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());117assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child118.getValidationAttempted());119assertElementName("A", child.getElementDeclaration().getName());120assertTypeName("idType", child.getTypeDefinition().getName());121122child = super.getChild(3);123assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());124assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child125.getValidationAttempted());126assertElementName("A", child.getElementDeclaration().getName());127assertTypeName("idrefType", child.getTypeDefinition().getName());128}129130private void checkValidResult() {131assertNoError(DUPLICATE_ID);132assertNoError(NO_ID_BINDING);133134assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());135assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode136.getValidationAttempted());137assertElementName("A", fRootNode.getElementDeclaration().getName());138assertTypeName("X", fRootNode.getTypeDefinition().getName());139140PSVIElementNSImpl child = super.getChild(1);141assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());142assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child143.getValidationAttempted());144assertElementName("A", child.getElementDeclaration().getName());145assertTypeName("idType", child.getTypeDefinition().getName());146147child = super.getChild(2);148assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());149assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child150.getValidationAttempted());151assertElementName("A", child.getElementDeclaration().getName());152assertTypeName("idType", child.getTypeDefinition().getName());153154child = super.getChild(3);155assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());156assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child157.getValidationAttempted());158assertElementName("A", child.getElementDeclaration().getName());159assertTypeName("idrefType", child.getTypeDefinition().getName());160}161}162163164