• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  Copyright (c) 2004 World Wide Web Consortium,
8  (Massachusetts Institute of Technology, Institut National de
9  Recherche en Informatique et en Automatique, Keio University). All
10  Rights Reserved. This program is distributed under the W3C's Software
11  Intellectual Property License. This program is distributed in the
12  hope that it will be useful, but WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE.
15  See W3C License http://www.w3.org/Consortium/Legal/ for more details.
16 
17  */
18 
19 package tests.org.w3c.dom;
20 
21 import org.w3c.dom.NamedNodeMap;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.DocumentType;
24 import org.w3c.dom.Element;
25 import org.w3c.dom.DOMException;
26 
27 import javax.xml.parsers.DocumentBuilder;
28 
29 /**
30  * An attempt to add an element to the named node map returned by notations
31  * should result in a NO_MODIFICATION_ERR or HIERARCHY_REQUEST_ERR.
32  *
33  * @author Curt Arnold
34  * @see <a
35  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D46829EF">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-D46829EF</a>
36  * @see <a
37  *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS</a>
38  */
39 public final class HCNotationsSetNamedItemNS extends DOMTestCase {
40 
41     DOMDocumentBuilderFactory factory;
42 
43     DocumentBuilder builder;
44 
setUp()45     protected void setUp() throws Exception {
46         super.setUp();
47         try {
48             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
49                     .getConfiguration1());
50             builder = factory.getBuilder();
51         } catch (Exception e) {
52             fail("Unexpected exception" + e.getMessage());
53         }
54     }
55 
tearDown()56     protected void tearDown() throws Exception {
57         factory = null;
58         builder = null;
59         super.tearDown();
60     }
61 
62     /**
63      * Runs the test case.
64      *
65      * @throws Throwable
66      *             Any uncaught exception causes test to fail
67      */
testNotationsSetNamedItemNS()68     public void testNotationsSetNamedItemNS() throws Throwable {
69         Document doc;
70         NamedNodeMap notations;
71         DocumentType docType;
72 
73         Element elem;
74         doc = (Document) load("hc_staff", builder);
75         docType = doc.getDoctype();
76 
77         if (!(("text/html".equals(getContentType())))) {
78             assertNotNull("docTypeNotNull", docType);
79             notations = docType.getNotations();
80             assertNotNull("notationsNotNull", notations);
81             elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "br");
82 
83             try {
84                 notations.setNamedItemNS(elem);
85                 fail("throw_HIER_OR_NO_MOD_ERR");
86 
87             } catch (DOMException ex) {
88                 switch (ex.code) {
89                 case 3:
90                     break;
91                 case 7:
92                     break;
93                 default:
94                     throw ex;
95                 }
96             }
97         }
98     }
99 
100 }
101