Home | History | Annotate | Download | only in dom
      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-2003 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.Document;
     31 import org.w3c.dom.DocumentType;
     32 import org.w3c.dom.DOMImplementation;
     33 import org.w3c.dom.Element;
     34 
     35 import javax.xml.parsers.DocumentBuilder;
     36 
     37 /**
     38  * The method getOwnerDocument returns the Document object associated with this
     39  * node
     40  *
     41  * Create a new DocumentType node. Since this node is not used with any Document
     42  * yet verify if the ownerDocument is null.
     43  *
     44  * @author IBM
     45  * @author Neil Delima
     46  * @see <a
     47  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#node-ownerDoc">http://www.w3.org/TR/DOM-Level-2-Core/core#node-ownerDoc</a>
     48  * @see <a
     49  *      href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=259">http://www.w3.org/Bugs/Public/show_bug.cgi?id=259</a>
     50  */
     51 @TestTargetClass(Node.class)
     52 public final class NodeGetOwnerDocument extends DOMTestCase {
     53 
     54     DOMDocumentBuilderFactory factory;
     55 
     56     DocumentBuilder builder;
     57 
     58     protected void setUp() throws Exception {
     59         super.setUp();
     60         try {
     61             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     62                     .getConfiguration1());
     63             builder = factory.getBuilder();
     64         } catch (Exception e) {
     65             fail("Unexpected exception" + e.getMessage());
     66         }
     67     }
     68 
     69     protected void tearDown() throws Exception {
     70         factory = null;
     71         builder = null;
     72         super.tearDown();
     73     }
     74 
     75     /**
     76      * Runs the test case.
     77      *
     78      * @throws Throwable
     79      *             Any uncaught exception causes test to fail
     80      */
     81     @TestTargetNew(
     82         level = TestLevel.PARTIAL,
     83         notes = "Verifies that getOwnerDocument method returns null.",
     84         method = "getOwnerDocument",
     85         args = {}
     86     )
     87     public void testGetOwnerDocument1() throws Throwable {
     88         Document doc;
     89         Document ownerDoc;
     90         DOMImplementation domImpl;
     91         DocumentType docType;
     92         String nullID = null;
     93 
     94         doc = (Document) load("staff", builder);
     95         domImpl = doc.getImplementation();
     96         docType = domImpl.createDocumentType("mydoc", nullID, nullID);
     97         ownerDoc = docType.getOwnerDocument();
     98         assertNull("nodegetownerdocument01", ownerDoc);
     99     }
    100     @TestTargetNew(
    101         level = TestLevel.COMPLETE,
    102         notes = "",
    103         method = "getOwnerDocument",
    104         args = {}
    105     )
    106     public void testGetOwnerDocument2() throws Throwable {
    107         Document doc;
    108         Document newDoc;
    109         Element newElem;
    110         Document ownerDocDoc;
    111         Document ownerDocElem;
    112         DOMImplementation domImpl;
    113         DocumentType docType;
    114         String nullNS = null;
    115 
    116         doc = (Document) load("staff", builder);
    117         domImpl = doc.getImplementation();
    118         docType = domImpl.createDocumentType("mydoc", nullNS, nullNS);
    119         newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test", "mydoc",
    120                 docType);
    121         ownerDocDoc = newDoc.getOwnerDocument();
    122         assertNull("nodegetownerdocument02_1", ownerDocDoc);
    123         newElem = newDoc
    124                 .createElementNS("http://www.w3.org/DOM/Test", "myelem");
    125         ownerDocElem = newElem.getOwnerDocument();
    126         assertNotNull("nodegetownerdocument02_2", ownerDocElem);
    127     }
    128 }
    129