1 16 17 package org.apache.commons.configuration; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.dom4j.Attribute; 23 import org.dom4j.Document; 24 import org.dom4j.Element; 25 import org.dom4j.io.SAXReader; 26 27 import junit.framework.TestCase; 28 29 34 public class TestHierarchicalConfigurationXMLReader extends TestCase 35 { 36 private static final String TEST_FILE = "conf/testHierarchicalXMLConfiguration.xml"; 37 38 private HierarchicalConfigurationXMLReader parser; 39 40 protected void setUp() throws Exception 41 { 42 XMLConfiguration config = 43 new XMLConfiguration(); 44 config.setFileName(TEST_FILE); 45 config.load(); 46 parser = new HierarchicalConfigurationXMLReader(config); 47 } 48 49 public void testParse() throws Exception 50 { 51 SAXReader reader = new SAXReader(parser); 52 Document document = reader.read("someSysID"); 53 54 Element root = document.getRootElement(); 55 assertEquals("config", root.getName()); 56 assertEquals(1, root.elements().size()); 57 Iterator itRoot = root.elementIterator(); 58 Element elemTabs = (Element) itRoot.next(); 59 60 assertEquals(2, elemTabs.elements().size()); 61 List tables = elemTabs.elements(); 62 Element tabUsr = (Element) tables.get(0); 63 assertEquals("table", tabUsr.getName()); 64 Element elemName = tabUsr.element("name"); 65 assertNotNull(elemName); 66 assertEquals("users", elemName.getTextTrim()); 67 Element elemFields = tabUsr.element("fields"); 68 assertNotNull(elemFields); 69 assertEquals(5, elemFields.elements().size()); 70 71 List attribs = tabUsr.attributes(); 72 assertEquals(1, attribs.size()); 73 Attribute attr = (Attribute) attribs.get(0); 74 assertEquals("tableType", attr.getName()); 75 assertEquals("system", attr.getValue()); 76 } 77 } 78 | Popular Tags |