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 Copyright (c) 2001-2004 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 See W3C License http://www.w3.org/Consortium/Legal/ for more details.
     17 
     18 */
     19 
     20 package org.w3c.domts.level1.core;
     21 
     22 import org.w3c.dom.*;
     23 
     24 
     25 import org.w3c.domts.DOMTestCase;
     26 import org.w3c.domts.DOMTestDocumentBuilderFactory;
     27 
     28 
     29 
     30 /**
     31  *     The "createElement(tagName)" method creates an Element
     32  *    of the type specified.  In addition, if there are known attributes
     33  *    with default values, Attr nodes representing them are automatically
     34  *    created and attached to the element.
     35  *    Retrieve the entire DOM document and invoke its
     36  *    "createElement(tagName)" method with tagName="address".
     37  *    The method should create an instance of an Element node
     38  *    whose tagName is "address".  The tagName "address" has an
     39  *    attribute with default values, therefore the newly created element
     40  *    will have them.
     41 * @author NIST
     42 * @author Mary Brady
     43 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-2141741547">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-2141741547</a>
     44 * @see <a href="http://lists.w3.org/Archives/Public/www-dom-ts/2002Mar/0002.html">http://lists.w3.org/Archives/Public/www-dom-ts/2002Mar/0002.html</a>
     45 */
     46 public final class documentcreateelementdefaultattr extends DOMTestCase {
     47 
     48    /**
     49     * Constructor.
     50     * @param factory document factory, may not be null
     51     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     52     */
     53    public documentcreateelementdefaultattr(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     54 
     55       org.w3c.domts.DocumentBuilderSetting[] settings =
     56           new org.w3c.domts.DocumentBuilderSetting[] {
     57 org.w3c.domts.DocumentBuilderSetting.validating
     58         };
     59         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     60         setFactory(testFactory);
     61 
     62     //
     63     //   check if loaded documents are supported for content type
     64     //
     65     String contentType = getContentType();
     66     preload(contentType, "staff", true);
     67     }
     68 
     69    /**
     70     * Runs the test case.
     71     * @throws Throwable Any uncaught exception causes test to fail
     72     */
     73    public void runTest() throws Throwable {
     74       Document doc;
     75       Element newElement;
     76       NamedNodeMap defaultAttr;
     77       Node child;
     78       String name;
     79       String value;
     80       doc = (Document) load("staff", true);
     81       newElement = doc.createElement("address");
     82       defaultAttr = newElement.getAttributes();
     83       child = defaultAttr.item(0);
     84       assertNotNull("defaultAttrNotNull", child);
     85       name = child.getNodeName();
     86       assertEquals("attrName", "street", name);
     87       value = child.getNodeValue();
     88       assertEquals("attrValue", "Yes", value);
     89       assertSize("attrCount", 1, defaultAttr);
     90       }
     91    /**
     92     *  Gets URI that identifies the test.
     93     *  @return uri identifier of test
     94     */
     95    public String getTargetURI() {
     96       return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentcreateelementdefaultattr";
     97    }
     98    /**
     99     * Runs this test from the command line.
    100     * @param args command line arguments
    101     */
    102    public static void main(final String[] args) {
    103         DOMTestCase.doMain(documentcreateelementdefaultattr.class, args);
    104    }
    105 }
    106 
    107