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 java.util.ArrayList;
     25 import java.util.List;
     26 
     27 import org.w3c.dom.Node;
     28 import org.w3c.dom.Document;
     29 import org.w3c.dom.Element;
     30 import org.w3c.dom.Attr;
     31 import org.w3c.dom.DocumentType;
     32 import org.w3c.dom.EntityReference;
     33 import org.w3c.dom.ProcessingInstruction;
     34 
     35 import javax.xml.parsers.DocumentBuilder;
     36 
     37 /**
     38  * The method "isSupported(feature,version)" Tests whether the DOM
     39  * implementation implements a specific feature and that feature is supported by
     40  * this node.
     41  *
     42  * Call the isSupported method on the document element node with a combination
     43  * of features versions and versions as below. Valid feature names are case
     44  * insensitive and versions "2.0", "1.0" and if the version is not specified,
     45  * supporting any version of the feature should return true. Check if the value
     46  * returned value was true.
     47  *
     48  * @author IBM
     49  * @author Neil Delima
     50  * @see <a
     51  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-Node-supports">http://www.w3.org/TR/DOM-Level-2-Core/core#Level-2-Core-Node-supports</a>
     52  */
     53 public final class NodeIsSupported extends DOMTestCase {
     54 
     55     DOMDocumentBuilderFactory factory;
     56 
     57     DocumentBuilder builder;
     58 
     59     protected void setUp() throws Exception {
     60         super.setUp();
     61         try {
     62             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     63                     .getConfiguration1());
     64             builder = factory.getBuilder();
     65         } catch (Exception e) {
     66             fail("Unexpected exception" + e.getMessage());
     67         }
     68     }
     69 
     70     protected void tearDown() throws Exception {
     71         factory = null;
     72         builder = null;
     73         super.tearDown();
     74     }
     75 
     76     /**
     77      * Runs the test case.
     78      *
     79      * @throws Throwable
     80      *             Any uncaught exception causes test to fail
     81      */
     82     public void testIsSupported1() throws Throwable {
     83         Document doc;
     84         Element element;
     85         String version = "";
     86         String version1 = "1.0";
     87         String version2 = "2.0";
     88         String featureCore;
     89         String featureXML;
     90         boolean success;
     91         List<String> featuresXML = new ArrayList<String>();
     92         featuresXML.add("XML");
     93         featuresXML.add("xmL");
     94 
     95         List<String> featuresCore = new ArrayList<String>();
     96         featuresCore.add("Core");
     97         featuresCore.add("CORE");
     98 
     99         doc = (Document) load("staffNS", builder);
    100         element = doc.getDocumentElement();
    101         for (int indexN10063 = 0; indexN10063 < featuresXML.size(); indexN10063++) {
    102             featureXML = (String) featuresXML.get(indexN10063);
    103             success = element.isSupported(featureXML, version);
    104             assertTrue("nodeissupported01_XML1", success);
    105             success = element.isSupported(featureXML, version1);
    106             assertTrue("nodeissupported01_XML2", success);
    107         }
    108         for (int indexN1007C = 0; indexN1007C < featuresCore.size(); indexN1007C++) {
    109             featureCore = (String) featuresCore.get(indexN1007C);
    110             success = element.isSupported(featureCore, version);
    111             assertTrue("nodeissupported01_Core1", success);
    112             success = element.isSupported(featureCore, version1);
    113             success = element.isSupported(featureCore, version2);
    114             assertTrue("nodeissupported01_Core3", success);
    115         }
    116     }
    117     public void testIsSupported2() throws Throwable {
    118         Document doc;
    119         Attr attribute;
    120         String version = "";
    121         String version1 = "1.0";
    122         String version2 = "2.0";
    123         String featureCore;
    124         String featureXML;
    125         boolean success;
    126         List<String> featuresXML = new ArrayList<String>();
    127         featuresXML.add("XML");
    128         featuresXML.add("xmL");
    129 
    130         List<String> featuresCore = new ArrayList<String>();
    131         featuresCore.add("Core");
    132         featuresCore.add("CORE");
    133 
    134         doc = (Document) load("staffNS", builder);
    135         attribute = doc.createAttribute("TestAttr");
    136         for (int indexN10064 = 0; indexN10064 < featuresXML.size(); indexN10064++) {
    137             featureXML = (String) featuresXML.get(indexN10064);
    138             success = attribute.isSupported(featureXML, version);
    139             assertTrue("nodeissupported02_XML1", success);
    140             success = attribute.isSupported(featureXML, version1);
    141             assertTrue("nodeissupported02_XML2", success);
    142         }
    143         for (int indexN1007D = 0; indexN1007D < featuresCore.size(); indexN1007D++) {
    144             featureCore = (String) featuresCore.get(indexN1007D);
    145             success = attribute.isSupported(featureCore, version);
    146             assertTrue("nodeissupported02_Core1", success);
    147             success = attribute.isSupported(featureCore, version1);
    148             success = attribute.isSupported(featureCore, version2);
    149             assertTrue("nodeissupported02_Core3", success);
    150         }
    151     }
    152     public void testIsSupported3() throws Throwable {
    153         Document doc;
    154         DocumentType docType;
    155         boolean success;
    156         doc = (Document) load("staffNS", builder);
    157         docType = doc.getDoctype();
    158         success = docType.isSupported("", "");
    159         assertFalse("nodeissupported03", success);
    160     }
    161     public void testIsSupported4() throws Throwable {
    162         Document doc;
    163         EntityReference entRef;
    164         boolean success;
    165         doc = (Document) load("staffNS", builder);
    166         entRef = doc.createEntityReference("ent1");
    167         assertNotNull("createdEntRefNotNull", entRef);
    168         success = entRef.isSupported("XML CORE", "");
    169         assertFalse("nodeissupported04", success);
    170     }
    171     public void testIsSupported5() throws Throwable {
    172         Document doc;
    173         ProcessingInstruction pi;
    174         boolean success;
    175         doc = (Document) load("staffNS", builder);
    176         pi = doc.createProcessingInstruction("PITarget", "PIData");
    177         success = pi.isSupported("-", "+");
    178         assertFalse("nodeissupported05", success);
    179     }
    180 }
    181