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