< prev index next >

test/javax/xml/jaxp/functional/org/w3c/dom/ptests/AttrTest.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 
  24 package org.w3c.dom.ptests;
  25 
  26 import static org.testng.Assert.assertEquals;
  27 import static org.testng.Assert.assertFalse;
  28 import static org.testng.Assert.assertNull;
  29 import static org.testng.Assert.assertTrue;
  30 import static org.w3c.dom.ptests.DOMTestUtil.createDOM;
  31 import jaxp.library.JAXPFileBaseTest;
  32 

  33 import org.testng.annotations.Test;
  34 import org.w3c.dom.Attr;
  35 import org.w3c.dom.Document;
  36 import org.w3c.dom.Element;
  37 import org.w3c.dom.NamedNodeMap;
  38 
  39 
  40 /*
  41  * @summary Test for the Attr Interface
  42  */
  43 public class AttrTest extends JAXPFileBaseTest {

  44     /*
  45      * Verify getName method against both existing Attr and new Attr.
  46      */
  47     @Test
  48     public void testGetName() throws Exception {
  49         Document document = createDOM("Attr01.xml");
  50         //test a new created Attr
  51         Attr attr = document.createAttribute("newAttribute");
  52         assertEquals(attr.getName(), "newAttribute");
  53 
  54         //test a Attr loaded from xml file
  55         Element elemNode = (Element) document.getElementsByTagName("book").item(1);
  56         Attr attr2 = (Attr) elemNode.getAttributes().item(0);
  57         assertEquals(attr2.getName(), "category1");
  58     }
  59 
  60     /*
  61      * Verify getOwnerElement method against both existing Attr and new Attr.
  62      */
  63     @Test


   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 
  24 package org.w3c.dom.ptests;
  25 
  26 import static org.testng.Assert.assertEquals;
  27 import static org.testng.Assert.assertFalse;
  28 import static org.testng.Assert.assertNull;
  29 import static org.testng.Assert.assertTrue;
  30 import static org.w3c.dom.ptests.DOMTestUtil.createDOM;

  31 
  32 import org.testng.annotations.Listeners;
  33 import org.testng.annotations.Test;
  34 import org.w3c.dom.Attr;
  35 import org.w3c.dom.Document;
  36 import org.w3c.dom.Element;
  37 import org.w3c.dom.NamedNodeMap;
  38 
  39 
  40 /*
  41  * @summary Test for the Attr Interface
  42  */
  43 @Listeners({jaxp.library.FilePolicy.class})
  44 public class AttrTest {
  45     /*
  46      * Verify getName method against both existing Attr and new Attr.
  47      */
  48     @Test
  49     public void testGetName() throws Exception {
  50         Document document = createDOM("Attr01.xml");
  51         //test a new created Attr
  52         Attr attr = document.createAttribute("newAttribute");
  53         assertEquals(attr.getName(), "newAttribute");
  54 
  55         //test a Attr loaded from xml file
  56         Element elemNode = (Element) document.getElementsByTagName("book").item(1);
  57         Attr attr2 = (Attr) elemNode.getAttributes().item(0);
  58         assertEquals(attr2.getName(), "category1");
  59     }
  60 
  61     /*
  62      * Verify getOwnerElement method against both existing Attr and new Attr.
  63      */
  64     @Test


< prev index next >