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