1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/*
3adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectThis Java source file was generated by test-to-java.xsl
4adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectand is a derived work from the source document.
5adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectThe source document contained the following notice:
6adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
7adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
8adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
9adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectCopyright (c) 2001-2004 World Wide Web Consortium,
10adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project(Massachusetts Institute of Technology, Institut National de
11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectRecherche en Informatique et en Automatique, Keio University).  All
12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectRights Reserved.  This program is distributed under the W3C's Software
13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectIntellectual Property License.  This program is distributed in the
14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projecthope that it will be useful, but WITHOUT ANY WARRANTY; without even
15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectthe implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectPURPOSE.
17adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
18adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source ProjectSee W3C License http://www.w3.org/Consortium/Legal/ for more details.
19adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
20adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
21adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project*/
22adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
23adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpackage org.w3c.domts.level2.core;
24adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
25adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.w3c.dom.*;
26adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
28adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.w3c.domts.DOMTestCase;
29adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport org.w3c.domts.DOMTestDocumentBuilderFactory;
30adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
31adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
32adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
33adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/**
34adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *     The "setAttributeNodeNS(newAttr)" adds a new attribute.
35adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    If an attribute with that local name and that namespaceURI is already
36adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    present in the element, it is replaced by the new one.
37adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
38adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    Retrieve the first emp:address element and add a new attribute
39adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    to the element.  Since an attribute with the same local name
40adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    and namespaceURI already exists, it is replaced by the new one and
41adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    returns the replaced "Attr" node.
42adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    This test uses the "createAttributeNS(namespaceURI,localName)
43adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *    method from the Document interface to create the new attribute to add.
44adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project* @author NIST
45adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project* @author Mary Brady
46adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-F68D095">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-F68D095</a>
47adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project*/
48adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpublic final class setAttributeNodeNS04 extends DOMTestCase {
49adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
50adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   /**
51adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * Constructor.
52adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * @param factory document factory, may not be null
53adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
54adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    */
55adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   public setAttributeNodeNS04(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
56adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
57adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      org.w3c.domts.DocumentBuilderSetting[] settings =
58adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project          new org.w3c.domts.DocumentBuilderSetting[] {
59adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectorg.w3c.domts.DocumentBuilderSetting.namespaceAware
60adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        };
61adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
62adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        setFactory(testFactory);
63adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
64adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    //
65adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    //   check if loaded documents are supported for content type
66adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    //
67adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    String contentType = getContentType();
68adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    preload(contentType, "staffNS", true);
69adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
70adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
71adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   /**
72adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * Runs the test case.
73adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * @throws Throwable Any uncaught exception causes test to fail
74adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    */
75adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   public void runTest() throws Throwable {
76adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      Document doc;
77adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      NodeList elementList;
78adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      Node testAddr;
79adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      Attr newAttr;
80adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      Attr newAddrAttr;
81adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      String newName;
82adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      doc = (Document) load("staffNS", true);
83adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      elementList = doc.getElementsByTagName("emp:address");
84adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      testAddr = elementList.item(0);
85adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      assertNotNull("empAddrNotNull", testAddr);
86adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      newAttr = doc.createAttributeNS("http://www.nist.gov", "xxx:domestic");
87adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      newAddrAttr = ((Element) /*Node */testAddr).setAttributeNodeNS(newAttr);
88adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      newName = newAddrAttr.getNodeName();
89adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      assertEquals("nodeName", "emp:domestic", newName);
90adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      }
91adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   /**
92adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    *  Gets URI that identifies the test.
93adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    *  @return uri identifier of test
94adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    */
95adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   public String getTargetURI() {
96adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project      return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNodeNS04";
97adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   }
98adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   /**
99adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * Runs this test from the command line.
100adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    * @param args command line arguments
101adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    */
102adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   public static void main(final String[] args) {
103adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        DOMTestCase.doMain(setAttributeNodeNS04.class, args);
104adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project   }
105adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project}
106adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
107