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.reloading;
19:
20: import java.io.File;
21: import java.io.FileWriter;
22:
23: import org.apache.commons.configuration.PropertiesConfiguration;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * Test case for the ManagedReloadingStrategy class.
29: *
30: * @author Nicolas De loof
31: */
32: public class TestManagedReloadingStrategy extends TestCase {
33:
34: public void testManagedRefresh() throws Exception {
35: File file = new File("target/testReload.properties");
36: if (file.exists()) {
37: file.delete();
38: }
39: // create the configuration file
40: FileWriter out = new FileWriter(file);
41: out.write("string=value1");
42: out.flush();
43: out.close();
44:
45: // load the configuration
46: PropertiesConfiguration config = new PropertiesConfiguration(
47: "target/testReload.properties");
48: ManagedReloadingStrategy strategy = new ManagedReloadingStrategy();
49: config.setReloadingStrategy(strategy);
50: assertEquals("Initial value", "value1", config
51: .getString("string"));
52:
53: // change the file
54: out = new FileWriter(file);
55: out.write("string=value2");
56: out.flush();
57: out.close();
58:
59: // test the automatic reloading
60: assertEquals("No automatic reloading", "value1", config
61: .getString("string"));
62: strategy.refresh();
63: assertEquals("Modified value with enabled reloading", "value2",
64: config.getString("string"));
65: }
66:
67: }
|