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