ElementRemoveAttributeNS.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1package tests.org.w3c.dom; 2 3import dalvik.annotation.TestInfo; 4import dalvik.annotation.TestLevel; 5import dalvik.annotation.TestTarget; 6import dalvik.annotation.TestTargetClass; 7 8import org.w3c.dom.Element; 9import org.w3c.dom.Attr; 10import org.w3c.dom.Document; 11 12import javax.xml.parsers.DocumentBuilder; 13 14/** 15 * The method removeAttributeNS removes an attribute by local name and namespace 16 * URI. Create a new element and add a new attribute node to it. Remove the 17 * attribute node using the removeAttributeNodeNS method. Check if the attribute 18 * was remove by invoking the hasAttributeNS method on the element and check if 19 * it returns false. 20 * 21 * @author IBM 22 * @author Neil Delima 23 * @see <a 24 * 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> 25 */ 26@TestTargetClass(Element.class) 27public final class ElementRemoveAttributeNS extends DOMTestCase { 28 29 DOMDocumentBuilderFactory factory; 30 31 DocumentBuilder builder; 32 33 protected void setUp() throws Exception { 34 super.setUp(); 35 try { 36 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 37 .getConfiguration1()); 38 builder = factory.getBuilder(); 39 } catch (Exception e) { 40 fail("Unexpected exception" + e.getMessage()); 41 } 42 } 43 44 protected void tearDown() throws Exception { 45 factory = null; 46 builder = null; 47 super.tearDown(); 48 } 49 50 /** 51 * Runs the test case. 52 * 53 * @throws Throwable 54 * Any uncaught exception causes test to fail 55 */ 56 @TestInfo( 57 level = TestLevel.PARTIAL, 58 purpose = "Doesn't verify DOMException.", 59 targets = { 60 @TestTarget( 61 methodName = "removeAttributeNS", 62 methodArgs = {java.lang.String.class, java.lang.String.class} 63 ) 64 }) 65 public void testRemoveAttributeNS() throws Throwable { 66 Document doc; 67 Element element; 68 boolean state; 69 Attr attribute; 70 71 doc = (Document) load("staff", builder); 72 element = doc.createElementNS("http://www.w3.org/DOM", "elem"); 73 attribute = doc.createAttributeNS( 74 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 75 element.setAttributeNodeNS(attribute); 76 element.removeAttributeNS( 77 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 78 state = element.hasAttributeNS( 79 "http://www.w3.org/DOM/Test/createAttributeNS", "attr"); 80 assertFalse("elementremoveattributens01", state); 81 } 82 83} 84