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 dalvik.annotation.TestTargets; 25import dalvik.annotation.TestLevel; 26import dalvik.annotation.TestTargetNew; 27import dalvik.annotation.TestTargetClass; 28 29import org.w3c.dom.Element; 30import org.w3c.dom.Document; 31import org.w3c.dom.NodeList; 32 33import javax.xml.parsers.DocumentBuilder; 34 35/** 36 * 37 * The "hasAttributeNS()" method for an Element should return false if the 38 * element does not have an attribute with the given local name and/or a 39 * namespace URI specified on this element or does not have a default value. 40 * Retrieve the first "address" element and the "hasAttributeNS()" method should 41 * return false since the element has "nomatch" as the local name and 42 * "http://www.usa.com" as the namespace URI. 43 * 44 * @author NIST 45 * @author Mary Brady 46 * @see <a 47 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElHasAttrNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElHasAttrNS</a> 48 */ 49@TestTargetClass(Element.class) 50public final class HasAttributeNS extends DOMTestCase { 51 52 DOMDocumentBuilderFactory factory; 53 54 DocumentBuilder builder; 55 56 protected void setUp() throws Exception { 57 super.setUp(); 58 try { 59 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 60 .getConfiguration2()); 61 builder = factory.getBuilder(); 62 } catch (Exception e) { 63 fail("Unexpected exception" + e.getMessage()); 64 } 65 } 66 67 protected void tearDown() throws Exception { 68 factory = null; 69 builder = null; 70 super.tearDown(); 71 } 72 73 /** 74 * Runs the test case. 75 * 76 * @throws Throwable 77 * Any uncaught exception causes test to fail 78 */ 79 @TestTargetNew( 80 level = TestLevel.PARTIAL, 81 notes = "Doesn't verify DOMException.", 82 method = "hasAttributeNS", 83 args = {java.lang.String.class, java.lang.String.class} 84 ) 85 public void testHasAttributeNS1() throws Throwable { 86 String localName = "nomatch"; 87 String namespaceURI = "http://www.usa.com"; 88 Document doc; 89 NodeList elementList; 90 Element testNode; 91 boolean state; 92 doc = (Document) load("staffNS", builder); 93 elementList = doc.getElementsByTagName("address"); 94 testNode = (Element) elementList.item(0); 95 state = testNode.hasAttributeNS(namespaceURI, localName); 96 assertFalse("throw_False", state); 97 } 98 @TestTargetNew( 99 level = TestLevel.PARTIAL, 100 notes = "Doesn't verify DOMException.", 101 method = "hasAttributeNS", 102 args = {java.lang.String.class, java.lang.String.class} 103 ) 104 public void testHasAttributeNS2() throws Throwable { 105 String localName = "domestic"; 106 String namespaceURI = "http://www.nomatch.com"; 107 Document doc; 108 NodeList elementList; 109 Element testNode; 110 boolean state; 111 doc = (Document) load("staffNS", builder); 112 elementList = doc.getElementsByTagName("address"); 113 testNode = (Element) elementList.item(0); 114 state = testNode.hasAttributeNS(namespaceURI, localName); 115 assertFalse("throw_False", state); 116 } 117 @TestTargetNew( 118 level = TestLevel.PARTIAL, 119 notes = "Doesn't verify DOMException.", 120 method = "hasAttributeNS", 121 args = {java.lang.String.class, java.lang.String.class} 122 ) 123 public void testHasAttributeNS3() throws Throwable { 124 String localName = "blank"; 125 String namespaceURI = "http://www.nist.gov"; 126 Document doc; 127 NodeList elementList; 128 Element testNode; 129 boolean state; 130 doc = (Document) load("staffNS", builder); 131 elementList = doc.getElementsByTagName("emp:address"); 132 testNode = (Element) elementList.item(0); 133 assertNotNull("empAddrNotNull", testNode); 134 state = testNode.hasAttributeNS(namespaceURI, localName); 135 assertFalse("throw_False", state); 136 } 137 138// Assumes validation. 139// public void testHasAttributeNS4() throws Throwable { 140// String localName = "district"; 141// String namespaceURI = "http://www.nist.gov"; 142// Document doc; 143// NodeList elementList; 144// Element testNode; 145// boolean state; 146// doc = (Document) load("staffNS", builder); 147// elementList = doc.getElementsByTagName("emp:address"); 148// testNode = (Element) elementList.item(0); 149// assertNotNull("empAddressNotNull", testNode); 150// state = testNode.hasAttributeNS(namespaceURI, localName); 151// assertTrue("hasAttribute", state); 152// } 153 @TestTargetNew( 154 level = TestLevel.PARTIAL, 155 notes = "Doesn't verify DOMException.", 156 method = "hasAttributeNS", 157 args = {java.lang.String.class, java.lang.String.class} 158 ) 159 public void testHasAttributeNS5() throws Throwable { 160 String localName = "domestic"; 161 String namespaceURI = "http://www.usa.com"; 162 Document doc; 163 NodeList elementList; 164 Element testNode; 165 boolean state; 166 doc = (Document) load("staffNS", builder); 167 elementList = doc.getElementsByTagName("address"); 168 testNode = (Element) elementList.item(0); 169 state = testNode.hasAttributeNS(namespaceURI, localName); 170 assertTrue("hasAttribute", state); 171 } 172} 173