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 static jaxp.library.JAXPTestUtilities.setSystemProperty; 27 28import java.io.ByteArrayInputStream; 29import java.io.StringReader; 30 31import javax.xml.XMLConstants; 32import javax.xml.transform.Source; 33import javax.xml.transform.sax.SAXSource; 34import javax.xml.transform.stream.StreamSource; 35import javax.xml.validation.Schema; 36import javax.xml.validation.SchemaFactory; 37import javax.xml.validation.Validator; 38 39import org.testng.annotations.BeforeClass; 40import org.testng.annotations.Listeners; 41import org.testng.annotations.Test; 42import org.xml.sax.InputSource; 43 44/* 45 * @test 46 * @bug 8144593 47 * @key intermittent 48 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest 49 * @compile -XDignore.symbol.file TestSAXDriver.java 50 * @run testng/othervm -DrunSecMngr=true common.ValidationWarningsTest 51 * @run testng/othervm common.ValidationWarningsTest 52 * @summary Check that warnings about unsupported properties from SAX 53 * parsers are suppressed during the xml validation process. 54 */ 55@Listeners({jaxp.library.InternalAPIPolicy.class}) 56public class ValidationWarningsTest extends WarningsTestBase { 57 58 @BeforeClass 59 public void setup() { 60 //Set test SAX driver implementation. 61 setSystemProperty("org.xml.sax.driver", "common.TestSAXDriver"); 62 } 63 64 @Test 65 public void testValidation() throws Exception { 66 startTest(); 67 } 68 69 //One iteration of xml validation test case. It will be called from each 70 //TestWorker task defined in WarningsTestBase class. 71 void doOneTestIteration() throws Exception { 72 Source src = new StreamSource(new StringReader(xml)); 73 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 74 SAXSource xsdSource = new SAXSource(new InputSource(new ByteArrayInputStream(xsd.getBytes()))); 75 Schema schema = schemaFactory.newSchema(xsdSource); 76 Validator v = schema.newValidator(); 77 v.validate(src); 78 } 79 80 //Xsd and Xml contents used in the validation test 81 private static final String xsd = "<?xml version='1.0'?>" 82 + " <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>" 83 + " <xs:element name='test' type='xs:string'/>\n" 84 + " </xs:schema>"; 85 private static final String xml = "<?xml version='1.0'?><test>Element</test>"; 86 87} 88