01: /**
02: * $RCSfile$
03: * $Revision
04: * $Date: 2007-09-12 01:38:05 -0700 (Wed, 12 Sep 2007) $
05: *
06: * Copyright (C) 1999-2004 Jive Software. All rights reserved.
07: *
08: * This software is the proprietary information of Jive Software. Use is subject to license terms.
09: */package org.jivesoftware.util;
10:
11: import junit.framework.TestCase;
12:
13: import java.io.ByteArrayInputStream;
14:
15: public class XMLPropertiesTest extends TestCase {
16:
17: public void testAttributes() throws Exception {
18: String xml = "<root><foo></foo></root>";
19: XMLProperties props = new XMLProperties(
20: new ByteArrayInputStream(xml.getBytes()));
21: assertNull(props.getAttribute("foo", "bar"));
22: xml = "<root><foo bar=\"test123\"></foo></root>";
23: props = new XMLProperties(new ByteArrayInputStream(xml
24: .getBytes()));
25: assertEquals(props.getAttribute("foo", "bar"), "test123");
26: }
27:
28: public void testGetProperty() throws Exception {
29: XMLProperties props = new XMLProperties(
30: "./resources/org/jivesoftware/util/XMLProperties.test01.xml");
31: assertEquals("123", props.getProperty("foo.bar"));
32: assertEquals("456", props.getProperty("foo.bar.baz"));
33: assertNull(props.getProperty("foo"));
34: assertNull(props.getProperty("nothing.something"));
35: }
36:
37: public void testGetChildPropertiesIterator() throws Exception {
38: XMLProperties props = new XMLProperties(
39: "./resources/org/jivesoftware/util/XMLProperties.test02.xml");
40: String[] names = { "a", "b", "c", "d" };
41: String[] values = { "1", "2", "3", "4" };
42: String[] children = props.getChildrenProperties("foo.bar");
43: for (int i = 0; i < children.length; i++) {
44: String prop = children[i];
45: assertEquals(names[i], prop);
46: String value = props.getProperty("foo.bar." + prop);
47: assertEquals(values[i], value);
48: i++;
49: }
50: }
51:
52: public void testGetPropertyWithXMLEntity() throws Exception {
53: String xml = "<root><foo>foo&bar</foo></root>";
54: XMLProperties props = new XMLProperties(
55: new ByteArrayInputStream(xml.getBytes()));
56: assertEquals("foo&bar", props.getProperty("foo"));
57: }
58: }
|