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  *     If the node to be added by the "setNamedItem(arg)" method
     32  *    already exists in the NamedNodeMap, it is replaced by
     33  *    the new one.
     34  *
     35  *    Retrieve the second employee and create a NamedNodeMap
     36  *    object from the attributes of the last child by
     37  *    invoking the "getAttributes()" method.  Once the
     38  *    list is created an invocation of the "setNamedItem(arg)"
     39  *    method is done with arg=newAttr, where newAttr is a
     40  *    new Attr Node previously created and whose node name
     41  *    already exists in the map.  The "setNamedItem(arg)"
     42  *    method should replace the already existing node with
     43  *    the new one.
     44  *    This node is then retrieved using the "getNamedItem(name)"
     45  *    method.  This test uses the "createAttribute(name)"
     46  *    method from the document interface
     47 * @author NIST
     48 * @author Mary Brady
     49 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788</a>
     50 * @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-349467F9">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-349467F9</a>
     51 */
     52 public final class namednodemapsetnameditemthatexists extends DOMTestCase {
     53 
     54    /**
     55     * Constructor.
     56     * @param factory document factory, may not be null
     57     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     58     */
     59    public namednodemapsetnameditemthatexists(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     60       super(factory);
     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       NodeList elementList;
     76       Attr newAttribute;
     77       Node testAddress;
     78       NamedNodeMap attributes;
     79       Attr districtNode;
     80       String attrValue;
     81       Node setNode;
     82       doc = (Document) load("staff", true);
     83       elementList = doc.getElementsByTagName("address");
     84       testAddress = elementList.item(1);
     85       newAttribute = doc.createAttribute("street");
     86       attributes = testAddress.getAttributes();
     87       setNode = attributes.setNamedItem(newAttribute);
     88       districtNode = (Attr) attributes.getNamedItem("street");
     89       attrValue = districtNode.getNodeValue();
     90       assertEquals("streetValue", "", attrValue);
     91       }
     92    /**
     93     *  Gets URI that identifies the test.
     94     *  @return uri identifier of test
     95     */
     96    public String getTargetURI() {
     97       return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapsetnameditemthatexists";
     98    }
     99    /**
    100     * Runs this test from the command line.
    101     * @param args command line arguments
    102     */
    103    public static void main(final String[] args) {
    104         DOMTestCase.doMain(namednodemapsetnameditemthatexists.class, args);
    105    }
    106 }
    107 
    108