Path: blob/master/test/jdk/javax/xml/jaxp/testng/validation/jdk8037819/IdentityConstraintCheckingTest.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;2526public class IdentityConstraintCheckingTest extends BaseTest {27// These values are unstable, since they're not actually error keys, but28// simply29// the first part of the error message.30public static final String DUPLICATE_UNIQUE = "cvc-identity-constraint.4.1";3132public static final String DUPLICATE_KEY = "cvc-identity-constraint.4.2.2";3334public static final String INVALID_KEYREF = "cvc-identity-constraint.4.3";3536protected String getXMLDocument() {37return "idc.xml";38}3940protected String getSchemaFile() {41return "idc.xsd";42}4344protected String[] getRelevantErrorIDs() {45return new String[] { DUPLICATE_UNIQUE, DUPLICATE_KEY, INVALID_KEYREF };46}4748public IdentityConstraintCheckingTest(String name) {49super(name);50}5152@BeforeClass53protected void setUp() throws Exception {54super.setUp();55}5657@AfterClass58protected void tearDown() throws Exception {59super.tearDown();60}6162@Test63public void testDefault() {64try {65reset();66validateDocument();67} catch (Exception e) {68fail("Validation failed: " + e.getMessage());69}7071checkDefault();72}7374@Test75public void testSetFalse() {76try {77reset();78fValidator.setFeature(IDC_CHECKING, false);79validateDocument();80} catch (Exception e) {81fail("Validation failed: " + e.getMessage());82}8384checkValidResult();85}8687@Test88public void testSetTrue() {89try {90reset();91fValidator.setFeature(IDC_CHECKING, true);92validateDocument();93} catch (Exception e) {94fail("Validation failed: " + e.getMessage());95}9697checkDefault();98}99100private void checkDefault() {101assertError(DUPLICATE_UNIQUE);102assertError(DUPLICATE_KEY);103assertError(INVALID_KEYREF);104105assertValidity(ItemPSVI.VALIDITY_INVALID, fRootNode.getValidity());106assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode107.getValidationAttempted());108assertElementName("itemList", fRootNode.getElementDeclaration()109.getName());110assertTypeName("itemListType", fRootNode.getTypeDefinition().getName());111112// this one is valid because it's the first one to define the unique113// value114PSVIElementNSImpl child = super.getChild(1);115assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());116assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child117.getValidationAttempted());118assertElementName("item", child.getElementDeclaration().getName());119assertTypeName("itemType", child.getTypeDefinition().getName());120121// invalid because it repeats the unique value122child = super.getChild(2);123assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());124assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child125.getValidationAttempted());126assertElementName("item", child.getElementDeclaration().getName());127assertTypeName("itemType", child.getTypeDefinition().getName());128129// invalid because it repeats the key130child = super.getChild(3);131assertValidity(ItemPSVI.VALIDITY_INVALID, child.getValidity());132assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child133.getValidationAttempted());134assertElementName("item", child.getElementDeclaration().getName());135assertTypeName("itemType", child.getTypeDefinition().getName());136137// valid because key references aren't figured out until the validation138// root139child = super.getChild(4);140assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());141assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child142.getValidationAttempted());143assertElementName("itemRef", child.getElementDeclaration().getName());144assertTypeName("string", child.getTypeDefinition().getName());145}146147private void checkValidResult() {148assertNoError(DUPLICATE_UNIQUE);149assertNoError(DUPLICATE_KEY);150assertNoError(INVALID_KEYREF);151152assertValidity(ItemPSVI.VALIDITY_VALID, fRootNode.getValidity());153assertValidationAttempted(ItemPSVI.VALIDATION_FULL, fRootNode154.getValidationAttempted());155assertElementName("itemList", fRootNode.getElementDeclaration()156.getName());157assertTypeName("itemListType", fRootNode.getTypeDefinition().getName());158159PSVIElementNSImpl child = super.getChild(1);160assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());161assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child162.getValidationAttempted());163assertElementName("item", child.getElementDeclaration().getName());164assertTypeName("itemType", child.getTypeDefinition().getName());165166child = super.getChild(2);167assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());168assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child169.getValidationAttempted());170assertElementName("item", child.getElementDeclaration().getName());171assertTypeName("itemType", child.getTypeDefinition().getName());172173child = super.getChild(3);174assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());175assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child176.getValidationAttempted());177assertElementName("item", child.getElementDeclaration().getName());178assertTypeName("itemType", child.getTypeDefinition().getName());179180child = super.getChild(4);181assertValidity(ItemPSVI.VALIDITY_VALID, child.getValidity());182assertValidationAttempted(ItemPSVI.VALIDATION_FULL, child183.getValidationAttempted());184assertElementName("itemRef", child.getElementDeclaration().getName());185assertTypeName("string", child.getTypeDefinition().getName());186}187}188189190