1/* 2 This Java source file was generated by test-to-java.xsl 3 and is a derived work from the source document. 4 The source document contained the following notice: 5 6 7 8 Copyright (c) 2001 World Wide Web Consortium, 9 (Massachusetts Institute of Technology, Institut National de 10 Recherche en Informatique et en Automatique, Keio University). All 11 Rights Reserved. This program is distributed under the W3C's Software 12 Intellectual Property License. This program is distributed in the 13 hope that it will be useful, but WITHOUT ANY WARRANTY; without even 14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 15 PURPOSE. 16 17 See W3C License http://www.w3.org/Consortium/Legal/ for more details. 18 19 20 */ 21 22package tests.org.w3c.dom; 23 24import org.w3c.dom.NamedNodeMap; 25import org.w3c.dom.Document; 26import org.w3c.dom.Node; 27import org.w3c.dom.NodeList; 28import org.w3c.dom.Attr; 29import org.w3c.dom.DOMException; 30 31import javax.xml.parsers.DocumentBuilder; 32 33/** 34 * The "removeNamedItemNS(namespaceURI,localName)" method for a NamedNodeMap 35 * should remove a node specified by localName and namespaceURI. 36 * 37 * Retrieve a list of elements with tag name "address". Access the second 38 * element from the list and get its attributes. Try to remove the attribute 39 * node with local name "domestic" and namespace uri "http://www.usa.com" with 40 * method removeNamedItemNS(namespaceURI,localName). Check to see if the node 41 * has been removed. 42 * 43 * @author NIST 44 * @author Mary Brady 45 * @see <a 46 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-1074577549">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-1074577549</a> 47 */ 48public final class RemoveNamedItemNS extends DOMTestCase { 49 50 DOMDocumentBuilderFactory factory; 51 52 DocumentBuilder builder; 53 54 protected void setUp() throws Exception { 55 super.setUp(); 56 try { 57 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 58 .getConfiguration2()); 59 builder = factory.getBuilder(); 60 } catch (Exception e) { 61 fail("Unexpected exception" + e.getMessage()); 62 } 63 } 64 65 protected void tearDown() throws Exception { 66 factory = null; 67 builder = null; 68 super.tearDown(); 69 } 70 71 /** 72 * Runs the test case. 73 * 74 * @throws Throwable 75 * Any uncaught exception causes test to fail 76 */ 77 public void testRemoveNamedItemNS1() throws Throwable { 78 Document doc; 79 NodeList elementList; 80 Node testAddress; 81 NamedNodeMap attributes; 82 Attr newAttr; 83 Node removedNode; 84 doc = (Document) load("staffNS", builder); 85 elementList = doc.getElementsByTagName("address"); 86 testAddress = elementList.item(1); 87 attributes = testAddress.getAttributes(); 88 removedNode = attributes.removeNamedItemNS("http://www.usa.com", 89 "domestic"); 90 assertNotNull("retval", removedNode); 91 newAttr = (Attr) attributes.getNamedItem("dmstc:domestic"); 92 assertNull("nodeRemoved", newAttr); 93 } 94 public void testRemoveNamedItemNS2() throws Throwable { 95 String namespaceURI = "http://www.usa.com"; 96 String localName = "domest"; 97 Document doc; 98 NodeList elementList; 99 Node testAddress; 100 NamedNodeMap attributes; 101 102 doc = (Document) load("staffNS", builder); 103 elementList = doc.getElementsByTagName("address"); 104 testAddress = elementList.item(1); 105 attributes = testAddress.getAttributes(); 106 107 { 108 boolean success = false; 109 try { 110 attributes.removeNamedItemNS(namespaceURI, 111 localName); 112 } catch (DOMException ex) { 113 success = (ex.code == DOMException.NOT_FOUND_ERR); 114 } 115 assertTrue("throw_NOT_FOUND_ERR", success); 116 } 117 } 118 119// Assumes validation. 120// public void testRemoveNamedItemNS3() throws Throwable { 121// String namespaceURI = "http://www.w3.org/2000/xmlns/"; 122// String localName = "local1"; 123// Document doc; 124// NodeList elementList; 125// Node testAddress; 126// NodeList nList; 127// Node child; 128// NodeList n2List; 129// Node child2; 130// NamedNodeMap attributes; 131// 132// int nodeType; 133// doc = (Document) load("staffNS", builder); 134// elementList = doc.getElementsByTagName("gender"); 135// testAddress = elementList.item(2); 136// nList = testAddress.getChildNodes(); 137// child = nList.item(0); 138// nodeType = (int) child.getNodeType(); 139// 140// if (1 == nodeType) { 141// child = doc.createEntityReference("ent4"); 142// assertNotNull("createdEntRefNotNull", child); 143// } 144// n2List = child.getChildNodes(); 145// child2 = n2List.item(0); 146// assertNotNull("notnull", child2); 147// attributes = child2.getAttributes(); 148// 149// { 150// boolean success = false; 151// try { 152// attributes.removeNamedItemNS(namespaceURI, 153// localName); 154// } catch (DOMException ex) { 155// success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); 156// } 157// assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success); 158// } 159// } 160} 161