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

SetNamedItemNS

public final class SetNamedItemNS extends DOMTestCase
The "setNamedItemNS(arg)" method for a NamedNodeMap should raise INUSE_ATTRIBUTE_ERR DOMException if arg is an Attr that is already an attribute of another Element object. Retrieve an attr node from the third "address" element whose local name is "domestic" and namespaceURI is "http://www.netzero.com". Invoke method setNamedItemNS(arg) on the map of the first "address" element with arg being the attr node from above. Method should raise INUSE_ATTRIBUTE_ERR DOMException.
author
NIST
author
Mary Brady
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-258A00AF')/constant[@name='INUSE_ATTRIBUTE_ERR'])
see
http://www.w3.org/TR/DOM-Level-2-Core/core#ID-setNamedItemNS
see
http://www.w3.org/TR/DOM-Level-2-Core/core#xpointer(id('ID-setNamedItemNS')/raises/exception[@name='DOMException']/descr/p[substring-before(.,':')='INUSE_ATTRIBUTE_ERR'])

Fields Summary
DOMDocumentBuilderFactory
factory
DocumentBuilder
builder
Constructors Summary
Methods Summary
protected voidsetUp()

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

        factory = null;
        builder = null;
        super.tearDown();
    
public voidtestSetNamedItemNS1()
Runs the test case.

throws
Throwable Any uncaught exception causes test to fail

      Document doc;
      NodeList elementList;
      Node anotherElement;
      NamedNodeMap anotherMap;
      Node arg;
      Node testAddress;
      NamedNodeMap map;
      
      doc = (Document) load("staffNS", builder);
      elementList = doc.getElementsByTagName("address");
      anotherElement = elementList.item(2);
      anotherMap = anotherElement.getAttributes();
      arg = anotherMap.getNamedItemNS("http://www.netzero.com", "domestic");
      testAddress = elementList.item(0);
      map = testAddress.getAttributes();
      
      {
         boolean success = false;
         try {
            map.setNamedItemNS(arg);
          } catch (DOMException ex) {
            success = (ex.code == DOMException.INUSE_ATTRIBUTE_ERR);
         }
         assertTrue("throw_INUSE_ATTRIBUTE_ERR", success);
      }
public voidtestSetNamedItemNS2()

          String namespaceURI = "http://www.usa.com";
          String qualifiedName = "dmstc:domestic";
          Document doc;
          Document anotherDoc;
          Node arg;
          NodeList elementList;
          Node testAddress;
          NamedNodeMap attributes;
         
          doc = (Document) load("staffNS", builder);
          anotherDoc = (Document) load("staffNS", builder);
          arg = anotherDoc.createAttributeNS(namespaceURI, qualifiedName);
          arg.setNodeValue("Maybe");
          elementList = doc.getElementsByTagName("address");
          testAddress = elementList.item(0);
          attributes = testAddress.getAttributes();
          
          {
             boolean success = false;
             try {
                attributes.setNamedItemNS(arg);
              } catch (DOMException ex) {
                success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
             }
             assertTrue("throw_WRONG_DOCUMENT_ERR", success);
          }
    
public voidtestSetNamedItemNS3()

          String namespaceURI = "http://www.nist.gov";
          String qualifiedName = "prefix:newAttr";
          Document doc;
          Node arg;
          NodeList elementList;
          Node testAddress;
          NamedNodeMap attributes;
          Node retnode;
          String value;
          
          doc = (Document) load("staffNS", builder);
          arg = doc.createAttributeNS(namespaceURI, qualifiedName);
          arg.setNodeValue("newValue");
          elementList = doc.getElementsByTagName("address");
          testAddress = elementList.item(0);
          attributes = testAddress.getAttributes();
          attributes.setNamedItemNS(arg);
          retnode = attributes.getNamedItemNS(namespaceURI, "newAttr");
          value = retnode.getNodeValue();
          assertEquals("throw_Equals", "newValue", value);
          
public voidtestSetNamedItemNS5()

          String namespaceURI = "http://www.usa.com";
          String qualifiedName = "dmstc:domestic";
          Document doc;
          Node arg;
          NodeList elementList;
          Node testAddress;
          NamedNodeMap attributes;
          Node retnode;
          String value;
          doc = (Document) load("staffNS", builder);
          arg = doc.createAttributeNS(namespaceURI, qualifiedName);
          arg.setNodeValue("newValue");
          elementList = doc.getElementsByTagName("address");
          testAddress = elementList.item(0);
          attributes = testAddress.getAttributes();
          retnode = attributes.setNamedItemNS(arg);
          value = retnode.getNodeValue();
          assertEquals("throw_Equals", "Yes", value);