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 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 java.util.ArrayList;
     25 import java.util.List;
     26 
     27 import org.w3c.dom.DOMImplementation;
     28 import org.w3c.dom.Document;
     29 import org.w3c.dom.DocumentType;
     30 
     31 import javax.xml.parsers.DocumentBuilder;
     32 
     33 /**
     34  * The method createDocumentType with valid values for qualifiedName, publicId
     35  * and systemId should create an empty DocumentType node.
     36  *
     37  * Invoke createDocument on this DOMImplementation with a valid qualifiedName
     38  * and different publicIds and systemIds. Check if the the DocumentType node was
     39  * created with its ownerDocument attribute set to null.
     40  *
     41  * @author IBM
     42  * @author Neil Delima
     43  * @see <a
     44  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-DOM-createDocument</a>
     45  */
     46 public final class DOMImplementationCreateDocumentType extends DOMTestCase {
     47 
     48     DOMDocumentBuilderFactory factory;
     49 
     50     DocumentBuilder builder;
     51 
     52     protected void setUp() throws Exception {
     53         super.setUp();
     54         try {
     55             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     56                     .getConfiguration1());
     57             builder = factory.getBuilder();
     58         } catch (Exception e) {
     59             fail("Unexpected exception" + e.getMessage());
     60         }
     61     }
     62 
     63     protected void tearDown() throws Exception {
     64         factory = null;
     65         builder = null;
     66         super.tearDown();
     67     }
     68 
     69     /**
     70      * Runs the test case.
     71      *
     72      * @throws Throwable
     73      *             Any uncaught exception causes test to fail
     74      */
     75     public void testCreateDocumentType1() throws Throwable {
     76         Document doc;
     77         DOMImplementation domImpl;
     78         DocumentType newDocType;
     79         Document ownerDocument;
     80         String qualifiedName = "test:root";
     81         String publicId;
     82         String systemId;
     83         List<String> publicIds = new ArrayList<String>();
     84         publicIds.add("1234");
     85         publicIds.add("test");
     86 
     87         List<String> systemIds = new ArrayList<String>();
     88         systemIds.add("");
     89         systemIds.add("test");
     90 
     91         doc = (Document) load("staffNS", builder);
     92         domImpl = doc.getImplementation();
     93         for (int indexN1005D = 0; indexN1005D < publicIds.size(); indexN1005D++) {
     94             publicId = (String) publicIds.get(indexN1005D);
     95             for (int indexN10061 = 0; indexN10061 < systemIds.size(); indexN10061++) {
     96                 systemId = (String) systemIds.get(indexN10061);
     97                 newDocType = domImpl.createDocumentType(qualifiedName,
     98                         publicId, systemId);
     99                 assertNotNull(
    100                         "domimplementationcreatedocumenttype01_newDocType",
    101                         newDocType);
    102                 ownerDocument = newDocType.getOwnerDocument();
    103                 assertNull(
    104                         "domimplementationcreatedocumenttype01_ownerDocument",
    105                         ownerDocument);
    106             }
    107         }
    108     }
    109     public void testCreateDocumentType2() throws Throwable {
    110         Document doc;
    111         DOMImplementation domImpl;
    112         DocumentType newDocType;
    113         Document ownerDocument;
    114         String publicId = "http://www.w3.org/DOM/Test/dom2.dtd";
    115         String systemId = "dom2.dtd";
    116         String qualifiedName;
    117         List<String> qualifiedNames = new ArrayList<String>();
    118         qualifiedNames.add("_:_");
    119         qualifiedNames.add("_:h0");
    120         qualifiedNames.add("_:test");
    121         qualifiedNames.add("_:_.");
    122         qualifiedNames.add("_:a-");
    123         qualifiedNames.add("l_:_");
    124         qualifiedNames.add("ns:_0");
    125         qualifiedNames.add("ns:a0");
    126         qualifiedNames.add("ns0:test");
    127         qualifiedNames.add("ns:EEE.");
    128         qualifiedNames.add("ns:_-");
    129         qualifiedNames.add("a.b:c");
    130         qualifiedNames.add("a-b:c.j");
    131         qualifiedNames.add("a-b:c");
    132 
    133         doc = (Document) load("staffNS", builder);
    134         domImpl = doc.getImplementation();
    135         for (int indexN10077 = 0; indexN10077 < qualifiedNames.size(); indexN10077++) {
    136             qualifiedName = (String) qualifiedNames.get(indexN10077);
    137             newDocType = domImpl.createDocumentType(qualifiedName, publicId,
    138                     systemId);
    139             assertNotNull("domimplementationcreatedocumenttype02_newDocType",
    140                     newDocType);
    141             ownerDocument = newDocType.getOwnerDocument();
    142             assertNull("domimplementationcreatedocumenttype02_ownerDocument",
    143                     ownerDocument);
    144         }
    145     }
    146     public void testCreateDocumentType4() throws Throwable {
    147         Document doc;
    148         DOMImplementation domImpl;
    149         DocumentType newDocType;
    150         Document ownerDocument;
    151         String publicId = "http://www.w3.org/DOM/Test/dom2.dtd";
    152         String systemId = "dom2.dtd";
    153         String qualifiedName;
    154         List<String> qualifiedNames = new ArrayList<String>();
    155         qualifiedNames.add("_:_");
    156         qualifiedNames.add("_:h0");
    157         qualifiedNames.add("_:test");
    158         qualifiedNames.add("_:_.");
    159         qualifiedNames.add("_:a-");
    160         qualifiedNames.add("l_:_");
    161         qualifiedNames.add("ns:_0");
    162         qualifiedNames.add("ns:a0");
    163         qualifiedNames.add("ns0:test");
    164         qualifiedNames.add("ns:EEE.");
    165         qualifiedNames.add("ns:_-");
    166         qualifiedNames.add("a.b:c");
    167         qualifiedNames.add("a-b:c.j");
    168         qualifiedNames.add("a-b:c");
    169 
    170         doc = (Document) load("staffNS", builder);
    171         domImpl = doc.getImplementation();
    172         for (int indexN10077 = 0; indexN10077 < qualifiedNames.size(); indexN10077++) {
    173             qualifiedName = (String) qualifiedNames.get(indexN10077);
    174             newDocType = domImpl.createDocumentType(qualifiedName, publicId,
    175                     systemId);
    176             assertNotNull("domimplementationcreatedocumenttype02_newDocType",
    177                     newDocType);
    178             ownerDocument = newDocType.getOwnerDocument();
    179             assertNull("domimplementationcreatedocumenttype02_ownerDocument",
    180                     ownerDocument);
    181         }
    182     }
    183 
    184 }
    185