< prev index next >

test/javax/xml/jaxp/functional/org/w3c/dom/ptests/ElementTest.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.XML_NS_URI;
  26 import static org.testng.Assert.assertEquals;
  27 import static org.testng.Assert.assertNull;
  28 import static org.testng.Assert.assertTrue;
  29 import static org.testng.Assert.fail;
  30 import static org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR;
  31 import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED;
  32 import static org.w3c.dom.ptests.DOMTestUtil.createDOM;
  33 import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS;
  34 import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument;
  35 
  36 import java.io.StringReader;
  37 
  38 import javax.xml.parsers.DocumentBuilderFactory;
  39 
  40 import jaxp.library.JAXPFileBaseTest;
  41 
  42 import org.testng.annotations.DataProvider;

  43 import org.testng.annotations.Test;
  44 import org.w3c.dom.Attr;
  45 import org.w3c.dom.DOMException;
  46 import org.w3c.dom.Document;
  47 import org.w3c.dom.Element;
  48 import org.w3c.dom.Node;
  49 import org.w3c.dom.NodeList;
  50 import org.xml.sax.InputSource;
  51 
  52 /*
  53  * @summary Test for the methods of Element Interface
  54  */
  55 public class ElementTest extends JAXPFileBaseTest {

  56     @Test
  57     public void testGetAttributeNS() throws Exception {
  58         Document document = createDOMWithNS("ElementSample01.xml");
  59         Element elemNode = (Element) document.getElementsByTagName("book").item(0);
  60         String s = elemNode.getAttributeNS("urn:BooksAreUs.org:BookInfo", "category");
  61         assertEquals(s, "research");
  62     }
  63 
  64     @Test
  65     public void testGetAttributeNodeNS() throws Exception {
  66         Document document = createDOMWithNS("ElementSample01.xml");
  67         Element elemNode = (Element) document.getElementsByTagName("book").item(0);
  68         Attr attr = elemNode.getAttributeNodeNS("urn:BooksAreUs.org:BookInfo", "category");
  69         assertEquals(attr.getValue(), "research");
  70 
  71     }
  72 
  73     /*
  74      * Test getAttributeNode to get a Attr and then remove it successfully by
  75      * removeAttributeNode.


   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.XML_NS_URI;
  26 import static org.testng.Assert.assertEquals;
  27 import static org.testng.Assert.assertNull;
  28 import static org.testng.Assert.assertTrue;
  29 import static org.testng.Assert.fail;
  30 import static org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR;
  31 import static org.w3c.dom.ptests.DOMTestUtil.DOMEXCEPTION_EXPECTED;
  32 import static org.w3c.dom.ptests.DOMTestUtil.createDOM;
  33 import static org.w3c.dom.ptests.DOMTestUtil.createDOMWithNS;
  34 import static org.w3c.dom.ptests.DOMTestUtil.createNewDocument;
  35 
  36 import java.io.StringReader;
  37 
  38 import javax.xml.parsers.DocumentBuilderFactory;
  39 


  40 import org.testng.annotations.DataProvider;
  41 import org.testng.annotations.Listeners;
  42 import org.testng.annotations.Test;
  43 import org.w3c.dom.Attr;
  44 import org.w3c.dom.DOMException;
  45 import org.w3c.dom.Document;
  46 import org.w3c.dom.Element;
  47 import org.w3c.dom.Node;
  48 import org.w3c.dom.NodeList;
  49 import org.xml.sax.InputSource;
  50 
  51 /*
  52  * @summary Test for the methods of Element Interface
  53  */
  54 @Listeners({jaxp.library.FilePolicy.class})
  55 public class ElementTest {
  56     @Test
  57     public void testGetAttributeNS() throws Exception {
  58         Document document = createDOMWithNS("ElementSample01.xml");
  59         Element elemNode = (Element) document.getElementsByTagName("book").item(0);
  60         String s = elemNode.getAttributeNS("urn:BooksAreUs.org:BookInfo", "category");
  61         assertEquals(s, "research");
  62     }
  63 
  64     @Test
  65     public void testGetAttributeNodeNS() throws Exception {
  66         Document document = createDOMWithNS("ElementSample01.xml");
  67         Element elemNode = (Element) document.getElementsByTagName("book").item(0);
  68         Attr attr = elemNode.getAttributeNodeNS("urn:BooksAreUs.org:BookInfo", "category");
  69         assertEquals(attr.getValue(), "research");
  70 
  71     }
  72 
  73     /*
  74      * Test getAttributeNode to get a Attr and then remove it successfully by
  75      * removeAttributeNode.


< prev index next >