1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import java.io.File;
20
21 import junit.framework.TestCase;
22
23 /***
24 * @author Emmanuel Bourg
25 * @version $Revision$, $Date: 2005-07-20 20:33:14 +0200 (Wed, 20 Jul 2005) $
26 */
27 public class TestXMLPropertiesConfiguration extends TestCase
28 {
29 public void testLoad() throws Exception
30 {
31 XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration("test.properties.xml");
32
33 assertEquals("header", "Description of the property list", conf.getHeader());
34
35 assertFalse("The configuration is empty", conf.isEmpty());
36 assertEquals("'key1' property", "value1", conf.getProperty("key1"));
37 assertEquals("'key2' property", "value2", conf.getProperty("key2"));
38 assertEquals("'key3' property", "value3", conf.getProperty("key3"));
39 }
40
41 public void testSave() throws Exception
42 {
43
44 XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration("test.properties.xml");
45
46
47 conf.addProperty("key4", "value4");
48 conf.clearProperty("key2");
49 conf.setHeader("Description of the new property list");
50
51
52 File saveFile = new File("target/test2.properties.xml");
53 if (saveFile.exists())
54 {
55 assertTrue(saveFile.delete());
56 }
57 conf.save(saveFile);
58
59
60 XMLPropertiesConfiguration conf2 = new XMLPropertiesConfiguration(saveFile);
61
62
63 assertEquals("header", "Description of the new property list", conf2.getHeader());
64
65 assertFalse("The configuration is empty", conf2.isEmpty());
66 assertEquals("'key1' property", "value1", conf2.getProperty("key1"));
67 assertEquals("'key3' property", "value3", conf2.getProperty("key3"));
68 assertEquals("'key4' property", "value4", conf2.getProperty("key4"));
69 }
70 }