1
2/*
3This Java source file was generated by test-to-java.xsl
4and is a derived work from the source document.
5The source document contained the following notice:
6
7
8Copyright (c) 2001-2004 World Wide Web Consortium,
9(Massachusetts Institute of Technology, Institut National de
10Recherche en Informatique et en Automatique, Keio University). All
11Rights Reserved. This program is distributed under the W3C's Software
12Intellectual Property License. This program is distributed in the
13hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15PURPOSE.
16See W3C License http://www.w3.org/Consortium/Legal/ for more details.
17
18*/
19
20package org.w3c.domts.level1.core;
21
22import org.w3c.dom.*;
23
24
25import org.w3c.domts.DOMTestCase;
26import org.w3c.domts.DOMTestDocumentBuilderFactory;
27
28
29
30/**
31 *     The "setValue()" method for an attribute causes the
32 *   DOMException NO_MODIFICATION_ALLOWED_ERR to be raised
33 *   if the node is readonly.
34 *   Obtain the children of the THIRD "gender" element.  The elements
35 *   content is an entity reference.  Get the "domestic" attribute
36 *   from the entity reference and execute the "setValue()" method.
37 *   This causes a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
38* @author NIST
39* @author Mary Brady
40* @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])</a>
41* @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#ID-221662474">http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#ID-221662474</a>
42* @see <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#xpointer(id('ID-221662474')/setraises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-core#xpointer(id('ID-221662474')/setraises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
43* @see <a href="http://www.w3.org/DOM/updates/REC-DOM-Level-1-19981001-errata.html">http://www.w3.org/DOM/updates/REC-DOM-Level-1-19981001-errata.html</a>
44* @see <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-221662474">http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core#ID-221662474</a>
45*/
46public final class attrsetvaluenomodificationallowederr extends DOMTestCase {
47
48   /**
49    * Constructor.
50    * @param factory document factory, may not be null
51    * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
52    */
53   public attrsetvaluenomodificationallowederr(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
54
55      org.w3c.domts.DocumentBuilderSetting[] settings =
56          new org.w3c.domts.DocumentBuilderSetting[] {
57org.w3c.domts.DocumentBuilderSetting.notExpandEntityReferences
58        };
59        DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
60        setFactory(testFactory);
61
62    //
63    //   check if loaded documents are supported for content type
64    //
65    String contentType = getContentType();
66    preload(contentType, "staff", true);
67    }
68
69   /**
70    * Runs the test case.
71    * @throws Throwable Any uncaught exception causes test to fail
72    */
73   public void runTest() throws Throwable {
74      Document doc;
75      NodeList genderList;
76      Node gender;
77      NodeList genList;
78      Node gen;
79      NodeList gList;
80      Node g;
81      NamedNodeMap attrList;
82      Attr attrNode;
83      doc = (Document) load("staff", true);
84      genderList = doc.getElementsByTagName("gender");
85      gender = genderList.item(2);
86      assertNotNull("genderNotNull", gender);
87      genList = gender.getChildNodes();
88      gen = genList.item(0);
89      assertNotNull("genderFirstChildNotNull", gen);
90      gList = gen.getChildNodes();
91      g = gList.item(0);
92      assertNotNull("genderFirstGrandchildNotNull", g);
93      attrList = g.getAttributes();
94      assertNotNull("attributesNotNull", attrList);
95      attrNode = (Attr) attrList.getNamedItem("domestic");
96      assertNotNull("attrNotNull", attrNode);
97
98      {
99         boolean success = false;
100         try {
101            attrNode.setValue("newvalue");
102          } catch (DOMException ex) {
103            success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
104         }
105         assertTrue("setValue_throws_NO_MODIFICATION", success);
106      }
107
108      {
109         boolean success = false;
110         try {
111            attrNode.setNodeValue("newvalue2");
112          } catch (DOMException ex) {
113            success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
114         }
115         assertTrue("setNodeValue_throws_NO_MODIFICATION", success);
116      }
117}
118   /**
119    *  Gets URI that identifies the test.
120    *  @return uri identifier of test
121    */
122   public String getTargetURI() {
123      return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/attrsetvaluenomodificationallowederr";
124   }
125   /**
126    * Runs this test from the command line.
127    * @param args command line arguments
128    */
129   public static void main(final String[] args) {
130        DOMTestCase.doMain(attrsetvaluenomodificationallowederr.class, args);
131   }
132}
133
134