NodeGetPrefix.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
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 dalvik.annotation.TestTargets; 26import dalvik.annotation.TestLevel; 27import dalvik.annotation.TestTargetNew; 28import dalvik.annotation.TestTargetClass; 29 30import org.w3c.dom.Node; 31import org.w3c.dom.Document; 32import org.w3c.dom.Element; 33import org.w3c.dom.Attr; 34 35import javax.xml.parsers.DocumentBuilder; 36 37/** 38 * The method getPrefix returns the namespace prefix of this node, or null if it is unspecified. 39 * 40 * Ceate two new element nodes and atribute nodes, with and without namespace prefixes. 41 * Retreive the prefix part of their qualified names using getPrefix and verify 42 * if it is correct. 43* @author IBM 44* @author Neil Delima 45* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSPrefix">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-NodeNSPrefix</a> 46*/ 47@TestTargetClass(Node.class) 48public final class NodeGetPrefix 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 .getConfiguration1()); 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 /** 73 * Runs the test case. 74 * @throws Throwable Any uncaught exception causes test to fail 75 */ 76 @TestTargetNew( 77 level = TestLevel.COMPLETE, 78 notes = "", 79 method = "getPrefix", 80 args = {} 81 ) 82 public void testGetPrefix() throws Throwable { 83 Document doc; 84 Element element; 85 Element qelement; 86 Attr attr; 87 Attr qattr; 88 String elemNoPrefix; 89 String elemPrefix; 90 String attrNoPrefix; 91 String attrPrefix; 92 doc = (Document) load("staff", builder); 93 element = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "elem"); 94 qelement = doc.createElementNS("http://www.w3.org/DOM/Test/elem", "qual:qelem"); 95 attr = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "attr"); 96 qattr = doc.createAttributeNS("http://www.w3.org/DOM/Test/attr", "qual:qattr"); 97 elemNoPrefix = element.getPrefix(); 98 elemPrefix = qelement.getPrefix(); 99 attrNoPrefix = attr.getPrefix(); 100 attrPrefix = qattr.getPrefix(); 101 assertNull("nodegetprefix03_1", elemNoPrefix); 102 assertEquals("nodegetprefix03_2", "qual", elemPrefix); 103 assertNull("nodegetprefix03_3", attrNoPrefix); 104 assertEquals("nodegetprefix03_4", "qual", attrPrefix); 105 } 106 107} 108 109