01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: public void testLoad() throws Exception {
30: XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration(
31: "test.properties.xml");
32:
33: assertEquals("header", "Description of the property list", conf
34: .getHeader());
35:
36: assertFalse("The configuration is empty", conf.isEmpty());
37: assertEquals("'key1' property", "value1", conf
38: .getProperty("key1"));
39: assertEquals("'key2' property", "value2", conf
40: .getProperty("key2"));
41: assertEquals("'key3' property", "value3", conf
42: .getProperty("key3"));
43: }
44:
45: public void testSave() throws Exception {
46: // load the configuration
47: XMLPropertiesConfiguration conf = new XMLPropertiesConfiguration(
48: "test.properties.xml");
49:
50: // update the configuration
51: conf.addProperty("key4", "value4");
52: conf.clearProperty("key2");
53: conf.setHeader("Description of the new property list");
54:
55: // save the configuration
56: File saveFile = new File("target/test2.properties.xml");
57: if (saveFile.exists()) {
58: assertTrue(saveFile.delete());
59: }
60: conf.save(saveFile);
61:
62: // reload the configuration
63: XMLPropertiesConfiguration conf2 = new XMLPropertiesConfiguration(
64: saveFile);
65:
66: // test the configuration
67: assertEquals("header", "Description of the new property list",
68: conf2.getHeader());
69:
70: assertFalse("The configuration is empty", conf2.isEmpty());
71: assertEquals("'key1' property", "value1", conf2
72: .getProperty("key1"));
73: assertEquals("'key3' property", "value3", conf2
74: .getProperty("key3"));
75: assertEquals("'key4' property", "value4", conf2
76: .getProperty("key4"));
77: }
78: }
|