FileDocCategorySizeDatePackage
RemoveAttributeNS.javaAPI DocAndroid 1.5 API5557Wed May 06 22:41:06 BST 2009tests.org.w3c.dom

RemoveAttributeNS.java

/*
 This Java source file was generated by test-to-java.xsl
 and is a derived work from the source document.
 The source document contained the following notice:



 Copyright (c) 2001-2004 World Wide Web Consortium, 
 (Massachusetts Institute of Technology, Institut National de
 Recherche en Informatique et en Automatique, Keio University).  All 
 Rights Reserved.  This program is distributed under the W3C's Software
 Intellectual Property License.  This program is distributed in the 
 hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 PURPOSE.  

 See W3C License http://www.w3.org/Consortium/Legal/ for more details.


 */

package tests.org.w3c.dom;

import dalvik.annotation.TestTargetClass; 

import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * The "removeAttributeNS(namespaceURI,localName)" method for an attribute
 * causes the DOMException NO_MODIFICATION_ALLOWED_ERR to be raised if the node
 * is readonly.
 * 
 * Obtain the children of the THIRD "gender" element. The elements content is an
 * entity reference. Try to remove an attribute from the entity reference by
 * executing the "removeAttributeNS(namespaceURI,localName)" method. This causes
 * a NO_MODIFICATION_ALLOWED_ERR DOMException to be thrown.
 * 
 * @author NIST
 * @author Mary Brady
 * @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>
 * @see <a
 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElRemAtNS</a>
 * @see <a
 *      href="http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-ElRemAtNS')/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-ElRemAtNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='NO_MODIFICATION_ALLOWED_ERR'])</a>
 */
@TestTargetClass(Attr.class) 
public final class RemoveAttributeNS extends DOMTestCase {

    DOMDocumentBuilderFactory factory;

    DocumentBuilder builder;

    protected void setUp() throws Exception {
        super.setUp();
        try {
            factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory
                    .getConfiguration2());
            builder = factory.getBuilder();
        } catch (Exception e) {
            fail("Unexpected exception" + e.getMessage());
        }
    }

    protected void tearDown() throws Exception {
        factory = null;
        builder = null;
        super.tearDown();
    }

    /**
     * Runs the test case.
     * 
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
// Assumes validation.
//    public void testRemoveAttributeNS1() throws Throwable {
//        Document doc;
//        NodeList genderList;
//        Node gender;
//        Node gen;
//        NodeList gList;
//        Element genElement;
//        int nodeType;
//        doc = (Document) load("staffNS", builder);
//        genderList = doc.getElementsByTagName("gender");
//        gender = genderList.item(2);
//        gen = gender.getFirstChild();
//        nodeType = (int) gen.getNodeType();
//
//        if (1 == nodeType) {
//            gen = doc.createEntityReference("ent4");
//            assertNotNull("createdEntRefNotNull", gen);
//        }
//        gList = gen.getChildNodes();
//        genElement = (Element) gList.item(0);
//        assertNotNull("notnull", genElement);
//
//        {
//            boolean success = false;
//            try {
//                genElement.removeAttributeNS("www.xyz.com", "local1");
//            } catch (DOMException ex) {
//                success = (ex.code == DOMException.NO_MODIFICATION_ALLOWED_ERR);
//            }
//            assertTrue("throw_NO_MODIFICATION_ALLOWED_ERR", success);
//        }
//    }

// Assumes validation
//    public void testRemoveAttributeNS2() throws Throwable {
//        Document doc;
//        NodeList elementList;
//        Node testAddr;
//        Attr addrAttr;
//        String attr;
//        String namespaceURI;
//        String localName;
//        String prefix;
//        doc = (Document) load("staffNS", builder);
//        elementList = doc.getElementsByTagName("emp:address");
//        testAddr = elementList.item(0);
//        ((Element) /* Node */testAddr).removeAttributeNS("http://www.nist.gov",
//                "local1");
//        elementList = doc.getElementsByTagName("emp:address");
//        testAddr = elementList.item(0);
//        addrAttr = ((Element) /* Node */testAddr).getAttributeNodeNS(
//                "http://www.nist.gov", "local1");
//        attr = ((Element) /* Node */testAddr).getAttributeNS(
//                "http://www.nist.gov", "local1");
//        namespaceURI = addrAttr.getNamespaceURI();
//        localName = addrAttr.getLocalName();
//        prefix = testAddr.getPrefix();
//        assertEquals("attr", "FALSE", attr);
//        assertEquals("uri", "http://www.nist.gov", namespaceURI);
//        assertEquals("lname", "local1", localName);
//        assertEquals("prefix", "emp", prefix);
//    }
}