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 8 9Copyright (c) 2001 World Wide Web Consortium, 10(Massachusetts Institute of Technology, Institut National de 11Recherche en Informatique et en Automatique, Keio University). All 12Rights Reserved. This program is distributed under the W3C's Software 13Intellectual Property License. This program is distributed in the 14hope that it will be useful, but WITHOUT ANY WARRANTY; without even 15the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16PURPOSE. 17 18See W3C License http://www.w3.org/Consortium/Legal/ for more details. 19 20 21*/ 22 23package org.w3c.domts.level2.core; 24 25import org.w3c.dom.*; 26 27 28import org.w3c.domts.DOMTestCase; 29import org.w3c.domts.DOMTestDocumentBuilderFactory; 30 31 32 33/** 34 * Testing Element.setAttributeNodeNS: If an attribute with that local name 35 * and that namespace URI is already present in the element, it is replaced 36 * by the new one. 37 * Create a new element and two new attribute nodes (in the same namespace 38 * and same localNames). 39 * Add the two new attribute nodes to the element node using the 40 * setAttributeNodeNS method. Check that only one attribute is added, check 41 * the value of this attribute. 42 * 43* @author IBM 44* @author Neil Delima 45* @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-ElSetAtNodeNS</a> 46*/ 47public final class elementsetattributenodens01 extends DOMTestCase { 48 49 /** 50 * Constructor. 51 * @param factory document factory, may not be null 52 * @throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration 53 */ 54 public elementsetattributenodens01(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException { 55 56 org.w3c.domts.DocumentBuilderSetting[] settings = 57 new org.w3c.domts.DocumentBuilderSetting[] { 58org.w3c.domts.DocumentBuilderSetting.namespaceAware 59 }; 60 DOMTestDocumentBuilderFactory testFactory = factory.newInstance(settings); 61 setFactory(testFactory); 62 63 // 64 // check if loaded documents are supported for content type 65 // 66 String contentType = getContentType(); 67 preload(contentType, "staff", true); 68 } 69 70 /** 71 * Runs the test case. 72 * @throws Throwable Any uncaught exception causes test to fail 73 */ 74 public void runTest() throws Throwable { 75 Document doc; 76 Element element; 77 Attr attribute1; 78 Attr attribute2; 79 Attr attrNode; 80 String attrName; 81 String attrNS; 82 String attrValue; 83 NamedNodeMap attributes; 84 Attr newAttribute; 85 int length; 86 doc = (Document) load("staff", true); 87 element = doc.createElementNS("http://www.w3.org/DOM/Test/Level2", "new:element"); 88 attribute1 = doc.createAttributeNS("http://www.w3.org/DOM/Test/att1", "p1:att"); 89 attribute2 = doc.createAttributeNS("http://www.w3.org/DOM/Test/att1", "p2:att"); 90 attribute2.setValue("value2"); 91 newAttribute = element.setAttributeNodeNS(attribute1); 92 newAttribute = element.setAttributeNodeNS(attribute2); 93 attrNode = element.getAttributeNodeNS("http://www.w3.org/DOM/Test/att1", "att"); 94 attrName = attrNode.getNodeName(); 95 attrNS = attrNode.getNamespaceURI(); 96 assertEquals("elementsetattributenodens01_attrName", "p2:att", attrName); 97 assertEquals("elementsetattributenodens01_attrNS", "http://www.w3.org/DOM/Test/att1", attrNS); 98 attributes = element.getAttributes(); 99 length = (int) attributes.getLength(); 100 assertEquals("length", 1, length); 101 } 102 /** 103 * Gets URI that identifies the test. 104 * @return uri identifier of test 105 */ 106 public String getTargetURI() { 107 return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/elementsetattributenodens01"; 108 } 109 /** 110 * Runs this test from the command line. 111 * @param args command line arguments 112 */ 113 public static void main(final String[] args) { 114 DOMTestCase.doMain(elementsetattributenodens01.class, args); 115 } 116} 117 118