1package tests.org.w3c.dom; 2 3import dalvik.annotation.TestTargets; 4import dalvik.annotation.TestLevel; 5import dalvik.annotation.TestTargetNew; 6import dalvik.annotation.TestTargetClass; 7 8import org.w3c.dom.NamedNodeMap; 9import org.w3c.dom.Document; 10import org.w3c.dom.Attr; 11import org.w3c.dom.Node; 12import org.w3c.dom.NodeList; 13 14import javax.xml.parsers.DocumentBuilder; 15 16/** 17 * The "getNamedItemNS(namespaceURI,localName)" method for a NamedNodeMap should 18 * return a node specified by localName and namespaceURI 19 * 20 * Retrieve a list of elements with tag name "address". Access the second 21 * element from the list and get its attributes. Try to retrieve the attribute 22 * node with local name "domestic" and namespace uri "http://www.usa.com" with 23 * method getNamedItemNS(namespaceURI,localName). 24 * 25 * @author NIST 26 * @author Mary Brady 27 * @see <a 28 * 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> 29 */ 30@TestTargetClass(NamedNodeMap.class) 31public final class GetNamedItemNS extends DOMTestCase { 32 33 DOMDocumentBuilderFactory factory; 34 35 DocumentBuilder builder; 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 try { 40 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 41 .getConfiguration2()); 42 builder = factory.getBuilder(); 43 } catch (Exception e) { 44 fail("Unexpected exception" + e.getMessage()); 45 } 46 } 47 48 protected void tearDown() throws Exception { 49 factory = null; 50 builder = null; 51 super.tearDown(); 52 } 53 54 /** 55 * Runs the test case. 56 * 57 * @throws Throwable 58 * Any uncaught exception causes test to fail 59 */ 60 @TestTargetNew( 61 level = TestLevel.PARTIAL, 62 notes = "Doesn't verify DOMException.", 63 method = "getNamedItem", 64 args = {java.lang.String.class} 65 ) 66 public void testGetNamedItemNS1() throws Throwable { 67 Document doc; 68 NodeList elementList; 69 Node testEmployee; 70 NamedNodeMap attributes; 71 Attr domesticAttr; 72 String attrName; 73 doc = (Document) load("staffNS", builder); 74 elementList = doc.getElementsByTagName("address"); 75 testEmployee = elementList.item(1); 76 attributes = testEmployee.getAttributes(); 77 domesticAttr = (Attr) attributes.getNamedItemNS("http://www.usa.com", 78 "domestic"); 79 attrName = domesticAttr.getNodeName(); 80 assertEquals("attrName", "dmstc:domestic", attrName); 81 } 82 @TestTargetNew( 83 level = TestLevel.PARTIAL, 84 notes = "Doesn't verify DOMException.", 85 method = "getNamedItemNS", 86 args = {java.lang.String.class, java.lang.String.class} 87 ) 88 public void testGetNamedItemNS2() throws Throwable { 89 String namespaceURI = "http://www.usa.com"; 90 String localName = "domest"; 91 Document doc; 92 NodeList elementList; 93 Node testEmployee; 94 NamedNodeMap attributes; 95 Attr newAttr; 96 doc = (Document) load("staffNS", builder); 97 elementList = doc.getElementsByTagName("address"); 98 testEmployee = elementList.item(1); 99 attributes = testEmployee.getAttributes(); 100 newAttr = (Attr) attributes.getNamedItemNS(namespaceURI, localName); 101 assertNull("throw_Null", newAttr); 102 } 103 104// Assumes validation. 105// public void testGetNamedItemNS3() throws Throwable { 106// Document doc; 107// DocumentType docType; 108// NamedNodeMap entities; 109// Entity entity; 110// String nullNS = null; 111// 112// doc = (Document) load("staffNS", builder); 113// docType = doc.getDoctype(); 114// entities = docType.getEntities(); 115// assertNotNull("entitiesNotNull", entities); 116// entity = (Entity) entities.getNamedItemNS(nullNS, "ent1"); 117// assertNotNull("entityNull", entity); 118// } 119 120// Assumes validation. 121// public void testGetNamedItemNS4() throws Throwable { 122// Document doc; 123// DocumentType docType; 124// NamedNodeMap notations; 125// Notation notation; 126// String nullNS = null; 127// 128// doc = (Document) load("staffNS", builder); 129// docType = doc.getDoctype(); 130// notations = docType.getNotations(); 131// assertNotNull("notationsNotNull", notations); 132// notation = (Notation) notations.getNamedItemNS(nullNS, "notation1"); 133// assertNotNull("notationNull", notation); 134// } 135} 136