ValidationWarningsTest.java revision 961:d92c3b89b2ac
1/* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24package common; 25 26import java.io.ByteArrayInputStream; 27import java.io.StringReader; 28import javax.xml.XMLConstants; 29import javax.xml.transform.Source; 30import javax.xml.transform.sax.SAXSource; 31import javax.xml.transform.stream.StreamSource; 32import javax.xml.validation.Schema; 33import javax.xml.validation.SchemaFactory; 34import javax.xml.validation.Validator; 35import org.testng.annotations.Test; 36import org.testng.annotations.BeforeClass; 37import org.xml.sax.InputSource; 38 39/* 40 * @test 41 * @bug 8144593 42 * @key intermittent 43 * @modules javax.xml/com.sun.org.apache.xerces.internal.jaxp 44 * @summary Check that warnings about unsupported properties from SAX 45 * parsers are suppressed during the xml validation process. 46 */ 47public class ValidationWarningsTest extends WarningsTestBase { 48 49 @BeforeClass 50 public void setup() { 51 //Set test SAX driver implementation. 52 System.setProperty("org.xml.sax.driver", "common.TestSAXDriver"); 53 } 54 55 @Test 56 public void testValidation() throws Exception { 57 startTest(); 58 } 59 60 //One iteration of xml validation test case. It will be called from each 61 //TestWorker task defined in WarningsTestBase class. 62 void doOneTestIteration() throws Exception { 63 Source src = new StreamSource(new StringReader(xml)); 64 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 65 SAXSource xsdSource = new SAXSource(new InputSource(new ByteArrayInputStream(xsd.getBytes()))); 66 Schema schema = schemaFactory.newSchema(xsdSource); 67 Validator v = schema.newValidator(); 68 v.validate(src); 69 } 70 71 //Xsd and Xml contents used in the validation test 72 private static final String xsd = "<?xml version='1.0'?>" 73 + " <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" 74 + " <xs:element name='test' type='xs:string'/>\n" 75 + " </xs:schema>"; 76 private static final String xml = "<?xml version='1.0'?><test>Element</test>"; 77 78} 79