< prev index next >

test/javax/xml/jaxp/unittest/validation/Bug4969732.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2015, 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 
  24 package validation;
  25 
  26 import java.io.StringReader;
  27 
  28 import javax.xml.parsers.SAXParserFactory;
  29 import javax.xml.transform.stream.StreamSource;
  30 import javax.xml.validation.Schema;
  31 import javax.xml.validation.SchemaFactory;
  32 import javax.xml.validation.TypeInfoProvider;
  33 import javax.xml.validation.ValidatorHandler;
  34 
  35 import org.testng.Assert;

  36 import org.testng.annotations.Test;
  37 import org.xml.sax.InputSource;
  38 import org.xml.sax.SAXException;
  39 import org.xml.sax.XMLReader;
  40 import org.xml.sax.helpers.DefaultHandler;
  41 
  42 /*
  43  * @bug 4969732
  44  * @summary Test TypeInfoProvider.getElementTypeInfo() throws IllegalStateException
  45  * in case the method is not called from method startElement() or endElement().
  46  */

  47 public class Bug4969732 {
  48 
  49     public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + "        xmlns:test='jaxp13_test'\n"
  50             + "        targetNamespace='jaxp13_test'\n" + "        elementFormDefault='qualified'>\n" + "    <element name='test' type='string'/>\n"
  51             + "</schema>\n";
  52 
  53     public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='jaxp13_test'>1234abc</ns:test>\n";
  54 
  55     private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
  56         SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
  57 
  58         StringReader reader = new StringReader(xsd);
  59         StreamSource xsdSource = new StreamSource(reader);
  60 
  61         Schema schema = schemaFactory.newSchema(xsdSource);
  62         return schema.newValidatorHandler();
  63     }
  64 
  65     private XMLReader createXMLReader() throws Exception {
  66         SAXParserFactory parserFactory = SAXParserFactory.newInstance();


   1 /*
   2  * Copyright (c) 2014, 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 
  24 package validation;
  25 
  26 import java.io.StringReader;
  27 
  28 import javax.xml.parsers.SAXParserFactory;
  29 import javax.xml.transform.stream.StreamSource;
  30 import javax.xml.validation.Schema;
  31 import javax.xml.validation.SchemaFactory;
  32 import javax.xml.validation.TypeInfoProvider;
  33 import javax.xml.validation.ValidatorHandler;
  34 
  35 import org.testng.Assert;
  36 import org.testng.annotations.Listeners;
  37 import org.testng.annotations.Test;
  38 import org.xml.sax.InputSource;
  39 import org.xml.sax.SAXException;
  40 import org.xml.sax.XMLReader;
  41 import org.xml.sax.helpers.DefaultHandler;
  42 
  43 /*
  44  * @bug 4969732
  45  * @summary Test TypeInfoProvider.getElementTypeInfo() throws IllegalStateException
  46  * in case the method is not called from method startElement() or endElement().
  47  */
  48 @Listeners({jaxp.library.BasePolicy.class})
  49 public class Bug4969732 {
  50 
  51     public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + "        xmlns:test='jaxp13_test'\n"
  52             + "        targetNamespace='jaxp13_test'\n" + "        elementFormDefault='qualified'>\n" + "    <element name='test' type='string'/>\n"
  53             + "</schema>\n";
  54 
  55     public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='jaxp13_test'>1234abc</ns:test>\n";
  56 
  57     private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
  58         SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
  59 
  60         StringReader reader = new StringReader(xsd);
  61         StreamSource xsdSource = new StreamSource(reader);
  62 
  63         Schema schema = schemaFactory.newSchema(xsdSource);
  64         return schema.newValidatorHandler();
  65     }
  66 
  67     private XMLReader createXMLReader() throws Exception {
  68         SAXParserFactory parserFactory = SAXParserFactory.newInstance();


< prev index next >