Home | History | Annotate | Download | only in core
      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 "setAttributeNS(namespaceURI,qualifiedName,value)" method adds a new attribute.
     35  *    If an attribute with the same local name and namespace URI is already present
     36  *    on the element, its prefix is changed to be the prefix part of the "qualifiedName",
     37  *    and its vale is changed to be the "value" paramter.
     38  *    null value if no previously existing Attr node with the
     39  *    same name was replaced.
     40  *
     41  *    Add a new attribute to the "emp:address" element.
     42  *    Check to see if the new attribute has been successfully added to the document
     43  *    by getting the attributes value, namespace URI, local Name and prefix.
     44  *    The prefix will be changed to the prefix part of the "qualifiedName"
     45  *    and its value changed to the "value" parameter.
     46 * @author NIST
     47 * @author Mary Brady
     48 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#">http://www.w3.org/TR/DOM-Level-2-Core/core#</a>
     49 */
     50 public final class setAttributeNS04 extends DOMTestCase {
     51 
     52    /**
     53     * Constructor.
     54     * @param factory document factory, may not be null
     55     * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
     56     */
     57    public setAttributeNS04(final DOMTestDocumentBuilderFactory factory)  throws org.w3c.domts.DOMTestIncompatibleException {
     58 
     59       org.w3c.domts.DocumentBuilderSetting[] settings =
     60           new org.w3c.domts.DocumentBuilderSetting[] {
     61 org.w3c.domts.DocumentBuilderSetting.namespaceAware
     62         };
     63         DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings);
     64         setFactory(testFactory);
     65 
     66     //
     67     //   check if loaded documents are supported for content type
     68     //
     69     String contentType = getContentType();
     70     preload(contentType, "staffNS", true);
     71     }
     72 
     73    /**
     74     * Runs the test case.
     75     * @throws Throwable Any uncaught exception causes test to fail
     76     */
     77    public void runTest() throws Throwable {
     78       Document doc;
     79       NodeList elementList;
     80       Node testAddr;
     81       Attr addrAttr;
     82       String resultAttr;
     83       String resultNamespaceURI;
     84       String resultLocalName;
     85       String resultPrefix;
     86       doc = (Document) load("staffNS", true);
     87       elementList = doc.getElementsByTagName("emp:address");
     88       testAddr = elementList.item(0);
     89       assertNotNull("empAddrNotNull", testAddr);
     90       ((Element) /*Node */testAddr).setAttributeNS("http://www.nist.gov", "newprefix:zone", "newValue");
     91       addrAttr = ((Element) /*Node */testAddr).getAttributeNodeNS("http://www.nist.gov", "zone");
     92       resultAttr = ((Element) /*Node */testAddr).getAttributeNS("http://www.nist.gov", "zone");
     93       assertEquals("attrValue", "newValue", resultAttr);
     94       resultNamespaceURI = addrAttr.getNamespaceURI();
     95       assertEquals("nsuri", "http://www.nist.gov", resultNamespaceURI);
     96       resultLocalName = addrAttr.getLocalName();
     97       assertEquals("lname", "zone", resultLocalName);
     98       resultPrefix = addrAttr.getPrefix();
     99       assertEquals("prefix", "newprefix", resultPrefix);
    100       }
    101    /**
    102     *  Gets URI that identifies the test.
    103     *  @return uri identifier of test
    104     */
    105    public String getTargetURI() {
    106       return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNS04";
    107    }
    108    /**
    109     * Runs this test from the command line.
    110     * @param args command line arguments
    111     */
    112    public static void main(final String[] args) {
    113         DOMTestCase.doMain(setAttributeNS04.class, args);
    114    }
    115 }
    116 
    117