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 import org.w3c.dom.DOMException; 31 32 import javax.xml.parsers.DocumentBuilder; 33 34 /** 35 * The "createDocument(namespaceURI,qualifiedName,doctype)" method for a 36 * DOMImplementation should raise NAMESPACE_ERR DOMException if parameter 37 * qualifiedName is malformed. 38 * 39 * Retrieve the DOMImplementation on the XMLNS Document. Invoke method 40 * createDocument(namespaceURI,qualifiedName,doctype) on the retrieved 41 * DOMImplementation with namespaceURI being the literal string 42 * "http://www.ecommerce.org/", qualifiedName as "prefix::local", and doctype as 43 * null. Method should raise NAMESPACE_ERR DOMException. 44 * 45 * @author NIST 46 * @author Mary Brady 47 * @see <a 48 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NAMESPACE_ERR'])</a> 49 * @see <a 50 * 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> 51 * @see <a 52 * href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('Level-2-Core-DOM-createDocument')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NAMESPACE_ERR'])</a> 53 */ 54 public final class CreateDocument extends DOMTestCase { 55 56 DOMDocumentBuilderFactory factory; 57 58 DocumentBuilder builder; 59 setUp()60 protected void setUp() throws Exception { 61 super.setUp(); 62 try { 63 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 64 .getConfiguration1()); 65 builder = factory.getBuilder(); 66 } catch (Exception e) { 67 fail("Unexpected exception" + e.getMessage()); 68 } 69 } 70 tearDown()71 protected void tearDown() throws Exception { 72 factory = null; 73 builder = null; 74 super.tearDown(); 75 } 76 77 /** 78 * Runs the test case. 79 * 80 * @throws Throwable 81 * Any uncaught exception causes test to fail 82 */ testCreateDocument1()83 public void testCreateDocument1() throws Throwable { 84 String namespaceURI = "http://www.ecommerce.org/"; 85 String malformedName = "prefix::local"; 86 Document doc; 87 DocumentType docType = null; 88 89 DOMImplementation domImpl; 90 91 doc = (Document) load("staffNS", builder); 92 domImpl = doc.getImplementation(); 93 94 boolean success = false; 95 try { 96 domImpl.createDocument(namespaceURI, malformedName, docType); 97 } catch (DOMException ex) { 98 success = (ex.code == DOMException.NAMESPACE_ERR); 99 } 100 assertTrue("throw_NAMESPACE_ERR", success); 101 102 } testCreateDocument2()103 public void testCreateDocument2() throws Throwable { 104 String namespaceURI = null; 105 106 String qualifiedName = "k:local"; 107 Document doc; 108 DocumentType docType = null; 109 110 DOMImplementation domImpl; 111 112 doc = (Document) load("staffNS", builder); 113 domImpl = doc.getImplementation(); 114 115 boolean success = false; 116 try { 117 domImpl.createDocument(namespaceURI, qualifiedName, docType); 118 } catch (DOMException ex) { 119 success = (ex.code == DOMException.NAMESPACE_ERR); 120 } 121 assertTrue("throw_NAMESPACE_ERR", success); 122 123 } 124 125 // public void testCreateDocument3() throws Throwable { 126 // String namespaceURI = "http://www.ecommerce.org/schema"; 127 // String qualifiedName = "namespaceURI:x"; 128 // Document doc; 129 // DocumentType docType; 130 // DOMImplementation domImpl; 131 // 132 // doc = (Document) load("staffNS", builder); 133 // docType = doc.getDoctype(); 134 // domImpl = doc.getImplementation(); 135 // 136 // boolean success = false; 137 // try { 138 // domImpl.createDocument(namespaceURI, qualifiedName, docType); 139 // } catch (DOMException ex) { 140 // success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); 141 // } 142 // assertTrue("throw_WRONG_DOCUMENT_ERR", success); 143 // 144 // } 145 146 // public void testCreateDocument4() throws Throwable { 147 // String namespaceURI = "http://www.ecommerce.org/schema"; 148 // String qualifiedName = "namespaceURI:x"; 149 // Document doc; 150 // DocumentType docType; 151 // DOMImplementation domImpl; 152 // Document aNewDoc; 153 // doc = (Document) load("staffNS", builder); 154 // aNewDoc = (Document) load("staffNS", builder); 155 // docType = doc.getDoctype(); 156 // domImpl = aNewDoc.getImplementation(); 157 // 158 // boolean success = false; 159 // try { 160 // aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName, 161 // docType); 162 // } catch (DOMException ex) { 163 // success = (ex.code == DOMException.WRONG_DOCUMENT_ERR); 164 // } 165 // assertTrue("throw_WRONG_DOCUMENT_ERR", success); 166 // 167 // } testCreateDocument5()168 public void testCreateDocument5() throws Throwable { 169 String namespaceURI = "http://www.ecommerce.org/schema"; 170 String qualifiedName; 171 Document doc; 172 DocumentType docType = null; 173 174 DOMImplementation domImpl; 175 176 List<String> illegalQNames = new ArrayList<String>(); 177 illegalQNames.add("namespaceURI:{"); 178 illegalQNames.add("namespaceURI:}"); 179 illegalQNames.add("namespaceURI:~"); 180 illegalQNames.add("namespaceURI:'"); 181 illegalQNames.add("namespaceURI:!"); 182 illegalQNames.add("namespaceURI:@"); 183 illegalQNames.add("namespaceURI:#"); 184 illegalQNames.add("namespaceURI:$"); 185 illegalQNames.add("namespaceURI:%"); 186 illegalQNames.add("namespaceURI:^"); 187 illegalQNames.add("namespaceURI:&"); 188 illegalQNames.add("namespaceURI:*"); 189 illegalQNames.add("namespaceURI:("); 190 illegalQNames.add("namespaceURI:)"); 191 illegalQNames.add("namespaceURI:+"); 192 illegalQNames.add("namespaceURI:="); 193 illegalQNames.add("namespaceURI:["); 194 illegalQNames.add("namespaceURI:]"); 195 illegalQNames.add("namespaceURI:\\"); 196 illegalQNames.add("namespaceURI:/"); 197 illegalQNames.add("namespaceURI:;"); 198 illegalQNames.add("namespaceURI:`"); 199 illegalQNames.add("namespaceURI:<"); 200 illegalQNames.add("namespaceURI:>"); 201 illegalQNames.add("namespaceURI:,"); 202 illegalQNames.add("namespaceURI:a "); 203 illegalQNames.add("namespaceURI:\""); 204 205 doc = (Document) load("staffNS", builder); 206 for (int indexN1009A = 0; indexN1009A < illegalQNames.size(); indexN1009A++) { 207 qualifiedName = (String) illegalQNames.get(indexN1009A); 208 domImpl = doc.getImplementation(); 209 210 boolean success = false; 211 try { 212 domImpl.createDocument(namespaceURI, qualifiedName, docType); 213 } catch (DOMException ex) { 214 success = (ex.code == DOMException.INVALID_CHARACTER_ERR); 215 } 216 assertTrue("throw_INVALID_CHARACTER_ERR", success); 217 218 } 219 } testCreateDocument6()220 public void testCreateDocument6() throws Throwable { 221 String namespaceURI = "http://ecommerce.org/schema"; 222 String qualifiedName = "xml:local"; 223 Document doc; 224 DocumentType docType = null; 225 226 DOMImplementation domImpl; 227 228 doc = (Document) load("staffNS", builder); 229 domImpl = doc.getImplementation(); 230 231 boolean success = false; 232 try { 233 domImpl.createDocument(namespaceURI, qualifiedName, docType); 234 } catch (DOMException ex) { 235 success = (ex.code == DOMException.NAMESPACE_ERR); 236 } 237 assertTrue("throw_NAMESPACE_ERR", success); 238 239 } testCreateDocument7()240 public void testCreateDocument7() throws Throwable { 241 String namespaceURI = "http://www.ecommerce.org/schema"; 242 String qualifiedName = "y:x"; 243 Document doc; 244 DocumentType docType = null; 245 246 DOMImplementation domImpl; 247 Document aNewDoc; 248 String nodeName; 249 String nodeValue; 250 doc = (Document) load("staffNS", builder); 251 domImpl = doc.getImplementation(); 252 aNewDoc = domImpl.createDocument(namespaceURI, qualifiedName, docType); 253 nodeName = aNewDoc.getNodeName(); 254 nodeValue = aNewDoc.getNodeValue(); 255 assertEquals("nodeName", "#document", nodeName); 256 assertNull("nodeValue", nodeValue); 257 } testCreateDocument8()258 public void testCreateDocument8() throws Throwable { 259 String namespaceURI = "http://www.example.org/schema"; 260 DocumentType docType = null; 261 262 DOMImplementation domImpl; 263 264 domImpl = builder.getDOMImplementation(); 265 266 // BEGIN android-changed 267 // Our exception priorities differ from the spec 268 try { 269 domImpl.createDocument(namespaceURI, "", docType); 270 fail(); 271 } catch (DOMException ex) { 272 } 273 // END android-changed 274 } 275 } 276