1 10 11 package org.jivesoftware.util; 12 13 import junit.framework.TestCase; 14 15 import java.io.ByteArrayInputStream ; 16 import java.util.Iterator ; 17 18 public class XMLPropertiesTest extends TestCase { 19 20 public void testAttributes() throws Exception { 21 String xml = "<root><foo></foo></root>"; 22 XMLProperties props = new XMLProperties(new ByteArrayInputStream (xml.getBytes())); 23 assertNull(props.getAttribute("foo","bar")); 24 xml = "<root><foo bar=\"test123\"></foo></root>"; 25 props = new XMLProperties(new ByteArrayInputStream (xml.getBytes())); 26 assertEquals(props.getAttribute("foo","bar"), "test123"); 27 } 28 29 public void testGetProperty() throws Exception { 30 XMLProperties props = new XMLProperties( 31 "./resources/org/jivesoftware/util/XMLProperties.test01.xml"); 32 assertEquals("123", props.getProperty("foo.bar")); 33 assertEquals("456", props.getProperty("foo.bar.baz")); 34 assertNull(props.getProperty("foo")); 35 assertNull(props.getProperty("nothing.something")); 36 } 37 38 public void testGetChildPropertiesIterator() throws Exception { 39 XMLProperties props = new XMLProperties( 40 "./resources/org/jivesoftware/util/XMLProperties.test02.xml"); 41 String [] names = {"a","b","c","d"}; 42 String [] values = {"1","2","3","4"}; 43 String [] children = props.getChildrenProperties("foo.bar"); 44 for (int i=0; i<children.length; i++) { 45 String prop = children[i]; 46 assertEquals(names[i], prop); 47 String value = props.getProperty("foo.bar." + prop); 48 assertEquals(values[i], value); 49 i++; 50 } 51 } 52 } 53 | Popular Tags |