< prev index next >

test/javax/xml/jaxp/unittest/validation/CR6708840Test.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.File;
  27 import java.io.FileWriter;
  28 
  29 import javax.xml.XMLConstants;
  30 import javax.xml.stream.XMLInputFactory;
  31 import javax.xml.stream.XMLOutputFactory;
  32 import javax.xml.stream.XMLStreamReader;
  33 import javax.xml.transform.Result;
  34 import javax.xml.transform.Source;
  35 import javax.xml.transform.stax.StAXSource;
  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 
  43 /*
  44  * @bug 6708840
  45  * @summary Test Validator can process StAXSource.
  46  */

  47 public class CR6708840Test {
  48 
  49     @Test
  50     public final void testStream() {
  51         try {
  52             SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  53             Schema schemaGrammar = schemaFactory.newSchema(new File(getClass().getResource("gMonths.xsd").getFile()));
  54 
  55             Validator schemaValidator = schemaGrammar.newValidator();
  56             Source xmlSource = new javax.xml.transform.stream.StreamSource(new File(CR6708840Test.class.getResource("gMonths.xml").toURI()));
  57             schemaValidator.validate(xmlSource);
  58 
  59         } catch (NullPointerException ne) {
  60             Assert.fail("NullPointerException when result is not specified.");
  61         } catch (Exception e) {
  62             Assert.fail(e.getMessage());
  63             e.printStackTrace();
  64         }
  65     }
  66 


   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.File;
  27 import java.io.FileWriter;
  28 
  29 import javax.xml.XMLConstants;
  30 import javax.xml.stream.XMLInputFactory;
  31 import javax.xml.stream.XMLOutputFactory;
  32 import javax.xml.stream.XMLStreamReader;
  33 import javax.xml.transform.Result;
  34 import javax.xml.transform.Source;
  35 import javax.xml.transform.stax.StAXSource;
  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 
  44 /*
  45  * @bug 6708840
  46  * @summary Test Validator can process StAXSource.
  47  */
  48 @Listeners({jaxp.library.FilePolicy.class})
  49 public class CR6708840Test {
  50 
  51     @Test
  52     public final void testStream() {
  53         try {
  54             SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  55             Schema schemaGrammar = schemaFactory.newSchema(new File(getClass().getResource("gMonths.xsd").getFile()));
  56 
  57             Validator schemaValidator = schemaGrammar.newValidator();
  58             Source xmlSource = new javax.xml.transform.stream.StreamSource(new File(CR6708840Test.class.getResource("gMonths.xml").toURI()));
  59             schemaValidator.validate(xmlSource);
  60 
  61         } catch (NullPointerException ne) {
  62             Assert.fail("NullPointerException when result is not specified.");
  63         } catch (Exception e) {
  64             Assert.fail(e.getMessage());
  65             e.printStackTrace();
  66         }
  67     }
  68 


< prev index next >