The Android Open Source Project | a0881d0 | 2009-01-09 17:50:54 -0800 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | This Java source file was generated by test-to-java.xsl |
| 4 | and is a derived work from the source document. |
| 5 | The source document contained the following notice: |
| 6 | |
| 7 | |
| 8 | |
| 9 | Copyright (c) 2001-2004 World Wide Web Consortium, |
| 10 | (Massachusetts Institute of Technology, Institut National de |
| 11 | Recherche en Informatique et en Automatique, Keio University). All |
| 12 | Rights Reserved. This program is distributed under the W3C's Software |
| 13 | Intellectual Property License. This program is distributed in the |
| 14 | hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
| 15 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | PURPOSE. |
| 17 | |
| 18 | See W3C License http://www.w3.org/Consortium/Legal/ for more details. |
| 19 | |
| 20 | |
| 21 | */ |
| 22 | |
| 23 | package org.w3c.domts.level2.core; |
| 24 | |
| 25 | import org.w3c.dom.*; |
| 26 | |
| 27 | |
| 28 | import org.w3c.domts.DOMTestCase; |
| 29 | import org.w3c.domts.DOMTestDocumentBuilderFactory; |
| 30 | |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * The "setNamedItemNS(arg)" method for a |
| 35 | * NamedNodeMap should raise NO_MODIFICATION_ALLOWED_ERR DOMException if |
| 36 | * this map is readonly. |
| 37 | * |
| 38 | * Retrieve a list of "gender" elements. Get access to the THIRD element |
| 39 | * which contains an ENTITY_REFERENCE child node. Get access to the node's |
| 40 | * map. Try to add an attribute node specified by arg with |
| 41 | * method setNamedItemNS(arg). This should result in NO_MODIFICATION_ALLOWED_ERR |
| 42 | * DOMException. |
| 43 | * @author NIST |
| 44 | * @author Mary Brady |
| 45 | * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='NO_MODIFICATION_ALLOWED_ERR'])</a> |
| 46 | * @see <a 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> |
| 47 | * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])">http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a> |
| 48 | */ |
| 49 | public final class setNamedItemNS04 extends DOMTestCase { |
| 50 | |
| 51 | /** |
| 52 | * Constructor. |
| 53 | * @param factory document factory, may not be null |
| 54 | * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration |
| 55 | */ |
| 56 | public setNamedItemNS04(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { |
| 57 | |
| 58 | org.w3c.domts.DocumentBuilderSetting[] settings = |
| 59 | new org.w3c.domts.DocumentBuilderSetting[] { |
| 60 | org.w3c.domts.DocumentBuilderSetting.namespaceAware |
| 61 | }; |
| 62 | DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings); |
| 63 | setFactory(testFactory); |
| 64 | |
| 65 | // |
| 66 | // check if loaded documents are supported for content type |
| 67 | // |
| 68 | String contentType = getContentType(); |
| 69 | preload(contentType, "staffNS", true); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Runs the test case. |
| 74 | * @throws Throwable Any uncaught exception causes test to fail |
| 75 | */ |
| 76 | public void runTest() throws Throwable { |
| 77 | String namespaceURI = "http://www.w3.org/2000/xmlns/"; |
| 78 | String localName = "local1"; |
| 79 | Document doc; |
| 80 | NodeList elementList; |
| 81 | Node testAddress; |
| 82 | NodeList nList; |
| 83 | Node child; |
| 84 | NodeList n2List; |
| 85 | Node child2; |
| 86 | NamedNodeMap attributes; |
| 87 | Node arg; |
| 88 | Node setNode; |
| 89 | int nodeType; |
| 90 | doc = (Document) load("staffNS", true); |
| 91 | elementList = doc.getElementsByTagName("gender"); |
| 92 | testAddress = elementList.item(2); |
| 93 | nList = testAddress.getChildNodes(); |
| 94 | child = nList.item(0); |
| 95 | nodeType = (int) child.getNodeType(); |
| 96 | |
| 97 | if (equals(1, nodeType)) { |
| 98 | child = doc.createEntityReference("ent4"); |
| 99 | assertNotNull("createdEntRefNotNull", child); |
| 100 | } |
| 101 | n2List = child.getChildNodes(); |
| 102 | child2 = n2List.item(0); |
| 103 | assertNotNull("notnull", child2); |
| 104 | attributes = child2.getAttributes(); |
| 105 | arg = attributes.getNamedItemNS(namespaceURI, localName); |
| 106 | |
| 107 | { |
| 108 | boolean success = false; |
| 109 | try { |
| 110 | setNode = attributes.setNamedItemNS(arg); |
| 111 | } catch (DOMException ex) { |
| 112 | success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR); |
| 113 | } |
| 114 | assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success); |
| 115 | } |
| 116 | } |
| 117 | /** |
| 118 | * Gets URI that identifies the test. |
| 119 | * @return uri identifier of test |
| 120 | */ |
| 121 | public String getTargetURI() { |
| 122 | return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setNamedItemNS04"; |
| 123 | } |
| 124 | /** |
| 125 | * Runs this test from the command line. |
| 126 | * @param args command line arguments |
| 127 | */ |
| 128 | public static void main(final String[] args) { |
| 129 | DOMTestCase.doMain(setNamedItemNS04.class, args); |
| 130 | } |
| 131 | } |
| 132 | |