< prev index next >

test/javax/xml/jaxp/functional/org/w3c/dom/ptests/DocumentTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 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 package org.w3c.dom.ptests;
  24 
  25 import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
  26 import static javax.xml.XMLConstants.XML_NS_URI;
  27 import static org.testng.Assert.assertEquals;
  28 import static org.testng.Assert.assertNotNull;
  29 import static org.testng.Assert.fail;
  30 import static org.w3c.dom.DOMException.NAMESPACE_ERR;
  31 import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED;
  32 import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS;
  33 import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument;
  34 import jaxp.library.JAXPFileBaseTest;
  35 
  36 import org.testng.annotations.DataProvider;

  37 import org.testng.annotations.Test;
  38 import org.w3c.dom.Attr;
  39 import org.w3c.dom.DOMException;
  40 import org.w3c.dom.Document;
  41 import org.w3c.dom.Element;
  42 import org.w3c.dom.NodeList;
  43 
  44 /*
  45  * @summary Test createAttributeNS, getElementsByTagNameNS and createElementNS method of Document
  46  */
  47 public class DocumentTest extends JAXPFileBaseTest {

  48 
  49     @DataProvider(name = "invalid-nsuri")
  50     public Object[][] getInvalidNamespaceURI() {
  51         return new Object[][] {
  52                 { " ", "xml:novel" }, //blank
  53                 { "hello", "xml:novel" }, //unqualified
  54                 { null, "xml:novel" }, //null
  55                 { "", "xmlns:novel" } };//empty
  56     }
  57 
  58     /*
  59      * Test for createAttributeNS method: verifies that DOMException is thrown
  60      * if reserved prefixes are used with an arbitrary namespace name.
  61      */
  62     @Test(dataProvider = "invalid-nsuri", expectedExceptions = DOMException.class)
  63     public void testCreateAttributeNSNeg(String namespaceURI, String name) throws Exception {
  64         Document document = createDOMWithNS("DocumentTest01.xml");
  65         document.createAttributeNS(namespaceURI, name);
  66     }
  67 


   1 /*
   2  * Copyright (c) 2003, 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 package org.w3c.dom.ptests;
  24 
  25 import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
  26 import static javax.xml.XMLConstants.XML_NS_URI;
  27 import static org.testng.Assert.assertEquals;
  28 import static org.testng.Assert.assertNotNull;
  29 import static org.testng.Assert.fail;
  30 import static org.w3c.dom.DOMException.NAMESPACE_ERR;
  31 import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED;
  32 import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS;
  33 import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument;

  34 
  35 import org.testng.annotations.DataProvider;
  36 import org.testng.annotations.Listeners;
  37 import org.testng.annotations.Test;
  38 import org.w3c.dom.Attr;
  39 import org.w3c.dom.DOMException;
  40 import org.w3c.dom.Document;
  41 import org.w3c.dom.Element;
  42 import org.w3c.dom.NodeList;
  43 
  44 /*
  45  * @summary Test createAttributeNS, getElementsByTagNameNS and createElementNS method of Document
  46  */
  47 @Listeners({jaxp.library.FilePolicy.class})
  48 public class DocumentTest {
  49 
  50     @DataProvider(name = "invalid-nsuri")
  51     public Object[][] getInvalidNamespaceURI() {
  52         return new Object[][] {
  53                 { " ", "xml:novel" }, //blank
  54                 { "hello", "xml:novel" }, //unqualified
  55                 { null, "xml:novel" }, //null
  56                 { "", "xmlns:novel" } };//empty
  57     }
  58 
  59     /*
  60      * Test for createAttributeNS method: verifies that DOMException is thrown
  61      * if reserved prefixes are used with an arbitrary namespace name.
  62      */
  63     @Test(dataProvider = "invalid-nsuri", expectedExceptions = DOMException.class)
  64     public void testCreateAttributeNSNeg(String namespaceURI, String name) throws Exception {
  65         Document document = createDOMWithNS("DocumentTest01.xml");
  66         document.createAttributeNS(namespaceURI, name);
  67     }
  68 


< prev index next >