Home | History | Annotate | Download | only in dom
      1 /*
      2  This Java source file was generated by test-to-java.xsl
      3  and is a derived work from the source document.
      4  The source document contained the following notice:
      5 
      6 
      7 
      8  Copyright (c) 2001 World Wide Web Consortium,
      9  (Massachusetts Institute of Technology, Institut National de
     10  Recherche en Informatique et en Automatique, Keio University).  All
     11  Rights Reserved.  This program is distributed under the W3C's Software
     12  Intellectual Property License.  This program is distributed in the
     13  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     15  PURPOSE.
     16 
     17  See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     18 
     19 
     20  */
     21 
     22 package tests.org.w3c.dom;
     23 
     24 import org.w3c.dom.Node;
     25 import org.w3c.dom.Document;
     26 import org.w3c.dom.NodeList;
     27 
     28 import javax.xml.parsers.DocumentBuilder;
     29 
     30 /**
     31  * The "hasAttributes()" method for a node should return false if the node does
     32  * not have an attribute. Retrieve the first "name" node and invoke the
     33  * "hasAttributes()" method. The method should return false since the node does
     34  * not have an attribute.
     35  *
     36  * @author NIST
     37  * @author Mary Brady
     38  * @see <a
     39  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeHasAttrs">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeHasAttrs</a>
     40  */
     41 public final class HasAttributes extends DOMTestCase {
     42 
     43     DOMDocumentBuilderFactory factory;
     44 
     45     DocumentBuilder builder;
     46 
     47     protected void setUp() throws Exception {
     48         super.setUp();
     49         try {
     50             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     51                     .getConfiguration1());
     52             builder = factory.getBuilder();
     53         } catch (Exception e) {
     54             fail("Unexpected exception" + e.getMessage());
     55         }
     56     }
     57 
     58     protected void tearDown() throws Exception {
     59         factory = null;
     60         builder = null;
     61         super.tearDown();
     62     }
     63 
     64     /**
     65      * Runs the test case.
     66      *
     67      * @throws Throwable
     68      *             Any uncaught exception causes test to fail
     69      */
     70     public void testHasAttributes1() throws Throwable {
     71         Document doc;
     72         NodeList addrList;
     73         Node addrNode;
     74         boolean state;
     75         doc = (Document) load("staff", builder);
     76         addrList = doc.getElementsByTagName("name");
     77         addrNode = addrList.item(0);
     78         state = addrNode.hasAttributes();
     79         assertFalse("throw_False", state);
     80     }
     81     public void testHasAttributes2() throws Throwable {
     82         Document doc;
     83         NodeList addrList;
     84         Node addrNode;
     85         boolean state;
     86         doc = (Document) load("staff", builder);
     87         addrList = doc.getElementsByTagName("address");
     88         addrNode = addrList.item(0);
     89         state = addrNode.hasAttributes();
     90         assertTrue("throw_True", state);
     91     }
     92 
     93 }
     94