< prev index next >

test/javax/xml/jaxp/unittest/validation/JaxpIssue49.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.FileInputStream;
  27 
  28 import javax.xml.XMLConstants;
  29 import javax.xml.transform.Source;
  30 import javax.xml.transform.Transformer;
  31 import javax.xml.transform.TransformerFactory;
  32 import javax.xml.transform.dom.DOMResult;
  33 import javax.xml.transform.dom.DOMSource;
  34 import javax.xml.transform.stream.StreamResult;
  35 import javax.xml.transform.stream.StreamSource;
  36 import javax.xml.validation.Schema;
  37 import javax.xml.validation.SchemaFactory;
  38 import javax.xml.validation.Validator;
  39 
  40 import org.testng.Assert;

  41 import org.testng.annotations.Test;
  42 import org.w3c.dom.Node;
  43 
  44 /*
  45  * @bug 6684227
  46  * @summary Test property current-element-node works.
  47  */

  48 public class JaxpIssue49 {
  49 
  50     private Schema schema;
  51     private Validator validator;
  52 
  53     @Test
  54     public void testValidatorTest() throws Exception {
  55         try {
  56             SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  57             String file = getClass().getResource("types.xsd").getFile();
  58             Source[] sources = new Source[] { new StreamSource(new FileInputStream(file), file) };
  59             Schema schema = sf.newSchema(sources);
  60             validator = schema.newValidator();
  61             validate();
  62         } catch (Exception e) {
  63             Node node = (Node) validator.getProperty("http://apache.org/xml/properties/dom/current-element-node");
  64             if (node != null) {
  65                 System.out.println("Node: " + node.getLocalName());
  66             } else
  67                 Assert.fail("No node returned");


   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.FileInputStream;
  27 
  28 import javax.xml.XMLConstants;
  29 import javax.xml.transform.Source;
  30 import javax.xml.transform.Transformer;
  31 import javax.xml.transform.TransformerFactory;
  32 import javax.xml.transform.dom.DOMResult;
  33 import javax.xml.transform.dom.DOMSource;
  34 import javax.xml.transform.stream.StreamResult;
  35 import javax.xml.transform.stream.StreamSource;
  36 import javax.xml.validation.Schema;
  37 import javax.xml.validation.SchemaFactory;
  38 import javax.xml.validation.Validator;
  39 
  40 import org.testng.Assert;
  41 import org.testng.annotations.Listeners;
  42 import org.testng.annotations.Test;
  43 import org.w3c.dom.Node;
  44 
  45 /*
  46  * @bug 6684227
  47  * @summary Test property current-element-node works.
  48  */
  49 @Listeners({jaxp.library.FilePolicy.class})
  50 public class JaxpIssue49 {
  51 
  52     private Schema schema;
  53     private Validator validator;
  54 
  55     @Test
  56     public void testValidatorTest() throws Exception {
  57         try {
  58             SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  59             String file = getClass().getResource("types.xsd").getFile();
  60             Source[] sources = new Source[] { new StreamSource(new FileInputStream(file), file) };
  61             Schema schema = sf.newSchema(sources);
  62             validator = schema.newValidator();
  63             validate();
  64         } catch (Exception e) {
  65             Node node = (Node) validator.getProperty("http://apache.org/xml/properties/dom/current-element-node");
  66             if (node != null) {
  67                 System.out.println("Node: " + node.getLocalName());
  68             } else
  69                 Assert.fail("No node returned");


< prev index next >