< prev index next >

test/javax/xml/jaxp/unittest/validation/Bug5072946.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 javax.xml.XMLConstants;
  27 import javax.xml.parsers.DocumentBuilder;
  28 import javax.xml.parsers.DocumentBuilderFactory;
  29 import javax.xml.transform.Transformer;
  30 import javax.xml.transform.dom.DOMResult;
  31 import javax.xml.transform.dom.DOMSource;
  32 import javax.xml.transform.sax.SAXTransformerFactory;
  33 import javax.xml.transform.sax.TransformerHandler;
  34 import javax.xml.validation.Schema;
  35 import javax.xml.validation.SchemaFactory;
  36 import javax.xml.validation.Validator;
  37 
  38 import org.testng.Assert;

  39 import org.testng.annotations.Test;
  40 import org.w3c.dom.Document;
  41 import org.w3c.dom.Element;
  42 import org.w3c.dom.Node;
  43 import org.xml.sax.InputSource;
  44 import org.xml.sax.XMLReader;
  45 import org.xml.sax.helpers.XMLReaderFactory;
  46 
  47 /*
  48  * @bug 5072946
  49  * @summary Test Validator.validate(DOMSource,DOMResult) outputs to the result.
  50  */

  51 public class Bug5072946 {
  52 
  53     @Test
  54     public void test1() throws Exception {
  55 
  56         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  57         dbf.setNamespaceAware(true);
  58         DocumentBuilder parser = dbf.newDocumentBuilder();
  59         Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));
  60 
  61         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  62         Schema s = sf.newSchema(Bug5072946.class.getResource("Bug5072946.xsd"));
  63         Validator v = s.newValidator();
  64 
  65         DOMResult r = new DOMResult();
  66         // r.setNode(dbf.newDocumentBuilder().newDocument());
  67         v.validate(new DOMSource(dom), r);
  68 
  69         Node node = r.getNode();
  70         Assert.assertNotNull(node);


   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 javax.xml.XMLConstants;
  27 import javax.xml.parsers.DocumentBuilder;
  28 import javax.xml.parsers.DocumentBuilderFactory;
  29 import javax.xml.transform.Transformer;
  30 import javax.xml.transform.dom.DOMResult;
  31 import javax.xml.transform.dom.DOMSource;
  32 import javax.xml.transform.sax.SAXTransformerFactory;
  33 import javax.xml.transform.sax.TransformerHandler;
  34 import javax.xml.validation.Schema;
  35 import javax.xml.validation.SchemaFactory;
  36 import javax.xml.validation.Validator;
  37 
  38 import org.testng.Assert;
  39 import org.testng.annotations.Listeners;
  40 import org.testng.annotations.Test;
  41 import org.w3c.dom.Document;
  42 import org.w3c.dom.Element;
  43 import org.w3c.dom.Node;
  44 import org.xml.sax.InputSource;
  45 import org.xml.sax.XMLReader;
  46 import org.xml.sax.helpers.XMLReaderFactory;
  47 
  48 /*
  49  * @bug 5072946
  50  * @summary Test Validator.validate(DOMSource,DOMResult) outputs to the result.
  51  */
  52 @Listeners({jaxp.library.FilePolicy.class})
  53 public class Bug5072946 {
  54 
  55     @Test
  56     public void test1() throws Exception {
  57 
  58         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  59         dbf.setNamespaceAware(true);
  60         DocumentBuilder parser = dbf.newDocumentBuilder();
  61         Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));
  62 
  63         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  64         Schema s = sf.newSchema(Bug5072946.class.getResource("Bug5072946.xsd"));
  65         Validator v = s.newValidator();
  66 
  67         DOMResult r = new DOMResult();
  68         // r.setNode(dbf.newDocumentBuilder().newDocument());
  69         v.validate(new DOMSource(dom), r);
  70 
  71         Node node = r.getNode();
  72         Assert.assertNotNull(node);


< prev index next >