Bug6971190Test.java revision 968:874082a9b565
178344Sobrien/* 278344Sobrien * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 398184Sgordon * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 478344Sobrien * 578344Sobrien * This code is free software; you can redistribute it and/or modify it 678344Sobrien * under the terms of the GNU General Public License version 2 only, as 7135252Sseanc * published by the Free Software Foundation. 8180564Sdougb * 978344Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1078344Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1178344Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1278344Sobrien * version 2 for more details (a copy is included in the LICENSE file that 13101851Sgordon * accompanied this code). 14101851Sgordon * 1578344Sobrien * You should have received a copy of the GNU General Public License version 16101851Sgordon * 2 along with this work; if not, write to the Free Software Foundation, 1778344Sobrien * 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 validation.tck; 25 26import java.io.IOException; 27 28import javax.xml.XMLConstants; 29import javax.xml.transform.stream.StreamSource; 30import javax.xml.validation.Schema; 31import javax.xml.validation.SchemaFactory; 32import javax.xml.validation.Validator; 33 34import org.testng.Assert; 35import org.testng.annotations.Listeners; 36import org.testng.annotations.Test; 37import org.xml.sax.SAXException; 38 39/* 40 * @test 41 * @bug 6971190 42 * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest 43 * @run testng/othervm -DrunSecMngr=true validation.tck.Bug6971190Test 44 * @run testng/othervm validation.tck.Bug6971190Test 45 * @summary Test Validation accepts UTF lexical presentation. 46 */ 47@Listeners({jaxp.library.FilePolicy.class}) 48public class Bug6971190Test { 49 static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; 50 static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource"; 51 52 @Test 53 public void test() { 54 try { 55 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 56 57 Schema schema = schemaFactory.newSchema(new StreamSource(Bug6971190Test.class.getResourceAsStream("Bug6971190.xsd"))); 58 Validator validator = schema.newValidator(); 59 /** 60 * validator.setErrorHandler(new ErrorHandler() { public void 61 * error(SAXParseException exception) throws SAXException { 62 * exception.printStackTrace(); } 63 * 64 * public void fatalError(SAXParseException exception) throws 65 * SAXException { exception.printStackTrace(); } 66 * 67 * public void warning(SAXParseException exception) throws 68 * SAXException { exception.printStackTrace(); } }); 69 */ 70 validator.validate(new StreamSource(Bug6971190Test.class.getResourceAsStream("Bug6971190.xml"))); 71 72 } catch (SAXException e) { 73 System.out.println(e.getMessage()); 74 Assert.fail(e.getMessage()); 75 76 } catch (IOException e) { 77 e.printStackTrace(); 78 System.out.println(e.getMessage()); 79 Assert.fail(e.getMessage()); 80 } 81 } 82 83 // test \W negative tests with positibve \w 84 @Test 85 public void testNegative() { 86 try { 87 SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 88 89 Schema schema = schemaFactory.newSchema(new StreamSource(Bug6971190Test.class.getResourceAsStream("Bug6971190_v.xsd"))); 90 Validator validator = schema.newValidator(); 91 92 validator.validate(new StreamSource(Bug6971190Test.class.getResourceAsStream("Bug6971190_v.xml"))); 93 94 } catch (SAXException e) { 95 e.printStackTrace(); 96 Assert.fail(e.getMessage()); 97 98 } catch (IOException e) { 99 e.printStackTrace(); 100 System.out.println(e.getMessage()); 101 } 102 } 103 104} 105 106