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 *     If the "setNamedItem(arg)" method replaces an already
32 *    existing node with the same name then the already
33 *    existing node is returned.
34 *
35 *    Retrieve the third 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 and return the existing node.
44 *    This test uses the "createAttribute(name)" method from
45 *    the document interface.
46* @author NIST
47* @author Mary Brady
48* @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>
49* @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>
50*/
51public final class namednodemapsetnameditemreturnvalue extends DOMTestCase {
52
53   /**
54    * Constructor.
55    * @param factory document factory, may not be null
56    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
57    */
58   public namednodemapsetnameditemreturnvalue(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
59      super(factory);
60
61    //
62    //   check if loaded documents are supported for content type
63    //
64    String contentType = getContentType();
65    preload(contentType, "staff", true);
66    }
67
68   /**
69    * Runs the test case.
70    * @throws Throwable Any uncaught exception causes test to fail
71    */
72   public void runTest() throws Throwable {
73      Document doc;
74      NodeList elementList;
75      Attr newAttribute;
76      Node testAddress;
77      NamedNodeMap attributes;
78      Node newNode;
79      String attrValue;
80      doc = (Document) load("staff", true);
81      elementList = doc.getElementsByTagName("address");
82      testAddress = elementList.item(2);
83      newAttribute = doc.createAttribute("street");
84      attributes = testAddress.getAttributes();
85      newNode = attributes.setNamedItem(newAttribute);
86      attrValue = newNode.getNodeValue();
87      assertEquals("returnedNodeValue", "No", attrValue);
88      }
89   /**
90    *  Gets URI that identifies the test.
91    *  @return uri identifier of test
92    */
93   public String getTargetURI() {
94      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/namednodemapsetnameditemreturnvalue";
95   }
96   /**
97    * Runs this test from the command line.
98    * @param args command line arguments
99    */
100   public static void main(final String[] args) {
101        DOMTestCase.doMain(namednodemapsetnameditemreturnvalue.class, args);
102   }
103}
104
105