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 22 package tests.org.w3c.dom; 23 24 import dalvik.annotation.TestTargets; 25 import dalvik.annotation.TestLevel; 26 import dalvik.annotation.TestTargetNew; 27 import dalvik.annotation.TestTargetClass; 28 29 import org.w3c.dom.Node; 30 import org.w3c.dom.Attr; 31 import org.w3c.dom.Document; 32 import org.w3c.dom.NodeList; 33 import org.w3c.dom.NamedNodeMap; 34 import org.w3c.dom.Element; 35 36 import javax.xml.parsers.DocumentBuilder; 37 38 /** 39 * The "getOwnerElement()" will return the Element node this attribute is 40 * attached to or null if this attribute is not in use. Get the "domestic" 41 * attribute from the first "address" node. Apply the "getOwnerElement()" method 42 * to get the Element associated with the attribute. The value returned should 43 * be "address". 44 * 45 * @author NIST 46 * @author Mary Brady 47 * @see <a 48 * 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> 49 */ 50 @TestTargetClass(Attr.class) 51 public final class OwnerElement extends DOMTestCase { 52 53 DOMDocumentBuilderFactory factory; 54 55 DocumentBuilder builder; 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 try { 60 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 61 .getConfiguration1()); 62 builder = factory.getBuilder(); 63 } catch (Exception e) { 64 fail("Unexpected exception" + e.getMessage()); 65 } 66 } 67 68 protected void tearDown() throws Exception { 69 factory = null; 70 builder = null; 71 super.tearDown(); 72 } 73 74 /** 75 * Runs the test case. 76 * 77 * @throws Throwable 78 * Any uncaught exception causes test to fail 79 */ 80 @TestTargetNew( 81 level = TestLevel.PARTIAL, 82 notes = "Verifies positive functionlity.", 83 method = "getOwnerElement", 84 args = {} 85 ) 86 public void testGetOwnerElement1() throws Throwable { 87 Document doc; 88 NodeList addressList; 89 Node testNode; 90 NamedNodeMap attributes; 91 Attr domesticAttr; 92 Element elementNode; 93 String name; 94 doc = (Document) load("staff", builder); 95 addressList = doc.getElementsByTagName("address"); 96 testNode = addressList.item(0); 97 attributes = testNode.getAttributes(); 98 domesticAttr = (Attr) attributes.getNamedItem("domestic"); 99 elementNode = domesticAttr.getOwnerElement(); 100 name = elementNode.getNodeName(); 101 assertEquals("throw_Equals", "address", name); 102 } 103 @TestTargetNew( 104 level = TestLevel.PARTIAL, 105 notes = "Verifies that getOwnerElement method returns null.", 106 method = "getOwnerElement", 107 args = {} 108 ) 109 public void testGetOwnerElement2() throws Throwable { 110 Document doc; 111 Attr newAttr; 112 Element elementNode; 113 doc = (Document) load("staff", builder); 114 newAttr = doc.createAttribute("newAttribute"); 115 elementNode = newAttr.getOwnerElement(); 116 assertNull("throw_Null", elementNode); 117 } 118 } 119