KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > util > XMLPropertiesTest


1 /**
2  * $RCSfile: XMLPropertiesTest.java,v $
3  * $Revision
4  * $Date: 2004/11/12 02:06:45 $
5  *
6  * Copyright (C) 1999-2004 Jive Software. All rights reserved.
7  *
8  * This software is the proprietary information of Jive Software. Use is subject to license terms.
9  */

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