1
2/*
3This Java source file was generated by test-to-java.xsl
4and is a derived work from the source document.
5The source document contained the following notice:
6
7
8Copyright (c) 2001 World Wide Web Consortium,
9(Massachusetts Institute of Technology, Institut National de
10Recherche en Informatique et en Automatique, Keio University). All
11Rights Reserved. This program is distributed under the W3C's Software
12Intellectual Property License. This program is distributed in the
13hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15PURPOSE.
16See W3C License http://www.w3.org/Consortium/Legal/ for more details.
17
18*/
19
20package org.w3c.domts.level1.core;
21
22import org.w3c.dom.*;
23
24
25import org.w3c.domts.DOMTestCase;
26import org.w3c.domts.DOMTestDocumentBuilderFactory;
27
28
29
30/**
31 *     The "setNamedItem(arg)" method adds a node using its
32 *    nodeName attribute.
33 *
34 *    Retrieve the second employee and create a NamedNodeMap
35 *    object from the attributes of the last child by
36 *    invoking the "getAttributes()" method.  Once the
37 *    list is created an invocation of the "setNamedItem(arg)"
38 *    method is done with arg=newAttr, where newAttr is a
39 *    new Attr Node previously created.  The "setNamedItem(arg)"
40 *    method should add then new node to the NamedNodeItem
41 *    object by using its "nodeName" attribute("district').
42 *    This node is then retrieved using the "getNamedItem(name)"
43 *    method.  This test uses the "createAttribute(name)"
44 *    method from the document interface.
45* @author NIST
46* @author Mary Brady
47* @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>
48* @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>
49*/
50public final class namednodemapsetnameditem extends DOMTestCase {
51
52   /**
53    * Constructor.
54    * @param factory document factory, may not be null
55    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
56    */
57   public namednodemapsetnameditem(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
58      super(factory);
59
60    //
61    //   check if loaded documents are supported for content type
62    //
63    String contentType = getContentType();
64    preload(contentType, "staff", true);
65    }
66
67   /**
68    * Runs the test case.
69    * @throws Throwable Any uncaught exception causes test to fail
70    */
71   public void runTest() throws Throwable {
72      Document doc;
73      NodeList elementList;
74      Attr newAttribute;
75      Node testAddress;
76      NamedNodeMap attributes;
77      Attr districtNode;
78      String attrName;
79      Node setNode;
80      doc = (Document) load("staff", true);
81      elementList = doc.getElementsByTagName("address");
82      testAddress = elementList.item(1);
83      newAttribute = doc.createAttribute("district");
84      attributes = testAddress.getAttributes();
85      setNode = attributes.setNamedItem(newAttribute);
86      districtNode = (Attr) attributes.getNamedItem("district");
87      attrName = districtNode.getNodeName();
88      assertEquals("namednodemapSetNamedItemAssert", "district", attrName);
89      }
90   /**
91    *  Gets URI that identifies the test.
92    *  @return uri identifier of test
93    */
94   public String getTargetURI() {
95      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapsetnameditem";
96   }
97   /**
98    * Runs this test from the command line.
99    * @param args command line arguments
100    */
101   public static void main(final String[] args) {
102        DOMTestCase.doMain(namednodemapsetnameditem.class, args);
103   }
104}
105
106