KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > TestXMLPropertiesConfiguration


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration;
18
19 import junit.framework.TestCase;
20
21 /**
22  * @author Emmanuel Bourg
23  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
24  */

25 public class TestXMLPropertiesConfiguration extends TestCase
26 {
27     public void testLoad() throws Exception JavaDoc
28     {
29         XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration("test.properties.xml");
30
31         assertEquals("header", "Description of the property list", conf.getHeader());
32
33         assertFalse("The configuration is empty", conf.isEmpty());
34         assertEquals("'key1' property", "value1", conf.getProperty("key1"));
35         assertEquals("'key2' property", "value2", conf.getProperty("key2"));
36         assertEquals("'key3' property", "value3", conf.getProperty("key3"));
37     }
38
39     public void testSave() throws Exception JavaDoc
40     {
41         // load the configuration
42
XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration("test.properties.xml");
43
44         // update the configuration
45
conf.addProperty("key4", "value4");
46         conf.clearProperty("key2");
47         conf.setHeader("Description of the new property list");
48
49         // save the configuration
50
conf.save("target/test2.properties.xml");
51
52         // reload the configuration
53
XMLPropertiesConfiguration conf2 = new XMLPropertiesConfiguration("target/test2.properties.xml");
54
55         // test the configuration
56
assertEquals("header", "Description of the new property list", conf2.getHeader());
57
58         assertFalse("The configuration is empty", conf2.isEmpty());
59         assertEquals("'key1' property", "value1", conf2.getProperty("key1"));
60         assertEquals("'key3' property", "value3", conf2.getProperty("key3"));
61         assertEquals("'key4' property", "value4", conf2.getProperty("key4"));
62     }
63 }
64
Popular Tags