Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/common/8144593/ValidationWarningsTest.java
38859 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.ByteArrayInputStream;24import java.io.StringReader;25import javax.xml.XMLConstants;26import javax.xml.transform.Source;27import javax.xml.transform.sax.SAXSource;28import javax.xml.transform.stream.StreamSource;29import javax.xml.validation.Schema;30import javax.xml.validation.SchemaFactory;31import javax.xml.validation.Validator;32import org.testng.annotations.Test;33import org.testng.annotations.BeforeClass;34import org.xml.sax.InputSource;3536/*37* @test38* @bug 814459339* @summary Check that warnings about unsupported properties from SAX40* parsers are suppressed during the xml validation process.41* @compile -XDignore.symbol.file TestSAXDriver.java42* @run testng/othervm ValidationWarningsTest43*/44public class ValidationWarningsTest extends WarningsTestBase {4546@BeforeClass47public void setup() {48//Set test SAX driver implementation.49System.setProperty("org.xml.sax.driver", "TestSAXDriver");50}5152@Test53public void testValidation() throws Exception {54startTest();55}5657//One iteration of xml validation test case. It will be called from each58//TestWorker task defined in WarningsTestBase class.59void doOneTestIteration() throws Exception {60Source src = new StreamSource(new StringReader(xml));61SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);62SAXSource xsdSource = new SAXSource(new InputSource(new ByteArrayInputStream(xsd.getBytes())));63Schema schema = schemaFactory.newSchema(xsdSource);64Validator v = schema.newValidator();65v.validate(src);66}6768//Xsd and Xml contents used in the validation test69private static final String xsd = "<?xml version='1.0'?>"70+ " <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>"71+ " <xs:element name='test' type='xs:string'/>\n"72+ " </xs:schema>";73private static final String xml = "<?xml version='1.0'?><test>Element</test>";7475}767778