1 package tests.org.w3c.dom; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 import org.w3c.dom.DOMImplementation; 7 import org.w3c.dom.Document; 8 9 import javax.xml.parsers.DocumentBuilder; 10 11 /** 12 * The "feature" parameter in the "hasFeature(feature,version)" method is the 13 * package name of the feature. Legal values are XML and HTML and CORE. (Test 14 * for feature core, lower case) 15 * 16 * Retrieve the entire DOM document and invoke its "getImplementation()" method. 17 * This should create a DOMImplementation object whose "hasFeature(feature, 18 * version)" method is invoked with feature equal to "core". The method should 19 * return a boolean "true". 20 * 21 * @author NIST 22 * @author Mary Brady 23 * @see <a 24 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-5CED94D7">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-5CED94D7</a> 25 */ 26 public final class DOMImplementationHasFeature extends DOMTestCase { 27 28 DOMDocumentBuilderFactory factory; 29 30 DocumentBuilder builder; 31 setUp()32 protected void setUp() throws Exception { 33 super.setUp(); 34 try { 35 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 36 .getConfiguration1()); 37 builder = factory.getBuilder(); 38 } catch (Exception e) { 39 fail("Unexpected exception" + e.getMessage()); 40 } 41 } 42 tearDown()43 protected void tearDown() throws Exception { 44 factory = null; 45 builder = null; 46 super.tearDown(); 47 } 48 49 /** 50 * Runs the test case. 51 * 52 * @throws Throwable 53 * Any uncaught exception causes test to fail 54 */ testHasFeatureCore()55 public void testHasFeatureCore() throws Throwable { 56 Document doc; 57 DOMImplementation domImpl; 58 boolean state; 59 doc = (Document) load("staff", builder); 60 domImpl = doc.getImplementation(); 61 state = domImpl.hasFeature("core", "2.0"); 62 assertTrue("domimplementationFeaturecoreAssert", state); 63 } testHasFeatureXml()64 public void testHasFeatureXml() throws Throwable { 65 Document doc; 66 DOMImplementation domImpl; 67 boolean state; 68 doc = (Document) load("staff", builder); 69 domImpl = doc.getImplementation(); 70 state = domImpl.hasFeature("xml", "2.0"); 71 assertTrue("domimplementationFeaturexmlVersion2Assert", state); 72 } testHasFeature1()73 public void testHasFeature1() throws Throwable { 74 Document doc; 75 DOMImplementation domImpl; 76 String version = ""; 77 String version1 = "1.0"; 78 String version2 = "2.0"; 79 String featureCore; 80 String featureXML; 81 boolean success; 82 List<String> featuresXML = new ArrayList<String>(); 83 featuresXML.add("XML"); 84 featuresXML.add("xmL"); 85 86 List<String> featuresCore = new ArrayList<String>(); 87 featuresCore.add("Core"); 88 featuresCore.add("CORE"); 89 90 doc = (Document) load("staffNS", builder); 91 domImpl = doc.getImplementation(); 92 for (int indexN10063 = 0; indexN10063 < featuresXML.size(); indexN10063++) { 93 featureXML = (String) featuresXML.get(indexN10063); 94 success = domImpl.hasFeature(featureXML, version); 95 assertTrue("domimplementationhasfeature01_XML_1", success); 96 success = domImpl.hasFeature(featureXML, version1); 97 assertTrue("domimplementationhasfeature01_XML_2", success); 98 } 99 for (int indexN1007C = 0; indexN1007C < featuresCore.size(); indexN1007C++) { 100 featureCore = (String) featuresCore.get(indexN1007C); 101 success = domImpl.hasFeature(featureCore, version); 102 assertTrue("domimplementationhasfeature01_Core_1", success); 103 success = domImpl.hasFeature(featureCore, version1); 104 success = domImpl.hasFeature(featureCore, version2); 105 assertTrue("domimplementationhasfeature01_Core_3", success); 106 } 107 } testHasFeature2()108 public void testHasFeature2() throws Throwable { 109 Document doc; 110 DOMImplementation domImpl; 111 boolean success; 112 doc = (Document) load("staffNS", builder); 113 domImpl = doc.getImplementation(); 114 success = domImpl.hasFeature("Blah Blah", ""); 115 assertFalse("domimplementationhasfeature02", success); 116 } 117 } 118