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 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 tests.org.w3c.dom; 24 25 import dalvik.annotation.TestTargets; 26 import dalvik.annotation.TestLevel; 27 import dalvik.annotation.TestTargetNew; 28 import dalvik.annotation.TestTargetClass; 29 30 import org.w3c.dom.Element; 31 import org.w3c.dom.Document; 32 import org.w3c.dom.Node; 33 import org.w3c.dom.NodeList; 34 import org.w3c.dom.CharacterData; 35 36 import javax.xml.parsers.DocumentBuilder; 37 38 /** 39 * The "normalize()" method puts all the nodes in the full 40 * depth of the sub-tree underneath this element into a 41 * "normal" form. 42 * 43 * Retrieve the third employee and access its second child. 44 * This child contains a block of text that is spread 45 * across multiple lines. The content of the "name" child 46 * should be parsed and treated as a single Text node. 47 * This appears to be a duplicate of elementnormalize.xml in DOM L1 Test Suite 48 * @author NIST 49 * @author Mary Brady 50 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-normalize">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-normalize</a> 51 * @see <a href="http://www.w3.org/TR/DOM-Level-2-Core/core#ID-72AB8359">http://www.w3.org/TR/DOM-Level-2-Core/core#ID-72AB8359</a> 52 */ 53 @TestTargetClass(Element.class) 54 public final class Normalize extends DOMTestCase { 55 56 DOMDocumentBuilderFactory factory; 57 58 DocumentBuilder builder; 59 60 protected void setUp() throws Exception { 61 super.setUp(); 62 try { 63 factory = new DOMDocumentBuilderFactory(DOMDocumentBuilderFactory 64 .getConfiguration1()); 65 builder = factory.getBuilder(); 66 } catch (Exception e) { 67 fail("Unexpected exception" + e.getMessage()); 68 } 69 } 70 71 protected void tearDown() throws Exception { 72 factory = null; 73 builder = null; 74 super.tearDown(); 75 } 76 /** 77 * Runs the test case. 78 * @throws Throwable Any uncaught exception causes test to fail 79 */ 80 @TestTargetNew( 81 level = TestLevel.COMPLETE, 82 notes = "", 83 method = "normalize", 84 args = {} 85 ) 86 public void testNormalize() throws Throwable { 87 Document doc; 88 Element root; 89 NodeList elementList; 90 Node firstChild; 91 NodeList textList; 92 CharacterData textNode; 93 String data; 94 doc = (Document) load("staff", builder); 95 root = doc.getDocumentElement(); 96 root.normalize(); 97 elementList = root.getElementsByTagName("name"); 98 firstChild = elementList.item(2); 99 textList = firstChild.getChildNodes(); 100 textNode = (CharacterData) textList.item(0); 101 data = textNode.getData(); 102 assertEquals("data", "Roger\n Jones", data); 103 } 104 105 } 106 107