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  Copyright (c) 2001-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.Element;
     24 import org.w3c.dom.DOMException;
     25 
     26 import javax.xml.parsers.DocumentBuilder;
     27 
     28 /**
     29  * Attempt to insert an element into an attribute list, should raise a
     30  * HIERARCHY_REQUEST_ERR.
     31  *
     32  * @author Curt Arnold
     33  * @see <a
     34  *      href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='HIERARCHY_REQUEST_ERR'])">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='HIERARCHY_REQUEST_ERR'])</a>
     35  * @see <a
     36  *      href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-1025163788</a>
     37  * @see <a
     38  *      href="http://www.w3.org/2000/11/DOM-Level-2-errata#core-4">http://www.w3.org/2000/11/DOM-Level-2-errata#core-4</a>
     39  */
     40 public final class HCNamedNodeMapInvalidType extends DOMTestCase {
     41 
     42     DOMDocumentBuilderFactory factory;
     43 
     44     DocumentBuilder builder;
     45 
     46     protected void setUp() throws Exception {
     47         super.setUp();
     48         try {
     49             factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
     50                     .getConfiguration1());
     51             builder = factory.getBuilder();
     52         } catch (Exception e) {
     53             fail("Unexpected exception" + e.getMessage());
     54         }
     55     }
     56 
     57     protected void tearDown() throws Exception {
     58         factory = null;
     59         builder = null;
     60         super.tearDown();
     61     }
     62 
     63     /**
     64      * Runs the test case.
     65      *
     66      * @throws Throwable
     67      *             Any uncaught exception causes test to fail
     68      */
     69     public void testNamedNodeMapInvalidType() throws Throwable {
     70         Document doc;
     71         NamedNodeMap attributes;
     72         Element docElem;
     73         Element newElem;
     74 
     75         doc = (Document) load("hc_staff", builder);
     76         docElem = doc.getDocumentElement();
     77         attributes = docElem.getAttributes();
     78         newElem = doc.createElement("html");
     79 
     80         {
     81             boolean success = false;
     82             try {
     83                 attributes.setNamedItem(newElem);
     84             } catch (DOMException ex) {
     85                 success = (ex.code == DOMException.HIERARCHY_REQUEST_ERR);
     86             }
     87             assertTrue("throw_HIERARCHY_REQUEST_ERR", success);
     88         }
     89     }
     90 
     91 }
     92