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 8 9Copyright (c) 2001 World Wide Web Consortium, 10(Massachusetts Institute of Technology, Institut National de 11Recherche en Informatique et en Automatique, Keio University). All 12Rights Reserved. This program is distributed under the W3C's Software 13Intellectual Property License. This program is distributed in the 14hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16PURPOSE. 17 18See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21*/ 22 23package tests.org.w3c.dom; 24 25import org.w3c.dom.NamedNodeMap; 26import org.w3c.dom.Document; 27import org.w3c.dom.Node; 28import org.w3c.dom.NodeList; 29import org.w3c.dom.DOMException; 30 31import javax.xml.parsers.DocumentBuilder; 32 33/** 34 * The "setNamedItemNS(arg)" method for a 35 * NamedNodeMap should raise INUSE_ATTRIBUTE_ERR DOMException if 36 * arg is an Attr that is already an attribute of another Element object. 37 * 38 * Retrieve an attr node from the third "address" element whose local name 39 * is "domestic" and namespaceURI is "http://www.netzero.com". 40 * Invoke method setNamedItemNS(arg) on the map of the first "address" element with 41 * arg being the attr node from above. Method should raise 42 * INUSE_ATTRIBUTE_ERR DOMException. 43* @author NIST 44* @author Mary Brady 45* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])</a> 46* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS</a> 47* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])</a> 48*/ 49public final class SetNamedItemNS extends DOMTestCase { 50 51 DOMDocumentBuilderFactory factory; 52 53 DocumentBuilder builder; 54 55 protected void setUp() throws Exception { 56 super.setUp(); 57 try { 58 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 59 .getConfiguration2()); 60 builder = factory.getBuilder(); 61 } catch (Exception e) { 62 fail("Unexpected exception" + e.getMessage()); 63 } 64 } 65 66 protected void tearDown() throws Exception { 67 factory = null; 68 builder = null; 69 super.tearDown(); 70 } 71 72 /** 73 * Runs the test case. 74 * @throws Throwable Any uncaught exception causes test to fail 75 */ 76 public void testSetNamedItemNS1() throws Throwable { 77 Document doc; 78 NodeList elementList; 79 Node anotherElement; 80 NamedNodeMap anotherMap; 81 Node arg; 82 Node testAddress; 83 NamedNodeMap map; 84 85 doc = (Document) load("staffNS", builder); 86 elementList = doc.getElementsByTagName("address"); 87 anotherElement = elementList.item(2); 88 anotherMap = anotherElement.getAttributes(); 89 arg = anotherMap.getNamedItemNS("http://www.netzero.com", "domestic"); 90 testAddress = elementList.item(0); 91 map = testAddress.getAttributes(); 92 93 { 94 boolean success = false; 95 try { 96 map.setNamedItemNS(arg); 97 } catch (DOMException ex) { 98 success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR); 99 } 100 assertTrue("throw_INUSE_ATTRIBUTE_ERR", success); 101 } 102} 103 public void testSetNamedItemNS2() throws Throwable { 104 String namespaceURI = "http://www.usa.com"; 105 String qualifiedName = "dmstc:domestic"; 106 Document doc; 107 Document anotherDoc; 108 Node arg; 109 NodeList elementList; 110 Node testAddress; 111 NamedNodeMap attributes; 112 113 doc = (Document) load("staffNS", builder); 114 anotherDoc = (Document) load("staffNS", builder); 115 arg = anotherDoc.createAttributeNS(namespaceURI, qualifiedName); 116 arg.setNodeValue("Maybe"); 117 elementList = doc.getElementsByTagName("address"); 118 testAddress = elementList.item(0); 119 attributes = testAddress.getAttributes(); 120 121 { 122 boolean success = false; 123 try { 124 attributes.setNamedItemNS(arg); 125 } catch (DOMException ex) { 126 success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); 127 } 128 assertTrue("throw_WRONG_DOCUMENT_ERR", success); 129 } 130 } 131 public void testSetNamedItemNS3() throws Throwable { 132 String namespaceURI = "http://www.nist.gov"; 133 String qualifiedName = "prefix:newAttr"; 134 Document doc; 135 Node arg; 136 NodeList elementList; 137 Node testAddress; 138 NamedNodeMap attributes; 139 Node retnode; 140 String value; 141 142 doc = (Document) load("staffNS", builder); 143 arg = doc.createAttributeNS(namespaceURI, qualifiedName); 144 arg.setNodeValue("newValue"); 145 elementList = doc.getElementsByTagName("address"); 146 testAddress = elementList.item(0); 147 attributes = testAddress.getAttributes(); 148 attributes.setNamedItemNS(arg); 149 retnode = attributes.getNamedItemNS(namespaceURI, "newAttr"); 150 value = retnode.getNodeValue(); 151 assertEquals("throw_Equals", "newValue", value); 152 } 153 154// Assumes validation. 155// public void testSetNamedItemNS4() throws Throwable { 156// String namespaceURI = "http://www.w3.org/2000/xmlns/"; 157// String localName = "local1"; 158// Document doc; 159// NodeList elementList; 160// Node testAddress; 161// NodeList nList; 162// Node child; 163// NodeList n2List; 164// Node child2; 165// NamedNodeMap attributes; 166// Node arg; 167// 168// int nodeType; 169// doc = (Document) load("staffNS", builder); 170// elementList = doc.getElementsByTagName("gender"); 171// testAddress = elementList.item(2); 172// nList = testAddress.getChildNodes(); 173// child = nList.item(0); 174// nodeType = (int) child.getNodeType(); 175// 176// if (1 == nodeType) { 177// child = doc.createEntityReference("ent4"); 178// assertNotNull("createdEntRefNotNull", child); 179// } 180// n2List = child.getChildNodes(); 181// child2 = n2List.item(0); 182// assertNotNull("notnull", child2); 183// attributes = child2.getAttributes(); 184// arg = attributes.getNamedItemNS(namespaceURI, localName); 185// 186// { 187// boolean success = false; 188// try { 189// attributes.setNamedItemNS(arg); 190// } catch (DOMException ex) { 191// success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); 192// } 193// assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success); 194// } 195// } 196 public void testSetNamedItemNS5() throws Throwable { 197 String namespaceURI = "http://www.usa.com"; 198 String qualifiedName = "dmstc:domestic"; 199 Document doc; 200 Node arg; 201 NodeList elementList; 202 Node testAddress; 203 NamedNodeMap attributes; 204 Node retnode; 205 String value; 206 doc = (Document) load("staffNS", builder); 207 arg = doc.createAttributeNS(namespaceURI, qualifiedName); 208 arg.setNodeValue("newValue"); 209 elementList = doc.getElementsByTagName("address"); 210 testAddress = elementList.item(0); 211 attributes = testAddress.getAttributes(); 212 retnode = attributes.setNamedItemNS(arg); 213 value = retnode.getNodeValue(); 214 assertEquals("throw_Equals", "Yes", value); 215 } 216 217} 218 219