Home | History | Annotate | Download | only in core
      1 
      2 /*
      3 This Java source file was generated by test-to-java.xsl
      4 and is a derived work from the source document.
      5 The source document contained the following notice:
      6 
      7 
      8 
      9 Copyright (c) 2001 World Wide Web Consortium,
     10 (Massachusetts Institute of Technology, Institut National de
     11 Recherche en Informatique et en Automatique, Keio University).  All
     12 Rights Reserved.  This program is distributed under the W3C's Software
     13 Intellectual Property License.  This program is distributed in the
     14 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
     15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     16 PURPOSE.
     17 
     18 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     19 
     20 
     21 */
     22 
     23 package org.w3c.domts.level2.core;
     24 
     25 import org.w3c.dom.*;
     26 
     27 
     28 import org.w3c.domts.DOMTestCase;
     29 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     30 
     31 
     32 
     33 /**
     34  *  The method hasAttributes returns whether this node (if it is an element) has any attributes.
     35  *  Create a new Document, Element and Attr node.  Add the Attr to the Element and append the
     36  *  Element to the Document.  Retreive the newly created element node from the document and check
     37  *  if it has attributes using hasAttributes.
     38 * @author IBM
     39 * @author Neil Delima
     40 * @see <a 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>
     41 */
     42 public final class nodehasattributes04 extends DOMTestCase {
     43 
     44    /**
     45     * Constructor.
     46     * @param factory document factory, may not be null
     47     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     48     */
     49    public nodehasattributes04(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     50 
     51       org.w3c.domts.DocumentBuilderSetting[] settings =
     52           new org.w3c.domts.DocumentBuilderSetting[] {
     53 org.w3c.domts.DocumentBuilderSetting.namespaceAware
     54         };
     55         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     56         setFactory(testFactory);
     57 
     58     //
     59     //   check if loaded documents are supported for content type
     60     //
     61     String contentType = getContentType();
     62     preload(contentType, "staffNS", false);
     63     }
     64 
     65    /**
     66     * Runs the test case.
     67     * @throws Throwable Any uncaught exception causes test to fail
     68     */
     69    public void runTest() throws Throwable {
     70       Document doc;
     71       Document newDoc;
     72       DocumentType docType = null;
     73 
     74       DOMImplementation domImpl;
     75       Element element;
     76       Element elementTest;
     77       Element elementDoc;
     78       Attr attribute;
     79       Node setNode;
     80       Node appendedChild;
     81       NodeList elementList;
     82       boolean hasAttributes;
     83       doc = (Document) load("staffNS", false);
     84       domImpl = doc.getImplementation();
     85       newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "test", docType);
     86       element = newDoc.createElementNS("http://www.w3.org/DOM/Test", "dom:elem");
     87       attribute = newDoc.createAttribute("attr");
     88       setNode = element.setAttributeNode(attribute);
     89       elementDoc = newDoc.getDocumentElement();
     90       appendedChild = elementDoc.appendChild(element);
     91       elementList = newDoc.getElementsByTagNameNS("http://www.w3.org/DOM/Test", "elem");
     92       elementTest = (Element) elementList.item(0);
     93       hasAttributes = elementTest.hasAttributes();
     94       assertTrue("nodehasattributes04", hasAttributes);
     95       }
     96    /**
     97     *  Gets URI that identifies the test.
     98     *  @return uri identifier of test
     99     */
    100    public String getTargetURI() {
    101       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/nodehasattributes04";
    102    }
    103    /**
    104     * Runs this test from the command line.
    105     * @param args command line arguments
    106     */
    107    public static void main(final String[] args) {
    108         DOMTestCase.doMain(nodehasattributes04.class, args);
    109    }
    110 }
    111 
    112