1 package tests.org.w3c.dom; 2 3 import org.w3c.dom.Document; 4 import org.w3c.dom.Element; 5 6 import javax.xml.parsers.DocumentBuilder; 7 8 /** 9 * The method getElementById returns the element whose ID is given by elementId. 10 * If not such element exists, returns null. 11 * 12 * Invoke the getElementById method on this Document object with an invalid 13 * elementId. This should return a null element. 14 * 15 * @author IBM 16 * @author Neil Delima 17 * @see <a 18 * href="http://www.w3.org/TR/DOM-Level-2-Core/core">http://www.w3.org/TR/DOM-Level-2-Core/core</a> 19 * @see <a 20 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getElBId">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-getElBId</a> 21 */ 22 public final class DocumentGeteEementById extends DOMTestCase { 23 24 DOMDocumentBuilderFactory factory; 25 26 DocumentBuilder builder; 27 setUp()28 protected void setUp() throws Exception { 29 super.setUp(); 30 try { 31 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 32 .getConfiguration1()); 33 builder = factory.getBuilder(); 34 } catch (Exception e) { 35 fail("Unexpected exception" + e.getMessage()); 36 } 37 } 38 tearDown()39 protected void tearDown() throws Exception { 40 factory = null; 41 builder = null; 42 super.tearDown(); 43 } 44 45 /** 46 * Runs the test case. 47 * 48 * @throws Throwable 49 * Any uncaught exception causes test to fail 50 */ testGetElementById()51 public void testGetElementById() throws Throwable { 52 Document doc; 53 Element element; 54 String elementId = "---"; 55 doc = (Document) load("staffNS", builder); 56 element = doc.getElementById(elementId); 57 assertNull("documentgetelementbyid01", element); 58 } 59 60 } 61